mainPalio4.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. import time
  2. from flask import Flask, request
  3. import requests
  4. from PIL import ImageFile, Image
  5. import os
  6. import shutil
  7. import subprocess
  8. from zipfile import ZipFile
  9. ImageFile.SAFEBLOCK = 2048 * 2048
  10. app = Flask(__name__)
  11. app.base_project = "/apps/3ps/build_apk/PalioLite"
  12. # app.base_project = "/Users/easysoft/Documents/PalioLite"
  13. app.temp_folder = "/apps/3ps/build_apk/BuildApk"
  14. # app.temp_folder = "/Users/easysoft/BuildApk"
  15. app.apk_folder = "/var/www/html/palio.io/dashboardv2/uploads"
  16. # app.apk_folder = "/Users/easysoft/"
  17. app.verbose = True
  18. app.ssl = (
  19. '/etc/ssl/star.newuniverse.io/star.newuniverse.io.crt', '/etc/ssl/star.newuniverse.io/STAR_newuniverse_io.key')
  20. # app.ssl =('/etc/ssl/STAR_palio_io/STAR_palio_io.crt', '/etc/ssl/STAR_palio_io/STAR_palio_io.pem')
  21. # app.ssl = None
  22. app.keytool = '/usr/bin/keytool'
  23. app.base_project_name = os.path.basename(app.base_project)
  24. def vprint(*data):
  25. if app.verbose:
  26. print(*data)
  27. def create_folder(package_id):
  28. path = os.path.join(app.temp_folder, package_id)
  29. if not os.path.exists(path):
  30. os.mkdir(path)
  31. else:
  32. shutil.rmtree(path)
  33. os.mkdir(path)
  34. vprint(path)
  35. path_dest = os.path.join(path, app.base_project_name)
  36. if not os.path.exists(path_dest):
  37. shutil.copytree(app.base_project, path_dest)
  38. code_path = "app/src/main/java/"
  39. orig_code = "com/example/qmeralitesamplecode"
  40. path_package_id = package_id.replace(".", "/")
  41. c_code_path = os.path.join(path_dest, code_path, path_package_id)
  42. orig_code_path = os.path.join(path_dest, code_path, orig_code)
  43. if not os.path.exists(c_code_path):
  44. shutil.copytree(orig_code_path, c_code_path)
  45. shutil.rmtree(orig_code_path)
  46. return path_dest, c_code_path
  47. def change_acc(c_code_path, acc, enable_sms):
  48. main_activity = os.path.join(c_code_path, "MAB.java")
  49. with open(main_activity, "r") as f:
  50. file_source = f.read()
  51. replaced = file_source.replace("***REPLACE***WITH***YOUR***QMERA***ACCOUNT***", acc)
  52. if enable_sms == 1:
  53. replaced = replaced.replace("isEnabledSMS = false", "isEnabledSMS = true")
  54. with open(main_activity, "w") as f:
  55. f.write(replaced)
  56. def change_url(c_code_path, url):
  57. main_activity = os.path.join(c_code_path, "MAB.java")
  58. with open(main_activity, "r") as f:
  59. file_source = f.read()
  60. replaced = file_source.replace("https://www.google.com", url)
  61. with open(main_activity, "w") as f:
  62. f.write(replaced)
  63. def change_name(path_dest, name, enable_sms):
  64. manifest = os.path.join(path_dest, "app/src/main/AndroidManifest.xml")
  65. string_res = os.path.join(path_dest, "app/src/main/res/values/strings.xml")
  66. with open(manifest, "r") as f:
  67. lines = f.readlines()
  68. # file_source = f.read()
  69. with open(manifest, "w") as f:
  70. for line in lines:
  71. if "NexilisLite" in line:
  72. line = line.replace("NexilisLite", name)
  73. if enable_sms == 0:
  74. if "SMS" not in line:
  75. f.write(line)
  76. else:
  77. f.write(line)
  78. with open(string_res, "r") as f:
  79. file_source = f.read()
  80. replaced = file_source.replace("Nexilis Sport", name)
  81. with open(string_res, "w") as f:
  82. f.write(replaced)
  83. def change_font(path_dest, font, package):
  84. if font == 1:
  85. path_package_id = package.replace(".", "/")
  86. code_path = "app/src/main/java/"
  87. code_path = os.path.join(path_dest, code_path, path_package_id)
  88. res_path = "app/src/main/res/"
  89. res_path = os.path.join(path_dest, res_path)
  90. javas = [os.path.join(dp, f) for dp, dn, filenames in os.walk(code_path) for f in filenames]
  91. res = [os.path.join(dp, f) for dp, dn, filenames in os.walk(res_path) for f in filenames if "xml" in f]
  92. button_apps_code_path = os.path.join(path_dest, "palio-button-app/src/main/java")
  93. button_apps_res_path = os.path.join(path_dest, "palio-button-app/src/main/res-pba/")
  94. lib_javas = [os.path.join(dp, f) for dp, dn, filenames in os.walk(button_apps_code_path) for f in filenames]
  95. lib_res = [os.path.join(dp, f) for dp, dn, filenames in os.walk(button_apps_res_path) for f in filenames if
  96. "xml" in f]
  97. for j in javas:
  98. print(j)
  99. if "ForumFragment.java" in j:
  100. with open(j, "r") as f:
  101. file_source = f.read()
  102. replaced = file_source.replace("pb_poppins", "roboto")
  103. with open(j, "w") as f:
  104. f.write(replaced)
  105. for j in res:
  106. print(j)
  107. with open(j, "r") as f:
  108. file_source = f.read()
  109. replaced = file_source.replace("pb_poppins", "roboto")
  110. with open(j, "w") as f:
  111. f.write(replaced)
  112. for j in lib_javas:
  113. print(j)
  114. with open(j, "r") as f:
  115. file_source = f.read()
  116. replaced = file_source.replace("pb_poppins", "roboto")
  117. with open(j, "w") as f:
  118. f.write(replaced)
  119. for j in lib_res:
  120. print(j)
  121. with open(j, "r") as f:
  122. file_source = f.read()
  123. replaced = file_source.replace("pb_poppins", "roboto")
  124. with open(j, "w") as f:
  125. f.write(replaced)
  126. def change_package(path_dest, package):
  127. build_gradle = os.path.join(path_dest, 'app/build.gradle')
  128. with open(build_gradle, "r") as f:
  129. file_source = f.read()
  130. replaced = file_source.replace("com.example.qmeralitesamplecode", package)
  131. with open(build_gradle, "w") as f:
  132. f.write(replaced)
  133. proguard = os.path.join(path_dest, 'app/proguard-rules.pro')
  134. with open(proguard, "r") as f:
  135. file_source = f.read()
  136. replaced = file_source.replace("com.example.qmeralitesamplecode", package)
  137. with open(proguard, "w") as f:
  138. f.write(replaced)
  139. manifest = os.path.join(path_dest, "app/src/main/AndroidManifest.xml")
  140. with open(manifest, "r") as f:
  141. file_source = f.read()
  142. replaced = file_source.replace("com.example.qmeralitesamplecode", package)
  143. with open(manifest, "w") as f:
  144. f.write(replaced)
  145. path_package_id = package.replace(".", "/")
  146. code_path = "app/src/main/java/"
  147. code_path = os.path.join(path_dest, code_path, path_package_id)
  148. res_path = "app/src/main/res/"
  149. res_path = os.path.join(path_dest, res_path)
  150. javas = [os.path.join(dp, f) for dp, dn, filenames in os.walk(code_path) for f in filenames]
  151. res = [os.path.join(dp, f) for dp, dn, filenames in os.walk(res_path) for f in filenames if "xml" in f]
  152. for j in javas:
  153. print(j)
  154. with open(j, "r") as f:
  155. file_source = f.read()
  156. replaced = file_source.replace("com.example.qmeralitesamplecode", package)
  157. with open(j, "w") as f:
  158. f.write(replaced)
  159. for j in res:
  160. print(j)
  161. with open(j, "r") as f:
  162. file_source = f.read()
  163. replaced = file_source.replace("com.example.qmeralitesamplecode", package)
  164. with open(j, "w") as f:
  165. f.write(replaced)
  166. gradle = os.path.join(path_dest, "app/build.gradle")
  167. with open(gradle, "r") as f:
  168. lines = f.readlines()
  169. # file_source = f.read()
  170. if package == "io.nexilis.digipos" or package == "io.nexilis.digisales":
  171. with open(gradle, "w") as f:
  172. counter = 0
  173. for line in lines:
  174. if counter == 0:
  175. if "forallapps" in line:
  176. counter = 3
  177. continue
  178. if "nexilis-libs" in line:
  179. continue
  180. if "temp-nexilis-client" in line:
  181. continue
  182. if "AP6ZuWCxBVTzLGiUjfacryBiwPQ" in line:
  183. continue
  184. else:
  185. f.write(line)
  186. else:
  187. counter = counter - 1
  188. else:
  189. with open(gradle, "w") as f:
  190. counter = 0
  191. for line in lines:
  192. if counter == 0:
  193. if "fordigisales" in line:
  194. counter = 3
  195. continue
  196. if "cx-button-libs" in line:
  197. continue
  198. if "cx-tsel-client" in line:
  199. continue
  200. if "AP5NjpoELAt7gHYMtnsrm9hxdGk" in line:
  201. continue
  202. else:
  203. f.write(line)
  204. else:
  205. counter = counter - 1
  206. if package == "com.nexilis.persija" or package == "io.newuniverse.GoToMalls" or package == "io.qmera.mylab":
  207. string_res = os.path.join(path_dest, "app/src/main/res/values/strings.xml")
  208. string_en_res = os.path.join(path_dest, "app/src/main/res/values-en/strings.xml")
  209. string_id_res = os.path.join(path_dest, "app/src/main/res/values-in/strings.xml")
  210. with open(string_res, "r") as f:
  211. file_source = f.read()
  212. replaced = file_source.replace("Nexilis", "Qmera")
  213. with open(string_res, "w") as f:
  214. f.write(replaced)
  215. with open(string_en_res, "r") as f:
  216. file_source = f.read()
  217. replaced = file_source.replace("Nexilis", "Qmera")
  218. with open(string_en_res, "w") as f:
  219. f.write(replaced)
  220. with open(string_id_res, "r") as f:
  221. file_source = f.read()
  222. replaced = file_source.replace("Nexilis", "Qmera")
  223. with open(string_id_res, "w") as f:
  224. f.write(replaced)
  225. old_img_powered = "app/src/main/res/drawable/pb_powered_button.png"
  226. old_img_powered = os.path.join(path_dest, old_img_powered)
  227. old_new_img_powered = "app/src/main/res/drawable/pb_powered_button_temp.png"
  228. old_new_img_powered = os.path.join(path_dest, old_new_img_powered)
  229. shutil.move(old_img_powered, old_new_img_powered)
  230. img_powered = "app/src/main/res/drawable/pb_powered_button1.png"
  231. img_powered = os.path.join(path_dest, img_powered)
  232. new_img_powered = "app/src/main/res/drawable/pb_powered_button.png"
  233. new_img_powered = os.path.join(path_dest, new_img_powered)
  234. shutil.move(img_powered, new_img_powered)
  235. def change_logo(path_dest, logo, logo_float=None):
  236. img_path = "app/src/main/res/drawable/ic_launcher.png"
  237. img_path = os.path.join(path_dest, img_path)
  238. img_notif = "app/src/main/res/drawable/pb_ball.png"
  239. img_notif = os.path.join(path_dest, img_notif)
  240. img_path_float = "app/src/main/res/drawable/pb_button.png"
  241. img_path_float = os.path.join(path_dest, img_path_float)
  242. if isinstance(logo, str):
  243. logo = requests.get('https://newuniverse.io/dashboardv2/uploads/logo/{}'.format(logo))
  244. with open(img_path, "wb") as f:
  245. f.write(logo.content)
  246. with open(img_path, "rb") as f:
  247. logo = Image.open(f)
  248. logo = logo.resize((512, 512))
  249. if logo_float:
  250. logo_float = requests.get('https://newuniverse.io/dashboardv2/uploads/logofloat/{}'.format(logo_float))
  251. with open(img_path_float, "wb") as f:
  252. f.write(logo_float.content)
  253. with open(img_path_float, "rb") as f:
  254. logo_float = Image.open(f)
  255. logo_float = logo_float.resize((150, 150))
  256. else:
  257. logo = Image.open(logo)
  258. logo = logo.resize((512, 512))
  259. if logo_float:
  260. logo_float = Image.open(logo_float)
  261. logo_float = logo_float.resize((150, 150))
  262. logo.save(img_path, "PNG")
  263. if logo_float:
  264. logo_float.save(img_path_float, "PNG")
  265. logo_float.save(img_notif, "PNG")
  266. def change_tab(path_dest, tabs, tab_icon, package, tab3_mode, tab_amount):
  267. default_tab_icon = ["tab{}.png".format(x) for x in tabs]
  268. for i, icon in enumerate(default_tab_icon):
  269. if not tab_icon[i]:
  270. continue
  271. img_path = "app/src/main/res/drawable"
  272. img_path = os.path.join(path_dest, img_path, icon)
  273. if isinstance(tab_icon[i], str):
  274. logo = requests.get('https://newuniverse.io/dashboardv2/uploads/tab_icon/{}'.format(tab_icon[i]))
  275. with open(img_path, "wb") as f:
  276. f.write(logo.content)
  277. with open(img_path, "rb") as f:
  278. logo = Image.open(f)
  279. logo = logo.resize((150, 150))
  280. logo.save(img_path, "PNG")
  281. else:
  282. logo = Image.open(tab_icon[i])
  283. logo = logo.resize((150, 150))
  284. logo.save(img_path, "PNG")
  285. path_package_id = package.replace(".", "/")
  286. code_path = "app/src/main/java/"
  287. sobj_code_path = os.path.join(path_dest, code_path, path_package_id, "SObj.java")
  288. print(sobj_code_path)
  289. with open(sobj_code_path, "r") as f:
  290. file_source = f.read()
  291. replaced = file_source.replace("1,2,3,4", ",".join(tabs))
  292. with open(sobj_code_path, "w") as f:
  293. f.write(replaced)
  294. main_code_path = os.path.join(path_dest, code_path, path_package_id, "MAB.java")
  295. with open(main_code_path, "r") as f:
  296. file_source = f.read()
  297. replaced = file_source.replace('tab3 = "0"', 'tab3 = "{}"'.format(tab3_mode))
  298. with open(main_code_path, "w") as f:
  299. f.write(replaced)
  300. prefs_code_path = os.path.join(path_dest, code_path, path_package_id, "util/PrefsUtil.java")
  301. with open(prefs_code_path, "r") as f:
  302. file_source = f.read()
  303. replaced = file_source.replace('DEFAULT_TAB_AMOUNT = "4"', 'DEFAULT_TAB_AMOUNT = "{}"'.format(tab_amount))
  304. with open(prefs_code_path, "w") as f:
  305. f.write(replaced)
  306. def change_fb(path_dest, fb_icon):
  307. default_fb_icon = ["pb_button_chat.png", "pb_button_call.png", "pb_button_cc.png", "pb_button_stream.png",
  308. "nexilis_fb_04.png"]
  309. for i in range(5):
  310. if not fb_icon[i]:
  311. continue
  312. img_path = "app/src/main/res/drawable-nodpi"
  313. img_path = os.path.join(path_dest, img_path, default_fb_icon[i])
  314. if isinstance(fb_icon[i], str):
  315. logo = requests.get('https://newuniverse.io/dashboardv2/uploads/fb_icon/{}'.format(fb_icon[i]))
  316. with open(img_path, "wb") as f:
  317. f.write(logo.content)
  318. with open(img_path, "rb") as f:
  319. logo = Image.open(f)
  320. logo = logo.resize((150, 150))
  321. logo.save(img_path, "PNG")
  322. else:
  323. logo = Image.open(fb_icon[i])
  324. logo = logo.resize((150, 150))
  325. logo.save(img_path, "PNG")
  326. def change_background(path_dest, background):
  327. # if isinstance(background, str):
  328. # background = background.split(",")
  329. # for i,b in enumerate(background):
  330. # n = i+1
  331. # img_path = "app/src/main/res/drawable-nodpi/pb_lbackground_{}.png".format(n)
  332. # img_path = os.path.join(path_dest, img_path)
  333. # logo = requests.get('https://newuniverse.io/dashboardv2/uploads/background/{}'.format(b))
  334. # with open(img_path, "wb") as f:
  335. # f.write(logo.content)
  336. # with open(img_path, "rb") as f:
  337. # logo = Image.open(f)
  338. # logo = logo.resize((600, 1250))
  339. # logo.save(img_path, "PNG")
  340. # else:
  341. # img_path = "app/src/main/res/drawable-nodpi/pb_lbackground_1.png"
  342. # logo = Image.open(background)
  343. # logo = logo.resize((600, 1250))
  344. # logo.save(img_path, "PNG")
  345. pass
  346. def change_access(path_dest, access_model, package):
  347. access = ["CPAAS_MODE_FLOATING", "CPAAS_MODE_DOCKED", "CPAAS_MODE_BURGER"]
  348. path_package_id = package.replace(".", "/")
  349. code_path = "app/src/main/java/"
  350. code_path = os.path.join(path_dest, code_path, path_package_id, "util", "PrefsUtil.java")
  351. print(code_path)
  352. with open(code_path, "r") as f:
  353. file_source = f.read()
  354. replaced = file_source.replace("= CPAAS_MODE_DOCKED", "= {}".format(access[access_model]))
  355. with open(code_path, "w") as f:
  356. f.write(replaced)
  357. pass
  358. def change_certificate(path_dest, key, keyfile, keytool):
  359. keyfile_name = "{}.keystore".format(key["alias"])
  360. keyfile_path = os.path.join(path_dest, keyfile_name)
  361. if keyfile:
  362. keyfile.save(keyfile_path)
  363. else:
  364. vprint("keytool run")
  365. os.chdir(path_dest)
  366. vprint("current working directory: ", os.getcwd())
  367. dname = "CN={}, OU={}, O={}, L={}, S={}, C={}".format(key["common_name"], key["organization_unit"],
  368. key["organization_name"], key["locality_name"],
  369. key["state_name"], key["country"])
  370. cmd = [keytool, "-genkey", "-v", "-keystore", keyfile_path, "-alias", key["alias"], "-keyalg", "RSA",
  371. "-keysize", "2048",
  372. "-validity", "10000", "-dname", dname, "-storepass", key["store_password"], "-keypass",
  373. key["key_password"]]
  374. vprint(cmd)
  375. subprocess.run(cmd)
  376. vprint("keytool end")
  377. build_gradle = os.path.join(path_dest, 'app/build.gradle')
  378. with open(build_gradle, "r") as f:
  379. file_source = f.read()
  380. replaced = file_source.replace("allyourbase", key["store_password"])
  381. replaced = replaced.replace("arebelongto", key["key_password"])
  382. replaced = replaced.replace("key-qmeralite", key["alias"])
  383. with open(build_gradle, "w") as f:
  384. f.write(replaced)
  385. def run_build(path_dest):
  386. gradlew = os.path.join(path_dest, "gradlew")
  387. ret = subprocess.run([gradlew, 'assembleRelease'])
  388. if ret.returncode == 0:
  389. ret = subprocess.run([gradlew, 'bundleRelease'])
  390. return ret.returncode
  391. def deliver_apk(path_dest, package_id, key, key_exists):
  392. apk_dir = os.path.join(path_dest, 'app/build/outputs/apk/release/app-release.apk')
  393. aab_dir = os.path.join(path_dest, 'app/build/outputs/bundle/release/app-release.aab')
  394. keystore_name = '{}.keystore'.format(key["alias"])
  395. keystore_dir = os.path.join(path_dest, keystore_name)
  396. timenow = time.time()
  397. apk_name = "{}{}.apk".format(package_id, timenow)
  398. aab_name = "{}{}.aab".format(package_id, timenow)
  399. zip_name = "{}{}.zip".format(package_id, timenow)
  400. new_apk_dir = os.path.join(app.apk_folder, apk_name)
  401. new_aab_dir = os.path.join(app.apk_folder, aab_name)
  402. new_dir = os.path.join(app.apk_folder, zip_name)
  403. vprint(apk_dir)
  404. try:
  405. shutil.move(apk_dir, new_apk_dir)
  406. shutil.move(aab_dir, new_aab_dir)
  407. with ZipFile(new_dir, 'w') as zip_file:
  408. zip_file.write(new_apk_dir, os.path.basename(new_apk_dir))
  409. zip_file.write(new_aab_dir, os.path.basename(new_aab_dir))
  410. if not key_exists:
  411. zip_file.write(keystore_dir, os.path.basename(keystore_dir))
  412. os.remove(new_apk_dir)
  413. os.remove(new_aab_dir)
  414. project_path = os.path.join(app.temp_folder, package_id)
  415. shutil.rmtree(project_path)
  416. return {"name": zip_name}
  417. except Exception as e:
  418. return str(e)
  419. def change_version(path_dest, version_code, version_name):
  420. build_gradle = os.path.join(path_dest, 'app/build.gradle')
  421. with open(build_gradle, "r") as f:
  422. file_source = f.read()
  423. replaced = file_source.replace("versionCode 3", "versionCode {}".format(version_code))
  424. replaced = replaced.replace('versionName "3.0"', 'versionName "{}"'.format(version_name))
  425. with open(build_gradle, "w") as f:
  426. f.write(replaced)
  427. @app.route('/', methods=["GET", "POST"])
  428. def build_apk():
  429. vprint('==============================================================')
  430. if request.method == 'POST':
  431. logo = None
  432. logo_float = None
  433. app_name = "NexilisLite"
  434. package_id = "com.app.nexilis"
  435. acc = None
  436. url = None
  437. keystore = None
  438. key_exists = False
  439. # tabs = ["1", "2", "3", "4"]
  440. tabs = []
  441. tab3_mode = "0"
  442. tab_amount = 6
  443. tab_icon = [None, None, None, None]
  444. fb_icon = [None, None, None, None, None]
  445. background = None
  446. version_code = "1"
  447. version_name = "1.0.0"
  448. font = 0
  449. enable_sms = 0
  450. key = {"alias": "nexilislite", "store_password": "allyourbase", "key_password": "arebelongto",
  451. "common_name": "all", "organization_unit": "your",
  452. "organization_name": "base", "locality_name": "are", "state_name": "belong", "country": "to"}
  453. if 'logo' in request.files:
  454. logo = request.files['logo']
  455. vprint(type(logo))
  456. elif 'logo' in request.form:
  457. logo = request.form['logo']
  458. vprint(type(logo))
  459. if 'logofloat' in request.files:
  460. logo_float = request.files['logofloat']
  461. vprint(type(logo_float))
  462. elif 'logofloat' in request.form:
  463. logo_float = request.form['logofloat']
  464. vprint(type(logo_float))
  465. if 'app_name' in request.files:
  466. app_name = request.files['app_name']
  467. vprint(app_name)
  468. elif 'app_name' in request.form:
  469. app_name = request.form['app_name']
  470. vprint(app_name)
  471. if 'package_id' in request.files:
  472. package_id = request.files['package_id']
  473. vprint(package_id)
  474. elif 'package_id' in request.form:
  475. package_id = request.form['package_id']
  476. vprint(package_id)
  477. if 'acc' in request.files:
  478. acc = request.files['acc']
  479. vprint(acc)
  480. elif 'acc' in request.form:
  481. acc = request.form['acc']
  482. vprint(acc)
  483. if 'url' in request.files:
  484. url = request.files['url']
  485. vprint(url)
  486. elif 'url' in request.form:
  487. url = request.form['url']
  488. vprint(url)
  489. if 'keystore' in request.files:
  490. keystore = request.files['keystore']
  491. key_exists = True
  492. elif 'keystore' in request.form:
  493. keystore = request.form['keystore']
  494. key_exists = True
  495. if 'alias' in request.form:
  496. if request.form['alias']:
  497. key["alias"] = request.form['alias']
  498. if 'store_password' in request.form:
  499. if request.form['store_password']:
  500. key["store_password"] = request.form['store_password']
  501. if 'key_password' in request.form:
  502. if request.form['key_password']:
  503. key["key_password"] = request.form['key_password']
  504. if keystore:
  505. if 'common_name' in request.form:
  506. if request.form['common_name']:
  507. key["common_name"] = request.form['common_name']
  508. if 'organization_unit' in request.form:
  509. if request.form['organization_unit']:
  510. key["organization_unit"] = request.form['organization_unit']
  511. if 'organization_name' in request.form:
  512. if request.form['organization_name']:
  513. key["organization_name"] = request.form['organization_name']
  514. if 'locality_name' in request.form:
  515. if request.form['locality_name']:
  516. key["locality_name"] = request.form['locality_name']
  517. if 'state_name' in request.form:
  518. if request.form['state_name']:
  519. key["state_name"] = request.form['state_name']
  520. if 'country' in request.form:
  521. if request.form['country']:
  522. key["country"] = request.form['country']
  523. tabs.append(request.form["tab1"])
  524. tabs.append(request.form["tab2"])
  525. if request.form['tab3']:
  526. tabs.append(request.form["tab3"])
  527. if request.form['tab4']:
  528. tabs.append(request.form["tab4"])
  529. if 'tab1_icon' in request.files:
  530. tab_icon[0] = request.files['tab1_icon']
  531. elif 'tab1_icon' in request.form:
  532. tab_icon[0] = request.form['tab1_icon']
  533. if 'tab2_icon' in request.files:
  534. tab_icon[1] = request.files['tab2_icon']
  535. elif 'tab2_icon' in request.form:
  536. tab_icon[1] = request.form['tab2_icon']
  537. if 'tab3_icon' in request.files:
  538. tab_icon[2] = request.files['tab3_icon']
  539. elif 'tab3_icon' in request.form:
  540. tab_icon[2] = request.form['tab3_icon']
  541. if 'tab4_icon' in request.files:
  542. tab_icon[3] = request.files['tab4_icon']
  543. elif 'tab4_icon' in request.form:
  544. tab_icon[3] = request.form['tab4_icon']
  545. if 'fb1_icon' in request.files:
  546. fb_icon[0] = request.files['fb1_icon']
  547. elif 'fb1_icon' in request.form:
  548. fb_icon[0] = request.form['fb1_icon']
  549. if 'fb2_icon' in request.files:
  550. fb_icon[1] = request.files['fb2_icon']
  551. elif 'fb2_icon' in request.form:
  552. fb_icon[1] = request.form['fb2_icon']
  553. if 'fb3_icon' in request.files:
  554. fb_icon[2] = request.files['fb3_icon']
  555. elif 'fb3_icon' in request.form:
  556. fb_icon[2] = request.form['fb3_icon']
  557. if 'fb4_icon' in request.files:
  558. fb_icon[3] = request.files['fb4_icon']
  559. elif 'fb4_icon' in request.form:
  560. fb_icon[3] = request.form['fb4_icon']
  561. if 'fb5_icon' in request.files:
  562. fb_icon[4] = request.files['fb5_icon']
  563. elif 'fb5_icon' in request.form:
  564. fb_icon[4] = request.form['fb5_icon']
  565. vprint("fb_icon: {}".format(fb_icon))
  566. access_model = int(request.form['access_model'])
  567. if 'tab3_mode' in request.form:
  568. tab3_mode = request.form['tab3_mode']
  569. if 'tab_amount' in request.form:
  570. tab_amount = int(request.form['tab_amount'])
  571. if 'font' in request.form:
  572. font = int(request.form['font'])
  573. if 'background' in request.files:
  574. background = request.files['background']
  575. elif 'background' in request.form:
  576. background = request.form['background']
  577. if 'version_code' in request.form:
  578. version_code = request.form['version_code']
  579. if 'version_name' in request.form:
  580. version_name = request.form['version_name']
  581. else:
  582. version_name = "1.0.{}".format(version_code)
  583. if 'enable_sms' in request.form:
  584. enable_sms = int(request.form['enable_sms'])
  585. path_dest, c_code_path = create_folder(package_id)
  586. vprint("path_dest: " + path_dest)
  587. vprint("c_code_path: " + c_code_path)
  588. if acc:
  589. change_acc(c_code_path, acc, enable_sms)
  590. if url:
  591. change_url(c_code_path, url)
  592. change_name(path_dest, app_name, enable_sms)
  593. change_certificate(path_dest, key, keystore, app.keytool)
  594. change_package(path_dest, package_id)
  595. change_version(path_dest, version_code, version_name)
  596. change_font(path_dest, font, package_id)
  597. if logo:
  598. change_logo(path_dest, logo, logo_float)
  599. if background:
  600. change_background(path_dest, background)
  601. change_fb(path_dest, fb_icon)
  602. change_access(path_dest, access_model, package_id)
  603. change_tab(path_dest, tabs, tab_icon, package_id, tab3_mode, tab_amount)
  604. os.chdir(path_dest)
  605. return_code = run_build(path_dest)
  606. if (return_code == 0):
  607. return deliver_apk(path_dest, package_id, key, key_exists)
  608. return "h"
  609. else:
  610. if 'e' in request.args:
  611. return request.args['e']
  612. return "Hello World!"
  613. if __name__ == '__main__':
  614. app.run(host='0.0.0.0', port=8072, debug=app.verbose, ssl_context=app.ssl)