Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from flask import Flask, request, send_file,
|
| 2 |
from flask_cors import CORS
|
| 3 |
import subprocess
|
| 4 |
import os
|
|
@@ -8,7 +8,7 @@ import re
|
|
| 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('/')
|
|
@@ -17,67 +17,72 @@ def home():
|
|
| 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 |
-
os.chmod(job_id, 0o777) # Ensure the folder is writable for signing
|
| 23 |
|
|
|
|
| 24 |
ipa = request.files['ipa']
|
| 25 |
p12 = request.files['p12']
|
| 26 |
prov = request.files['provision']
|
| 27 |
password = request.form.get('password', '1234')
|
| 28 |
|
|
|
|
| 29 |
ipa_path = os.path.join(job_id, "app.ipa")
|
| 30 |
p12_path = os.path.join(job_id, "cert.p12")
|
| 31 |
prov_path = os.path.join(job_id, "prov.mobileprovision")
|
| 32 |
out_path = os.path.join(job_id, "signed.ipa")
|
| 33 |
|
|
|
|
| 34 |
ipa.save(ipa_path)
|
| 35 |
p12.save(p12_path)
|
| 36 |
prov.save(prov_path)
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
try:
|
| 42 |
-
#
|
| 43 |
-
result = subprocess.run(command,
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
# Save the
|
| 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 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
<body style="display:flex; flex-direction:column; align-items:center; justify-content:center; height:100vh; font-family:-apple-system, sans-serif; background-color:#f2f2f7;">
|
| 63 |
-
<div style="background:white; padding:30px; border-radius:20px; box-shadow:0 10px 25px rgba(0,0,0,0.1); text-align:center;">
|
| 64 |
-
<h2 style="color:#1c1c1e; margin-bottom:10px;">Ready to Install</h2>
|
| 65 |
-
<p style="color:#8e8e93; margin-bottom:25px;">Bundle ID: <b>{bundle_id}</b></p>
|
| 66 |
-
<a href="itms-services://?action=download-manifest&url={plist_url}"
|
| 67 |
-
style="background:#007AFF; color:white; padding:15px 40px; text-decoration:none; border-radius:12px; font-weight:600; display:inline-block;">
|
| 68 |
-
Install App
|
| 69 |
-
</a>
|
| 70 |
-
</div>
|
| 71 |
-
<p style="margin-top:20px; color:#8e8e93; font-size:12px;">Make sure you are using Safari on iOS.</p>
|
| 72 |
-
</body>
|
| 73 |
-
</html>
|
| 74 |
-
'''
|
| 75 |
-
|
| 76 |
except Exception as e:
|
| 77 |
return f"System Error: {str(e)}", 500
|
| 78 |
|
| 79 |
@app.route('/plist/<job_id>')
|
| 80 |
def serve_plist(job_id):
|
|
|
|
| 81 |
try:
|
| 82 |
with open(os.path.join(job_id, "bundle_id.txt"), "r") as f:
|
| 83 |
bundle_id = f.read().strip()
|
|
@@ -86,6 +91,7 @@ def serve_plist(job_id):
|
|
| 86 |
|
| 87 |
ipa_direct_url = f"{BASE_URL}/download/{job_id}"
|
| 88 |
|
|
|
|
| 89 |
plist_content = f"""<?xml version="1.0" encoding="UTF-8"?>
|
| 90 |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
| 91 |
<plist version="1.0">
|
|
@@ -118,12 +124,15 @@ def serve_plist(job_id):
|
|
| 118 |
</dict>
|
| 119 |
</plist>"""
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
@app.route('/download/<job_id>')
|
| 125 |
def download_ipa(job_id):
|
| 126 |
-
#
|
| 127 |
return send_file(
|
| 128 |
os.path.join(job_id, "signed.ipa"),
|
| 129 |
mimetype='application/octet-stream',
|
|
|
|
| 1 |
+
from flask import Flask, request, send_file, redirect
|
| 2 |
from flask_cors import CORS
|
| 3 |
import subprocess
|
| 4 |
import os
|
|
|
|
| 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('/')
|
|
|
|
| 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
|
| 42 |
+
# -z 0: No compression for instant speed on MacBook Air/HF
|
| 43 |
+
command = [
|
| 44 |
+
"zsign",
|
| 45 |
+
"-k", p12_path,
|
| 46 |
+
"-p", password,
|
| 47 |
+
"-m", prov_path,
|
| 48 |
+
"-o", out_path,
|
| 49 |
+
"-z", "0",
|
| 50 |
+
ipa_path
|
| 51 |
+
]
|
| 52 |
|
| 53 |
try:
|
| 54 |
+
# We capture both stdout and stderr because zsign logs vary
|
| 55 |
+
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
| 56 |
+
combined_output = result.stdout + result.stderr
|
| 57 |
|
| 58 |
+
# 6. Improved Regex to prevent the "com.simplebit.dynamic" mismatch in image.png
|
| 59 |
+
match = re.search(r"Bundle\s?Id:\s+([a-zA-Z0-9\.-]+)", combined_output, re.IGNORECASE)
|
| 60 |
+
|
| 61 |
+
if match:
|
| 62 |
+
bundle_id = match.group(1).strip()
|
| 63 |
+
else:
|
| 64 |
+
# Fallback search for any string matching a standard reverse-DNS bundle ID
|
| 65 |
+
fallback_match = re.search(r"([a-zA-Z]{2,}\.[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+)", combined_output)
|
| 66 |
+
bundle_id = fallback_match.group(1) if fallback_match else "com.simplebit.dynamic"
|
| 67 |
|
| 68 |
+
# Save the confirmed ID to ensure the /plist route uses the right one
|
| 69 |
with open(os.path.join(job_id, "bundle_id.txt"), "w") as f:
|
| 70 |
f.write(bundle_id)
|
| 71 |
|
| 72 |
+
# 7. Redirect to the itms-services protocol for iOS installation
|
| 73 |
plist_url = f"{BASE_URL}/plist/{job_id}"
|
| 74 |
+
return redirect(f"itms-services://?action=download-manifest&url={plist_url}")
|
| 75 |
|
| 76 |
+
except subprocess.CalledProcessError as e:
|
| 77 |
+
# Captures specific zsign errors (like wrong password) for debugging
|
| 78 |
+
error_logs = e.stderr if e.stderr else e.stdout
|
| 79 |
+
return f"Signing failed. Zsign output: {error_logs}", 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
except Exception as e:
|
| 81 |
return f"System Error: {str(e)}", 500
|
| 82 |
|
| 83 |
@app.route('/plist/<job_id>')
|
| 84 |
def serve_plist(job_id):
|
| 85 |
+
# Retrieve the dynamic bundle ID extracted during the sign phase
|
| 86 |
try:
|
| 87 |
with open(os.path.join(job_id, "bundle_id.txt"), "r") as f:
|
| 88 |
bundle_id = f.read().strip()
|
|
|
|
| 91 |
|
| 92 |
ipa_direct_url = f"{BASE_URL}/download/{job_id}"
|
| 93 |
|
| 94 |
+
# Manifest required by iOS to install apps over-the-air
|
| 95 |
plist_content = f"""<?xml version="1.0" encoding="UTF-8"?>
|
| 96 |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
| 97 |
<plist version="1.0">
|
|
|
|
| 124 |
</dict>
|
| 125 |
</plist>"""
|
| 126 |
|
| 127 |
+
plist_path = os.path.join(job_id, "manifest.plist")
|
| 128 |
+
with open(plist_path, "w") as f:
|
| 129 |
+
f.write(plist_content)
|
| 130 |
+
|
| 131 |
+
return send_file(plist_path, mimetype='text/xml')
|
| 132 |
|
| 133 |
@app.route('/download/<job_id>')
|
| 134 |
def download_ipa(job_id):
|
| 135 |
+
# Sends the final binary to the iPhone
|
| 136 |
return send_file(
|
| 137 |
os.path.join(job_id, "signed.ipa"),
|
| 138 |
mimetype='application/octet-stream',
|