feat: iTunes redirect
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
from urllib.request import urlopen
|
||||
from base64 import b64decode
|
||||
import socket
|
||||
import json
|
||||
@@ -24,20 +25,38 @@ def generatePlist(data: dict) -> str:
|
||||
|
||||
|
||||
class PlistServer(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
try:
|
||||
b64 = self.path.split('?d=')[-1] + '=='
|
||||
data = json.loads(b64decode(b64)) # type: dict
|
||||
rv = generatePlist(data)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
rv = ''
|
||||
def makeHeader(self, contentType):
|
||||
self.send_response(200)
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
if rv:
|
||||
self.send_header('Content-type', 'application/xml')
|
||||
if contentType:
|
||||
self.send_header('Content-type', contentType)
|
||||
self.end_headers()
|
||||
self.wfile.write(bytes(rv, 'utf-8') if rv else b'Parsing error')
|
||||
|
||||
def do_GET(self):
|
||||
try:
|
||||
action, value = self.path.split('?', 1)[-1].split('=', 1)
|
||||
if action == 'r':
|
||||
# http.client.HTTPResponse
|
||||
with urlopen(value) as response:
|
||||
mimeType = response.headers.get('Content-Type')
|
||||
self.makeHeader(mimeType)
|
||||
|
||||
while True:
|
||||
tmp = response.read(8096)
|
||||
if not tmp:
|
||||
break
|
||||
self.wfile.write(tmp)
|
||||
|
||||
elif action == 'd':
|
||||
data = json.loads(b64decode(value + '==')) # type: dict
|
||||
rv = bytes(generatePlist(data), 'utf-8')
|
||||
self.makeHeader('application/xml')
|
||||
self.wfile.write(rv)
|
||||
|
||||
else:
|
||||
return
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
def getLocalIp():
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
<?php
|
||||
$X = json_decode(base64_decode($_GET['d']));
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
if ($X->u) {
|
||||
header('Content-Type: application/xml');
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>
|
||||
if ($_GET['r']) {
|
||||
echo stream_get_contents(fopen($_GET['r'], "rb"));
|
||||
} elseif ($_GET['d']) {
|
||||
$X = json_decode(base64_decode($_GET['d']));
|
||||
if ($X->u) {
|
||||
header('Content-Type: application/xml');
|
||||
echo '<?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>items</key><array><dict><key>assets</key><array><dict>
|
||||
<key>kind</key><string>software-package</string>
|
||||
@@ -18,7 +21,10 @@ if ($X->u) {
|
||||
<key>kind</key><string>software</string>
|
||||
<key>title</key><string>'.$X->n.'</string>
|
||||
</dict></dict></array></dict></plist>';
|
||||
} else {
|
||||
echo 'Parsing error.';
|
||||
}
|
||||
} else {
|
||||
echo 'Parsing error.';
|
||||
echo 'Error.';
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user