Ejemplo n.º 1
0
 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;
     }
 }
Ejemplo n.º 2
0
 public function connect_google($in_upload_state = "")
 {
     set_include_path(get_include_path() . PATH_SEPARATOR . BASEPATH . '../assets/google_api/src');
     require_once 'Google/Client.php';
     require_once 'Google/Service/YouTube.php';
     $this->load->library('session');
     $client = new Google_Client();
     $client->setApplicationName("Zeepro youtube upload");
     $client->setClientId("652807238221-vrc4no9o0t9mdb48ltc69v215henenm4.apps.googleusercontent.com");
     $client->setClientSecret("PPww8vp8cOVcqeHioL7HbCFx");
     $client->setScopes('https://www.googleapis.com/auth/youtube');
     $redirect = filter_var('https://sso.zeepro.com/redirect.ashx', FILTER_SANITIZE_URL);
     $client->setRedirectUri($redirect);
     $client->setAccessType('offline');
     $youtube = new Google_Service_YouTube($client);
     if (isset($_GET['code'])) {
         if (strval($this->session->userdata('state')) !== strval($_GET['state'])) {
             var_dump($this->session->all_userdata());
             die('The session state did not match.');
         }
         $client->authenticate($_GET['code']);
         $this->session->set_userdata('token', $client->getAccessToken());
         $this->session->set_userdata('code', $_GET['code']);
     }
     if ($this->session->userdata('token') !== FALSE) {
         $client->setAccessToken($this->session->userdata('token'));
         if ($client->isAccessTokenExpired()) {
             $currentTokenData = json_decode($this->session->userdata('token'));
             if (isset($currentTokenData->refresh_token)) {
                 $client->refreshToken($tokenData->refresh_token);
             }
         }
     }
     if ($client->getAccessToken() && $in_upload_state != "") {
         $this->load->helper('zimapi');
         try {
             $videoPath = ZIMAPI_FILEPATH_TIMELAPSE;
             // Create a snippet with title, description, tags and category ID
             // Create an asset resource and set its snippet metadata and type.
             // This example sets the video's title, description, keyword tags, and
             // video category.
             $snippet = new Google_Service_YouTube_VideoSnippet();
             $snippet->setTitle($this->session->userdata('yt_title'));
             $snippet->setDescription($this->session->userdata("yt_desc"));
             $snippet->setTags($this->session->userdata("yt_tags"));
             // Numeric video category. See https://developers.google.com/youtube/v3/docs/videoCategories/list
             $snippet->setCategoryId("22");
             // Set the video's status to "public". Valid statuses are "public", "private" and "unlisted".
             $status = new Google_Service_YouTube_VideoStatus();
             $status->privacyStatus = $this->session->userdata('yt_privacy');
             // Associate the snippet and status objects with a new video resource.
             $video = new Google_Service_YouTube_Video();
             $video->setSnippet($snippet);
             $video->setStatus($status);
             // Specify the size of each chunk of data, in bytes. Set a higher value for
             // reliable connection as fewer chunks lead to faster uploads. Set a lower
             // value for better recovery on less reliable connections.
             $chunkSizeBytes = 1 * 1024 * 1024;
             // Setting the defer flag to true tells the client to return a request which can be called
             // with ->execute(); instead of making the API call immediately.
             $client->setDefer(true);
             // Create a request for the API's videos.insert method to create and upload the video.
             $insertRequest = $youtube->videos->insert("status,snippet", $video);
             // Create a MediaFileUpload object for resumable uploads.
             $media = new Google_Http_MediaFileUpload($client, $insertRequest, 'video/mp4', null, true, $chunkSizeBytes);
             $media->setFileSize(filesize($videoPath));
             // Read the media file and upload it chunk by chunk.
             $status = false;
             $handle = fopen($videoPath, "rb");
             while (!$status && !feof($handle)) {
                 $chunk = fread($handle, $chunkSizeBytes);
                 $status = $media->nextChunk($chunk);
             }
             fclose($handle);
             $client->setDefer(false);
             $this->session->unset_userdata(array('yt_title', 'yt_desc', 'yt_tags', 'yt_privacy'));
             echo "<h3>Video Uploaded</h3><ul>";
             echo sprintf('<li>%s (%s)</li>', $status['snippet']['title'], $status['id']);
             echo '</ul>';
             //stats info
             $this->load->helper('printerlog');
             PrinterLog_statsShareVideo(PRINTERLOG_STATS_LABEL_YOUTUBE);
         } catch (Google_ServiceException $e) {
             $this->_exitWithError500(sprintf('<p>A service error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage())));
         } catch (Google_Exception $e) {
             $this->_exitWithError500(sprintf('<p>An client error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage())));
         }
         $this->session->set_userdata('token', $client->getAccessToken());
     } else {
         $this->load->helper(array('zimapi', 'corestatus'));
         $prefix = CoreStatus_checkTromboning() ? 'https://' : 'http://';
         $data = array('printersn' => ZimAPI_getSerial(), 'URL' => $prefix . $_SERVER['HTTP_HOST'] . '/share/video_upload');
         $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data)));
         $context = stream_context_create($options);
         @file_get_contents('https://sso.zeepro.com/url.ashx', false, $context);
         $result = substr($http_response_header[0], 9, 3);
         if ($result == 200) {
             //echo 'ca marche';
         }
         $state = ZimAPI_getSerial();
         $client->setState($state);
         $this->session->set_userdata('state', $state);
         $authUrl = $client->createAuthUrl();
         $this->output->set_header("Location: " . $authUrl);
     }
     return;
 }
Ejemplo n.º 3
0
 public function rebooting()
 {
     $this->load->library('parser');
     $this->load->helper(array('zimapi', 'corestatus'));
     $this->lang->load('manage/reboot', $this->config->item('language'));
     $template_data = array('hint' => t('hint'), 'tromboning' => CoreStatus_checkTromboning() ? "true" : "false");
     if (ERROR_OK != ZimAPI_reboot()) {
         $this->output->set_header('Location: /manage');
         return;
     }
     $this->_parseBaseTemplate(t('title_reboot'), $this->parser->parse('manage/rebooting', $template_data, TRUE));
     return;
 }
Ejemplo n.º 4
0
    define('PRINTLIST_MODEL_CALIBRATION', '_nozzle_calibration');
    define('PRINTLIST_FILE_GCODE', 'model.gcode');
    define('PRINTLIST_FILE_GCODE_BZ2', 'model.gcode.bz2');
    define('PRINTLIST_FILE_JSON', 'model.json');
    define('PRINTLIST_GLOBAL_URL_RDV', 'zeepro.com');
    // 	define('PRINTLIST_GETPIC_BASE_WEB',	base_url() . 'getpicture');
    //for IIS, we use only HTTP_HOST?
    // 	if ($_SERVER['SERVER_PORT'] != 80) {
    //  		define('PRINTLIST_GETPIC_BASE_WEB',	'http://' . $_SERVER['HTTP_HOST'] . ':' . $_SERVER['SERVER_PORT'] . base_url('rest/getpicture'));
    // 	} else {
    // 		define('PRINTLIST_GETPIC_BASE_WEB',	'http://' . $_SERVER['HTTP_HOST'] . base_url('rest/getpicture'));
    // 	}
    // 	if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) {
    // 	if ($_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR']
    // 			&& substr($_SERVER['HTTP_HOST'], -strlen(PRINTLIST_GLOBAL_URL_RDV)) === PRINTLIST_GLOBAL_URL_RDV) {
    if (CoreStatus_checkTromboning()) {
        // SSL connection
        define('PRINTLIST_GETPIC_BASE_WEB', 'https://' . $_SERVER['HTTP_HOST'] . base_url('rest/getpicture'));
    } else {
        define('PRINTLIST_GETPIC_BASE_WEB', 'http://' . $_SERVER['HTTP_HOST'] . base_url('rest/getpicture'));
    }
    define('PRINTLIST_GETPIC_PRM_MID', 'id');
    define('PRINTLIST_GETPIC_PRM_PIC', 'p');
}
function ModelList_add($data_array)
{
    global $CFG;
    $printlist_basepath = $CFG->config['printlist'];
    $model_path = '';
    $model_pictures = array();
    $model_names = array();
Ejemplo n.º 5
0
function PrinterState_checkTimelapseCondition(&$data_json)
{
    $timelapse_exist = FALSE;
    $timelapse_done = FALSE;
    $CI =& get_instance();
    $CI->load->helper('zimapi');
    $timelapse_exist = ZimAPI_checkTimelapse($timelapse_done);
    if ($timelapse_exist == TRUE) {
        if ($timelapse_done == TRUE) {
            $timelapse_url = $_SERVER['HTTP_HOST'] . '/tmp/' . ZIMAPI_FILENAME_TIMELAPSE;
            $CI->load->helper('corestatus');
            if (CoreStatus_checkTromboning()) {
                $timelapse_url = 'https://' . $timelapse_url;
            } else {
                $timelapse_url = 'http://' . $timelapse_url;
            }
            $data_json[PRINTERSTATE_TITLE_TIMELAPSE] = $timelapse_url;
        } else {
            $data_json[PRINTERSTATE_TITLE_TIMELAPSE] = PRINTERSTATE_VALUE_TIMELAPSE_GENERATION;
        }
    }
    return;
}
Ejemplo n.º 6
0
function PrinterLog_statsWebAgent()
{
    $CI =& get_instance();
    $CI->load->helper('corestatus');
    return PrinterLog__logStats(array(PRINTERLOG_STATS_TITLE_CATEGORY => PRINTERLOG_STATS_CATEGORY_WEB, PRINTERLOG_STATS_TITLE_ACTION => PRINTERLOG_STATS_ACTION_REQUEST, PRINTERLOG_STATS_TITLE_LABEL => array(PRINTERLOG_STATS_NAVIG_URL => $_SERVER['REQUEST_URI'], PRINTERLOG_STATS_NAVIG_AGENT => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : NULL, PRINTERLOG_STATS_NAVIG_REMOTE => CoreStatus_checkTromboning() ? PRINTERLOG_STATS_VALUE_ON : PRINTERLOG_STATS_VALUE_OFF), PRINTERLOG_STATS_TITLE_VALUE => NULL));
}