Example #1
0
def api_listall():
    id = str(time.time())
    ret = APIHandler.Manager.list_all()
    if ret:
        return success(id, ret)
    else:
        return failure(id, "Nothing")
Example #2
0
def api_status():
    id = str(time.time())
    ret, ret_content = APIHandler.Manager.vserial_status()
    if ret:
        return success(id, ret_content)
    else:
        return failure(id, ret_content)
Example #3
0
def api_load(params):
    if not type(params) is dict:
        params = to_dict(params)
    id = params.get("id") or uuid.uuid1()
    npshost = None
    npsuser = None
    gate = None
    auth_code = None
    config = ConfigParser()
    if os.access(os.getcwd() + '\\config.ini', os.F_OK):
        config.read('config.ini')
        if config.has_option('thingscloud', 'npshost'):
            npshost = config.get('thingscloud', 'npshost')
        if config.has_option('thingscloud', 'npsuser'):
            npsuser = config.get('thingscloud', 'npsuser')
        if config.has_option('thingscloud', 'gate'):
            gate = config.get('thingscloud', 'gate')
        if config.has_option('thingscloud', 'accesskey'):
            if len(config.get('thingscloud', 'accesskey')) == 48:
                auth_code = base64.b64decode(
                    config.get('thingscloud', 'accesskey').encode()).decode()
    else:
        return None
    ret = {
        "npshost": npshost,
        "npsuser": npsuser,
        "gate": gate,
        "auth_code": auth_code
    }
    if ret:
        return success(id, ret)
    else:
        return failure(id, "error")
Example #4
0
def api_ping(params: pingItem):
	if not type(params) is dict:
		params = params.dict()
	id = params.get("id") or uuid.uuid1()
	ret = params
	if ret:
		return success(id, params)
	else:
		return failure(id, "error")
Example #5
0
def api_ping(params: pingItem):
    if not type(params) is dict:
        params = params.dict()
    id = params.get("id") or uuid.uuid1()
    ret = APIHandler.Manager.enable_heartbeat(True, 60)
    if ret:
        return success(id, ret)
    else:
        return failure(id, "error")
Example #6
0
def api_result(params):
    if not type(params) is dict:
        params = to_dict(params)
    id = params.get("id") or uuid.uuid1()
    ret = APIHandler.Manager.get_bench()
    if ret:
        return success(id, ret)
    else:
        return failure(id, 'error')
Example #7
0
def api_stop(params: stopItem):
    if not type(params) is dict:
        params = params.dict()
    # print(json.dumps(params, sort_keys=True, indent=4, separators=(',', ':')))
    id = params.get("id") or uuid.uuid1()
    ret, ret_content = APIHandler.Manager.stop_vserial()
    if ret:
        return success(id, ret_content)
    else:
        return failure(id, ret_content)
Example #8
0
def run():
    accentuate("Starting the Public Computer Cleaner!")
    log(f"Created by {AUTHOR}. Version {VERSION}. Repo: {REPO}.\n")
    progVars = getVariables()
    if not progVars['on-switch']:
        warn("Stopping program. Global ON switch is set to 'OFF'.")
        return
    if progVars['monthly-reporter'] == progVars['computer-name']:
        checkIfDate(progVars['sendgrid-api-key'], progVars['monthly-reporter-debug'], progVars['computer-name'], progVars['from-email'], progVars['to-email'], progVars['email-subject'])
    else:
        log("Did not check if monthly report needed to be sent because this computer is not the monthly reporter.")
    runSecPref = progVars['alert-before-run']
    if runSecPref:
        log("Alerting before run, in accordance with variable setting.")
        showToast("Computer cleaner begins in 15 seconds.", "This removes all local information. To avoid this, please move the mouse.", duration=10, threaded=True)
        alertSound(1)
        time.sleep(9)
        showToast("Computer cleaner begins in 5 seconds.", "This removes all local information. To avoid this, please move the mouse.", duration=5, threaded=True)
        alertSound(5)
    log("Starting timer.")
    startCleanTime = time.perf_counter()
    log("Calling Cleaner algorithm...")
    cleanerResults = runCleaner()
    success("Completed Cleaner algorithm.")
    log("Calling Chrome algorithm...")
    chromeResults = runChrome()
    log("Calling Edge algorithm...")
    edgeResults = runEdge()
    log("Calling Windows algorithm...")
    windowsResults = runWindows(progVars['keep-name-regex'], progVars['keep-vendor-regex'])
    log("Completed all algorithms.")
    log("Compiling stats of this run.")
    res = {}
    res.update(cleanerResults)
    res.update(chromeResults)
    res.update(edgeResults)
    res.update(windowsResults)
    res.update({'times-ran': 1})
    log("Attempting to send results of run.")
    sendResults(progVars['computer-name'], res)
    sendLogs(progVars['computer-name'], res)
    endCleanTime = time.perf_counter()
    log(f'Completed in {endCleanTime - startCleanTime:0.4f} s')
