Exemple #1
0
def system_reboot():
    if not check_admin(request_user):
        return jsonify(build_error(ERROR_NOT_AUTHORIZED, "Insufficient privileges for request.")), UNAUTHORIZED

    sh.reboot()
    
    return jsonify(), ACCEPTED
Exemple #2
0
def system_reboot():
    if not check_admin(request_user):
        return jsonify(
            build_error(ERROR_NOT_AUTHORIZED,
                        "Insufficient privileges for request.")), UNAUTHORIZED

    sh.reboot()

    return jsonify(), ACCEPTED
Exemple #3
0
def system_reboot():
    with sh.sudo:
        try:
            sh.sync()
            sh.reboot()
        except sh.ErrorReturnCode_1:
            flash('Unable to reboot device!', 'error')
            return redirect(url_for('settings.host'))

    flash('Rebooting device!', 'success')
    return redirect(url_for('settings.host'))
def system_reboot():
    with sh.sudo:
        try:
            sh.sync()
            sh.reboot()
        except sh.ErrorReturnCode_1:
            flash('Unable to reboot device!', 'error')
            return redirect(url_for('settings.host'))

    flash('Rebooting device!', 'success')
    return redirect(url_for('settings.host'))
def system_reboot():
    if not check_admin(request_user):
        return jsonify(build_error(ERROR_NOT_AUTHORIZED, "Insufficient privileges for request.")), UNAUTHORIZED

    try:
        sh.reboot()
    except sh.ErrorReturnCode_1:
        return jsonify(build_error(ERROR_NOT_AUTHORIZED, "System did not respond correctly.")), UNAUTHORIZED
    except sh.ErrorReturnCode_143:
        pass

    return jsonify(), ACCEPTED
Exemple #6
0
def system_reboot():
    if not check_admin(request_user):
        return jsonify(
            build_error(ERROR_NOT_AUTHORIZED,
                        "Insufficient privileges for request.")), UNAUTHORIZED

    try:
        sh.reboot()
    except sh.ErrorReturnCode_1:
        return jsonify(
            build_error(ERROR_NOT_AUTHORIZED,
                        "System did not respond correctly.")), UNAUTHORIZED
    except sh.ErrorReturnCode_143:
        pass

    return jsonify(), ACCEPTED
Exemple #7
0
print('\033[1;32;40m images written to images.log file')

print('\033[1;32;40m checking gpio for boot selection')
for gpio_pin, image in boot_selector_config.gpio_image.items():
    gpio.setup(gpio_pin, gpio.IN, pull_up_down=gpio.PUD_UP)
    gpio_state = gpio.input(gpio_pin)
    print('\033[1;36;40m \tgpio {0} = {1}'.format(gpio_pin,
                                                  not bool(gpio_state)))
    if not gpio_state:
        #looking for a LOW signal
        try:
            print(
                '\033[1;32;40m writing {0} to /mnt/data/runonce'.format(image))
            sh.echo(image, _out=runonce_file)
            runonce_file.close()
            print('\033[1;33;40m rebooting in:')
            for t in reversed(range(boot_selector_config.countdown)):
                print('\033[1;31;40m \t{0}'.format(t))
                sleep(1)
            gpio.cleanup()
            sh.reboot()
        except Exception as e:
            print('\033[1;31;40m {0}\n{1} -> {2}'.format(
                e,
                type(e).__name__, e.args))
            quit(2)
gpio.cleanup()
runonce_file.close()
print('\033[1;31;40m error: check the switch connections or config')
quit(2)
Exemple #8
0
def parse_rfcomm(line):
    """
    Parses the command received from the client and executes it.
    """
    global type_pswd
    global ap
    global net_interface
    global net_scan
    global wifi_on
    global hotspot_enabled
    global led_thread_run
    global emergency_led_run
    if type_pswd is True:
        type_pswd = False
        if line != "#":
            print("Connecting to Wi-Fi AP " + ap)
            bt_send("Busy=Connecting to Wi-Fi AP " + ap)
            try:
                print(str(nmcli("device", "wifi", "connect", ap, "password", line)))
                print("Done.")
                send_ip()
            except ErrorReturnCode as e:
                log_err("Unable to connect!")
                print(str(e))
    else:
        if len(line) == 2:
            if line == "01":
                if hotspot_enabled is True:
                    stop_hotspot()
                try:
                    print("Turning off Wi-Fi...")
                    bt_send("Busy=Turning off Wi-Fi...")
                    print(str(nmcli("radio", "wifi", "off")))
                    wifi_on = False
                    bt_send("WiFi=False")
                    print("Done.")
                except ErrorReturnCode as e:
                    log_err("Unable to turn off Wi-Fi!")
                    print(str(e))
            elif line == "02":
                turn_on_wifi()
            elif line == "03":
                start_hotspot()
            elif line == "04":
                stop_hotspot()
            elif line == "05":
                send_ip()
            elif line == "06":
                bt_send("Busy=Looking for Wi-Fi access points...")
                print("Looking for Wi-Fi access points...")
                try:
                    net_scan = list(Cell.all(net_interface))
                    if len(net_scan) == 0:
                        bt_send("WiFiAPs=[]")
                    else:
                        net_scan.sort(key=get_ap_quality, reverse=True)
                        msg = "WiFiAPs=[" + net_scan[0].ssid + \
                              "(" + net_scan[0].quality + ")"
                        for i in range(1, min(len(net_scan), 10)):
                            msg = msg + ", " + \
                                  net_scan[i].ssid + \
                                  "(" + net_scan[i].quality + ")"
                        bt_send(msg + "]")
                        print("Done.")
                except InterfaceError as e:
                    log_err("Unable to scan!")
                    print(str(e))
            elif line == "07":
                shutdown_pi()
            elif line == "08":
                log("Rebooting...")
                led_thread_run = False
                emergency_led_run = False
                sleep(0.5)
                reboot("now")
            elif line[0] == '1':
                i = int(line[1])
                if 0 <= i < min(len(net_scan), 10):
                    ap = str(net_scan[i].ssid)
                    print("Connecting to Wi-Fi AP " + ap)
                    bt_send("Busy=Connecting to Wi-Fi AP " + ap)
                    try:
                        print(str(nmcli("connection", "up", "id", ap)))
                        print("Done.")
                        send_ip()
                    except ErrorReturnCode as e:
                        bt_send("TypePswd=" + ap)
                        type_pswd = True
                else:
                    log_err("Invalid command!")
            elif line[0] == '2':
                if line[1] == '0':
                    stop_indi()
                elif line[1] == '1':
                    indiweb_start()
                else:
                    print("Received: \"" + line + "\"")
                    log_err("Invalid command!")
            else:
                print("Received: \"" + line + "\"")
                log_err("Invalid command!")
        else:
            print("Received: \"" + line + "\"")
            log_err("Invalid command!")
 def reboot(self):
     _logger.info("Rebooting...")
     sh.reboot()
 def ui_command_reboot(self):
     """ reboot - reboot system. """
     #status.tasks.reboot.delay()
     print sh.reboot()