Beispiel #1
0
def api_package_status():
    response = apiresponse.APIResponse()
    if resources.apt_locked() == b'FREE':
        response.insert_value("Status","Free")
        return response.get_json(),200
    else:
        response.insert_value("Status","Locked")
        return  response.get_json(),200
Beispiel #2
0
def login():
    content = request.json
    ip = content['ip']
    password = content['password']

    response = apiresponse.APIResponse()
    response.insert_value("IP", str(ip))
    return response.get_json()
Beispiel #3
0
def api_delete_user():
    content = request.json
    response = apiresponse.APIResponse()
    if users.delete_user(str(content['username']['s']['s'])):  # Will return 1 if user hasn't been created
        response.insert_value("Status", "OK")
    else:
        response.insert_value("Error", "Couldn't delete user")
    return response.get_json()
Beispiel #4
0
def api_change_password():
    content = request.json
    user = content['username']
    new_pass = content['new_password']
    old_pass = content['old_pass']
    # TODO: Implement function in users.py
    response = apiresponse.APIResponse()
    response.insert_value("Status", "OK")
    return response.get_json()
Beispiel #5
0
def api_create_user():
    content = request.json
    print(content)
    response = apiresponse.APIResponse()
    if users.create_user(content['username'], content['auth']):
        response.insert_value("Status", "OK")
        response.insert_value("Message", "User " + content['username'] + " created")
    else:
        response.insert_value("Error", "Couldn't create user")
    return response.get_json()
Beispiel #6
0
def api_stop_process():
    content = request.json
    response = apiresponse.APIResponse()
    process_name = content["name"]["s"]
    if "|" in process_name or "&" in process_name:
        response.insert_value("Status", "Error")
        return response.get_json(),400

    if process.delete_process(str(process_name)):
        response.insert_value("Status", "OK")
        return response.get_json()
    else:
        response.insert_value("Status", "Error")
        return response.get_json(),400
Beispiel #7
0
def api_delete_package():
    content = request.json
    response = apiresponse.APIResponse()

    package_name = content["name"]['s']
    print(package_name)
    pkgManager = packages.PackageManager("yum")

    if pkgManager.remove(package_name):
        response.insert_value("Status", "OK")
        return response.get_json(), 200
    else:
        response.insert_value("Status", "Error")
        return response.get_json(), 400
Beispiel #8
0
def api_install_package():
    content = request.json

    response = apiresponse.APIResponse()

    package_name = content["name"]
    pkgManager = packages.PackageManager("yum")
    if "|" in package_name or "&" in package_name:
        response.insert_value("Status", "Error")
        return response.get_json(), 400

    if pkgManager.install(package_name):
        response.insert_value("Status", "OK")
        return response.get_json(), 200
    else:
        response.insert_value("Status", "Erorr")
        return response.get_json(), 400
Beispiel #9
0
def api_ram():
    response = apiresponse.APIResponse()
    response.insert_value("Value", resources.get_ram_usage_percent())
    return response.get_json()
Beispiel #10
0
def api_disk():
    response = apiresponse.APIResponse()
    response.insert_value("Value", resources.get_disk_space())
    return response.get_json(), 200
Beispiel #11
0
def api_shutdown():
    response = apiresponse.APIResponse()
    response.insert_value("Value", "Ok")
    actions.shutdown()
    return response.get_json(), 200
Beispiel #12
0
def api_battery():
    response = apiresponse.APIResponse()
    response.insert_value("Plug", resources.get_battery_plugged())
    response.insert_value("Value", resources.get_battery_percentage())
    return response.get_json(), 200
Beispiel #13
0
def api_get_cpu():
    response = apiresponse.APIResponse()
    response.insert_value("Value", resources.get_cpu_usage())
    return response.get_json()