示例#1
0
function ZimAPI_setNetwork($string_json)
{
    $array_config = json_decode($string_json);
    if ($array_config) {
        if (isset($array_config[ZIMAPI_TITLE_TOPOLOGY]) && isset($array_config[ZIMAPI_TITLE_MEDIUM])) {
            if ($array_config[ZIMAPI_TITLE_MEDIUM] == ZIMAPI_VALUE_WIFI) {
                if (!isset($array_config[ZIMAPI_TITLE_SSID]) || !isset($array_config[ZIMAPI_TITLE_PASSWD])) {
                    return ERROR_MISS_PRM;
                }
                $ssid = $array_config[ZIMAPI_TITLE_SSID];
                $pwd = $array_config[ZIMAPI_TITLE_PASSWD];
                if ($array_config[ZIMAPI_TITLE_TOPOLOGY] == ZIMAPI_VALUE_NETWORK) {
                    return ZimAPI_setcWifi($ssid, $pwd);
                } else {
                    if ($array_config[ZIMAPI_TITLE_TOPOLOGY] == ZIMAPI_VALUE_P2P) {
                        return ZimAPI_setsWifi($ssid, $pwd);
                    } else {
                        return ERROR_WRONG_PRM;
                    }
                }
            } else {
                if ($array_config[ZIMAPI_TITLE_MEDIUM] == ZIMAPI_VALUE_ETH && $array_config[ZIMAPI_TITLE_TOPOLOGY] == ZIMAPI_VALUE_NETWORK) {
                    if (isset($array_config[ZIMAPI_TITLE_CUS_IP]) || isset($array_config[ZIMAPI_TITLE_CUS_GW]) || isset($array_config[ZIMAPI_TITLE_CUS_MK])) {
                        if (!isset($array_config[ZIMAPI_TITLE_CUS_IP]) || !isset($array_config[ZIMAPI_TITLE_CUS_GW]) || !isset($array_config[ZIMAPI_TITLE_CUS_MK])) {
                            return ERROR_MISS_PRM;
                        }
                        $ip = $array_config[ZIMAPI_TITLE_CUS_IP];
                        $gateway = $array_config[ZIMAPI_TITLE_CUS_GW];
                        $mask = $array_config = $array_config[ZIMAPI_TITLE_CUS_MK];
                        return ZimAPI_setcEth($ip, $mask, $gateway);
                    } else {
                        return ZimAPI_setpEth();
                    }
                } else {
                    return ERROR_WRONG_PRM;
                }
            }
        } else {
            return ERROR_MISS_PRM;
        }
    } else {
        return ERROR_WRONG_PRM;
    }
}
示例#2
0
 public function wifipswd()
 {
     $template_data = array();
     $body_page = NULL;
     $valid = TRUE;
     $this->load->library(array('parser', 'form_validation'));
     $this->load->helper(array('zimapi', 'corestatus'));
     $this->lang->load('connection/master', $this->config->item('language'));
     $this->lang->load('connection/wifipswd', $this->config->item('language'));
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $this->form_validation->set_rules('password_confirm', 'Password confirmation', 'matches[password]');
         $valid = $this->form_validation->run();
         $ssid = $this->input->post('ssid');
         $mode = $this->input->post('mode');
         if ($valid != FALSE) {
             $passwd = $this->input->post('password');
             $ret_val = ZimAPI_setcWifi($ssid, $passwd);
             if ($ret_val != ERROR_OK) {
                 // 				$error = t('invalid data');
                 $this->output->set_header("Location:/connection/wifissid" . ($mode == 'wizard') ? '/wizard' : NULL);
                 return;
             } else {
                 //$this->confirmation();
                 if ($mode == 'wizard') {
                     // 					$this->confirmation_wizard();
                     // 					$this->in_progress();
                     if (!CoreStatus_wantActivation()) {
                         $this->load->helper('printerlog');
                         PrinterLog_logError('can not set need activation status', __FILE__, __LINE__);
                     }
                     ZimAPI_restartNetwork();
                     $this->output->set_header("Location:/connection/in_progress/" . rawurlencode($ssid));
                     return;
                 } else {
                     if (!CoreStatus_wantHostname()) {
                         $this->load->helper('printerlog');
                         PrinterLog_logError('can not set need hostname status', __FILE__, __LINE__);
                     }
                     $this->output->set_header("Location:/printerstate/sethostname");
                     return;
                 }
             }
         }
     } else {
         $ssid = $this->input->get('ssid');
         $mode = $this->input->get('mode');
     }
     $template_data = array('title' => htmlspecialchars(t("network", $ssid)), 'ssid' => $ssid, 'label' => htmlspecialchars(t("network password")), 'back' => t('Back'), 'submit' => htmlspecialchars(t("OK")), 'mode' => $mode == 'wizard' ? 'wizard' : 'normal', 'confirm_password' => t('confirm_password'), 'show_password' => t('show_password'), 'err_msg' => $valid == FALSE ? t('err_msg') : "");
     $body_page = $this->parser->parse('connection/wifipswd', $template_data, TRUE);
     // parse all page
     $this->_generate_framePage($body_page);
     return;
 }