def main(): banner = """ ██╗ ██╗████████╗████████╗██████╗ ██╗███████╗ ██████╗ ███████╗██╗ ██╗███████╗██╗ ██╗███████╗██╗ ██╗ ██║ ██║╚══██╔══╝╚══██╔══╝██╔══██╗ ██╔╝██╔════╝ ██╔══██╗██╔════╝██║ ██║██╔════╝██║ ██║██╔════╝██║ ██║ ███████║ ██║ ██║ ██████╔╝██╔╝ ███████╗ ██████╔╝█████╗ ██║ ██║███████╗███████║█████╗ ██║ ██║ ██╔══██║ ██║ ██║ ██╔═══╝██╔╝ ╚════██║ ██╔══██╗██╔══╝ ╚██╗ ██╔╝╚════██║██╔══██║██╔══╝ ██║ ██║ ██║ ██║ ██║ ██║ ██║ ██╔╝ ███████║ ██║ ██║███████╗ ╚████╔╝ ███████║██║ ██║███████╗███████╗███████╗ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝╚══════╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝ By: 3v4Si0N """ print(colored(banner, 'yellow')) parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('host', help='Listen Host', type=str) parser.add_argument('port', help='Listen Port', type=int) parser.add_argument('--ssl', default=False, action="store_true", help='Send traffic over ssl') parser.add_argument('--autocomplete', default=False, action="store_true", help='Autocomplete powershell functions') args = parser.parse_args() try: HOST = args.host PORT = args.port global AUTOCOMPLETE global MODULES server = HTTPServer((HOST, PORT), myHandler) print(time.asctime(), 'Server UP - %s:%s' % (HOST, PORT)) MODULES = loadModules() if (args.ssl): cert = certificate.Certificate() if ((cert.checkCertPath() == False) or cert.checkCertificateExpiration()): cert.genCertificate() server.socket = ssl.wrap_socket(server.socket, certfile='certificate/cacert.pem', keyfile='certificate/private.pem', server_side=True) if (args.autocomplete): AUTOCOMPLETE = True else: readline.set_completer_delims(" ") readline.parse_and_bind("tab: complete") server.serve_forever() except KeyboardInterrupt: print(' received, shutting down the web server') server.socket.close()
def run(simManager): # load iccid print("DEBUG___get sim iccid") idicc = simManager.read("AT+CCID\r\n") # if iccid.find("AT+CCID") != -1: idicc = idicc.replace("AT+CCID", "") print('DEBUG___get iccid success : ', idicc) with open("env.json", "r+") as jsonFile: data_json = json.load(jsonFile) jsonFile.close() # Close the JSON file #load OTA downLoad = DownloadSource("DOWNLOAD", data_json["OTA_Server"], data_json["OTA_path"]) # load certificate print("DEBUG___load ca, path") cert = certificate.Certificate(idicc, data_json["API_key"], data_json["API_gatewaytoken"], data_json["API_endpoint"]) if cert.isExisted(): print('DEBUG___ca, key available') else: print("DEBUG___Cannot locate ca and key files") print("DEBUG___init sensor") ss = sensor.Sensor(data_json["SENSOR_pin"], data_json["SENSOR_type"]) print("DEBUG___sensor pin, type, each: ", data_json["SENSOR_pin"], data_json["SENSOR_type"], data_json["SENSOR_intervaltime"]) awsConf = json.loads(file.load("./keys/" + idicc + ".json")) print('DEBUG___init sender') sd = sender.Sender("./keys/rootca.crt", "./keys/" + idicc + ".crt", "./keys/" + idicc + ".key", awsConf.get("topic"), awsConf.get("endpoint"), int(awsConf.get("port"))) sd.connect() print('DEBUG___inited sender') sms = simManager.read("AT+CMGR=12\r\n") # sms = converter.pdu_to_text(sms.replace("AT+CMGR=12+CMGR: 1,,100", "")) print('DEBUG___Receive OTA SMS success : ', sms) log(idicc) # send data while ready: simStateChange() newData = ss.get() newData["ICCID"] = idicc newData["location"] = "demo" newData = json.dumps(newData) sd.send(newData) time.sleep(data_json["SENSOR_intervaltime"]) if sms != "": print('DEBUG________________OTA BEGIN') downLoad.download() downLoad.backup() #downLoad.remove() downLoad.extract() #downLoad.resetService() time.sleep(10) os.system('sudo chmod 666 /dev/ttyS0') print("DEBUG__________Restart") os.system('cd ..') os.system('cd /home/pi/workspace/singtel/Singtel_VNSIM/') os.system( 'sudo chmod a+x /home/pi/workspace/singtel/Singtel_VNSIM/main.py' ) os.execv(__file__, sys.argv)