Example #9
0
def api_remove(params):
	if not type(params) is dict:
		params = params.dict()
	id = params.get("id") or uuid.uuid1()
	config = ConfigParser()
	if os.access(os.getcwd() + '\\config.ini', os.F_OK):
		config.read('config.ini')
		config.remove_section("thingscloud")
		config.write(open('config.ini', 'w'))
		return success(id, "ok")
	else:
		return failure(id, "config.ini does not exist")
Example #10
0
    async def get(self):
        try:
            name = self.get_argument("name")
            message = self.get_argument("msg")
        except:
            return self.send_error(400)

        websocket = await tornado.websocket.websocket_connect(
            "ws://localhost/ws")
        await websocket.write_message("msg {} {}".format(name, message))
        msg = await websocket.read_message()
        websocket.close()
        self.write(helper.success({"response": msg}))
Example #11
0
def api_ready(params: gateItem):
    if not type(params) is dict:
        params = params.dict()
    # print(json.dumps(params, sort_keys=True, indent=4, separators=(',', ':')))
    id = params.get("id") or uuid.uuid1()
    auth_code = params.get("auth_code") or APPCtrl().get_accesskey()
    if auth_code:
        APIHandler.Manager.TRAccesskey = auth_code
    else:
        return failure(id, "params lost  auth_code")
    ret, ret_content = APIHandler.Manager.vserial_ready(params.get("gate"))
    if ret:
        return success(id, ret_content)
    else:
        return failure(id, ret_content)
Example #12
0
def api_gatelist(params):
	if not type(params) is dict:
		params = to_dict(params)
	# print(json.dumps(params, sort_keys=True, indent=4, separators=(',', ':')))
	id = params.get("id") or uuid.uuid1()
	auth_code = params.get("auth_code") or APPCtrl().get_accesskey()
	if auth_code:
		APIHandler.Manager.TRAccesskey = auth_code
	else:
		return failure(id, "params lost  auth_code")
	ret = APIHandler.Manager.gatelist()
	if ret:
		return success(id, ret)
	else:
		return failure(id, "error")
Example #13
0
def api_bench(params: benchItem):
    if not type(params) is dict:
        params = params.dict()
    # print(json.dumps(params, sort_keys=True, indent=4, separators=(',', ':')))
    id = params.get("id") or uuid.uuid1()
    host = params.get("host")
    port = params.get("port")
    size = params.get("size")
    direct = params.get("direct")
    if not is_ipv4(host):
        return failure(id, "host must be ipv4")
    ret = APIHandler.Manager.speed_bench(host, port, size, direct)
    if ret:
        return success(id, ret)
    else:
        return failure(id, 'error')
Example #14
0
def api_start(params: vnetItem):
    if not type(params) is dict:
        params = params.dict()
    # print(json.dumps(params, sort_keys=True, indent=4, separators=(',', ':')))
    id = params.get("id") or uuid.uuid1()
    host = params.get("host")
    user = params.get("user")
    gate = params.get("gate")
    ret, ret_content = None, None
    if host and user and gate:
        if not urlCheck(host).get_url():
            return failure(id, "host must be domain or ipv4 or url")
        else:
            vret, vret_content = APIHandler.Manager.vnet_status()
            if vret:
                str = "用户 {0} 正在使用中……,如需重新配置,请先停止再启动".format(
                    vret_content.userinfo.get("name"))
                return failure(id, str)
            else:
                auth_code = params.get(
                    "auth_code") or APPCtrl().get_accesskey()
                if auth_code:
                    APIHandler.Manager.TRAccesskey = auth_code
                else:
                    return failure(id, "params lost  auth_code")
                if params.get("local_ip"):
                    if is_ipv4(params.get("local_ip")):
                        APIHandler.Manager.userinfo[
                            'local_vnet_ip'] = params.get("local_ip")
                if params.get("dest_ip"):
                    if is_ipv4(params.get("dest_ip")):
                        APIHandler.Manager.userinfo['dest_ip'] = params.get(
                            "dest_ip")
                APIHandler.Manager.nps_host = urlCheck(host).get_url()
                APIHandler.Manager.userinfo['name'] = user
                APIHandler.Manager.userinfo['tunnel_host'] = urlCheck(
                    host).get_host()
                APIHandler.Manager.userinfo['gate'] = gate
                ret, ret_content = APIHandler.Manager.start_vnet()
    else:
        ret_content = "params lost  host or user or gate"
    if ret:
        return success(id, ret_content)
    else:
        return failure(id, ret_content)
