gabefromsimplebit commited on
Commit
b7a588e
·
verified ·
1 Parent(s): cbd2792

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +15 -39
app.py CHANGED
@@ -4,76 +4,63 @@ import subprocess
4
  import os
5
  import uuid
6
  import re
 
7
 
8
  app = Flask(__name__)
9
  CORS(app)
10
 
11
- # Base URL for your Hugging Face Space
12
  BASE_URL = "https://gabefromsimplebit-simplebit-signer.hf.space"
13
 
14
  @app.route('/')
15
  def home():
16
- return "SimpleBit Engine is Online!"
17
 
18
  @app.route('/sign', methods=['POST'])
19
  def sign():
20
- # 1. Create a unique folder for this signing job
21
  job_id = str(uuid.uuid4())[:8]
22
  os.makedirs(job_id, exist_ok=True)
23
 
24
- # 2. Get files from the form
25
  ipa = request.files['ipa']
26
  p12 = request.files['p12']
27
  prov = request.files['provision']
28
  password = request.form.get('password', '1234')
29
 
30
- # 3. Define paths
31
  ipa_path = os.path.join(job_id, "app.ipa")
32
  p12_path = os.path.join(job_id, "cert.p12")
33
  prov_path = os.path.join(job_id, "prov.mobileprovision")
34
  out_path = os.path.join(job_id, "signed.ipa")
35
 
36
- # 4. Save uploaded files
37
  ipa.save(ipa_path)
38
  p12.save(p12_path)
39
  prov.save(prov_path)
40
 
41
- # 5. Run zsign command with optimizations
42
- # -z 0: No compression (Fastest)
43
- # -e: Inject entitlements (Fixes "Unable to Install")
44
- command = [
45
- "zsign",
46
- "-k", p12_path,
47
- "-p", password,
48
- "-m", prov_path,
49
- "-o", out_path,
50
- "-z", "0",
51
- "-c",
52
- ipa_path
53
- ]
54
 
55
  try:
56
- # Run zsign and capture output to extract the real Bundle ID
57
- result = subprocess.run(command, capture_output=True, text=True, check=True)
58
 
59
- # Regex to find the real Bundle ID in zsign's logs
 
 
 
 
60
  match = re.search(r"Bundle Id:\s+([\w\.-]+)", result.stdout)
61
  bundle_id = match.group(1) if match else "com.simplebit.dynamic"
62
 
63
- # Save the Bundle ID to a file so the /plist route can find it
64
  with open(os.path.join(job_id, "bundle_id.txt"), "w") as f:
65
  f.write(bundle_id)
66
 
67
- # 6. Redirect to the itms-services protocol
68
  plist_url = f"{BASE_URL}/plist/{job_id}"
69
  return redirect(f"itms-services://?action=download-manifest&url={plist_url}")
70
 
71
  except Exception as e:
72
- return f"Signing failed: {str(e)}", 500
73
 
74
  @app.route('/plist/<job_id>')
75
  def serve_plist(job_id):
76
- # Read the dynamic bundle ID we extracted during signing
77
  try:
78
  with open(os.path.join(job_id, "bundle_id.txt"), "r") as f:
79
  bundle_id = f.read().strip()
@@ -82,7 +69,6 @@ def serve_plist(job_id):
82
 
83
  ipa_direct_url = f"{BASE_URL}/download/{job_id}"
84
 
85
- # Manifest required by iOS to install apps over-the-air
86
  plist_content = f"""<?xml version="1.0" encoding="UTF-8"?>
87
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
88
  <plist version="1.0">
@@ -115,21 +101,11 @@ def serve_plist(job_id):
115
  </dict>
116
  </plist>"""
117
 
118
- plist_path = os.path.join(job_id, "manifest.plist")
119
- with open(plist_path, "w") as f:
120
- f.write(plist_content)
121
-
122
- return send_file(plist_path, mimetype='text/xml')
123
 
124
  @app.route('/download/<job_id>')
