main.py 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  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, mode: 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. else:
  67. f.write(indented_str(2, "// if (id == R.id.action_cc) {"))
  68. f.write(indented_str(3, "// API.openContactCenter();"))
  69. f.write(indented_str(3, "// return true;"))
  70. f.write(indented_str(2, "// }"))
  71. if features["nc"]["status"]:
  72. f.write(indented_str(2, "if (id == R.id.action_nc) {"))
  73. f.write(indented_str(3, "API.openNotificationCenter();"))
  74. f.write(indented_str(3, "return true;"))
  75. f.write(indented_str(2, "}"))
  76. else:
  77. f.write(indented_str(2, "// if (id == R.id.action_nc) {"))
  78. f.write(indented_str(3, "// API.openNotificationCenter();"))
  79. f.write(indented_str(3, "// return true;"))
  80. f.write(indented_str(2, "// }"))
  81. if features["im"]["status"]:
  82. f.write(indented_str(2, "if (id == R.id.action_chats) {"))
  83. f.write(indented_str(3, "API.openChat();"))
  84. f.write(indented_str(3, "return true;"))
  85. f.write(indented_str(2, "}"))
  86. else:
  87. f.write(indented_str(2, "// if (id == R.id.action_chats) {"))
  88. f.write(indented_str(3, "// API.openChat();"))
  89. f.write(indented_str(3, "// return true;"))
  90. f.write(indented_str(2, "// }"))
  91. if features["call"]["status"]:
  92. f.write(indented_str(2, "if (id == R.id.action_call) {"))
  93. f.write(indented_str(3, "API.openCall();"))
  94. f.write(indented_str(3, "return true;"))
  95. f.write(indented_str(2, "}"))
  96. else:
  97. f.write(indented_str(2, "// if (id == R.id.action_call) {"))
  98. f.write(indented_str(3, "// API.openCall();"))
  99. f.write(indented_str(3, "// return true;"))
  100. f.write(indented_str(2, "// }"))
  101. if features["ls"]["status"]:
  102. f.write(indented_str(2, "if (id == R.id.action_ls) {"))
  103. f.write(indented_str(3, "API.openOptionsStreaming();"))
  104. f.write(indented_str(3, "return true;"))
  105. f.write(indented_str(2, "}"))
  106. else:
  107. f.write(indented_str(2, "// if (id == R.id.action_ls) {"))
  108. f.write(indented_str(3, "// API.openOptionsStreaming();"))
  109. f.write(indented_str(3, "// return true;"))
  110. f.write(indented_str(2, "// }"))
  111. elif "//SECURITY" in line:
  112. if security["show_security"]:
  113. f.write(indented_str(2, "API.setShowSecurityShieldDialog(true);"))
  114. f.write(os.linesep)
  115. else:
  116. f.write(indented_str(2, "// API.setShowSecurityShieldDialog(true);"))
  117. f.write(os.linesep)
  118. if security["emulator"]:
  119. f.write(indented_str(2, "API.setCheckEmulator(true);"))
  120. f.write(os.linesep)
  121. else:
  122. f.write(indented_str(2, "// API.setCheckEmulator(true);"))
  123. f.write(os.linesep)
  124. if security["debug"]:
  125. f.write(indented_str(2, "API.setCheckAdb(true);"))
  126. f.write(os.linesep)
  127. if security["sim_swap"]:
  128. f.write(indented_str(2,
  129. "API.setCheckSimCardSwapListener(MainActivity.this, new SimCardDetectionCallback() {"))
  130. f.write(os.linesep)
  131. f.write(indented_str(3, "@Override"))
  132. f.write(indented_str(3, "public boolean onSimCardChange() {"))
  133. f.write(indented_str(4, "return false;"))
  134. f.write(indented_str(3, "}"))
  135. f.write(os.linesep)
  136. f.write(indented_str(3, "@Override"))
  137. f.write(indented_str(3, "public void onError(String s) {"))
  138. f.write(os.linesep)
  139. f.write(indented_str(3, "}"))
  140. f.write(indented_str(2, "});"))
  141. f.write(os.linesep)
  142. else:
  143. f.write(indented_str(2,
  144. "/* API.setCheckSimCardSwapListener(MainActivity.this, new SimCardDetectionCallback() {"))
  145. f.write(os.linesep)
  146. f.write(indented_str(3, "@Override"))
  147. f.write(indented_str(3, "public boolean onSimCardChange() {"))
  148. f.write(indented_str(4, "return false;"))
  149. f.write(indented_str(3, "}"))
  150. f.write(os.linesep)
  151. f.write(indented_str(3, "@Override"))
  152. f.write(indented_str(3, "public void onError(String s) {"))
  153. f.write(os.linesep)
  154. f.write(indented_str(3, "}"))
  155. f.write(indented_str(2, "}); */"))
  156. f.write(os.linesep)
  157. if security["malware"]:
  158. f.write(indented_str(2, "API.setCheckMalware(true);"))
  159. f.write(os.linesep)
  160. else:
  161. f.write(indented_str(2, "// API.setCheckMalware(true);"))
  162. f.write(os.linesep)
  163. if security["capture"]:
  164. f.write(indented_str(2, "API.setPreventScreenCapture(true);"))
  165. f.write(os.linesep)
  166. else:
  167. f.write(indented_str(2, "// API.setPreventScreenCapture(true);"))
  168. f.write(os.linesep)
  169. if security["call_forwarding"]:
  170. f.write(indented_str(2, "API.setCheckCallForwarding(true);"))
  171. f.write(os.linesep)
  172. else:
  173. f.write(indented_str(2, "// API.setCheckCallForwarding(true);"))
  174. f.write(os.linesep)
  175. if security["secure_folder"]:
  176. f.write(indented_str(2, "API.openSecureFolder();"))
  177. f.write(os.linesep)
  178. else:
  179. f.write(indented_str(2, "// API.openSecureFolder();"))
  180. f.write(os.linesep)
  181. elif "//SMS" in line:
  182. if features["sms"]["status"]:
  183. f.write(indented_str(2, "API.setEnabledSMS(true);"))
  184. else:
  185. f.write(indented_str(2, "// API.setEnabledSMS(true);"))
  186. elif "//EMAIL" in line:
  187. if features["email"]["status"]:
  188. f.write(indented_str(2, "API.setEnabledEmail(true);"))
  189. else:
  190. f.write(indented_str(2, "// API.setEnabledEmail(true);"))
  191. elif "//BREAK" in line:
  192. if mode == "floating":
  193. f.write("}")
  194. break
  195. else:
  196. f.write(indented_str(0,""))
  197. elif "//FLOATING" in line:
  198. if mode == "floating":
  199. f.write(indented_str(6, "ArrayList<FloatingButton> fb = new ArrayList<>();"))
  200. if features["cc"]["status"]:
  201. f.write(indented_str(6, 'fb.add(new FloatingButton(FloatingButton.FEATURE.CONTACT_CENTER, ""));'))
  202. else:
  203. f.write(indented_str(6,
  204. '// fb.add(new FloatingButton(FloatingButton.FEATURE.CONTACT_CENTER, ""));'))
  205. if features["nc"]["status"]:
  206. f.write(indented_str(6, 'fb.add(new FloatingButton(FloatingButton.FEATURE.NOTIF_CENTER, ""));'))
  207. else:
  208. f.write(indented_str(6,
  209. '// fb.add(new FloatingButton(FloatingButton.FEATURE.NOTIF_CENTER, ""));'))
  210. if features["im"]["status"]:
  211. f.write(
  212. indented_str(6, 'fb.add(new FloatingButton(FloatingButton.FEATURE.MESSAGING, ""));'))
  213. else:
  214. f.write(indented_str(6,
  215. '// fb.add(new FloatingButton(FloatingButton.FEATURE.MESSAGING, ""));'))
  216. if features["call"]["status"]:
  217. f.write(
  218. indented_str(6, 'fb.add(new FloatingButton(FloatingButton.FEATURE.AUDIO_VIDEO_CALL, ""));'))
  219. else:
  220. f.write(indented_str(6,
  221. '// fb.add(new FloatingButton(FloatingButton.FEATURE.AUDIO_VIDEO_CALL, ""));'))
  222. if features["ls"]["status"]:
  223. f.write(
  224. indented_str(6, 'fb.add(new FloatingButton(FloatingButton.FEATURE.STREAMING, ""));'))
  225. else:
  226. f.write(indented_str(6,
  227. '// fb.add(new FloatingButton(FloatingButton.FEATURE.STREAMING, ""));'))
  228. f.write(indented_str(6,
  229. 'API.configureFloating(fb);'))
  230. else:
  231. f.write(indented_str(0, ""))
  232. elif "API.connect" in line:
  233. if mode == "floating":
  234. replaced = line.replace("0", "1")
  235. f.write(replaced)
  236. else:
  237. f.write(line)
  238. else:
  239. f.write(line)
  240. with open(xml_menu_path, "r") as f:
  241. lines = f.readlines()
  242. with open(xml_menu_path, "w") as f:
  243. for line in lines:
  244. if "<!-- FEATURES -->" in line:
  245. n = 100
  246. f.write(indented_str(1, "<item"))
  247. f.write(indented_str(2, 'android:id="@+id/action_settings"'))
  248. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  249. f.write(indented_str(2, 'android:title="Settings"'))
  250. f.write(indented_str(2, 'app:showAsAction="never" />'))
  251. n = n + 1
  252. f.write(indented_str(1, "<item"))
  253. f.write(indented_str(2, 'android:id="@+id/action_profile"'))
  254. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  255. f.write(indented_str(2, 'android:title="Profile"'))
  256. f.write(indented_str(2, 'app:showAsAction="never" />'))
  257. n = n + 1
  258. if features["cc"]["status"]:
  259. f.write(indented_str(1, "<item"))
  260. f.write(indented_str(2, 'android:id="@+id/action_cc"'))
  261. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  262. f.write(indented_str(2, 'android:title="Contact Center"'))
  263. f.write(indented_str(2, 'app:showAsAction="never" />'))
  264. n = n + 1
  265. else:
  266. f.write(indented_str(1, "<!-- <item"))
  267. f.write(indented_str(2, 'android:id="@+id/action_cc"'))
  268. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  269. f.write(indented_str(2, 'android:title="Contact Center"'))
  270. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  271. n = n + 1
  272. if features["nc"]["status"]:
  273. f.write(indented_str(1, "<item"))
  274. f.write(indented_str(2, 'android:id="@+id/action_nc"'))
  275. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  276. f.write(indented_str(2, 'android:title="Notification Center"'))
  277. f.write(indented_str(2, 'app:showAsAction="never" />'))
  278. n = n + 1
  279. else:
  280. f.write(indented_str(1, "<!-- <item"))
  281. f.write(indented_str(2, 'android:id="@+id/action_nc"'))
  282. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  283. f.write(indented_str(2, 'android:title="Notification Center"'))
  284. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  285. n = n + 1
  286. if features["im"]["status"]:
  287. f.write(indented_str(1, "<item"))
  288. f.write(indented_str(2, 'android:id="@+id/action_chats"'))
  289. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  290. f.write(indented_str(2, 'android:title="Instant Messaging"'))
  291. f.write(indented_str(2, 'app:showAsAction="never" />'))
  292. n = n + 1
  293. else:
  294. f.write(indented_str(1, "<!-- <item"))
  295. f.write(indented_str(2, 'android:id="@+id/action_chats"'))
  296. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  297. f.write(indented_str(2, 'android:title="Instant Messaging"'))
  298. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  299. n = n + 1
  300. if features["call"]["status"]:
  301. f.write(indented_str(1, "<item"))
  302. f.write(indented_str(2, 'android:id="@+id/action_call"'))
  303. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  304. f.write(indented_str(2, 'android:title="Call"'))
  305. f.write(indented_str(2, 'app:showAsAction="never" />'))
  306. n = n + 1
  307. else:
  308. f.write(indented_str(1, "<!-- <item"))
  309. f.write(indented_str(2, 'android:id="@+id/action_call"'))
  310. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  311. f.write(indented_str(2, 'android:title="Call"'))
  312. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  313. n = n + 1
  314. if features["ls"]["status"]:
  315. f.write(indented_str(1, "<item"))
  316. f.write(indented_str(2, 'android:id="@+id/action_ls"'))
  317. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  318. f.write(indented_str(2, 'android:title="Streaming"'))
  319. f.write(indented_str(2, 'app:showAsAction="never" />'))
  320. n = n + 1
  321. else:
  322. f.write(indented_str(1, "<!-- <item"))
  323. f.write(indented_str(2, 'android:id="@+id/action_ls"'))
  324. f.write(indented_str(2, f'android:orderInCategory="{n}"'))
  325. f.write(indented_str(2, 'android:title="Streaming"'))
  326. f.write(indented_str(2, 'app:showAsAction="never" /> -->'))
  327. n = n + 1
  328. else:
  329. f.write(line)
  330. elif platform == "android_flutter":
  331. main_act_path = os.path.join(path_dest, "lib/main.dart")
  332. main_act_android = os.path.join(path_dest, "android/app/src/main/java/com/example/paliolitesamplecodeflutter/MainActivity.java")
  333. with open(main_act_path, "r") as f:
  334. lines = f.readlines()
  335. with open(main_act_path, "w") as f:
  336. features_str = []
  337. for line in lines:
  338. if "'Features List'" in line:
  339. features_str.append("Settings")
  340. features_str.append("Profile")
  341. if features["cc"]["status"]:
  342. features_str.append("'Contact Center'")
  343. else:
  344. features_str.append("// 'Contact Center'")
  345. if features["nc"]["status"]:
  346. features_str.append("'Notification Center'")
  347. else:
  348. features_str.append("// 'Notification Center'")
  349. if features["im"]["status"]:
  350. features_str.append("'Instant Messaging'")
  351. else:
  352. features_str.append("// 'Instant Messaging'")
  353. if features["call"]["status"]:
  354. features_str.append("'Call'")
  355. else:
  356. features_str.append("// 'Call'")
  357. if features["ls"]["status"]:
  358. features_str.append("'Streaming'")
  359. else:
  360. features_str.append("// 'Streaming'")
  361. for feature_str in features_str:
  362. f.write(indented_str(8, f"{feature_str},", spaces=2))
  363. elif "//FEATURES" in line:
  364. f.write(indented_str(3, 'case "Settings":', spaces=2))
  365. f.write(indented_str(4, 'nativeChannel.invokeMethod("openSettings");', spaces=2))
  366. f.write(indented_str(4, "break;", spaces=2))
  367. f.write(indented_str(3, 'case "Profile":', spaces=2))
  368. f.write(indented_str(4, 'nativeChannel.invokeMethod("openProfile");', spaces=2))
  369. f.write(indented_str(4, "break;", spaces=2))
  370. if features["cc"]["status"]:
  371. f.write(indented_str(3, 'case "Contact Center":', spaces=2))
  372. f.write(indented_str(4, 'nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  373. f.write(indented_str(4, "break;", spaces=2))
  374. else:
  375. f.write(indented_str(3, '// case "Contact Center":', spaces=2))
  376. f.write(indented_str(4, '// nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  377. f.write(indented_str(4, "// break;", spaces=2))
  378. if features["nc"]["status"]:
  379. f.write(indented_str(3, 'case "Notification Center":', spaces=2))
  380. f.write(indented_str(4, 'nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  381. f.write(indented_str(4, "break;", spaces=2))
  382. else:
  383. f.write(indented_str(3, '// case "Notification Center":', spaces=2))
  384. f.write(indented_str(4, '// nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  385. f.write(indented_str(4, "// break;", spaces=2))
  386. if features["im"]["status"]:
  387. f.write(indented_str(3, 'case "Instant Messaging":', spaces=2))
  388. f.write(indented_str(4, 'nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  389. f.write(indented_str(4, "break;", spaces=2))
  390. else:
  391. f.write(indented_str(3, '// case "Instant Messaging":', spaces=2))
  392. f.write(indented_str(4, '// nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  393. f.write(indented_str(4, "// break;", spaces=2))
  394. if features["call"]["status"]:
  395. f.write(indented_str(3, 'case "Call":', spaces=2))
  396. f.write(indented_str(4, 'nativeChannel.invokeMethod("openCall");', spaces=2))
  397. f.write(indented_str(4, "break;", spaces=2))
  398. else:
  399. f.write(indented_str(3, '// case "Call":', spaces=2))
  400. f.write(indented_str(4, '// nativeChannel.invokeMethod("openCall");', spaces=2))
  401. f.write(indented_str(4, "// break;", spaces=2))
  402. if features["ls"]["status"]:
  403. f.write(indented_str(3, 'case "Streaming":', spaces=2))
  404. f.write(indented_str(4, 'nativeChannel.invokeMethod("openStreaming");', spaces=2))
  405. f.write(indented_str(4, "break;", spaces=2))
  406. else:
  407. f.write(indented_str(3, '// case "Streaming":', spaces=2))
  408. f.write(indented_str(4, '// nativeChannel.invokeMethod("openStreaming");', spaces=2))
  409. f.write(indented_str(4, "// break;", spaces=2))
  410. else:
  411. f.write(line)
  412. with open(main_act_android, "r") as f:
  413. lines = f.readlines()
  414. with open(main_act_android, "w") as f:
  415. for line in lines:
  416. if "//SECURITY" in line:
  417. if security["show_security"]:
  418. f.write(indented_str(2, "API.setShowSecurityShieldDialog(true);"))
  419. f.write(os.linesep)
  420. else:
  421. f.write(indented_str(2, "// API.setShowSecurityShieldDialog(true);"))
  422. f.write(os.linesep)
  423. if security["emulator"]:
  424. f.write(indented_str(2, "API.setCheckEmulator(true);"))
  425. f.write(os.linesep)
  426. else:
  427. f.write(indented_str(2, "// API.setCheckEmulator(true);"))
  428. f.write(os.linesep)
  429. if security["debug"]:
  430. f.write(indented_str(2, "API.setCheckAdb(true);"))
  431. f.write(os.linesep)
  432. if security["sim_swap"]:
  433. f.write(indented_str(2,
  434. "API.setCheckSimCardSwapListener(MainActivity.this, new SimCardDetectionCallback() {"))
  435. f.write(os.linesep)
  436. f.write(indented_str(3, "@Override"))
  437. f.write(indented_str(3, "public boolean onSimCardChange() {"))
  438. f.write(indented_str(4, "return false;"))
  439. f.write(indented_str(3, "}"))
  440. f.write(os.linesep)
  441. f.write(indented_str(3, "@Override"))
  442. f.write(indented_str(3, "public void onError(String s) {"))
  443. f.write(os.linesep)
  444. f.write(indented_str(3, "}"))
  445. f.write(indented_str(2, "});"))
  446. f.write(os.linesep)
  447. else:
  448. f.write(indented_str(2,
  449. "/* API.setCheckSimCardSwapListener(MainActivity.this, new SimCardDetectionCallback() {"))
  450. f.write(os.linesep)
  451. f.write(indented_str(3, "@Override"))
  452. f.write(indented_str(3, "public boolean onSimCardChange() {"))
  453. f.write(indented_str(4, "return false;"))
  454. f.write(indented_str(3, "}"))
  455. f.write(os.linesep)
  456. f.write(indented_str(3, "@Override"))
  457. f.write(indented_str(3, "public void onError(String s) {"))
  458. f.write(os.linesep)
  459. f.write(indented_str(3, "}"))
  460. f.write(indented_str(2, "}); */"))
  461. f.write(os.linesep)
  462. if security["malware"]:
  463. f.write(indented_str(2, "API.setCheckMalware(true);"))
  464. f.write(os.linesep)
  465. else:
  466. f.write(indented_str(2, "// API.setCheckMalware(true);"))
  467. f.write(os.linesep)
  468. if security["capture"]:
  469. f.write(indented_str(2, "API.setPreventScreenCapture(true);"))
  470. f.write(os.linesep)
  471. else:
  472. f.write(indented_str(2, "// API.setPreventScreenCapture(true);"))
  473. f.write(os.linesep)
  474. if security["call_forwarding"]:
  475. f.write(indented_str(2, "API.setCheckCallForwarding(true);"))
  476. f.write(os.linesep)
  477. else:
  478. f.write(indented_str(2, "// API.setCheckCallForwarding(true);"))
  479. f.write(os.linesep)
  480. if security["secure_folder"]:
  481. f.write(indented_str(2, "API.openSecureFolder();"))
  482. f.write(os.linesep)
  483. else:
  484. f.write(indented_str(2, "// API.openSecureFolder();"))
  485. f.write(os.linesep)
  486. elif "//SMS" in line:
  487. if features["sms"]["status"]:
  488. f.write(indented_str(2, "API.setEnabledSMS(true);"))
  489. else:
  490. f.write(indented_str(2, "// API.setEnabledSMS(true);"))
  491. elif "//EMAIL" in line:
  492. if features["email"]["status"]:
  493. f.write(indented_str(2, "API.setEnabledEmail(true);"))
  494. else:
  495. f.write(indented_str(2, "// API.setEnabledEmail(true);"))
  496. elif "//FLOATING" in line:
  497. if mode == "floating":
  498. f.write(indented_str(6, "ArrayList<FloatingButton> fb = new ArrayList<>();"))
  499. if features["cc"]["status"]:
  500. f.write(indented_str(6,
  501. 'fb.add(new FloatingButton(FloatingButton.FEATURE.CONTACT_CENTER, ""));'))
  502. else:
  503. f.write(indented_str(6,
  504. '// fb.add(new FloatingButton(FloatingButton.FEATURE.CONTACT_CENTER, ""));'))
  505. if features["nc"]["status"]:
  506. f.write(
  507. indented_str(6, 'fb.add(new FloatingButton(FloatingButton.FEATURE.NOTIF_CENTER, ""));'))
  508. else:
  509. f.write(indented_str(6,
  510. '// fb.add(new FloatingButton(FloatingButton.FEATURE.NOTIF_CENTER, ""));'))
  511. if features["im"]["status"]:
  512. f.write(
  513. indented_str(6, 'fb.add(new FloatingButton(FloatingButton.FEATURE.MESSAGING, ""));'))
  514. else:
  515. f.write(indented_str(6,
  516. '// fb.add(new FloatingButton(FloatingButton.FEATURE.MESSAGING, ""));'))
  517. if features["call"]["status"]:
  518. f.write(
  519. indented_str(6,
  520. 'fb.add(new FloatingButton(FloatingButton.FEATURE.AUDIO_VIDEO_CALL, ""));'))
  521. else:
  522. f.write(indented_str(6,
  523. '// fb.add(new FloatingButton(FloatingButton.FEATURE.AUDIO_VIDEO_CALL, ""));'))
  524. if features["ls"]["status"]:
  525. f.write(
  526. indented_str(6, 'fb.add(new FloatingButton(FloatingButton.FEATURE.STREAMING, ""));'))
  527. else:
  528. f.write(indented_str(6,
  529. '// fb.add(new FloatingButton(FloatingButton.FEATURE.STREAMING, ""));'))
  530. f.write(indented_str(6,
  531. 'API.configureFloating(fb);'))
  532. else:
  533. f.write(indented_str(0, ""))
  534. elif "API.connect" in line:
  535. if mode == "floating":
  536. replaced = line.replace("0", "1")
  537. f.write(replaced)
  538. else:
  539. f.write(line)
  540. else:
  541. f.write(line)
  542. elif platform == "android_ionic":
  543. main_act_path = os.path.join(path_dest,"src/app/app.component.ts")
  544. with open(main_act_path, "r") as f:
  545. lines = f.readlines()
  546. with open(main_act_path, "w") as f:
  547. for line in lines:
  548. if "//FEATURES" in line:
  549. f.write(indented_str(4, '{', spaces=2))
  550. f.write(indented_str(5, "text: 'Settings',", spaces=2))
  551. f.write(indented_str(5, "handler: () => {", spaces=2))
  552. f.write(indented_str(6, "this.openSettings();", spaces=2))
  553. f.write(indented_str(5, "},", spaces=2))
  554. f.write(indented_str(4, "},", spaces=2))
  555. f.write(indented_str(4, '{', spaces=2))
  556. f.write(indented_str(5, "text: 'Profile',", spaces=2))
  557. f.write(indented_str(5, "handler: () => {", spaces=2))
  558. f.write(indented_str(6, "this.openProfile();", spaces=2))
  559. f.write(indented_str(5, "},", spaces=2))
  560. f.write(indented_str(4, "},", spaces=2))
  561. if features["cc"]["status"]:
  562. f.write(indented_str(4, '{', spaces=2))
  563. f.write(indented_str(5, "text: 'Contact Center',", spaces=2))
  564. f.write(indented_str(5, "handler: () => {", spaces=2))
  565. f.write(indented_str(6, "this.openContactCenter();", spaces=2))
  566. f.write(indented_str(5, "},", spaces=2))
  567. f.write(indented_str(4, "},", spaces=2))
  568. else:
  569. f.write(indented_str(4, '// {', spaces=2))
  570. f.write(indented_str(5, "// text: 'Contact Center',", spaces=2))
  571. f.write(indented_str(5, "// handler: () => {", spaces=2))
  572. f.write(indented_str(6, "// this.openContactCenter();", spaces=2))
  573. f.write(indented_str(5, "// },", spaces=2))
  574. f.write(indented_str(4, "// },", spaces=2))
  575. if features["nc"]["status"]:
  576. f.write(indented_str(4, '{', spaces=2))
  577. f.write(indented_str(5, "text: 'Notification Center',", spaces=2))
  578. f.write(indented_str(5, "handler: () => {", spaces=2))
  579. f.write(indented_str(6, "this.openNotificationCenter();", spaces=2))
  580. f.write(indented_str(5, "},", spaces=2))
  581. f.write(indented_str(4, "},", spaces=2))
  582. else:
  583. f.write(indented_str(4, '// {', spaces=2))
  584. f.write(indented_str(5, "// text: 'Notification Center',", spaces=2))
  585. f.write(indented_str(5, "// handler: () => {", spaces=2))
  586. f.write(indented_str(6, "// this.openNotificationCenter();", spaces=2))
  587. f.write(indented_str(5, "// },", spaces=2))
  588. f.write(indented_str(4, "// },", spaces=2))
  589. if features["im"]["status"]:
  590. f.write(indented_str(4, '{', spaces=2))
  591. f.write(indented_str(5, "text: 'Instant Messaging',", spaces=2))
  592. f.write(indented_str(5, "handler: () => {", spaces=2))
  593. f.write(indented_str(6, "this.openChat();", spaces=2))
  594. f.write(indented_str(5, "},", spaces=2))
  595. f.write(indented_str(4, "},", spaces=2))
  596. else:
  597. f.write(indented_str(4, '// {', spaces=2))
  598. f.write(indented_str(5, "// text: 'Instant Messaging',", spaces=2))
  599. f.write(indented_str(5, "// handler: () => {", spaces=2))
  600. f.write(indented_str(6, "// this.openChat();", spaces=2))
  601. f.write(indented_str(5, "// },", spaces=2))
  602. f.write(indented_str(4, "// },", spaces=2))
  603. if features["call"]["status"]:
  604. f.write(indented_str(4, '{', spaces=2))
  605. f.write(indented_str(5, "text: 'Call',", spaces=2))
  606. f.write(indented_str(5, "handler: () => {", spaces=2))
  607. f.write(indented_str(6, "this.openCall();", spaces=2))
  608. f.write(indented_str(5, "},", spaces=2))
  609. f.write(indented_str(4, "},", spaces=2))
  610. else:
  611. f.write(indented_str(4, '// {', spaces=2))
  612. f.write(indented_str(5, "// text: 'Call',", spaces=2))
  613. f.write(indented_str(5, "// handler: () => {", spaces=2))
  614. f.write(indented_str(6, "// this.openCall();", spaces=2))
  615. f.write(indented_str(5, "// },", spaces=2))
  616. f.write(indented_str(4, "// },", spaces=2))
  617. if features["ls"]["status"]:
  618. f.write(indented_str(4, '{', spaces=2))
  619. f.write(indented_str(5, "text: 'Streaming',", spaces=2))
  620. f.write(indented_str(5, "handler: () => {", spaces=2))
  621. f.write(indented_str(6, "this.openStreaming();", spaces=2))
  622. f.write(indented_str(5, "},", spaces=2))
  623. f.write(indented_str(4, "},", spaces=2))
  624. else:
  625. f.write(indented_str(4, '// {', spaces=2))
  626. f.write(indented_str(5, "// text: 'Streaming',", spaces=2))
  627. f.write(indented_str(5, "// handler: () => {", spaces=2))
  628. f.write(indented_str(6, "// this.openStreaming();", spaces=2))
  629. f.write(indented_str(5, "// },", spaces=2))
  630. f.write(indented_str(4, "// },", spaces=2))
  631. else:
  632. f.write(line)
  633. elif platform == "android_react":
  634. main_act_path = os.path.join(path_dest, "App.tsx")
  635. with open(main_act_path, "r") as f:
  636. lines = f.readlines()
  637. with open(main_act_path, "w") as f:
  638. for line in lines:
  639. if "'Features'" in line:
  640. f.write(indented_str(4, "'Setting',", spaces=2))
  641. f.write(indented_str(4, "'Profile',", spaces=2))
  642. if features["cc"]["status"]:
  643. f.write(indented_str(4, "'Contact Center',", spaces=2))
  644. else:
  645. f.write(indented_str(4, "// 'Contact Center',", spaces=2))
  646. if features["nc"]["status"]:
  647. f.write(indented_str(4, "'Notification Center',", spaces=2))
  648. else:
  649. f.write(indented_str(4, "// 'Notification Center',", spaces=2))
  650. if features["im"]["status"]:
  651. f.write(indented_str(4, "'Chat',", spaces=2))
  652. else:
  653. f.write(indented_str(4, "// 'Chat',", spaces=2))
  654. if features["call"]["status"]:
  655. f.write(indented_str(4, "'Call',", spaces=2))
  656. else:
  657. f.write(indented_str(4, "// 'Call',", spaces=2))
  658. if features["ls"]["status"]:
  659. f.write(indented_str(4, "'Live Streaming',", spaces=2))
  660. else:
  661. f.write(indented_str(4, "// 'Live Streaming',", spaces=2))
  662. elif "//FEATURES1" in line:
  663. n = 0
  664. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  665. f.write(indented_str(6, "CallNative.openSetting();", spaces=2))
  666. f.write(indented_str(5, "}", spaces=2))
  667. n = n + 1
  668. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  669. f.write(indented_str(6, "CallNative.openProfile();", spaces=2))
  670. f.write(indented_str(5, "}", spaces=2))
  671. n = n + 1
  672. if features["cc"]["status"]:
  673. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  674. f.write(indented_str(6, "CallNative.openContactCenter();", spaces=2))
  675. f.write(indented_str(5, "}", spaces=2))
  676. n = n + 1
  677. else:
  678. f.write(indented_str(5, "// if (buttonIndex === 2) {", spaces=2))
  679. f.write(indented_str(6, "// CallNative.openContactCenter();", spaces=2))
  680. f.write(indented_str(5, "// }", spaces=2))
  681. if features["nc"]["status"]:
  682. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  683. f.write(indented_str(6, "CallNative.openNotificationCenter();", spaces=2))
  684. f.write(indented_str(5, "}", spaces=2))
  685. n = n + 1
  686. else:
  687. f.write(indented_str(5, "// if (buttonIndex === 3) {", spaces=2))
  688. f.write(indented_str(6, "// CallNative.openNotificationCenter();", spaces=2))
  689. f.write(indented_str(5, "// }", spaces=2))
  690. if features["im"]["status"]:
  691. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  692. f.write(indented_str(6, "CallNative.openChat();", spaces=2))
  693. f.write(indented_str(5, "}", spaces=2))
  694. n = n + 1
  695. else:
  696. f.write(indented_str(5, "// if (buttonIndex === 4) {", spaces=2))
  697. f.write(indented_str(6, "// CallNative.openChat();", spaces=2))
  698. f.write(indented_str(5, "// }", spaces=2))
  699. if features["call"]["status"]:
  700. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  701. f.write(indented_str(6, "CallNative.openCall();", spaces=2))
  702. f.write(indented_str(5, "}", spaces=2))
  703. n = n + 1
  704. else:
  705. f.write(indented_str(5, "// if (buttonIndex === 5) {", spaces=2))
  706. f.write(indented_str(6, "// CallNative.openCall();", spaces=2))
  707. f.write(indented_str(5, "// }", spaces=2))
  708. if features["ls"]["status"]:
  709. f.write(indented_str(5, f"if (buttonIndex === {n}) {{", spaces=2))
  710. f.write(indented_str(6, "CallNative.openStreaming();", spaces=2))
  711. f.write(indented_str(5, "}", spaces=2))
  712. n = n + 1
  713. else:
  714. f.write(indented_str(5, "// if (buttonIndex === 6) {", spaces=2))
  715. f.write(indented_str(6, "// CallNative.openStreaming();", spaces=2))
  716. f.write(indented_str(5, "// }", spaces=2))
  717. elif "//FEATURES2" in line:
  718. n = 0
  719. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  720. f.write(indented_str(3, "try {", spaces=2))
  721. f.write(indented_str(4, "CallNative.openSetting();", spaces=2))
  722. f.write(indented_str(3, "} catch (e) {", spaces=2))
  723. f.write(indented_str(4, "console.log(e);", spaces=2))
  724. f.write(indented_str(3, "}", spaces=2))
  725. f.write(indented_str(2, "}", spaces=2))
  726. n = n + 1
  727. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  728. f.write(indented_str(3, "try {", spaces=2))
  729. f.write(indented_str(4, "CallNative.openProfile();", spaces=2))
  730. f.write(indented_str(3, "} catch (e) {", spaces=2))
  731. f.write(indented_str(4, "console.log(e);", spaces=2))
  732. f.write(indented_str(3, "}", spaces=2))
  733. f.write(indented_str(2, "}", spaces=2))
  734. n = n + 1
  735. if features["cc"]["status"]:
  736. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  737. f.write(indented_str(3, "try {", spaces=2))
  738. f.write(indented_str(4, "CallNative.openContactCenter();", spaces=2))
  739. f.write(indented_str(3, "} catch (e) {", spaces=2))
  740. f.write(indented_str(4, "console.log(e);", spaces=2))
  741. f.write(indented_str(3, "}", spaces=2))
  742. f.write(indented_str(2, "}", spaces=2))
  743. n = n + 1
  744. else:
  745. f.write(indented_str(2, "// if (buttonIndex === 2) {", spaces=2))
  746. f.write(indented_str(3, "// try {", spaces=2))
  747. f.write(indented_str(4, "// CallNative.openContactCenter();", spaces=2))
  748. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  749. f.write(indented_str(4, "// console.log(e);", spaces=2))
  750. f.write(indented_str(3, "// }", spaces=2))
  751. f.write(indented_str(2, "// }", spaces=2))
  752. if features["nc"]["status"]:
  753. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  754. f.write(indented_str(3, "try {", spaces=2))
  755. f.write(indented_str(4, "CallNative.openNotificationCenter();", spaces=2))
  756. f.write(indented_str(3, "} catch (e) {", spaces=2))
  757. f.write(indented_str(4, "console.log(e);", spaces=2))
  758. f.write(indented_str(3, "}", spaces=2))
  759. f.write(indented_str(2, "}", spaces=2))
  760. n = n + 1
  761. else:
  762. f.write(indented_str(2, "// if (buttonIndex === 3) {", spaces=2))
  763. f.write(indented_str(3, "// try {", spaces=2))
  764. f.write(indented_str(4, "// CallNative.openNotificationCenter();", spaces=2))
  765. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  766. f.write(indented_str(4, "// console.log(e);", spaces=2))
  767. f.write(indented_str(3, "// }", spaces=2))
  768. f.write(indented_str(2, "// }", spaces=2))
  769. if features["im"]["status"]:
  770. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  771. f.write(indented_str(3, "try {", spaces=2))
  772. f.write(indented_str(4, "CallNative.openChat();", spaces=2))
  773. f.write(indented_str(3, "} catch (e) {", spaces=2))
  774. f.write(indented_str(4, "console.log(e);", spaces=2))
  775. f.write(indented_str(3, "}", spaces=2))
  776. f.write(indented_str(2, "}", spaces=2))
  777. n = n + 1
  778. else:
  779. f.write(indented_str(2, "// if (buttonIndex === 4) {", spaces=2))
  780. f.write(indented_str(3, "// try {", spaces=2))
  781. f.write(indented_str(4, "// CallNative.openChat();", spaces=2))
  782. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  783. f.write(indented_str(4, "// console.log(e);", spaces=2))
  784. f.write(indented_str(3, "// }", spaces=2))
  785. f.write(indented_str(2, "// }", spaces=2))
  786. if features["call"]["status"]:
  787. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  788. f.write(indented_str(3, "try {", spaces=2))
  789. f.write(indented_str(4, "CallNative.openCall();", spaces=2))
  790. f.write(indented_str(3, "} catch (e) {", spaces=2))
  791. f.write(indented_str(4, "console.log(e);", spaces=2))
  792. f.write(indented_str(3, "}", spaces=2))
  793. f.write(indented_str(2, "}", spaces=2))
  794. n = n + 1
  795. else:
  796. f.write(indented_str(2, "// if (buttonIndex === 5) {", spaces=2))
  797. f.write(indented_str(3, "// try {", spaces=2))
  798. f.write(indented_str(4, "// CallNative.openCall();", spaces=2))
  799. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  800. f.write(indented_str(4, "// console.log(e);", spaces=2))
  801. f.write(indented_str(3, "// }", spaces=2))
  802. f.write(indented_str(2, "// }", spaces=2))
  803. if features["ls"]["status"]:
  804. f.write(indented_str(2, f"if (buttonIndex === {n}) {{", spaces=2))
  805. f.write(indented_str(3, "try {", spaces=2))
  806. f.write(indented_str(4, "CallNative.openStreaming();", spaces=2))
  807. f.write(indented_str(3, "} catch (e) {", spaces=2))
  808. f.write(indented_str(4, "console.log(e);", spaces=2))
  809. f.write(indented_str(3, "}", spaces=2))
  810. f.write(indented_str(2, "}", spaces=2))
  811. n = n + 1
  812. else:
  813. f.write(indented_str(2, "// if (buttonIndex === {n}) {", spaces=2))
  814. f.write(indented_str(3, "// try {", spaces=2))
  815. f.write(indented_str(4, "// CallNative.openStreaming();", spaces=2))
  816. f.write(indented_str(3, "// } catch (e) {", spaces=2))
  817. f.write(indented_str(4, "// console.log(e);", spaces=2))
  818. f.write(indented_str(3, "// }", spaces=2))
  819. f.write(indented_str(2, "// }", spaces=2))
  820. elif "//FEATURES3" in line:
  821. n = 0
  822. f.write(indented_str(5, "<Button", spaces=2))
  823. f.write(indented_str(6, 'title="Setting"', spaces=2))
  824. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  825. f.write(indented_str(5, "/>", spaces=2))
  826. n = n + 1
  827. f.write(indented_str(5, "<Button", spaces=2))
  828. f.write(indented_str(6, 'title="Profile"', spaces=2))
  829. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  830. f.write(indented_str(5, "/>", spaces=2))
  831. n = n + 1
  832. if features["cc"]["status"]:
  833. f.write(indented_str(5, "<Button", spaces=2))
  834. f.write(indented_str(6, 'title="Contact Center"', spaces=2))
  835. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  836. f.write(indented_str(5, "/>", spaces=2))
  837. n = n + 1
  838. else:
  839. f.write(indented_str(5, "{/* <Button", spaces=2))
  840. f.write(indented_str(6, 'title="Contact Center"', spaces=2))
  841. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(2)}}', spaces=2))
  842. f.write(indented_str(5, "/> */}", spaces=2))
  843. if features["nc"]["status"]:
  844. f.write(indented_str(5, "<Button", spaces=2))
  845. f.write(indented_str(6, 'title="Notification Center"', spaces=2))
  846. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  847. f.write(indented_str(5, "/>", spaces=2))
  848. n = n + 1
  849. else:
  850. f.write(indented_str(5, "{/* <Button", spaces=2))
  851. f.write(indented_str(6, 'title="Notification Center"', spaces=2))
  852. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(3)}}', spaces=2))
  853. f.write(indented_str(5, "/> */}", spaces=2))
  854. if features["im"]["status"]:
  855. f.write(indented_str(5, "<Button", spaces=2))
  856. f.write(indented_str(6, 'title="Chat"', spaces=2))
  857. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  858. f.write(indented_str(5, "/>", spaces=2))
  859. n = n + 1
  860. else:
  861. f.write(indented_str(5, "{/* <Button", spaces=2))
  862. f.write(indented_str(6, 'title="Chat"', spaces=2))
  863. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(4)}}', spaces=2))
  864. f.write(indented_str(5, "/> */}", spaces=2))
  865. if features["call"]["status"]:
  866. f.write(indented_str(5, "<Button", spaces=2))
  867. f.write(indented_str(6, 'title="Call"', spaces=2))
  868. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  869. f.write(indented_str(5, "/>", spaces=2))
  870. n = n + 1
  871. else:
  872. f.write(indented_str(5, "{/* <Button", spaces=2))
  873. f.write(indented_str(6, 'title="Call"', spaces=2))
  874. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(5)}}', spaces=2))
  875. f.write(indented_str(5, "/> */}", spaces=2))
  876. if features["ls"]["status"]:
  877. f.write(indented_str(5, "<Button", spaces=2))
  878. f.write(indented_str(6, 'title="Live Streaming"', spaces=2))
  879. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress({n})}}', spaces=2))
  880. f.write(indented_str(5, "/>", spaces=2))
  881. n = n + 1
  882. else:
  883. f.write(indented_str(5, "{/* <Button", spaces=2))
  884. f.write(indented_str(6, 'title="Live Streaming"', spaces=2))
  885. f.write(indented_str(6, f'onPress={{() => handleActionSheetPress(5)}}', spaces=2))
  886. f.write(indented_str(5, "/> */}", spaces=2))
  887. else:
  888. f.write(line)
  889. elif platform == "ios":
  890. main_act_path = os.path.join(path_dest, "ExampleCode/ViewController.swift")
  891. with open(main_act_path, "r") as f:
  892. lines = f.readlines()
  893. with open(main_act_path, "w") as f:
  894. for line in lines:
  895. if "//FEATURES" in line:
  896. f.write(indented_str(3, 'UIAction(title: "Setting".localized(), handler: {(_) in'))
  897. f.write(indented_str(4, "APIS.openSetting();"))
  898. f.write(indented_str(3, "}),"))
  899. f.write(indented_str(3, 'UIAction(title: "Profile".localized(), handler: {(_) in'))
  900. f.write(indented_str(4, "APIS.openProfile();"))
  901. f.write(indented_str(3, "}),"))
  902. if features["cc"]["status"]:
  903. f.write(indented_str(3, 'UIAction(title: "Contact Center".localized(), handler: {(_) in'))
  904. f.write(indented_str(4, "APIS.openContactCenter();"))
  905. f.write(indented_str(3, "}),"))
  906. else:
  907. f.write(indented_str(3, '// UIAction(title: "Contact Center".localized(), handler: {(_) in'))
  908. f.write(indented_str(4, "// APIS.openContactCenter();"))
  909. f.write(indented_str(3, "// }),"))
  910. if features["nc"]["status"]:
  911. f.write(indented_str(3, 'UIAction(title: "Notification Center".localized(), handler: {(_) in'))
  912. f.write(indented_str(4, "APIS.openNotificationCenter();"))
  913. f.write(indented_str(3, "}),"))
  914. else:
  915. f.write(indented_str(3, '// UIAction(title: "Notification Center".localized(), handler: {(_) in'))
  916. f.write(indented_str(4, "// APIS.openNotificationCenter();"))
  917. f.write(indented_str(3, "// }),"))
  918. if features["im"]["status"]:
  919. f.write(indented_str(3, 'UIAction(title: "Chat".localized(), handler: {(_) in'))
  920. f.write(indented_str(4, "APIS.openChat();"))
  921. f.write(indented_str(3, "}),"))
  922. else:
  923. f.write(indented_str(3, '// UIAction(title: "Chat".localized(), handler: {(_) in'))
  924. f.write(indented_str(4, "// APIS.openChat();"))
  925. f.write(indented_str(3, "// }),"))
  926. if features["call"]["status"]:
  927. f.write(indented_str(3, 'UIAction(title: "Call".localized(), handler: {(_) in'))
  928. f.write(indented_str(4, "APIS.openCall();"))
  929. f.write(indented_str(3, "}),"))
  930. else:
  931. f.write(indented_str(3, '// UIAction(title: "Call".localized(), handler: {(_) in'))
  932. f.write(indented_str(4, "// APIS.openCall();"))
  933. f.write(indented_str(3, "// }),"))
  934. if features["ls"]["status"]:
  935. f.write(indented_str(3, 'UIAction(title: "Live Streaming".localized(), handler: {(_) in'))
  936. f.write(indented_str(4, "APIS.openStreaming();"))
  937. f.write(indented_str(3, "}),"))
  938. else:
  939. f.write(indented_str(3, '// UIAction(title: "Live Streaming".localized(), handler: {(_) in'))
  940. f.write(indented_str(4, "// APIS.openStreaming();"))
  941. f.write(indented_str(3, "// }),"))
  942. else:
  943. f.write(line)
  944. elif platform == "ios_flutter":
  945. main_act_path = os.path.join(path_dest, "lib/main.dart")
  946. with open(main_act_path, "r") as f:
  947. lines = f.readlines()
  948. with open(main_act_path, "w") as f:
  949. features_str = []
  950. for line in lines:
  951. if "'Features List'" in line:
  952. features_str.append("Settings")
  953. features_str.append("Profile")
  954. if features["cc"]["status"]:
  955. features_str.append("'Contact Center'")
  956. else:
  957. features_str.append("// 'Contact Center'")
  958. if features["nc"]["status"]:
  959. features_str.append("'Notification Center'")
  960. else:
  961. features_str.append("// 'Notification Center'")
  962. if features["im"]["status"]:
  963. features_str.append("'Instant Messaging'")
  964. else:
  965. features_str.append("// 'Instant Messaging'")
  966. if features["call"]["status"]:
  967. features_str.append("'Call'")
  968. else:
  969. features_str.append("// 'Call'")
  970. if features["ls"]["status"]:
  971. features_str.append("'Streaming'")
  972. else:
  973. features_str.append("// 'Streaming'")
  974. for feature_str in features_str:
  975. f.write(indented_str(8, f"{feature_str},", spaces=2))
  976. elif "//FEATURES" in line:
  977. f.write(indented_str(3, 'case "Settings":', spaces=2))
  978. f.write(indented_str(4, 'nativeChannel.invokeMethod("openSettings");', spaces=2))
  979. f.write(indented_str(4, "break;", spaces=2))
  980. f.write(indented_str(3, 'case "Profile":', spaces=2))
  981. f.write(indented_str(4, 'nativeChannel.invokeMethod("openProfile");', spaces=2))
  982. f.write(indented_str(4, "break;", spaces=2))
  983. if features["cc"]["status"]:
  984. f.write(indented_str(3, 'case "Contact Center":', spaces=2))
  985. f.write(indented_str(4, 'nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  986. f.write(indented_str(4, "break;", spaces=2))
  987. else:
  988. f.write(indented_str(3, '// case "Contact Center":', spaces=2))
  989. f.write(indented_str(4, '// nativeChannel.invokeMethod("openContactCenter");', spaces=2))
  990. f.write(indented_str(4, "// break;", spaces=2))
  991. if features["nc"]["status"]:
  992. f.write(indented_str(3, 'case "Notification Center":', spaces=2))
  993. f.write(indented_str(4, 'nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  994. f.write(indented_str(4, "break;", spaces=2))
  995. else:
  996. f.write(indented_str(3, '// case "Notification Center":', spaces=2))
  997. f.write(indented_str(4, '// nativeChannel.invokeMethod("openNotificationCenter");', spaces=2))
  998. f.write(indented_str(4, "// break;", spaces=2))
  999. if features["im"]["status"]:
  1000. f.write(indented_str(3, 'case "Instant Messaging":', spaces=2))
  1001. f.write(indented_str(4, 'nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  1002. f.write(indented_str(4, "break;", spaces=2))
  1003. else:
  1004. f.write(indented_str(3, '// case "Instant Messaging":', spaces=2))
  1005. f.write(indented_str(4, '// nativeChannel.invokeMethod("openInstantMessaging");', spaces=2))
  1006. f.write(indented_str(4, "// break;", spaces=2))
  1007. if features["call"]["status"]:
  1008. f.write(indented_str(3, 'case "Call":', spaces=2))
  1009. f.write(indented_str(4, 'nativeChannel.invokeMethod("openCall");', spaces=2))
  1010. f.write(indented_str(4, "break;", spaces=2))
  1011. else:
  1012. f.write(indented_str(3, '// case "Call":', spaces=2))
  1013. f.write(indented_str(4, '// nativeChannel.invokeMethod("openCall");', spaces=2))
  1014. f.write(indented_str(4, "// break;", spaces=2))
  1015. if features["ls"]["status"]:
  1016. f.write(indented_str(3, 'case "Streaming":', spaces=2))
  1017. f.write(indented_str(4, 'nativeChannel.invokeMethod("openStreaming");', spaces=2))
  1018. f.write(indented_str(4, "break;", spaces=2))
  1019. else:
  1020. f.write(indented_str(3, '// case "Streaming":', spaces=2))
  1021. f.write(indented_str(4, '// nativeChannel.invokeMethod("openStreaming");', spaces=2))
  1022. f.write(indented_str(4, "// break;", spaces=2))
  1023. else:
  1024. f.write(line)
  1025. elif platform == "ios_ionic":
  1026. main_act_path = os.path.join(path_dest, "src/app/app.component.ts")
  1027. with open(main_act_path, "r") as f:
  1028. lines = f.readlines()
  1029. with open(main_act_path, "w") as f:
  1030. for line in lines:
  1031. if "//FEATURES" in line:
  1032. f.write(indented_str(4, '{', spaces=2))
  1033. f.write(indented_str(5, "text: 'Settings',", spaces=2))
  1034. f.write(indented_str(5, "handler: () => {", spaces=2))
  1035. f.write(indented_str(6, "this.openSettings();", spaces=2))
  1036. f.write(indented_str(5, "},", spaces=2))
  1037. f.write(indented_str(4, "},", spaces=2))
  1038. f.write(indented_str(4, '{', spaces=2))
  1039. f.write(indented_str(5, "text: 'Profile',", spaces=2))
  1040. f.write(indented_str(5, "handler: () => {", spaces=2))
  1041. f.write(indented_str(6, "this.openProfile();", spaces=2))
  1042. f.write(indented_str(5, "},", spaces=2))
  1043. f.write(indented_str(4, "},", spaces=2))
  1044. if features["cc"]["status"]:
  1045. f.write(indented_str(4, '{', spaces=2))
  1046. f.write(indented_str(5, "text: 'Contact Center',", spaces=2))
  1047. f.write(indented_str(5, "handler: () => {", spaces=2))
  1048. f.write(indented_str(6, "this.openContactCenter();", spaces=2))
  1049. f.write(indented_str(5, "},", spaces=2))
  1050. f.write(indented_str(4, "},", spaces=2))
  1051. else:
  1052. f.write(indented_str(4, '// {', spaces=2))
  1053. f.write(indented_str(5, "// text: 'Contact Center',", spaces=2))
  1054. f.write(indented_str(5, "// handler: () => {", spaces=2))
  1055. f.write(indented_str(6, "// this.openContactCenter();", spaces=2))
  1056. f.write(indented_str(5, "// },", spaces=2))
  1057. f.write(indented_str(4, "// },", spaces=2))
  1058. if features["nc"]["status"]:
  1059. f.write(indented_str(4, '{', spaces=2))
  1060. f.write(indented_str(5, "text: 'Notification Center',", spaces=2))
  1061. f.write(indented_str(5, "handler: () => {", spaces=2))
  1062. f.write(indented_str(6, "this.openNotificationCenter();", spaces=2))
  1063. f.write(indented_str(5, "},", spaces=2))
  1064. f.write(indented_str(4, "},", spaces=2))
  1065. else:
  1066. f.write(indented_str(4, '// {', spaces=2))
  1067. f.write(indented_str(5, "// text: 'Notification Center',", spaces=2))
  1068. f.write(indented_str(5, "// handler: () => {", spaces=2))
  1069. f.write(indented_str(6, "// this.openNotificationCenter();", spaces=2))
  1070. f.write(indented_str(5, "// },", spaces=2))
  1071. f.write(indented_str(4, "// },", spaces=2))
  1072. if features["im"]["status"]:
  1073. f.write(indented_str(4, '{', spaces=2))
  1074. f.write(indented_str(5, "text: 'Instant Messaging',", spaces=2))
  1075. f.write(indented_str(5, "handler: () => {", spaces=2))
  1076. f.write(indented_str(6, "this.openChat();", spaces=2))
  1077. f.write(indented_str(5, "},", spaces=2))
  1078. f.write(indented_str(4, "},", spaces=2))
  1079. else:
  1080. f.write(indented_str(4, '// {', spaces=2))
  1081. f.write(indented_str(5, "// text: 'Instant Messaging',", spaces=2))
  1082. f.write(indented_str(5, "// handler: () => {", spaces=2))
  1083. f.write(indented_str(6, "// this.openChat();", spaces=2))
  1084. f.write(indented_str(5, "// },", spaces=2))
  1085. f.write(indented_str(4, "// },", spaces=2))
  1086. if features["call"]["status"]:
  1087. f.write(indented_str(4, '{', spaces=2))
  1088. f.write(indented_str(5, "text: 'Call',", spaces=2))
  1089. f.write(indented_str(5, "handler: () => {", spaces=2))
  1090. f.write(indented_str(6, "this.openCall();", spaces=2))
  1091. f.write(indented_str(5, "},", spaces=2))
  1092. f.write(indented_str(4, "},", spaces=2))
  1093. else:
  1094. f.write(indented_str(4, '// {', spaces=2))
  1095. f.write(indented_str(5, "// text: 'Call',", spaces=2))
  1096. f.write(indented_str(5, "// handler: () => {", spaces=2))
  1097. f.write(indented_str(6, "// this.openCall();", spaces=2))
  1098. f.write(indented_str(5, "// },", spaces=2))
  1099. f.write(indented_str(4, "// },", spaces=2))
  1100. if features["ls"]["status"]:
  1101. f.write(indented_str(4, '{', spaces=2))
  1102. f.write(indented_str(5, "text: 'Streaming',", spaces=2))
  1103. f.write(indented_str(5, "handler: () => {", spaces=2))
  1104. f.write(indented_str(6, "this.openStreaming();", spaces=2))
  1105. f.write(indented_str(5, "},", spaces=2))
  1106. f.write(indented_str(4, "},", spaces=2))
  1107. else:
  1108. f.write(indented_str(4, '// {', spaces=2))
  1109. f.write(indented_str(5, "// text: 'Streaming',", spaces=2))
  1110. f.write(indented_str(5, "// handler: () => {", spaces=2))
  1111. f.write(indented_str(6, "// this.openStreaming();", spaces=2))
  1112. f.write(indented_str(5, "// },", spaces=2))
  1113. f.write(indented_str(4, "// },", spaces=2))
  1114. else:
  1115. f.write(line)
  1116. elif platform == "ios_react":
  1117. pass
  1118. def deliver_zip(path_dest, uid):
  1119. rand_name = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(32))
  1120. zip_name = f"{rand_name}"
  1121. new_dir = os.path.join(app.zip_folder, zip_name)
  1122. try:
  1123. shutil.make_archive(new_dir, 'zip', path_dest)
  1124. project_path = os.path.join(app.temp_folder, uid)
  1125. shutil.rmtree(project_path)
  1126. return {"status": "0", "name": zip_name + ".zip"}
  1127. except Exception as e:
  1128. return {"status": "4", "message": "Deliver ZIP failed"}
  1129. @app.route('/', methods=["GET", "POST"])
  1130. def build_project():
  1131. vprint('==============================================================')
  1132. if request.method == 'POST':
  1133. platform = "android_flutter"
  1134. mode = "burger"
  1135. feature_dict = {
  1136. "im": {
  1137. "android_name": "action_chats",
  1138. "status": False
  1139. },
  1140. "cc": {
  1141. "android_name": "action_cc",
  1142. "status": False
  1143. },
  1144. "call": {
  1145. "android_name": "action_call",
  1146. "status": False
  1147. },
  1148. "ls": {
  1149. "android_name": "action_ls",
  1150. "status": False
  1151. },
  1152. "settings": {
  1153. "android_name": "action_settings",
  1154. "status": False
  1155. },
  1156. "nc": {
  1157. "android_name": "action_nc",
  1158. "status": False
  1159. },
  1160. "sms": {
  1161. "status": False
  1162. },
  1163. "email": {
  1164. "status": False
  1165. },
  1166. }
  1167. security_dict = {
  1168. "malware": False,
  1169. "clone": False,
  1170. "emulator": False,
  1171. "debug": False,
  1172. "sim_swap": False,
  1173. "capture": False,
  1174. "call_forwarding": False,
  1175. "secure_folder": False,
  1176. "show_security": False,
  1177. }
  1178. try:
  1179. if "feature_im" in request.form:
  1180. feature_dict["im"]["status"] = request.form["feature_im"] == "1"
  1181. if "feature_cc" in request.form:
  1182. feature_dict["cc"]["status"] = request.form["feature_cc"] == "1"
  1183. if "feature_vc" in request.form:
  1184. feature_dict["call"]["status"] = request.form["feature_vc"] == "1"
  1185. if "feature_ac" in request.form:
  1186. feature_dict["call"]["status"] = request.form["feature_ac"] == "1"
  1187. if "feature_ls" in request.form:
  1188. feature_dict["ls"]["status"] = request.form["feature_ls"] == "1"
  1189. if "feature_nc" in request.form:
  1190. feature_dict["nc"]["status"] = request.form["feature_nc"] == "1"
  1191. if "feature_sms" in request.form:
  1192. feature_dict["sms"]["status"] = request.form["feature_sms"] == "1"
  1193. if "feature_email" in request.form:
  1194. feature_dict["email"]["status"] = request.form["feature_email"] == "1"
  1195. if "feature_settings" in request.form:
  1196. feature_dict["settings"]["status"] = request.form["feature_settings"] == "1"
  1197. if "security_malware" in request.form:
  1198. security_dict["malware"] = request.form["security_malware"] == "1"
  1199. if "security_clone" in request.form:
  1200. security_dict["clone"] = request.form["security_clone"] == "1"
  1201. if "security_emulator" in request.form:
  1202. security_dict["emulator"] = request.form["security_emulator"] == "1"
  1203. if "security_debug" in request.form:
  1204. security_dict["debug"] = request.form["security_debug"] == "1"
  1205. if "security_sim_swap" in request.form:
  1206. security_dict["sim_swap"] = request.form["security_sim_swap"] == "1"
  1207. if "security_capture" in request.form:
  1208. security_dict["capture"] = request.form["security_capture"] == "1"
  1209. if "security_call_forwarding" in request.form:
  1210. security_dict["call_forwarding"] = request.form["security_call_forwarding"] == "1"
  1211. if "security_secure_folder" in request.form:
  1212. security_dict["secure_folder"] = request.form["security_secure_folder"] == "1"
  1213. if "show_security" in request.form:
  1214. security_dict["show_security"] = request.form["show_security"] == "1"
  1215. else:
  1216. security_dict["show_security"] = (security_dict["malware"] or security_dict["clone"]
  1217. or security_dict["emulator"] or security_dict["debug"]
  1218. or security_dict["sim_swap"] or security_dict["capture"]
  1219. or security_dict["call_forwarding"]
  1220. or security_dict["secure_folder"])
  1221. if "platform" in request.form:
  1222. platform = request.form["platform"]
  1223. if "mode" in request.form:
  1224. mode = request.form["mode"]
  1225. except BaseException as e:
  1226. vprint(traceback.format_exc())
  1227. return {"status": "1", "message": "Parameter mismatch\n{}\n".format(str(e))}, 400
  1228. try:
  1229. uu_id = str(uuid.uuid4())
  1230. path_dest = create_folder(platform, uu_id)
  1231. change(platform, mode, path_dest, feature_dict, security_dict)
  1232. return deliver_zip(path_dest, uu_id)
  1233. except BaseException as e:
  1234. vprint(traceback.format_exc())
  1235. return {"status": "2", "message": "Process failure\n{}\n".format(str(e))}, 200
  1236. else:
  1237. if 'e' in request.args:
  1238. return request.args['e']
  1239. return "Hello World!"
  1240. if __name__ == '__main__':
  1241. app.run(host='0.0.0.0', port=8056, debug=app.verbose, ssl_context=app.ssl)