Example #15
0
def api_save(params: configItem):
	if not type(params) is dict:
		params = params.dict()
	id = params.get("id") or uuid.uuid1()
	npshost = params.get("npshost")
	npsuser = params.get("npsuser")
	gate = params.get("gate")
	accesskey = params.get("auth_code")
	if len(accesskey) == 36:
		accesskey = base64.b64encode(accesskey.encode()).decode()
		config = ConfigParser()
		if os.access(os.getcwd() + '\\config.ini', os.F_OK):
			config.read('config.ini')
			if not config.has_section("thingscloud"):
				config.add_section("thingscloud")
			print("@@@@@@@@@@@", npshost, npsuser, gate, accesskey)
			if npshost:
				config.set("thingscloud", 'npshost', npshost)
			else:
				config.remove_option("thingscloud", 'npshost')
			if npsuser:
				config.set("thingscloud", 'npsuser', npsuser)
			else:
				config.remove_option("thingscloud", 'npsuser')
			if gate:
				config.set("thingscloud", 'gate', gate)
			else:
				config.remove_option("thingscloud", 'gate')
			config.set("thingscloud", 'accesskey', accesskey)
			config.write(open('config.ini', 'w'))
		else:
			config.read('config.ini')
			config.add_section("thingscloud")
			if npshost:
				config.set("thingscloud", 'npshost', npshost)
			if npsuser:
				config.set("thingscloud", 'npsuser', npsuser)
			if gate:
				config.set("thingscloud", 'gate', gate)
			config.set("thingscloud", 'accesskey', accesskey)
			config.write(open('config.ini', 'w'))
		return success(id, "ok")
	else:
		return failure(id, "auth_code is error")
Example #16
0
def api_action(params: actionItem):
    if not type(params) is dict:
        params = params.dict()
    # print(json.dumps(params, sort_keys=True, indent=4, separators=(',', ':')))
    id = params.get("id") or uuid.uuid1()
    auth_code = params.get("auth_code") or APPCtrl().get_accesskey()
    if auth_code:
        APIHandler.Manager.TRAccesskey = auth_code
    else:
        return failure(id, "params lost  auth_code")
    gate = params.get("gate")
    action = params.get("action")
    if action not in ["install", "uninstall", "start", "stop", "upgrade"]:
        return failure(id, "action is unsupported")
    ret, ret_content = APIHandler.Manager.vserial_action(gate, action)
    if ret:
        return success(id, ret_content)
    else:
        return failure(id, ret_content)
Example #17
0
def api_start(params: startItem):
    if not type(params) is dict:
        params = params.dict()
    # print(json.dumps(params, sort_keys=True, indent=4, separators=(',', ':')))
    id = params.get("id") or uuid.uuid1()
    host = params.get("host")
    user = params.get("user")
    gate = params.get("gate")
    port = params.get("gate_port")
    ret, ret_content = None, None
    if not port:
        return failure(id, "params port_name lost")
    if host and user and gate:
        vret, vret_content = APIHandler.Manager.vserial_status()
        if vret:
            str = "用户 {0} 正在使用中……,如需重新配置,请先停止再启动".format(
                vret_content.userinfo.get("name"))
            return failure(id, str)
        else:
            auth_code = params.get("auth_code") or APPCtrl().get_accesskey()
            if auth_code:
                APIHandler.Manager.TRAccesskey = auth_code
            else:
                return failure(id, "params lost  auth_code")
            if params.get("port"):
                APIHandler.Manager.frps_port = params.get("port")
            if params.get("token"):
                APIHandler.Manager.frps_token = params.get("token")
            APIHandler.Manager.frps_host = "http://" + host + ":2699"
            APIHandler.Manager.userinfo['name'] = user
            APIHandler.Manager.userinfo['tunnel_host'] = host
            APIHandler.Manager.userinfo['gate'] = gate
            APIHandler.Manager.userinfo['gate_port_name'] = port.lower()
            ret, ret_content = APIHandler.Manager.start_vserial()
    else:
        ret_content = "params lost  host or user or gate"
    if ret:
        return success(id, ret_content)
    else:
        return failure(id, ret_content)
Example #18
0
def api_npstunnel(params):
    if not type(params) is dict:
        params = to_dict(params)
    id = params.get("id") or uuid.uuid1()
    host = params.get("host")
    user = params.get("user")
    ret, ret_content = None, None
    if host and user:
        if not urlCheck(host).get_url():
            return failure(id, "host must be domain or ipv4 or url")
        else:
            APIHandler.Manager.nps_host = urlCheck(host).get_url()
            APIHandler.Manager.userinfo['name'] = user
            APIHandler.Manager.userinfo['tunnel_host'] = urlCheck(
                host).get_host()
            ret, ret_content = APIHandler.Manager.nps_tunnel()
    else:
        ret_content = "params lost  host or user"
    if ret:
        return success(id, ret_content)
    else:
        return failure(id, ret_content)