import os
import random
import string
import traceback
import shutil
import uuid
from flask import Flask, request
# base_directory = "/home/easysoft054/Projects/git-es"
base_directory = "/Users/maronakins/Documents"
ALLOWED_EXTENSIONS_ICON = {'png'}
app = Flask(__name__)
app.base_project = {
"android": base_directory + "/EmbedFeatures/NexilisSampleCode",
"android_flutter": base_directory + "/EmbedFeatures/NexilisSampleCodeFlutter-Android",
"android_ionic": base_directory + "/EmbedFeatures/NexilisSampleCodeIonic-Android",
"android_react": base_directory + "/EmbedFeatures/NexilisSampleCodeReact-Android",
"ios": base_directory + "/EmbedFeatures/NexilisSampleCode-iOS",
"ios_flutter": base_directory + "/EmbedFeatures/NexilisSampleCodeFlutter-iOS",
"ios_ionic": base_directory + "/EmbedFeatures/NexilisSampleCodeIonic-iOS",
"ios_react": base_directory + "/EmbedFeatures/NexilisSampleCodeReact-iOS",
"security_shield": base_directory + "/EmbedFeatures/NexilisSampleCodeShield",
"security_shield_react": base_directory + "/EmbedFeatures/NexilisSampleCodeShieldReact",
}
app.temp_folder = base_directory + "/EmbedFeatures/BuildExample"
app.zip_folder = base_directory + "/EmbedFeatures/uploads"
# app.ssl = ('/usr/src/app/ssl/STAR_newuniverse_io.crt', '/usr/src/app/ssl/STAR_nexilis.key')
app.ssl = None
app.verbose = True
def vprint(*data):
if app.verbose:
print(*data)
def indented_str(n, s, line=True, spaces=4) -> str:
return " " * n * spaces + s + os.linesep if line else ""
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS_ICON
def create_folder(platform, uid):
path = os.path.join(app.temp_folder, uid)
if not os.path.exists(path):
os.mkdir(path)
else:
shutil.rmtree(path)
os.mkdir(path)
vprint(path)
base_project = app.base_project[platform]
base_project_name = os.path.basename(base_project)
path_dest = os.path.join(path, base_project_name)
if not os.path.exists(path_dest):
shutil.copytree(base_project, path_dest)
return path_dest
def write_android_manifest(manifest_path: str, features: dict, security: dict):
with open(manifest_path, "r") as f:
lines = f.readlines()
with open(manifest_path, "w") as f:
for line in lines:
if "" in line:
if features["sms"]["status"]:
f.write(indented_str(1, ''))
f.write(indented_str(1, ''))
f.write(indented_str(1, ''))
f.write(indented_str(1, ''))
f.write(indented_str(1, ''))
else:
f.write(indented_str(1, ''))
f.write(
indented_str(1, ''))
f.write(indented_str(1, ''))
f.write(indented_str(1, ''))
f.write(indented_str(1, ''))
elif "" in line:
if security["malware"] or security["side_load"]:
f.write(indented_str(1, ''))
f.write(indented_str(1, ''))
else:
f.write(indented_str(1, ''))
f.write(indented_str(1,
''))
else:
f.write(line)
def write_android_menu_item(f, menu_id: str, n: int, label:str, is_active:bool):
f.write(indented_str(1, "%s %s' % ("" if is_active else " -->")))
def write_android_menu(xml_menu_path: str, features: dict, security: dict):
with open(xml_menu_path, "r") as f:
lines = f.readlines()
with open(xml_menu_path, "w") as f:
for line in lines:
if "" in line:
n = 100
write_android_menu_item(f, "action_nc", n, "Notification Center", features["nc"]["status"])
n = n + 1
write_android_menu_item(f, "action_cc", n, "Contact Center", features["cc"]["status"])
n = n + 1
write_android_menu_item(f, "action_ls", n, "Live Streaming", features["ls"]["status"])
n = n + 1
write_android_menu_item(f, "action_chats", n, "Unified Messaging", features["im"]["status"])
n = n + 1
write_android_menu_item(f, "action_audio_call", n, "VoIP Call", features["ac"]["status"])
n = n + 1
write_android_menu_item(f, "action_video_call", n, "Video Call", features["vc"]["status"])
n = n + 1
write_android_menu_item(f, "action_call", n, "Call", features["call"]["status"])
n = n + 1
write_android_menu_item(f, "action_sf", n, "Secure Folder", features["secure_folder"]["status"])
n = n + 1
write_android_menu_item(f, "action_conpost", n, "Social Hub", features["conpost"]["status"])
n = n + 1
write_android_menu_item(f, "action_news_update", n, "News and Update", features["news_update"]["status"])
n = n + 1
write_android_menu_item(f, "action_custom_url", n, "Custom URL", features["custom_url"]["status"])
n = n + 1
write_android_menu_item(f, "action_xapps", n, "External Apps", features["xapps"]["status"])
n = n + 1
write_android_menu_item(f, "action_conference_room", n, "Conference Room", features["conference_room"]["status"])
n = n + 1
write_android_menu_item(f, "action_community", n, "Community", features["community"]["status"])
n = n + 1
write_android_menu_item(f, "action_status_update", n, "Status Updates", features["status_update"]["status"])
n = n + 1
write_android_menu_item(f, "action_call_log", n, "Call Log", features["call_log"]["status"])
n = n + 1
write_android_menu_item(f, "action_create_channel", n, "Create Channel", features["create_channel"]["status"])
n = n + 1
write_android_menu_item(f, "action_secure_browser", n, "Secure Browser", features["secure_browser"]["status"])
n = n + 1
write_android_menu_item(f, "action_ppob", n, "PPOB Agent", features["ppob"]["status"])
n = n + 1
write_android_menu_item(f, "action_wallet", n, "Wallet", features["wallet"]["status"])
n = n + 1
write_android_menu_item(f, "action_social_commerce", n, "Social Commerce", features["social_commerce"]["status"])
n = n + 1
write_android_menu_item(f, "action_contact_list", n, "Contact List", features["contact_list"]["status"])
n = n + 1
write_android_menu_item(f, "action_settings", n, "Settings", True)
n = n + 1
write_android_menu_item(f, "action_profile", n, "Profile", True)
n = n + 1
else:
f.write(line)
def write_android_menu_item_onselect(f, menu_id: str, function_call: str, is_active: bool):
f.write(indented_str(2, "%sif (id == R.id.%s) {" % ("" if is_active else "// ", menu_id)))
f.write(indented_str(3, "%s%s;" % ("" if is_active else "// ", function_call)))
f.write(indented_str(3, "%sreturn true;" % ("" if is_active else "// ")))
f.write(indented_str(2, "%s}" % ("" if is_active else "// ")))
def write_android_grid_item_onclick(f, var_name: str, button_id: str, function_call: str, is_active: bool):
f.write(indented_str(2, "%sImageView %s = findViewById(R.id.%s);" % ("" if is_active else "// ", var_name, button_id)))
f.write(indented_str(2, "%s%s.setOnClickListener(v -> {" % ("" if is_active else "// ", var_name)))
f.write(indented_str(3, "%s%s;" % ("" if is_active else "// ", function_call)))
f.write(indented_str(2, "%s});" % ("" if is_active else "// ")))
f.write(indented_str(0, ""))
def write_android_grid_item_layout(f, item_id: str, src_id:str, is_active: bool):
line_start = "" if is_active else ""
f.write(indented_str(1, f'{line_start}{line_end}'))
def write_floating_button(f, features: dict, security: dict, spaces=4):
f.write(indented_str(6, ""))
def write_flutter_menu_item_invoke(f, label: str, function_call: str, is_active: bool):
line_start = "" if is_active else "// "
f.write(indented_str(3, f'{line_start}case "{label}":', spaces=2))
f.write(indented_str(4, f'{line_start}nativeChannel.invokeMethod("{function_call}");', spaces=2))
f.write(indented_str(4, f'{line_start}break;', spaces=2))
def write_flutter_main(main_act_path, features: dict, security: dict):
with open(main_act_path, "r") as f:
lines = f.readlines()
with open(main_act_path, "w") as f:
features_str = []
for line in lines:
if "'Features List'" in line:
features_str.append("%s'Notification Center'" % ("" if features["nc"]["status"] else "// "))
features_str.append("%s'Contact Center'" % ("" if features["cc"]["status"] else "// "))
features_str.append("%s'Live Streaming'" % ("" if features["ls"]["status"] else "// "))
features_str.append("%s'Unified Messaging'" % ("" if features["im"]["status"] else "// "))
features_str.append("%s'VoIP Call'" % ("" if features["ac"]["status"] else "// "))
features_str.append("%s'Video Call'" % ("" if features["vc"]["status"] else "// "))
features_str.append("%s'Call'" % ("" if features["call"]["status"] else "// "))
features_str.append("%s'Secure Folder'" % ("" if features["secure_folder"]["status"] else "// "))
features_str.append("%s'Social Hub'" % ("" if features["conpost"]["status"] else "// "))
features_str.append("%s'News and Update'" % ("" if features["news_update"]["status"] else "// "))
features_str.append("%s'Custom URL'" % ("" if features["custom_url"]["status"] else "// "))
features_str.append("%s'External Apps'" % ("" if features["xapps"]["status"] else "// "))
features_str.append("%s'Conference Room'" % ("" if features["conference_room"]["status"] else "// "))
features_str.append("%s'Community'" % ("" if features["community"]["status"] else "// "))
features_str.append("%s'Status Updates'" % ("" if features["status_update"]["status"] else "// "))
features_str.append("%s'Call Log'" % ("" if features["call_log"]["status"] else "// "))
features_str.append("%s'Create Channel'" % ("" if features["create_channel"]["status"] else "// "))
features_str.append("%s'Secure Browser'" % ("" if features["secure_browser"]["status"] else "// "))
features_str.append("%s'PPOB Agent'" % ("" if features["ppob"]["status"] else "// "))
features_str.append("%s'Wallet'" % ("" if features["wallet"]["status"] else "// "))
features_str.append("%s'Social Commerce'" % ("" if features["social_commerce"]["status"] else "// "))
features_str.append("%s'Contact List'" % ("" if features["contact_list"]["status"] else "// "))
features_str.append("'Settings'")
features_str.append("'Profile'")
for feature_str in features_str:
f.write(indented_str(8, f"{feature_str},", spaces=2))
elif "//FEATURES" in line:
write_flutter_menu_item_invoke(f, "Settings", "openSettings", True)
write_flutter_menu_item_invoke(f, "Profile", "openProfile", True)
write_flutter_menu_item_invoke(f, "Contact Center", "openContactCenter", features["cc"]["status"])
write_flutter_menu_item_invoke(f, "Notification Center", "openNotificationCenter", features["nc"]["status"])
write_flutter_menu_item_invoke(f, "Unified Messaging", "openInstantMessaging", features["im"]["status"])
write_flutter_menu_item_invoke(f, "VoIP Call", "openAudioCall", features["ac"]["status"])
write_flutter_menu_item_invoke(f, "Video Call", "openVideoCall", features["vc"]["status"])
write_flutter_menu_item_invoke(f, "Call", "openCall", features["call"]["status"])
write_flutter_menu_item_invoke(f, "Live Streaming", "openStreaming", features["ls"]["status"])
write_flutter_menu_item_invoke(f, "Secure Folder", "openSecureFolder", features["secure_folder"]["status"])
write_flutter_menu_item_invoke(f, "Custom URL", "openCustomURL", features["custom_url"]["status"])
write_flutter_menu_item_invoke(f, "External Apps", "openExternalApps", features["xapps"]["status"])
write_flutter_menu_item_invoke(f, "Social Hub", "openUserGeneratedContent", features["conpost"]["status"])
write_flutter_menu_item_invoke(f, "PPOB Agent", "openPPOB", features["ppob"]["status"])
write_flutter_menu_item_invoke(f, "Wallet", "openWallet", features["wallet"]["status"])
write_flutter_menu_item_invoke(f, "Social Commerce", "openSocialCommerce", features["social_commerce"]["status"])
write_flutter_menu_item_invoke(f, "News and Update", "openNewsUpdate", features["news_update"]["status"])
write_flutter_menu_item_invoke(f, "Contact List", "openConversation", features["contact_list"]["status"])
write_flutter_menu_item_invoke(f, "Community", "openCommunity", features["community"]["status"])
write_flutter_menu_item_invoke(f, "Conference Room", "openConferenceRoom", features["conference_room"]["status"])
write_flutter_menu_item_invoke(f, "Status Updates", "openStatusUpdates", features["status_update"]["status"])
write_flutter_menu_item_invoke(f, "Call Log", "openCallLog", features["call_log"]["status"])
write_flutter_menu_item_invoke(f, "Create Channel", "createChannel", features["create_channel"]["status"])
write_flutter_menu_item_invoke(f, "Secure Browser", "secureBrowser", features["secure_browser"]["status"])
else:
f.write(line)
def write_ionic_menu_handler(f, label: str, function_call: str, is_active: bool):
line_start = "" if is_active else "// "
f.write(indented_str(4, '%s{', spaces=2) % ("" if is_active else "// "))
f.write(indented_str(5, "%stext: '%s',", spaces=2) % ("" if is_active else "// ", label))
f.write(indented_str(5, "%shandler: () => {", spaces=2) % ("" if is_active else "// "))
f.write(indented_str(6, "%sthis.%s;", spaces=2) % ("" if is_active else "// ", function_call))
f.write(indented_str(5, "%s},", spaces=2) % ("" if is_active else "// "))
f.write(indented_str(4, "%s},", spaces=2) % ("" if is_active else "// "))
def write_ionic_main(main_act_path, features: dict, security: dict):
with open(main_act_path, "r") as f:
lines = f.readlines()
with open(main_act_path, "w") as f:
for line in lines:
if "//FEATURES" in line:
write_ionic_menu_handler(f, "Settings", "openSettings", True)
write_ionic_menu_handler(f, "Profile", "openProfile", True)
write_ionic_menu_handler(f, "Contact Center", "openContactCenter", features["cc"]["status"])
write_ionic_menu_handler(f, "Notification Center", "openNotificationCenter", features["nc"]["status"])
write_ionic_menu_handler(f, "Unified Messaging", "openChat", features["im"]["status"])
write_ionic_menu_handler(f, "VoIP Call", "openAudioCall", features["ac"]["status"])
write_ionic_menu_handler(f, "Video Call", "openVideoCall", features["vc"]["status"])
write_ionic_menu_handler(f, "Call", "openCall", features["call"]["status"])
write_ionic_menu_handler(f, "Live Streaming", "openStreaming", features["ls"]["status"])
write_ionic_menu_handler(f, "Secure Folder", "openSecureFolder", features["secure_folder"]["status"])
write_ionic_menu_handler(f, "Custom URL", "openCustomURL", features["custom_url"]["status"])
write_ionic_menu_handler(f, "External Apps", "openExternalApps", features["xapps"]["status"])
write_ionic_menu_handler(f, "Social Hub", "openUserGeneratedContent", features["conpost"]["status"])
write_ionic_menu_handler(f, "PPOB Agent", "openPPOB", features["ppob"]["status"])
write_ionic_menu_handler(f, "Wallet", "openWallet", features["wallet"]["status"])
write_ionic_menu_handler(f, "Social Commerce", "openSocialCommerce", features["social_commerce"]["status"])
write_ionic_menu_handler(f, "News and Update", "openNewsUpdate", features["news_update"]["status"])
write_ionic_menu_handler(f, "Contact List", "openConversation", features["contact_list"]["status"])
write_ionic_menu_handler(f, "Community", "openCommunity", features["community"]["status"])
write_ionic_menu_handler(f, "Conference Room", "openConferenceRoom", features["conference_room"]["status"])
write_ionic_menu_handler(f, "Status Updates", "openStatusUpdates", features["status_update"]["status"])
write_ionic_menu_handler(f, "Call Log", "openCallLog", features["call_log"]["status"])
write_ionic_menu_handler(f, "Create Channel", "createChannel", features["create_channel"]["status"])
write_ionic_menu_handler(f, "Secure Browser", "secureBrowser", features["secure_browser"]["status"])
else:
f.write(line)
def write_react_call_native_1(f, n: int, function_call: str, is_active: bool):
line_start = "" if is_active else "// "
f.write(indented_str(5, "%sif (buttonIndex === %s) {" % (line_start, str(n)), spaces=2))
f.write(indented_str(6, "%sCallNative.%s();" % (line_start, function_call), spaces=2))
f.write(indented_str(5, "%s}" % (line_start), spaces=2))
def write_react_call_native_1_arg(f, n: int, function_call: str, function_arg: str, is_active: bool):
line_start = "" if is_active else "// "
f.write(indented_str(5, "%sif (buttonIndex === %s) {" % (line_start, str(n)), spaces=2))
f.write(indented_str(6, "%sCallNative.%s(%s);" % (line_start, function_call, function_arg), spaces=2))
f.write(indented_str(5, "%s}" % (line_start), spaces=2))
def write_react_call_native(f, n: int, function_call: str, is_active: bool):
line_start = "" if is_active else "// "
f.write(indented_str(2, "%sif (buttonIndex === %s) {" % (line_start, str(n)), spaces=2))
f.write(indented_str(3, "%stry {" % (line_start), spaces=2))
f.write(indented_str(4, "%sCallNative.%s();" % (line_start, function_call), spaces=2))
f.write(indented_str(3, "%s} catch (e) {" % (line_start), spaces=2))
f.write(indented_str(4, "%sconsole.log(e);" % (line_start), spaces=2))
f.write(indented_str(3, "%s}" % (line_start), spaces=2))
f.write(indented_str(2, "%s}" % (line_start), spaces=2))
def write_react_call_native_arg(f, n: int, function_call: str, function_arg: str, is_active: bool):
line_start = "" if is_active else "// "
f.write(indented_str(2, "%sif (buttonIndex === %s) {" % (line_start, str(n)), spaces=2))
f.write(indented_str(3, "%stry {" % (line_start), spaces=2))
f.write(indented_str(4, "%sCallNative.%s(%s);" % (line_start, function_call, function_arg), spaces=2))
f.write(indented_str(3, "%s} catch (e) {" % (line_start), spaces=2))
f.write(indented_str(4, "%sconsole.log(e);" % (line_start), spaces=2))
f.write(indented_str(3, "%s}" % (line_start), spaces=2))
f.write(indented_str(2, "%s}" % (line_start), spaces=2))
def write_react_button_press(f, n: int, title: str, is_active: bool):
line_start = "" if is_active else "{/* "
line_end = "" if is_active else " */}"
f.write(indented_str(5, f'{line_start}