Пример #1
0
    def _load_info(self):
        self.cur.execute("SELECT key FROM machine_info;")
        rows = self.cur.fetchall()
        c_info = [row[0] for row in rows]    # current info

        infos = []
        infos.append(("kiosk_id", ""))
        infos.append(("external_ip", ""))
        infos.append(("internal_ip", ""))
        infos.append(("mac", ""))
        infos.append(("software", get_machine_version()))
        infos.append(("upgrade_time", ""))
        infos.append(("firmware", ""))
        infos.append(("timezone", ""))
        infos.append(("start_time", ""))
        infos.append(("printer_status", ""))
        infos.append(("inactive_reason", ""))

        # verify
        machine_id = get_machine_id()
        now = get_cur_time()
        add_list = []
        for info in infos:
            if info[0] not in c_info:
                _id = get_db_uuid()
                param = (_id, machine_id, info[0], info[1], now)
                add_list.append(param)

        if add_list:
            self.db.add_kv("machine_info", add_list)
Пример #2
0
 def _heart_beat(self):
     try:
         with self.lock:
             r = HeartBeat(get_machine_id())
             data = Protocol().heart_to_raw(r)
             self.cli.send(data)
     except Exception as e:
         log.warning("heatbeat: %s" % str(e))
Пример #3
0
    def __init__(self):
        self.config = get_config("ckc")

        try:
            self.machine_id = get_machine_id().upper()
        except Exception:
            self.machine_id = ""
        log.debug("old machine_id:%s" % self.machine_id)
        self._get_mac()
        self.machine_type = get_machine_type(real=True)
Пример #4
0
    def on_recv(self):
        """ recieve request and return reply. """
        protocol = Protocol()
        _type, body = self._on_recv_body(protocol)

        if _type == MSG_TYPE_REQUEST:
            reply_code = code.SUCCESS
            # break up the request
            sub_data = None
            reply_msg = None
            recv_data = None
            try:
                req_id, func_name, params = body["id"], body["func"], body[
                    "params"]

                log.info("in %s(%s)" % (func_name, params))

                # get the result for the request

                cab_cli = Client(cab_host, cab_port)
                cab_cli.send(
                    json.dumps({
                        "func": func_name,
                        "params": params
                    }).encode())
                recv_data = cab_cli.recv(80960)

                recv_data_dic = json.loads(recv_data)

                reply_code = recv_data_dic.get("code")
                sub_data = recv_data_dic.get("sub_data", None)
                reply_msg = recv_data_dic.get("reply_msg", None)

            except ConnectionRefusedError as e:
                reply_code = code.UNAVALIABLE_SERVICE

            except Exception as ex:
                log.warning(str(traceback.format_exc()))
                reply_code = code.FAILED
                _msg = str(ex)

            reply_msg = reply_msg if reply_msg else code.CODE2MSG.get(
                reply_code, "Unknown Error")

            log.info("raw out: %s" % recv_data)

            sub_data = json.dumps({}) if not sub_data else json.dumps(sub_data)
            reply = Reply(req_id, get_machine_id(), reply_code, reply_msg,
                          sub_data)

            msg = protocol.reply_to_raw(reply)
            # print "reply msg: ", msg
            self.send_to_remote(msg)
        else:
            log.error("Unknown Message Ignoring...")
Пример #5
0
def register():
    api = "/Api/register"

    machine_id = get_machine_id()
    machine_type = get_machine_type()
    mac = get_machine_uuid()

    params = {"id": machine_id,
              "machine_type": machine_type,
              "mac": mac}
    return _http_call(api, params)
Пример #6
0
def upload_file(file, dst=""):
    api = "/Api/uploadfile"
    url = "%s%s" % (WEB_SERVER, api)
    log.info("upload: %s" % file)
    data = {"machine_id": get_machine_id(),
            "path": dst}
    # if not dst:
    # files = {"file": open(file, "rb")}
    # else:
    files = {"file": ("f", open(file, "rb"))}
    return _http_call(api, data, files, jsonly=False)
Пример #7
0
    def register(self):
        while True:
            try:
                machine_id = get_machine_id()
                res = register()
                log.info("id: %s, register: %s" % (machine_id, res))
                status = res["status"]
                if status == 1:
                    register_id = res.get("machine_id")
                    if machine_id == "" or register_id != machine_id:
                        set_machine_id(register_id)
                    return
                else:
                    continue

            except Exception as e:
                log.warning("register: %s" % str(e))
            time.sleep(5)
Пример #8
0
    def _load_config(self):
        self.cur.execute("SELECT key FROM machine_config;")
        rows = self.cur.fetchall()
        c_config = [row[0] for row in rows]    # current config

        configs = []
        configs.append(("general_policy", "{}"))
        # verify
        machine_id = get_machine_id()
        now = get_cur_time()
        add_list = []
        for config in configs:
            if config[0] not in c_config:
                _id = get_db_uuid()
                param = (_id, machine_id, config[0], config[1], now)
                add_list.append(param)

        if add_list:
            self.db.add_kv("machine_config", add_list)
Пример #9
0
 def _send_heardbeat(self):
     r = HeartBeat(get_machine_id())
     data = Protocol().heart_to_raw(r)
     self.send_to_remote(data)
Пример #10
0
def report_printer_status(status):
    api = "/Api/report_printer_status"
    machine_id = get_machine_id()
    params = {"machine_id": machine_id,
              "status": status}
    return _http_call(api, params)
Пример #11
0
def report_printer_params(params):
    api = "/Api/report_printer_params"
    machine_id = get_machine_id()
    params = {"machine_id": machine_id,
              "params": params}
    return _http_call(api, params)