125
  def download_ipa(job_id):
126
- # Direct link for iOS to grab the signed IPA
127
- return send_file(
128
- os.path.join(job_id, "signed.ipa"),
129
- mimetype='application/octet-stream',
130
- as_attachment=True
131
- )
132
 
133
  if __name__ == "__main__":
134
- # Standard port for Hugging Face Spaces
135
  app.run(host="0.0.0.0", port=7860)
 
4
  import os
5
  import uuid
6
  import re
7
+ import shutil
8
 
9
  app = Flask(__name__)
10
  CORS(app)
11
 
 
12
  BASE_URL = "https://gabefromsimplebit-simplebit-signer.hf.space"
13
 
14
  @app.route('/')
15
  def home():
16
+ return "SimpleBit Engine is Online and Ready!"
17
 
18
  @app.route('/sign', methods=['POST'])
19
  def sign():
 
20
  job_id = str(uuid.uuid4())[:8]
21
  os.makedirs(job_id, exist_ok=True)
22
 
 
23
  ipa = request.files['ipa']
24
  p12 = request.files['p12']
25
  prov = request.files['provision']
26
  password = request.form.get('password', '1234')
27
 
 
28
  ipa_path = os.path.join(job_id, "app.ipa")
29
  p12_path = os.path.join(job_id, "cert.p12")
30
  prov_path = os.path.join(job_id, "prov.mobileprovision")
31
  out_path = os.path.join(job_id, "signed.ipa")
32
 
 
33
  ipa.save(ipa_path)
34
  p12.save(p12_path)
35
  prov.save(prov_path)
36
 
37
+ # Use shell=True and quotes around the password to handle special characters
38
+ # This is the most compatible way to run zsign on Linux
39
+ command = f"zsign -k '{p12_path}' -p '{password}' -m '{prov_path}' -o '{out_path}' -z 0 '{ipa_path}'"
 
 
 
 
 
 
 
 
 
 
40
 
41
  try:
42
+ # We capture everything to see the REAL error
43
+ result = subprocess.run(command, shell=True, capture_output=True, text=True)
44
 
45
+ if result.returncode != 0:
46
+ # If it fails, we show you the exact console output from zsign
47
+ return f"Zsign Error (Code {result.returncode}): {result.stdout} {result.stderr}", 500
48
+
49
+ # Success! Now get the Bundle ID
50
  match = re.search(r"Bundle Id:\s+([\w\.-]+)", result.stdout)
51
  bundle_id = match.group(1) if match else "com.simplebit.dynamic"
52
 
 
53
  with open(os.path.join(job_id, "bundle_id.txt"), "w") as f:
54
  f.write(bundle_id)
55
 
 
56
  plist_url = f"{BASE_URL}/plist/{job_id}"
57
  return redirect(f"itms-services://?action=download-manifest&url={plist_url}")
58
 
59
  except Exception as e:
60
+ return f"System Error: {str(e)}", 500
61
 
62
  @app.route('/plist/<job_id>')
63
  def serve_plist(job_id):
 
64
  try:
65
  with open(os.path.join(job_id, "bundle_id.txt"), "r") as f:
66
  bundle_id = f.read().strip()
 
69
 
70
  ipa_direct_url = f"{BASE_URL}/download/{job_id}"
71
 
 
72
  plist_content = f"""<?xml version="1.0" encoding="UTF-8"?>
73
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
74
  <plist version="1.0">
 
101
  </dict>
102
  </plist>"""
103
 
104
+ return send_file(os.path.join(job_id, "manifest.plist"), mimetype='text/xml')
 
 
 
 
105
 
106
  @app.route('/download/<job_id>')
107
  def download_ipa(job_id):
108
+ return send_file(os.path.join(job_id, "signed.ipa"), mimetype='application/octet-stream')
 
 
 
 
 
109
 
110
  if __name__ == "__main__":
 
111
  app.run(host="0.0.0.0", port=7860)