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})
def usr_take_picture(devId, op): if (db_api.user_check_dev_mgmt(devId)): if (op == 'shot'): return jsonify({"success": db_api.user_take_pic(devId), "is_mgmt": True}) return jsonify({"success": False, "is_mgmt": True}) """ if (op == 'query'): if (db_api.user_check_dev_fetch(devId)): return jsonify({"success": True, "file": str(devId), "is_mgmt": True}) return jsonify({"success": False, "is_mgmt": True}) if (op == 'get'): content = request.json if (isinstance(content, dict) and "file" in content): return send_from_directory(file_dir, "dev_" + str(devId) + '.jpg') return jsonify({"success": False, "is_mgmt": True}) """ return jsonify({"success": False, "is_mgmt": False})
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})
def usr_move_servo(devId): if (db_api.user_check_dev_mgmt(devId)): content = request.json if ('inc_dec' in content and 'xy' in content): db_api.user_servo_inc(devId, content['inc_dec'], content['xy']) return jsonify({"success": True}) if ('pos_x' in content and 'pos_y' in content): # tested db_api.user_servo_pos(devId, content['pos_x'], content['pos_y']) return jsonify({"success": True}) return jsonify({"success": False, "is_mgmt": True}) return jsonify({"success": False, "is_mgmt": False})
def usr_check_mgmt(devId): return jsonify({"is_mgmt": db_api.user_check_dev_mgmt(devId)})