Ejemplo n.º 1
0
def usr_control_ssh(devId, op):
    if (db_api.user_check_dev_mgmt(devId)):
        if (op == "start"):
            return jsonify({"success": db_api.user_ssh_enable(devId),
                            "port": 10000+devId})

        if (op == "stop"):
            return jsonify({"success": db_api.user_ssh_disable(devId)})

        if (op == "zombie"):
            kill_pids_of_port(10000+devId)
            return jsonify({"success": True})

        if (op == "restart"):
            db_api.user_ssh_restart(devId)
            return jsonify({"success": db_api.user_ssh_restart(devId),
                            "port": 10000+devId})

        if (op == "renew"):
            content = request.json

            if (isinstance(content, int)):
                if content > 90*60:
                    return jsonify({"success": False})
                else:
                    global ssh_timeout
                    db_api.update_activity(devId)
                    ssh_timeout = max(content, ssh_timeout)
                    return jsonify({"success": True})
            else:
                return jsonify({"success": False})

    return jsonify({"success": False, "is_mgmt": False})
Ejemplo n.º 2
0
def usr_renew_mgmt(devId, time):
    if (db_api.user_check_dev_mgmt(devId)):
        global manage_timeout
        if (time > 30*60):
            return jsonify({"success": False, "is_mgmt": True})
        else:
            manage_timeout = max(time, manage_timeout)
            db_api.update_activity(devId)
            return jsonify({"success": True, "is_mgmt": True})

    return jsonify({"success": False, "is_mgmt": False})