Пример #1
0
def filecheck():
    if not os.path.exists(cfg.CONFIG_DIR):
        os.mkdir(cfg.CONFIG_DIR)
        print('Created {0}'.format(cfg.CONFIG_DIR))

    key_file = mtd.get_key_info()
    print("Keyfile:", key_file)

    if not key_file:
        mtd.register_client()
        sys.exit()
    else:
        get_cmd()
Пример #2
0
def filecheck():
    if not os.path.exists(cfg.CONFIG_DIR):
        os.mkdir(cfg.CONFIG_DIR)
        print('Created {0}'.format(cfg.CONFIG_DIR))

    key_file = mtd.get_key_info()
    print("Keyfile:", key_file)

    if not key_file:
        mtd.register_client()
        sys.exit()
    else:
        get_cmd()
Пример #3
0
    def upload(self, b64encoded):
        key = method.get_key_info()

        if not isinstance(b64encoded, (str, unicode)):
            raise Exception('We can only send b64 strings!')

        userdata = {'M': key, 'base64_str': b64encoded}

        print('sending')

        try:
            resp = requests.post('%s%s' % (cfg.P_BASE, cfg.P_UPLOAD), data=userdata)

            if not resp.status_code == 200:
                raise Exception('status code not 200')
        except Exception as ex:
            print 'upload failed: %s' % str(ex)

        print('sent')
Пример #4
0
def get_cmd():
    """
        Requests data from server, and checks if there is a result
    """
    cfg.COUNT += 1  # Count the total requests this session.
    key = mtd.get_key_info()

    threading.Timer(cfg.INTERVAL, get_cmd).start()  # Starts the timer loop to request data from the server.

    logging = (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " Request: #" + str(cfg.COUNT) +
               " With a set interval of: " + str(cfg.INTERVAL))  # Sets string for logbook.
    print(logging)  # To see the result in the terminal.
    mtd.error_logging(logging)  # Writing to log file.

    content = communication.getdata(cfg.P_BASE, cfg.P_GET, key)

    if key == content:
        content = communication.getdata(cfg.P_BASE, cfg.P_MESSAGE, key)
        print('Key is in imported_content', content)
        parse_cmd(content, key)
Пример #5
0
def request():
    """
        Requests data from the server, it gets the base64 encoded string from a file.
        This string contains API and KEY authentication.
    """
    data = mtd.get_key_info()
    client_ip = mtd.get_client_ip()

    # The Encoded data in a base64 string, so I can post spaces and weird characters.
    # Decode they key, so its not double encoded.
    data = base64.b64decode(data)
    post_data = base64.b64encode(data + ',' + cfg.G_PCNAME + ',' + cfg.G_OSNAME + ',' + client_ip)

    print("server data = " + post_data)
    # Request URL with a get parameter, which makes it easier to store the data on the server self.
    s = communication.getdata(cfg.P_BASE, cfg.P_DATA, post_data)
    print(s)

    # Starting loop to get a server reply.
    get_cmd()
Пример #6
0
def request():
    """
        Requests data from the server, it gets the base64 encoded string from a file.
        This string contains API and KEY authentication.
    """
    data = mtd.get_key_info()
    client_ip = mtd.get_client_ip()

    # The Encoded data in a base64 string, so I can post spaces and weird characters.
    # Decode they key, so its not double encoded.
    data = base64.b64decode(data)
    post_data = base64.b64encode(data + ',' + cfg.G_PCNAME + ',' +
                                 cfg.G_OSNAME + ',' + client_ip)

    print("server data = " + post_data)
    # Request URL with a get parameter, which makes it easier to store the data on the server self.
    s = communication.getdata(cfg.P_BASE, cfg.P_DATA, post_data)
    print(s)

    # Starting loop to get a server reply.
    get_cmd()
Пример #7
0
def get_cmd():
    """
        Requests data from server, and checks if there is a result
    """
    cfg.COUNT += 1  # Count the total requests this session.
    key = mtd.get_key_info()

    threading.Timer(cfg.INTERVAL, get_cmd).start(
    )  # Starts the timer loop to request data from the server.

    logging = (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
               " Request: #" + str(cfg.COUNT) + " With a set interval of: " +
               str(cfg.INTERVAL))  # Sets string for logbook.
    print(logging)  # To see the result in the terminal.
    mtd.error_logging(logging)  # Writing to log file.

    content = communication.getdata(cfg.P_BASE, cfg.P_GET, key)

    if key == content:
        content = communication.getdata(cfg.P_BASE, cfg.P_MESSAGE, key)
        print('Key is in imported_content', content)
        parse_cmd(content, key)