1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Pythonista]iPhone単体でAPN構成プロファイル作るやつ作った

Last updated at Posted at 2019-12-02

つくった

世の中にはAPNを頻繁に変える人もいるらしい
深夜に1時間半ぐらいで作った
なのでちゃんと動くか分からない

こんな感じ

コード

なるべく単一のコードで済むようにしたのでいろいろアレ
適当に作ったのでいろいろアレ

apn.py

# -*- coding: utf-8 -*-
import ui
import time
import base64
import console
import clipboard
import webbrowser
from http.server import HTTPServer, CGIHTTPRequestHandler

class Handler(CGIHTTPRequestHandler):
    cgi_directories = ["./"]

class apnui(ui.View):

    def __init__(self):
        self.main_view = ui.View(frame=(0, 0, ui.get_screen_size()[
                            0], ui.get_screen_size()[1]))
        self.main_view.name = 'APN Settings'
        self.main_view.background_color = 'white'
        space = 45

        self.nameui = ui.TextField(frame=(self.main_view.width*0.2, space, self.main_view.width*0.8, 30))
        self.nameui.alignment = ui.ALIGN_RIGHT
        self.main_view.add_subview(self.nameui)

        name_t = ui.TextView(frame=(0, space, self.main_view.width*0.2, 30))
        name_t.alignment = ui.ALIGN_LEFT
        name_t.text = 'Name'
        self.main_view.add_subview(name_t)

        self.passwd = ui.TextField(
            frame=(self.main_view.width*0.2, space*2, self.main_view.width*0.8, 30))
        self.passwd.alignment = ui.ALIGN_RIGHT
        self.main_view.add_subview(self.passwd)

        passwd_t = ui.TextView(frame=(0, space*2, self.main_view.width*0.2, 30))
        passwd_t.alignment = ui.ALIGN_LEFT
        passwd_t.text = 'Password'
        self.main_view.add_subview(passwd_t)

        self.uname = ui.TextField(
            frame=(self.main_view.width*0.2, space*3, self.main_view.width*0.8, 30))
        self.uname.alignment = ui.ALIGN_RIGHT
        self.uname.text = ''
        self.main_view.add_subview(self.uname)

        uname_t = ui.TextView(frame=(0, space*3, self.main_view.width*0.2, 30))
        uname_t.alignment = ui.ALIGN_LEFT
        uname_t.text = 'UserName'
        self.main_view.add_subview(uname_t)

        self.button = ui.Button()
        self.button.frame = (self.main_view.width*0.1, space*5, self.main_view.width*0.8, 30)
        self.button.title = 'Complete'
        self.button.action = self.button_tapped
        self.button.background_color = (0, 0, 0, 0.5)
        self.button.tint_color = ('white')
        self.main_view.add_subview(self.button)

        self.main_view.present('sheet')

    def button_tapped(self, sender):
        apnbase = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict>	<key>ConsentText</key>	<dict>		<key>default</key>		<string>ASEINet APN Configuration profile</string>	</dict>	<key>PayloadContent</key>	<array>		<dict>			<key>AttachAPN</key>			<dict>				<key>Name</key>				<string>{0}</string>				<key>AuthenticationType</key>				<string>CHAP</string>				<key>Username</key>				<string>{1}</string>				<key>Password</key>				<string>{2}</string>			</dict>			<key>APNs</key>			<array>				<dict>					<key>Name</key>					<string>{0}</string>					<key>AuthenticationType</key>					<string>CHAP</string>					<key>Username</key>					<string>{1}</string>					<key>Password</key>					<string>{2}</string>				</dict>			</array>			<key>PayloadDisplayName</key>			<string></string>			<key>PayloadIdentifier</key>			<string>com.aseinet.cellular</string>			<key>PayloadOrganization</key>			<string>ASEINet.NE.JP</string>			<key>PayloadType</key>			<string>com.apple.cellular</string>			<key>PayloadUUID</key>			<string>6B08253E-D5BB-4FC4-A5CD-825FB965B5AA</string>			<key>PayloadVersion</key>			<integer>1</integer>		</dict>	</array>	<key>PayloadDisplayName</key>	<string>ASEINet APN Profile (Ver. 1.2)</string>	<key>PayloadDescription</key>	<string>Apply APN-setting to your iOS device.</string>	<key>PayloadIdentifier</key>	<string>com.aseinet</string>	<key>PayloadOrganization</key>	<string>ASEINet.NE.JP</string>	<key>PayloadRemovalDisallowed</key>	<false/>	<key>PayloadType</key>	<string>Configuration</string>	<key>PayloadUUID</key>	<string>560EB0FF-BE89-46C7-8DC9-6CA77E1A4453</string>	<key>PayloadVersion</key>	<integer>1</integer></dict></plist>'.format(self.nameui.text,self.uname.text,self.passwd.text)
        path_w = './apn.mobileconfig'
        apnbase = apnbase.replace('           ','')
        with open(path_w, mode='w') as f:
            f.write(apnbase)
            
        console.alert('WebServer Start','Copied url to clipboard','OK',hide_cancel_button=True)
        self.button.title = 'Running Server...'
        time.sleep(1)
        clipboard.set('http://localhost:8080')
        #console.alert('Running server...')
        PORT = 8080
        httpd = HTTPServer(("", PORT), Handler)
        httpd.serve_forever()

v = apnui()

おわりに

需要あんのか?これ
Pythonistaが落ちるのはご愛嬌

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?