function ZimAPI_setSSH($mode) { $output = array(); $ret_val = 0; $mode = strtolower($mode); switch ($mode) { case 'off': exec(ZIMAPI_CMD_SSH_OFF); break; case 'on': $mode_current = NULL; if (ZimAPI_getSSH($mode_current)) { if ($mode_current == FALSE) { exec(ZIMAPI_CMD_SSH_ON); } else { $CI =& get_instance(); $CI->load->helper('printerlog'); PrinterLog_logMessage('remote ssh already opened', __FILE__, __LINE__); } } else { return ERROR_INTERNAL; } break; default: return ERROR_WRONG_PRM; break; } return ERROR_OK; }
public function printerinfo() { $template_data = array(); $temp_info = array(); $array_info = NULL; //array() // $sso_name = NULL; $ssh_mode = NULL; $ssh_link = NULL; // $ip_addr6 = NULL; $this->load->helper(array('printerstate', 'zimapi')); $this->load->library('parser'); $this->lang->load('printerstate/printerinfo', $this->config->item('language')); $this->lang->load('printerstate/index', $this->config->item('language')); // ZimAPI_getPrinterSSOName($sso_name); $temp_info = PrinterState_getInfoAsArray(); // if (is_array($temp_info[ZIMAPI_TITLE_IPV6])) { // foreach ($temp_info[ZIMAPI_TITLE_IPV6] as $ip_scope => $ip_addr) { // if (!is_null($ip_addr6)) { // $ip_addr6 .= ', '; // } // $ip_addr6 .= $ip_addr . ' (' . t($ip_scope) . ')'; // } // } // else { // $ip_addr6 = $temp_info[ZIMAPI_TITLE_IPV6]; // } if (ZimAPI_getSSH($ssh_mode, $ssh_link) && $ssh_mode == TRUE) { $ssh_mode = t('function_on') . ' (' . $ssh_link . ')'; } else { $ssh_mode = t('function_off'); } // $hostname = "no hostname"; // ZimAPI_getHostname($hostname); $array_info = array(array('title' => t('version_title'), 'value' => $this->parser->parse('printerstate/printerinfo_grid_b', array('id' => 'button_release', 'value' => $temp_info[PRINTERSTATE_TITLE_VERSION], 'link' => '/printerstate/upgradenote', 'button' => '{button_release}'), TRUE)), array('title' => t('next_version_title'), 'value' => $temp_info[PRINTERSTATE_TITLE_VERSION_N]), array('title' => t('type_title'), 'value' => $temp_info[PRINTERSTATE_TITLE_TYPE]), array('title' => t('serial_title'), 'value' => $temp_info[PRINTERSTATE_TITLE_SERIAL]), array('title' => t('extruder_title'), 'value' => $temp_info[PRINTERSTATE_TITLE_NB_EXTRUD]), array('title' => t('marlin_title'), 'value' => $temp_info[PRINTERSTATE_TITLE_VER_MARLIN]), array('title' => t('ip_address'), 'value' => $temp_info[ZIMAPI_TITLE_IP]), array('title' => t('remote_control'), 'value' => $ssh_mode), array('title' => t('sso_name'), 'value' => $this->parser->parse('printerstate/printerinfo_grid_b', array('id' => 'button_sso', 'value' => array_key_exists(PRINTERSTATE_TITLE_SSO_NAME, $temp_info) ? $temp_info[PRINTERSTATE_TITLE_SSO_NAME] : "", 'link' => '/activation/?returnUrl=printerstate/printerinfo', 'button' => '{button_sso}'), TRUE))); // parse the main body $template_data = array('array_info' => $array_info, 'back' => t('back'), 'home' => t('Home'), 'button_sso' => array_key_exists(PRINTERSTATE_TITLE_SSO_NAME, $temp_info) ? t('button_rename_sso') : t('button_active_sso'), 'button_fqdn' => t('button_rename_sso'), 'button_release' => t('button_release')); // parse all page $this->_parseBaseTemplate(t('printerstate_printerinfo_pagetitle'), $this->parser->parse('printerstate/printerinfo', $template_data, TRUE)); return; }
public function get() { $parameter = NULL; $cr = 0; $display = NULL; $api_prm = NULL; $this->load->helper(array('printerstate', 'zimapi')); $parameter = $this->input->get('p'); //return false if missing if ($parameter) { switch ($parameter) { case PRINTERSTATE_PRM_EXTRUDER: $cr = PrinterState_getExtruder($display); //$abb_extruder break; case PRINTERSTATE_PRM_TEMPER: // check which temperature we want $has_e = $this->input->get('e'); $has_h = $this->input->get('h'); $has_v = $this->input->get('v'); if ($has_e === FALSE && $has_h === FALSE) { $cr = ERROR_MISS_PRM; } else { if (!($has_e === FALSE) && !($has_h === FALSE)) { $cr = ERROR_WRONG_PRM; } else { if (!($has_e === FALSE) && !($has_v === FALSE)) { // refuse getting data not existed for mono extruder if ($has_v == 'l' && $this->config->item('nb_extruder') == 1) { $cr = ERROR_WRONG_PRM; } else { if (in_array($has_v, array('l', 'r'))) { // $tmp_array = PrinterState_getExtruderTemperaturesAsArray(); // $cr = ERROR_OK; // $display = ($has_v == 'l') // ? $tmp_array[PRINTERSTATE_LEFT_EXTRUD] // : $tmp_array[PRINTERSTATE_RIGHT_EXTRUD]; $cr = PrinterState_getTemperature($display, 'e', $has_v); } else { $cr = ERROR_WRONG_PRM; } } } else { $api_prm = $has_e === FALSE ? 'h' : 'e'; $cr = PrinterState_getTemperature($display, $api_prm); } } } break; case PRINTERSTATE_PRM_CARTRIDGE: $api_prm = $this->input->get('v'); // refuse getting data not existed for mono extruder if ($api_prm == 'l' && $this->config->item('nb_extruder') == 1) { $cr = ERROR_WRONG_PRM; } else { $cr = PrinterState_getCartridge($display, $api_prm); } break; case PRINTERSTATE_PRM_INFO: //TODO need add SSO account $cr = ERROR_OK; $display = PrinterState_getInfo(); break; case 'render': $this->_return_under_construction(); return; break; case PRINTERSTATE_PRM_ACCELERATION: $cr = PrinterState_getAcceleration($display); break; case PRINTERSTATE_PRM_SPEED_MOVE: case PRINTERSTATE_PRM_SPEED_EXTRUDE: $cr = PrinterState_getSpeed($display); break; case PRINTERSTATE_PRM_COLDEXTRUSION: $value = NULL; $cr = PrinterState_getColdExtrusion($value); if ($cr == ERROR_OK) { if ($value == TRUE) { $display = 'on'; } else { $display = 'off'; } } break; case PRINTERSTATE_PRM_FILAMENT: $value = NULL; $api_prm = $this->input->get('v'); // refuse getting data not existed for mono extruder if ($api_prm == 'l' && $this->config->item('nb_extruder') == 1) { $cr = ERROR_WRONG_PRM; } else { if ($api_prm) { $cr = ERROR_OK; $value = PrinterState_getFilamentStatus($api_prm); if ($value == TRUE) { $display = 'true'; } else { $display = 'false'; } } else { $cr = ERROR_MISS_PRM; } } break; case PRINTERSTATE_PRM_ENDSTOP: $status = NULL; $abb_endstop = $this->input->get('axis'); $cr = PrinterState_getEndstop($abb_endstop, $status); if ($cr == ERROR_OK) { $display = $status ? 'on' : 'off'; } break; case PRINTERSTATE_PRM_STRIPLED: $value = NULL; $cr = PrinterState_getStripLedStatus($value); if ($cr == ERROR_OK) { if ($value == TRUE) { $display = 'on'; } else { $display = 'off'; } } break; case PRINTERSTATE_PRM_HEADLED: $value = NULL; $cr = PrinterState_getTopLedStatus($value); if ($cr == ERROR_OK) { if ($value == TRUE) { $display = 'on'; } else { $display = 'off'; } } break; case PRINTERSTATE_PRM_OFFSET: $value = NULL; $axis = $this->input->get('axis'); if ($axis) { $cr = PrinterState_getOffset($axis, $value); if ($cr == ERROR_OK) { $display = $value; } } else { $cr = ERROR_MISS_PRM; } break; case PRINTERSTATE_PRM_POSITION: $cr = PrinterState_getPosition($display); break; case ZIMAPI_PRM_CAPTURE: $path_capture = ''; $password = $this->input->get('password'); if (!ZimAPI_checkCameraPassword($password)) { $cr = ERROR_WRONG_PWD; break; } $this->load->helper('file'); if (ZimAPI_cameraCapture($path_capture)) { $this->output->set_content_type(get_mime_by_extension($path_capture))->set_output(@file_get_contents($path_capture)); return; } else { $cr = ERROR_INTERNAL; } break; case ZIMAPI_PRM_VIDEO_MODE: if (ZimAPI_checkCamera($display)) { $cr = ERROR_OK; } else { $cr = ERROR_INTERNAL; } break; case ZIMAPI_PRM_PRESET: if (ZimAPI_getPreset($display)) { $cr = ERROR_OK; } else { $cr = ERROR_INTERNAL; } break; case ZIMAPI_PRM_UPGRADE: if (ZimAPI_getUpgradeMode($display)) { $cr = ERROR_OK; } else { $cr = ERROR_INTERNAL; } if ($display != 'off') { $display = 'on'; } break; case ZIMAPI_PRM_PROXY: if (ZimAPI_getTromboning()) { $display = 'on'; } else { $display = 'off'; } $cr = ERROR_OK; break; case ZIMAPI_PRM_SSH: $status_current = NULL; if (ZimAPI_getSSH($status_current)) { $cr = ERROR_OK; if ($status_current) { $display = 'on'; } else { $display = 'off'; } } else { $cr = ERROR_INTERNAL; } break; case ZIMAPI_PRM_STATS: if (ZimAPI_getStatistic()) { $display = 'on'; } else { $display = 'off'; } $cr = ERROR_OK; break; default: $cr = ERROR_WRONG_PRM; break; } } else { $cr = ERROR_MISS_PRM; } if ($cr != ERROR_OK) { $display = $cr . " " . t(MyERRMSG($cr)); } $this->output->set_status_header($cr, $display); // http_response_code($cr); $this->output->set_content_type(RETURN_CONTENT_TYPE); // echo $display; $this->load->library('parser'); $this->parser->parse('plaintxt', array('display' => $display)); return; }