main.py 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. import os
  2. import random
  3. import string
  4. import traceback
  5. import shutil
  6. import uuid
  7. from flask import Flask, request
  8. app = Flask(__name__)
  9. app.base_project = {
  10. "android": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCode",
  11. "android_flutter": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCodeFlutter-Android",
  12. "android_ionic": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCodeIonic-Android",
  13. "android_react": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCodeReact-Android",
  14. "ios": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCode-iOS",
  15. "ios_flutter": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCodeFlutter-iOS",
  16. "ios_ionic": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCodeIonic-iOS",
  17. "ios_react": "/Users/maronakins/Documents/EmbedFeatures/NexilisSampleCodeReact-iOS"
  18. }
  19. app.temp_folder = "/Users/maronakins/Documents/EmbedFeatures/BuildExample"
  20. app.zip_folder = "/Users/maronakins/Documents/EmbedFeatures/uploads"
  21. # app.ssl = ('/usr/src/app/ssl/STAR_newuniverse_io.crt', '/usr/src/app/ssl/STAR_newuniverse.io.key')
  22. app.ssl = None
  23. app.verbose = True
  24. def vprint(*data):
  25. if app.verbose:
  26. print(*data)
  27. def indented_str(n, s, line=True, spaces=4) -> str:
  28. return " " * n * spaces + s + os.linesep if line else ""
  29. def create_folder(platform, uid):
  30. path = os.path.join(app.temp_folder, uid)
  31. if not os.path.exists(path):
  32. os.mkdir(path)
  33. else:
  34. shutil.rmtree(path)
  35. os.mkdir(path)
  36. vprint(path)
  37. base_project = app.base_project[platform]
  38. base_project_name = os.path.basename(base_project)
  39. path_dest = os.path.join(path, base_project_name)
  40. if not os.path.exists(path_dest):
  41. shutil.copytree(base_project, path_dest)
  42. return path_dest
  43. def change(platform: str, path_dest: str, features: dict, security: dict):
  44. if platform == "android":
  45. main_act_path = os.path.join(path_dest,
  46. "app/src/main/java/com/example/nexilissamplecodeburger/MainActivity.java")
  47. xml_menu_path = os.path.join(path_dest, "app/src/main/res/menu/menu_main.xml")
  48. with open(main_act_path, "r") as f:
  49. lines = f.readlines()
  50. with open(main_act_path, "w") as f:
  51. for line in lines:
  52. if "//FEATURES" in line:
  53. f.write(indented_str(2, "if (id == R.id.action_settings) {"))
  54. f.write(indented_str(3, "API.openSettings();"))
  55. f.write(indented_str(3, "return true;"))
  56. f.write(indented_str(2, "}"))
  57. f.write(indented_str(2, "if (id == R.id.action_profile) {"))
  58. f.write(indented_str(3, "API.openProfile();"))
  59. f.write(indented_str(3, "return true;"))
  60. f.write(indented_str(2, "}"))
  61. if features["cc"]["status"]:
  62. f.write(indented_str(2, "if (id == R.id.action_cc) {"))
  63. f.write(indented_str(3, "API.openContactCenter();"))
  64. f.write(indented_str(3, "return true;"))
  65. f.write(indented_str(2, "}"))
  66. if features["nc"]["status"]:
  67. f.write(indented_str(2, "if (id == R.id.action_nc) {"))
  68. f.write(indented_str(3, "API.openNotificationCenter();"))
  69. f.write(indented_str(3, "return true;"))
  70. f.write(indented_str(2, "}"))
  71. if features["im"]["status"]:
  72. f.write(indented_str(2, "if (id == R.id.action_chats) {"))
  73. f.write(indented_str(3, "API.openChat();"))
  74. f.write(indented_str(3, "return true;"))
  75. f.write(indented_str(2, "}"))
  76. if features["call"]["status"]:
  77. f.write(indented_str(2, "if (id == R.id.action_call) {"))
  78. f.write(indented_str(3, "API.openCall();"))
  79. f.write(indented_str(3, "return true;"))
  80. f.write(indented_str(2, "}"))
  81. if features["ls"]["status"]:
  82. f.write(indented_str(2, "if (id == R.id.action_ls) {"))
  83. f.write(indented_str(3, "API.openOptionsStreaming();"))
  84. f.write(indented_str(3, "return true;"))
  85. f.write(indented_str(2, "}"))
  86. elif "//SECURITY" in line:
  87. if security["show_security"]:
  88. f.write(indented_str(2, "API.setShowSecurityShieldDialog(true);"))
  89. f.write(os.linesep)
  90. if security["emulator"]:
  91. f.write(indented_str(2, "API.setCheckEmulator(true);"))
  92. f.write(os.linesep)
  93. if security["debug"]:
  94. f.write(indented_str(2, "API.setCheckAdb(true);"))
  95. f.write(os.linesep)
  96. if security["sim_swap"]:
  97. f.write(indented_str(2,
  98. "API.setCheckSimCardSwapListener(MainActivity.this, new SimCardDetectionCallback() {"))
  99. f.write(os.linesep)
  100. f.write(indented_str(3, "@Override"))
  101. f.write(indented_str(3, "public boolean onSimCardChange() {"))
  102. f.write(indented_str(4, "return false;"))
  103. f.write(indented_str(3, "}"))
  104. f.write(os.linesep)
  105. f.write(indented_str(3, "@Override"))
  106. f.write(indented_str(3, "public boolean onError(String s) {"))
  107. f.write(os.linesep)
  108. f.write(indented_str(3, "}"))
  109. f.write(indented_str(2, "});"))
  110. f.write(os.linesep)
  111. if security["malware"]:
  112. f.write(indented_str(2, "API.setCheckMalware(true);"))
  113. f.write(os.linesep)
  114. if security["capture"]:
  115. f.write(indented_str(2, "API.setPreventScreenCapture(true);"))
  116. f.write(os.linesep)
  117. if security["call_forwarding"]:
  118. f.write(indented_str(2, "API.setCheckCallForwarding(true);"))
  119. f.write(os.linesep)
  120. if security["secure_folder"]:
  121. f.write(indented_str(2, "API.openSecureFolder();"))
  122. f.write(os.linesep)
  123. elif "//SMS" in line and features["sms"]["status"]:
  124. f.write(indented_str(2, "API.setEnabledSMS(true);"))
  125. elif "//EMAIL" in line and features["email"]["status"]:
  126. f.write(indented_str(2, "API.setEnabledEmail(true);"))
  127. else:
  128. f.write(line)
  129. with open(xml_menu_path, "r") as f:
  130. lines = f.readlines()
  131. with open(xml_menu_path, "w") as f:
  132. for line in lines:
  133. if "<!-- FEATURES -->" in line:
  134. n = 100
  135. f.write(indented_str(1, "<item"))
  136. f.write(indented_str(2, 'android:id="@+id/action_settings"'))
  137. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  138. f.write(indented_str(2, 'android:title="Settings"'))
  139. f.write(indented_str(2, 'app:showAsAction="never" />'))
  140. n = n + 1
  141. f.write(indented_str(1, "<item"))
  142. f.write(indented_str(2, 'android:id="@+id/action_profile"'))
  143. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  144. f.write(indented_str(2, 'android:title="Profile"'))
  145. f.write(indented_str(2, 'app:showAsAction="never" />'))
  146. n = n + 1
  147. if features["cc"]["status"]:
  148. f.write(indented_str(1, "<item"))
  149. f.write(indented_str(2, 'android:id="@+id/action_cc"'))
  150. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  151. f.write(indented_str(2, 'android:title="Contact Center"'))
  152. f.write(indented_str(2, 'app:showAsAction="never" />'))
  153. n = n + 1
  154. if features["nc"]["status"]:
  155. f.write(indented_str(1, "<item"))
  156. f.write(indented_str(2, 'android:id="@+id/action_nc"'))
  157. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  158. f.write(indented_str(2, 'android:title="Notification Center"'))
  159. f.write(indented_str(2, 'app:showAsAction="never" />'))
  160. n = n + 1
  161. if features["im"]["status"]:
  162. f.write(indented_str(1, "<item"))
  163. f.write(indented_str(2, 'android:id="@+id/action_chats"'))
  164. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  165. f.write(indented_str(2, 'android:title="Instant Messaging"'))
  166. f.write(indented_str(2, 'app:showAsAction="never" />'))
  167. n = n + 1
  168. if features["call"]["status"]:
  169. f.write(indented_str(1, "<item"))
  170. f.write(indented_str(2, 'android:id="@+id/action_call"'))
  171. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  172. f.write(indented_str(2, 'android:title="Call"'))
  173. f.write(indented_str(2, 'app:showAsAction="never" />'))
  174. n = n + 1
  175. if features["ls"]["status"]:
  176. f.write(indented_str(1, "<item"))
  177. f.write(indented_str(2, 'android:id="@+id/action_ls"'))
  178. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  179. f.write(indented_str(2, 'android:title="Streaming"'))
  180. f.write(indented_str(2, 'app:showAsAction="never" />'))
  181. n = n + 1
  182. else:
  183. f.write(line)
  184. elif platform == "android_flutter":
  185. main_act_path = os.path.join(path_dest, "lib/main.dart")
  186. with open(main_act_path, "r") as f:
  187. lines = f.readlines()
  188. with open(main_act_path, "w") as f:
  189. features_str = []
  190. for line in lines:
  191. if "'Features List'" in line:
  192. features_str.append("Settings")
  193. features_str.append("Profile")
  194. if features["cc"]["status"]:
  195. features_str.append("Contact Center")
  196. if features["nc"]["status"]:
  197. features_str.append("Notification Center")
  198. if features["im"]["status"]:
  199. features_str.append("Instant Messaging")
  200. if features["call"]["status"]:
  201. features_str.append("Call")
  202. if features["ls"]["status"]:
  203. features_str.append("Streaming")
  204. result_str = ", ".join([f"'{n}'" for n in features_str])
  205. replaced = line.replace("'Features List'", result_str)
  206. f.write(replaced)
  207. elif "//FEATURES" in line:
  208. f.write(indented_str(3, 'case "Settings":', spaces=2))
  209. f.write(indented_str(4, 'nativeChannel.invokeMethod("openSettings");', spaces=2))
  210. f.write(indented_str(4, "break;", spaces=2))
  211. f.write(indented_str(3, 'case "Profile":', spaces=2))
  212. f.write(indented_str(4, 'nativeChannel.invokeMethod("openProfile");', spaces=2))
  213. f.write(indented_str(4, "break;", spaces=2))
  214. if features["cc"]["status"]:
  215. f.write(indented_str(3, 'case "Contact Center":', spaces=2))
  216. f.write(indented_str(4, 'nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  217. f.write(indented_str(4, "break;", spaces=2))
  218. if features["nc"]["status"]:
  219. f.write(indented_str(3, 'case "Notification Center":', spaces=2))
  220. f.write(indented_str(4, 'nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  221. f.write(indented_str(4, "break;", spaces=2))
  222. if features["im"]["status"]:
  223. f.write(indented_str(3, 'case "Instant Messaging":', spaces=2))
  224. f.write(indented_str(4, 'nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  225. f.write(indented_str(4, "break;", spaces=2))
  226. if features["call"]["status"]:
  227. f.write(indented_str(3, 'case "Call":', spaces=2))
  228. f.write(indented_str(4, 'nativeChannel.invokeMethod("openCall");', spaces=2))
  229. f.write(indented_str(4, "break;", spaces=2))
  230. if features["ls"]["status"]:
  231. f.write(indented_str(3, 'case "Streaming":', spaces=2))
  232. f.write(indented_str(4, 'nativeChannel.invokeMethod("openStreaming");', spaces=2))
  233. f.write(indented_str(4, "break;", spaces=2))
  234. else:
  235. f.write(line)
  236. elif platform == "android_ionic":
  237. main_act_path = os.path.join(path_dest,"src/app/app.component.ts")
  238. with open(main_act_path, "r") as f:
  239. lines = f.readlines()
  240. with open(main_act_path, "w") as f:
  241. for line in lines:
  242. if "//FEATURES" in line:
  243. f.write(indented_str(4, '{', spaces=2))
  244. f.write(indented_str(5, "text: 'Settings',", spaces=2))
  245. f.write(indented_str(5, "handler: () => {", spaces=2))
  246. f.write(indented_str(6, "this.openSettings();", spaces=2))
  247. f.write(indented_str(5, "},", spaces=2))
  248. f.write(indented_str(4, "},", spaces=2))
  249. f.write(indented_str(4, '{', spaces=2))
  250. f.write(indented_str(5, "text: 'Profile',", spaces=2))
  251. f.write(indented_str(5, "handler: () => {", spaces=2))
  252. f.write(indented_str(6, "this.openProfile();", spaces=2))
  253. f.write(indented_str(5, "},", spaces=2))
  254. f.write(indented_str(4, "},", spaces=2))
  255. if features["cc"]["status"]:
  256. f.write(indented_str(4, '{', spaces=2))
  257. f.write(indented_str(5, "text: 'Contact Center',", spaces=2))
  258. f.write(indented_str(5, "handler: () => {", spaces=2))
  259. f.write(indented_str(6, "this.openContactCenter();", spaces=2))
  260. f.write(indented_str(5, "},", spaces=2))
  261. f.write(indented_str(4, "},", spaces=2))
  262. if features["nc"]["status"]:
  263. f.write(indented_str(4, '{', spaces=2))
  264. f.write(indented_str(5, "text: 'Notification Center',", spaces=2))
  265. f.write(indented_str(5, "handler: () => {", spaces=2))
  266. f.write(indented_str(6, "this.openNotificationCenter();", spaces=2))
  267. f.write(indented_str(5, "},", spaces=2))
  268. f.write(indented_str(4, "},", spaces=2))
  269. if features["im"]["status"]:
  270. f.write(indented_str(4, '{', spaces=2))
  271. f.write(indented_str(5, "text: 'Instant Messaging',", spaces=2))
  272. f.write(indented_str(5, "handler: () => {", spaces=2))
  273. f.write(indented_str(6, "this.openChat();", spaces=2))
  274. f.write(indented_str(5, "},", spaces=2))
  275. f.write(indented_str(4, "},", spaces=2))
  276. if features["call"]["status"]:
  277. f.write(indented_str(4, '{', spaces=2))
  278. f.write(indented_str(5, "text: 'Call',", spaces=2))
  279. f.write(indented_str(5, "handler: () => {", spaces=2))
  280. f.write(indented_str(6, "this.openCall();", spaces=2))
  281. f.write(indented_str(5, "},", spaces=2))
  282. f.write(indented_str(4, "},", spaces=2))
  283. if features["ls"]["status"]:
  284. f.write(indented_str(4, '{', spaces=2))
  285. f.write(indented_str(5, "text: 'Streaming',", spaces=2))
  286. f.write(indented_str(5, "handler: () => {", spaces=2))
  287. f.write(indented_str(6, "this.openStreaming();", spaces=2))
  288. f.write(indented_str(5, "},", spaces=2))
  289. f.write(indented_str(4, "},", spaces=2))
  290. else:
  291. f.write(line)
  292. elif platform == "android_react":
  293. pass
  294. elif platform == "ios":
  295. main_act_path = os.path.join(path_dest,
  296. "ExampleCode/ViewController.swift")
  297. with open(main_act_path, "r") as f:
  298. lines = f.readlines()
  299. with open(main_act_path, "w") as f:
  300. for line in lines:
  301. if "//FEATURES" in line:
  302. f.write(indented_str(3, 'UIAction(title: "Setting".localized(), handler: {(_) in'))
  303. f.write(indented_str(4, "APIS.openSetting();"))
  304. f.write(indented_str(3, "}),"))
  305. f.write(indented_str(3, 'UIAction(title: "Profile".localized(), handler: {(_) in'))
  306. f.write(indented_str(4, "APIS.openProfile();"))
  307. f.write(indented_str(3, "}),"))
  308. if features["cc"]["status"]:
  309. f.write(indented_str(3, 'UIAction(title: "Contact Center".localized(), handler: {(_) in'))
  310. f.write(indented_str(4, "APIS.openContactCenter();"))
  311. f.write(indented_str(3, "}),"))
  312. if features["nc"]["status"]:
  313. f.write(indented_str(3, 'UIAction(title: "Notification Center".localized(), handler: {(_) in'))
  314. f.write(indented_str(4, "APIS.openNotificationCenter();"))
  315. f.write(indented_str(3, "}),"))
  316. if features["im"]["status"]:
  317. f.write(indented_str(3, 'UIAction(title: "Chat".localized(), handler: {(_) in'))
  318. f.write(indented_str(4, "APIS.openChat();"))
  319. f.write(indented_str(3, "}),"))
  320. if features["call"]["status"]:
  321. f.write(indented_str(3, 'UIAction(title: "Call".localized(), handler: {(_) in'))
  322. f.write(indented_str(4, "APIS.openCall();"))
  323. f.write(indented_str(3, "}),"))
  324. if features["ls"]["status"]:
  325. f.write(indented_str(3, 'UIAction(title: "Live Streaming".localized(), handler: {(_) in'))
  326. f.write(indented_str(4, "APIS.openStreaming();"))
  327. f.write(indented_str(3, "}),"))
  328. else:
  329. f.write(line)
  330. elif platform == "ios_flutter":
  331. main_act_path = os.path.join(path_dest, "lib/main.dart")
  332. with open(main_act_path, "r") as f:
  333. lines = f.readlines()
  334. with open(main_act_path, "w") as f:
  335. features_str = []
  336. for line in lines:
  337. if "'Features List'" in line:
  338. features_str.append("Settings")
  339. features_str.append("Profile")
  340. if features["cc"]["status"]:
  341. features_str.append("Contact Center")
  342. if features["nc"]["status"]:
  343. features_str.append("Notification Center")
  344. if features["im"]["status"]:
  345. features_str.append("Instant Messaging")
  346. if features["call"]["status"]:
  347. features_str.append("Call")
  348. if features["ls"]["status"]:
  349. features_str.append("Streaming")
  350. result_str = ", ".join([f"'{n}'" for n in features_str])
  351. replaced = line.replace("'Features List'", result_str)
  352. f.write(replaced)
  353. elif "//FEATURES" in line:
  354. f.write(indented_str(3, 'case "Settings":', spaces=2))
  355. f.write(indented_str(4, 'nativeChannel.invokeMethod("openSettings");', spaces=2))
  356. f.write(indented_str(4, "break;", spaces=2))
  357. f.write(indented_str(3, 'case "Profile":', spaces=2))
  358. f.write(indented_str(4, 'nativeChannel.invokeMethod("openProfile");', spaces=2))
  359. f.write(indented_str(4, "break;", spaces=2))
  360. if features["cc"]["status"]:
  361. f.write(indented_str(3, 'case "Contact Center":', spaces=2))
  362. f.write(indented_str(4, 'nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  363. f.write(indented_str(4, "break;", spaces=2))
  364. if features["nc"]["status"]:
  365. f.write(indented_str(3, 'case "Notification Center":', spaces=2))
  366. f.write(indented_str(4, 'nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  367. f.write(indented_str(4, "break;", spaces=2))
  368. if features["im"]["status"]:
  369. f.write(indented_str(3, 'case "Instant Messaging":', spaces=2))
  370. f.write(indented_str(4, 'nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  371. f.write(indented_str(4, "break;", spaces=2))
  372. if features["call"]["status"]:
  373. f.write(indented_str(3, 'case "Call":', spaces=2))
  374. f.write(indented_str(4, 'nativeChannel.invokeMethod("openCall");', spaces=2))
  375. f.write(indented_str(4, "break;", spaces=2))
  376. if features["ls"]["status"]:
  377. f.write(indented_str(3, 'case "Streaming":', spaces=2))
  378. f.write(indented_str(4, 'nativeChannel.invokeMethod("openStreaming");', spaces=2))
  379. f.write(indented_str(4, "break;", spaces=2))
  380. else:
  381. f.write(line)
  382. elif platform == "ios_ionic":
  383. main_act_path = os.path.join(path_dest, "src/app/app.component.ts")
  384. with open(main_act_path, "r") as f:
  385. lines = f.readlines()
  386. with open(main_act_path, "w") as f:
  387. for line in lines:
  388. if "//FEATURES" in line:
  389. f.write(indented_str(4, '{', spaces=2))
  390. f.write(indented_str(5, "text: 'Settings',", spaces=2))
  391. f.write(indented_str(5, "handler: () => {", spaces=2))
  392. f.write(indented_str(6, "this.openSettings();", spaces=2))
  393. f.write(indented_str(5, "},", spaces=2))
  394. f.write(indented_str(4, "},", spaces=2))
  395. f.write(indented_str(4, '{', spaces=2))
  396. f.write(indented_str(5, "text: 'Profile',", spaces=2))
  397. f.write(indented_str(5, "handler: () => {", spaces=2))
  398. f.write(indented_str(6, "this.openProfile();", spaces=2))
  399. f.write(indented_str(5, "},", spaces=2))
  400. f.write(indented_str(4, "},", spaces=2))
  401. if features["cc"]["status"]:
  402. f.write(indented_str(4, '{', spaces=2))
  403. f.write(indented_str(5, "text: 'Contact Center',", spaces=2))
  404. f.write(indented_str(5, "handler: () => {", spaces=2))
  405. f.write(indented_str(6, "this.openContactCenter();", spaces=2))
  406. f.write(indented_str(5, "},", spaces=2))
  407. f.write(indented_str(4, "},", spaces=2))
  408. if features["nc"]["status"]:
  409. f.write(indented_str(4, '{', spaces=2))
  410. f.write(indented_str(5, "text: 'Notification Center',", spaces=2))
  411. f.write(indented_str(5, "handler: () => {", spaces=2))
  412. f.write(indented_str(6, "this.openNotificationCenter();", spaces=2))
  413. f.write(indented_str(5, "},", spaces=2))
  414. f.write(indented_str(4, "},", spaces=2))
  415. if features["im"]["status"]:
  416. f.write(indented_str(4, '{', spaces=2))
  417. f.write(indented_str(5, "text: 'Instant Messaging',", spaces=2))
  418. f.write(indented_str(5, "handler: () => {", spaces=2))
  419. f.write(indented_str(6, "this.openChat();", spaces=2))
  420. f.write(indented_str(5, "},", spaces=2))
  421. f.write(indented_str(4, "},", spaces=2))
  422. if features["call"]["status"]:
  423. f.write(indented_str(4, '{', spaces=2))
  424. f.write(indented_str(5, "text: 'Call',", spaces=2))
  425. f.write(indented_str(5, "handler: () => {", spaces=2))
  426. f.write(indented_str(6, "this.openCall();", spaces=2))
  427. f.write(indented_str(5, "},", spaces=2))
  428. f.write(indented_str(4, "},", spaces=2))
  429. if features["ls"]["status"]:
  430. f.write(indented_str(4, '{', spaces=2))
  431. f.write(indented_str(5, "text: 'Streaming',", spaces=2))
  432. f.write(indented_str(5, "handler: () => {", spaces=2))
  433. f.write(indented_str(6, "this.openStreaming();", spaces=2))
  434. f.write(indented_str(5, "},", spaces=2))
  435. f.write(indented_str(4, "},", spaces=2))
  436. else:
  437. f.write(line)
  438. elif platform == "ios_react":
  439. pass
  440. def deliver_zip(path_dest, uid):
  441. rand_name = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(32))
  442. zip_name = f"{rand_name}"
  443. new_dir = os.path.join(app.zip_folder, zip_name)
  444. try:
  445. shutil.make_archive(new_dir, 'zip', path_dest)
  446. project_path = os.path.join(app.temp_folder, uid)
  447. shutil.rmtree(project_path)
  448. return {"status": "0", "name": zip_name + ".zip"}
  449. except Exception as e:
  450. return {"status": "4", "message": "Deliver ZIP failed"}
  451. @app.route('/', methods=["GET", "POST"])
  452. def build_project():
  453. vprint('==============================================================')
  454. if request.method == 'POST':
  455. platform = "ios_ionic"
  456. feature_dict = {
  457. "im": {
  458. "android_name": "action_chats",
  459. "status": True
  460. },
  461. "cc": {
  462. "android_name": "action_cc",
  463. "status": False
  464. },
  465. "call": {
  466. "android_name": "action_call",
  467. "status": True
  468. },
  469. "ls": {
  470. "android_name": "action_ls",
  471. "status": True
  472. },
  473. "settings": {
  474. "android_name": "action_settings",
  475. "status": False
  476. },
  477. "nc": {
  478. "android_name": "action_nc",
  479. "status": False
  480. },
  481. "sms": {
  482. "status": False
  483. },
  484. "email": {
  485. "status": False
  486. },
  487. }
  488. security_dict = {
  489. "malware": False,
  490. "clone": False,
  491. "emulator": False,
  492. "debug": False,
  493. "sim_swap": False,
  494. "capture": False,
  495. "call_forwarding": False,
  496. "secure_folder": False,
  497. "show_security": False,
  498. }
  499. try:
  500. if "feature_im" in request.form:
  501. feature_dict["im"]["status"] = request.form["feature_im"] == "1"
  502. if "feature_cc" in request.form:
  503. feature_dict["cc"]["status"] = request.form["feature_cc"] == "1"
  504. if "feature_vc" in request.form:
  505. feature_dict["call"]["status"] = request.form["feature_vc"] == "1"
  506. if "feature_ac" in request.form:
  507. feature_dict["call"]["status"] = request.form["feature_ac"] == "1"
  508. if "feature_ls" in request.form:
  509. feature_dict["ls"]["status"] = request.form["feature_ls"] == "1"
  510. if "feature_nc" in request.form:
  511. feature_dict["nc"]["status"] = request.form["feature_nc"] == "1"
  512. if "feature_sms" in request.form:
  513. feature_dict["sms"]["status"] = request.form["feature_sms"] == "1"
  514. if "feature_email" in request.form:
  515. feature_dict["email"]["status"] = request.form["feature_email"] == "1"
  516. if "feature_settings" in request.form:
  517. feature_dict["settings"]["status"] = request.form["feature_settings"] == "1"
  518. if "security_malware" in request.form:
  519. security_dict["malware"] = request.form["security_malware"] == "1"
  520. if "security_clone" in request.form:
  521. security_dict["clone"] = request.form["security_clone"] == "1"
  522. if "security_emulator" in request.form:
  523. security_dict["emulator"] = request.form["security_emulator"] == "1"
  524. if "security_debug" in request.form:
  525. security_dict["debug"] = request.form["security_debug"] == "1"
  526. if "security_sim_swap" in request.form:
  527. security_dict["sim_swap"] = request.form["security_sim_swap"] == "1"
  528. if "security_capture" in request.form:
  529. security_dict["capture"] = request.form["security_capture"] == "1"
  530. if "security_call_forwarding" in request.form:
  531. security_dict["call_forwarding"] = request.form["security_call_forwarding"] == "1"
  532. if "security_secure_folder" in request.form:
  533. security_dict["secure_folder"] = request.form["security_secure_folder"] == "1"
  534. if "show_security" in request.form:
  535. security_dict["show_security"] = request.form["show_security"] == "1"
  536. else:
  537. security_dict["show_security"] = (security_dict["malware"] or security_dict["clone"]
  538. or security_dict["emulator"] or security_dict["debug"]
  539. or security_dict["sim_swap"] or security_dict["capture"]
  540. or security_dict["call_forwarding"]
  541. or security_dict["secure_folder"])
  542. if "platform" in request.form:
  543. platform = request.form["platform"]
  544. except BaseException as e:
  545. vprint(traceback.format_exc())
  546. return {"status": "1", "message": "Parameter mismatch\n{}\n".format(str(e))}, 400
  547. try:
  548. uu_id = str(uuid.uuid4())
  549. path_dest = create_folder(platform, uu_id)
  550. change(platform, path_dest, feature_dict, security_dict)
  551. return deliver_zip(path_dest, uu_id)
  552. except BaseException as e:
  553. vprint(traceback.format_exc())
  554. return {"status": "2", "message": "Process failure\n{}\n".format(str(e))}, 200
  555. else:
  556. if 'e' in request.args:
  557. return request.args['e']
  558. return "Hello World!"
  559. if __name__ == '__main__':
  560. app.run(host='0.0.0.0', port=8056, debug=app.verbose, ssl_context=app.ssl)