public function branch() { $url = $this->input->post('url'); if ($url) { if (FALSE !== @file_get_contents($url) || $this->input->post('force')) { $cr = 0; $this->load->helper('errorcode'); if ($this->input->post('permanent')) { $ret_val = 0; $output = array(); exec('sudo ' . $this->config->item('siteutil') . ' upgrade_url "' . $url . '"', $output, $ret_val); if ($ret_val != ERROR_NORMAL_RC_OK) { $cr = ERROR_WRONG_PRM; } else { $cr = ERROR_OK; } } else { $this->load->helper('zimapi'); $cr = ZimAPI_setUpgradeMode('change', $url); } $this->load->library('parser'); $this->output->set_status_header($cr, MyERRMSG($cr)); $this->parser->parse('plaintxt', array('display' => MyERRMSG($cr))); } } else { //TODO change load view into parser? $this->load->helper('form'); $this->load->view('template/branch_switch'); } return; }
public function changecartridge_action($mode = '') { $abb_cartridge = $this->input->get('v'); if (!$abb_cartridge && !in_array($abb_cartridge, array('l', 'r'))) { $this->output->set_status_header(403); // invalid request return; } if ($mode == 'unload_r') { $mode = 'unload'; } else { if ($mode == 'load_r') { $mode = 'load'; } else { if ($mode != 'cancel_unload') { //block request when not in idle $this->load->helper('corestatus'); if (CoreStatus_checkInIdle() == FALSE) { $this->output->set_status_header(403); // bad request return; } } } } switch ($mode) { case 'unload': $ret_val = PrinterState_unloadFilament($abb_cartridge); if ($ret_val != ERROR_OK) { $this->output->set_status_header($ret_val, MyERRMSG($ret_val)); } break; case 'cancel_unload': $ret_val = 0; @unlink(PRINTERSTATE_FILE_UNLOAD_HEAT); $ret_val = CoreStatus_setInIdle(); if ($ret_val == FALSE) { $this->load->helper('printerlog'); PrinterLog_logError('can not set idle after cancelling unloading', __FILE__, __LINE__); $this->output->set_status_header(ERROR_INTERNAL); } break; case 'load': $ret_val = PrinterState_loadFilament($abb_cartridge); if ($ret_val != ERROR_OK) { $this->output->set_status_header($ret_val); } break; case 'detail': $id_model = $this->input->get('id'); $this->_display_changecartridge_cartridge_detail($abb_cartridge, $id_model); break; case 'write': $ret_val = 0; $array_data = array(); $array_old = array(); $color = $this->input->get('c'); $temper = (int) $this->input->get('t'); $material = (int) $this->input->get('m'); $length = (int) $this->input->get('l') * 1000; $abb_cartridge = $this->input->get('v'); // get cartridge type from old RFID $ret_val = PrinterState_getCartridgeAsArray($array_old, $abb_cartridge, FALSE); if ($ret_val != ERROR_OK) { $this->output->set_status_header(403); $this->load->helper('printerlog'); PrinterLog_logMessage('read rfid error: ' . $ret_val, __FILE__, __LINE__); break; } // change color from name to hex code $this->load->helper('printlist'); $ret_val = ModelList__changeColorName($color); if ($ret_val == ERROR_WRONG_PRM) { $this->output->set_status_header(404); $this->load->helper('printerlog'); PrinterLog_logMessage('unknown color name: ' . $color, __FILE__, __LINE__); break; } $color = str_replace('#', '', $color); // write RFID card $array_data = array(PRINTERSTATE_TITLE_COLOR => $color, PRINTERSTATE_TITLE_EXT_TEMPER => $temper, PRINTERSTATE_TITLE_INITIAL => $length, PRINTERSTATE_TITLE_MATERIAL => $material, PRINTERSTATE_TITLE_CARTRIDGE => $array_old[PRINTERSTATE_TITLE_CARTRIDGE]); $ret_val = PrinterState_setCartridgeAsArray($abb_cartridge, $array_data); if ($ret_val != ERROR_OK) { $this->output->set_status_header(403); $this->load->helper('printerlog'); PrinterLog_logMessage('write rfid error: ' . $ret_val, __FILE__, __LINE__); break; } break; default: $this->output->set_status_header(403); // unknown request break; } return; }
function gcode_ajax() { $cr = 0; $display = NULL; $gcode_path = NULL; $id_model = $this->input->get('id'); $this->load->helper('printer'); $cr = Printer_getFileFromModel(PRINTER_TYPE_GCODELIB, $id_model, $gcode_path); if ($cr == ERROR_OK) { if (file_exists($gcode_path)) { // $this->load->helper('file'); // $this->output->set_content_type(get_mime_by_extension($gcode_path))->set_output(@file_get_contents($gcode_path)); // $this->load->helper('download'); // force_download('library.gcode', @file_get_contents($gcode_path)); $this->_sendFileContent($gcode_path, 'library.gcode'); return; } else { $cr = ERROR_INTERNAL; } } $display = $cr . " " . t(MyERRMSG($cr)); $this->output->set_status_header($cr, $display); // http_response_code($cr); $this->output->set_content_type('text/plain; charset=UTF-8'); $this->load->library('parser'); $this->parser->parse('plaintxt', array('display' => $display)); //optional return; }
function rendering() { $cr = 0; $path_image = NULL; $display = NULL; $rho = $this->input->get('r'); $theta = $this->input->get('t'); $delta = $this->input->get('d'); $color1 = $this->input->get('c1'); $color2 = $this->input->get('c2'); // check color input if (!preg_match('/^#[0-9A-Fa-f]{6}$/', $color1)) { $color1 = NULL; } if (!preg_match('/^#[0-9A-Fa-f]{6}$/', $color2)) { $color2 = NULL; } // assign default value if necessary $this->load->helper('zimapi'); if ($theta === FALSE) { $theta = ZIMAPI_VALUE_DEFAULT_THETA; } if ($delta === FALSE) { $delta = ZIMAPI_VALUE_DEFAULT_DELTA; } if ($rho === FALSE) { $rho = ZIMAPI_VALUE_DEFAULT_RHO; } if ((int) $rho < 0) { $cr = ERROR_WRONG_PRM; } else { $file_info = array(); $file_cartridge = NULL; $this->load->helper('slicer'); $cr = Slicer_rendering((int) $rho, (int) $theta, (int) $delta, $path_image, $color1, $color2); if ($cr == ERROR_OK) { //TODO add the possibility of making path everywhere, but not only in /var/www/tmp/ $this->load->helper('file'); $file_info = get_file_info(realpath($path_image), array('name')); $display = '/tmp/' . $file_info['name'] . '?' . time(); } } if ($cr != ERROR_OK) { $display = $cr . " " . t(MyERRMSG($cr)); } else { if (!file_exists(realpath($path_image))) { // in the case: $cr == ERROR_OK $cr = ERROR_INTERNAL; $display = 'preview image unavailable'; } } $this->output->set_status_header($cr, $cr != ERROR_OK ? $display : 'ok'); $this->output->set_content_type('txt_u'); $this->load->library('parser'); $this->parser->parse('plaintxt', array('display' => $display)); return; }
public function __construct() { global $CFG; parent::__construct(); // $this->load->helper(array('corestatus', 'url')); $this->load->helper(array('corestatus', 'printerlog')); // set proper error handler set_error_handler(array($this, 'errorToSSO')); // add header to disable cache (IE need these headers) $this->output->set_header('Pragma: no-cache'); $this->output->set_header('Cache-Control: no-cache'); // initialisation status files if (!CoreStatus_initialFile()) { $this->load->helper('printerlog'); PrinterLog_logError('status files initialisation error when MY_Controller started', __FILE__, __LINE__); // let request failed $this->_exitWithError500('file initialisation error'); } // check tromboning autorisation if (CoreStatus_checkTromboning(FALSE)) { $this->load->helper(array('printerlog', 'errorcode')); PrinterLog_logMessage('detected and refused tromboning connection', __FILE__, __LINE__); // let request failed $this->_exitWithError500(ERROR_REMOTE_REFUSE . ' ' . MyERRMSG(ERROR_REMOTE_REFUSE), ERROR_REMOTE_REFUSE); } // Workflow management if (CoreStatus_checkCallREST()) { // we place the control for REST web service in his own class // because there are the special error codes for REST web service // and we do not need them in normal condition return; } else { $status_current = ''; $url_redirect = ''; $array_status = array(); // stats info (do not stats rest, app can initialize cookies in each request) $this->load->library('session'); if (FALSE === $this->input->cookie('stats_browserLog')) { $this->input->set_cookie('stats_browserLog', 'ok', 2592000); // 30 days for browser stats PrinterLog_statsWebAgent(); } // check initialization issue if (CoreStatus_checkInInitialization()) { if (CoreStatus_checkCallInitialization($url_redirect)) { return; // we are calling the right page } } else { if (CoreStatus_checkCallInitialization()) { $url_redirect = '/'; } else { if (CoreStatus_checkInUSB()) { if (CoreStatus_checkCallUSB($url_redirect)) { return; // we are calling the right page } } else { if (CoreStatus_checkCallUSB()) { $url_redirect = '/'; } else { if (CoreStatus_checkCallDebug()) { // we always let these interfaces go for debug return; } else { if (CoreStatus_checkInConnection()) { if (CoreStatus_checkCallNoBlockPageInConnection()) { return; // we are calling set hostname, activation or account page } if (CoreStatus_checkCallConnection($url_redirect)) { return; // we are calling the right page } } else { if (CoreStatus_checkCallConnection()) { $url_redirect = '/'; } else { if (!CoreStatus_checkInIdle($status_current, $array_status)) { switch ($status_current) { case CORESTATUS_VALUE_RECOVERY: //TODO finish and test me if (CoreStatus_checkCallRecovery($url_redirect)) { return; // we are calling the right page } break; case CORESTATUS_VALUE_PRINT: if (CoreStatus_checkCallPrinting($array_status, $url_redirect)) { return; // we are calling the right page } break; case CORESTATUS_VALUE_CANCEL: if (CoreStatus_checkCallCanceling($url_redirect)) { return; // we are calling the right page } break; case CORESTATUS_VALUE_LOAD_FILA_L: case CORESTATUS_VALUE_LOAD_FILA_R: if (CoreStatus_checkCallloading($url_redirect)) { return; // we are calling the right page } // return; // we do not block users when charging filament break; case CORESTATUS_VALUE_UNLOAD_FILA_L: case CORESTATUS_VALUE_UNLOAD_FILA_R: //FIXME finish here to block users if (CoreStatus_checkCallUnloading($url_redirect)) { return; // we are calling the right page } break; case CORESTATUS_VALUE_SLICE: if (CoreStatus_checkCallSlicing($url_redirect)) { return; } break; default: $url_redirect = '/'; // internal error, never reach here normally break; } } else { if (CoreStatus_checkCallPrintingAjax() || CoreStatus_checkCallCancelingAjax()) { // let ajax request failed when we finishing printing / canceling $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; header($protocol . ' 403'); header('Content-type: text/plain; charset=UTF-8'); echo 'Not in printing / canceling'; exit; } else { if (CoreStatus_checkCallPrinting() || CoreStatus_checkCallCanceling()) { $url_redirect = '/'; } else { if (CoreStatus_checkInPrinted()) { if (CoreStatus_checkCallEndPrinting($url_redirect) || CoreStatus_checkCallEndPrintingPlus()) { return; } } else { if (CoreStatus_checkCallEndPrinting()) { $url_redirect = '/'; // redirect to homepage when we have no timelapse } } } } if ($url_redirect) { header('Location: ' . $url_redirect); exit; } return; // continue to generate the current page } } } } } } } } // log error if we have no redirect url when reaching here if (is_null($url_redirect)) { $this->load->helper('printerlog'); PrinterLog_logError('no redirect place when MY_Controller finished', __FILE__, __LINE__); } header('Location: ' . $url_redirect); exit; } }
public function sendemail_ajax() { $cr = 0; $display = NULL; $this->load->helper('zimapi'); $email = $this->input->post('email'); $model = $this->input->post('model'); if ($email && $model) { $emails = explode(',', $email); // check parenthesis surround, add them if not exist if (strlen($model) && ($model[0] != '(' || $model[strlen($model) - 1] != ')')) { $model = '(' . $model . ')'; } $cr = ZimAPI_sendTimelapse($emails, $model); } else { $cr = ERROR_MISS_PRM; } $display = $cr . " " . t(MyERRMSG($cr)); $this->output->set_status_header($cr, $display); return; }
function gcode_ajax() { $cr = 0; $display = NULL; $status_array = array(); $this->load->helper(array('printerstate', 'slicer')); $status_array = PrinterState_checkStatusAsArray(); if ($status_array[PRINTERSTATE_TITLE_STATUS] == CORESTATUS_VALUE_SLICED) { $gcode_path = $this->config->item('temp') . SLICER_FILE_MODEL; if (file_exists($gcode_path)) { // $this->load->helper('file'); // $this->output->set_content_type(get_mime_by_extension($gcode_path))->set_output(@file_get_contents($gcode_path)); // $this->load->helper('download'); // force_download('slice.gcode', @file_get_contents($gcode_path)); $this->_sendFileContent($gcode_path, 'slice.gcode'); return; } else { $cr = ERROR_INTERNAL; } } else { $cr = ERROR_EMPTY_PLATFORM; } $display = $cr . " " . t(MyERRMSG($cr)); $this->output->set_status_header($cr, $display); // http_response_code($cr); $this->output->set_content_type('text/plain; charset=UTF-8'); $this->load->library('parser'); $this->parser->parse('plaintxt', array('display' => $display)); //optional return; }