コード例 #1
0
ファイル: printerstate.php プロジェクト: Jaesin/zim-web
 public function sethostname()
 {
     $template_data = array();
     $error = '';
     $ret_val = 0;
     $hostname = NULL;
     $restart = NULL;
     $this->load->library('parser');
     $this->lang->load('printerstate/sethostname', $this->config->item('language'));
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $hostname = $this->input->post('hostname');
         $restart = $this->input->post('restart');
         $returnUrl = $this->input->post('returnUrl');
         if ((int) $restart == 0) {
             $restart = FALSE;
         } else {
             $restart = TRUE;
         }
         if ($hostname) {
             $this->load->helper('zimapi');
             $code = ZimAPI_setHostname($hostname, $restart);
             if (!CoreStatus_finishHostname()) {
                 $this->load->helper('printerlog');
                 PrinterLog_logError('can not remove need hostname status', __FILE__, __LINE__);
             }
             if ($code == ERROR_OK) {
                 $hint_message = NULL;
                 $network_info = array();
                 $err = ZimAPI_getNetworkInfoAsArray($network_info);
                 if ($err != ERROR_OK) {
                     $this->load->helper('printerlog');
                     PrinterLog_logError('can not retrieve connection info array', __FILE__, __LINE__);
                     $error = t("network_array_error");
                 } else {
                     if ($network_info[ZIMAPI_TITLE_TOPOLOGY] == ZIMAPI_VALUE_P2P) {
                         $hint_message = t('p2p', $network_info[ZIMAPI_TITLE_SSID]);
                     } else {
                         if ($restart == TRUE) {
                             $hint_message = t('finish_hint', array($hostname, $hostname, $hostname, $hostname));
                         } else {
                             $hint_message = t('finish_hint_norestart', array($hostname, $hostname));
                         }
                     }
                     //parse the main body
                     $template_data = array('hint' => $hint_message);
                     // parse all page
                     $this->_parseBaseTemplate(t('page_title'), $this->parser->parse('printerstate/sethostname_finish', $template_data, TRUE));
                     return;
                 }
             } else {
                 if ($code == ERROR_WRONG_PRM) {
                     $error = t('bad_char');
                 } else {
                     $error = t('set_error');
                 }
             }
         } else {
             $error = t('no_input');
         }
     }
     if ($restart === NULL) {
         if (FALSE === $this->input->get('norestart')) {
             $restart = TRUE;
         } else {
             $restart = FALSE;
         }
     }
     $ret_val = ZimAPI_getHostname($hostname);
     if ($ret_val != ERROR_OK) {
         $hostname = 'zim';
     }
     // parse the main body
     $template_data = array('hint' => t('set_hint'), 'set_button' => t('set_button'), 'error' => $error, 'back' => t('back'), 'home_button' => t('home_button'), 'hostname' => $hostname, 'info_text' => t('info_text'), 'length_error' => t('length_error'), 'restart' => $restart ? 1 : 0);
     // parse all page
     $this->_parseBaseTemplate(t('page_title'), $this->parser->parse('printerstate/sethostname', $template_data, TRUE));
     return;
 }
コード例 #2
0
ファイル: zimapi_helper.php プロジェクト: Jaesin/zim-web
function ZimAPI_setPrinterSSOName($value, $set_hostname = TRUE)
{
    $CI =& get_instance();
    $filename = $CI->config->item('conf') . ZIMAPI_FILE_SSO_NAME;
    if ($set_hostname == TRUE) {
        $cr = ZimAPI_setHostname($value, FALSE);
        if ($cr != ERROR_OK) {
            return $cr;
        }
    } else {
        //TODO check if it is necessary to add verification here
        if (strlen($value) > 9 || strlen($value) == 0 || !preg_match('/^[A-Za-z0-9]+$/', $hostname)) {
            return ERROR_WRONG_PRM;
        }
    }
    if ($value == NULL) {
        unlink($filename);
    } else {
        try {
            $fp = fopen($filename, 'w');
            if ($fp) {
                fwrite($fp, $value);
                fclose($fp);
            } else {
                $CI->load->helper('printerlog');
                PrinterLog_logError('open sso name file error', __FILE__, __LINE__);
                return ERROR_INTERNAL;
            }
        } catch (Exception $e) {
            $CI->load->helper('printerlog');
            PrinterLog_logError('write printer sso name error', __FILE__, __LINE__);
            return ERROR_INTERNAL;
        }
    }
    return ERROR_OK;
}