Exemple #1
0
 public function activation_form()
 {
     $this->load->library('parser');
     $this->lang->load('activation/activation_confirm', $this->config->item('language'));
     $file = 'template/activation/activation_form';
     if ($this->input->server('REQUEST_METHOD') == 'POST') {
         $this->load->library('form_validation');
         $this->form_validation->set_rules('printer_name', 'Printer name', 'required');
         if ($this->form_validation->run()) {
             $this->load->helper('zimapi');
             extract($_POST);
             $url = 'https://sso.zeepro.com/addprinter.ashx';
             $data = array('email' => $this->session->userdata('email'), 'password' => $this->session->userdata('password'), 'printersn' => ZimAPI_getSerial(), 'printername' => $printer_name);
             $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($url, false, $context);
             $result = substr($http_response_header[0], 9, 3);
             if ($result == 200) {
                 ZimAPI_setPrinterSSOName($printer_name);
                 $file = 'template/activation/activation_confirm';
                 /*if (isset($_GET['returnUrl']))
                 			$this->output->set_header("Location:/" . $_GET['returnUrl']);
                 		else
                 			$this->output->set_header("Location:/");*/
             } else {
                 $this->output->set_header("Location:/activation/activation_form");
             }
         }
     }
     $body_page = $this->parser->parse($file, array(), TRUE);
     // parse all page
     $template_data = array('lang' => $this->config->item('language_abbr'), 'headers' => '<title>Zim - Activation</title>', 'contents' => $body_page, 'name_printer' => t('name_printer'), 'back' => t('back'), 'congrats' => t('congrats'), 'confirmation_message' => t('hint'), 'returnUrl' => isset($_GET['returnUrl']) ? "/" . $_GET['returnUrl'] : "/");
     $this->parser->parse('basetemplate', $template_data);
 }
Exemple #2
0
 public function index()
 {
     global $CFG;
     $this->load->library('parser');
     if (file_exists($CFG->config['conf'] . '/G-code.json')) {
         $this->_display_controlIndex();
     } else {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $this->load->helper('zimapi');
             $temp_serial = ZimAPI_getSerial();
             if (strtoupper($this->input->post('serial')) != strtoupper($temp_serial)) {
                 $template_data = array('err_msg' => 'Incorrect serial number');
                 $this->_parseBaseTemplate('Advanced user', $this->parser->parse('advanceduser/register', $template_data, TRUE));
             } else {
                 $url = 'https://stat.service.zeepro.com/log.ashx';
                 $data = array('printersn' => $temp_serial, 'version' => '1', 'category' => 'gcode', 'action' => 'register');
                 $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($url, false, $context);
                 $result = substr($http_response_header[0], 9, 3);
                 if ($result != 200) {
                     $template_data = array('err_msg' => 'Can\'t connect to the Internet');
                     $this->_parseBaseTemplate('Advanced user', $this->parser->parse('advanceduser/register', $template_data, TRUE));
                 } else {
                     $fp = fopen($CFG->config['conf'] . '/G-code.json', 'w');
                     if ($fp) {
                         fwrite($fp, json_encode(array('register' => date("c"))));
                         fclose($fp);
                         $this->_display_controlIndex();
                     } else {
                         $template_data = array('err_msg' => 'Internal error');
                         $this->_parseBaseTemplate('Advanced user', $this->parser->parse('advanceduser/register', $template_data, TRUE));
                     }
                 }
             }
         } else {
             $template_data = array('err_msg' => '');
             $this->_parseBaseTemplate('Advanced user', $this->parser->parse('advanceduser/register', $template_data, TRUE));
         }
     }
     return;
 }
Exemple #3
0
 private function _assign_wizard($email, $password)
 {
     $context = NULL;
     $printer_name = NULL;
     $cr = 0;
     $option = array();
     $this->load->helper('zimapi');
     if (ERROR_OK != ZimAPI_getHostname($printer_name)) {
         $printer_name = 'zim';
     }
     $data = array('email' => $email, 'password' => $password, 'printersn' => ZimAPI_getSerial(), 'printername' => $printer_name);
     $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/addprinter.ashx', false, $context);
     $result = substr($http_response_header[0], 9, 3);
     if ($result == 200) {
         ZimAPI_setPrinterSSOName($printer_name);
         return TRUE;
     }
     return FALSE;
 }
Exemple #4
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;
 }
function PrinterState_getInfoAsArray()
{
    $CI =& get_instance();
    $CI->load->helper('zimapi');
    $version_marlin = NULL;
    $name_sso = NULL;
    $hostname = NULL;
    $network_data = array();
    $platform_size = array();
    $array_return = array();
    $cr = 0;
    $cr = PrinterState_getMarlinVersion($version_marlin);
    if ($cr != ERROR_OK) {
        $version_marlin = 'N/A';
    }
    $cr = ZimAPI_getHostname($hostname);
    if ($cr != ERROR_OK) {
        $hostname = 'N/A';
    }
    PrinterState_getPrintSize($platform_size);
    $cr = ZimAPI_getNetworkInfoAsArray($network_data);
    $array_return = array(PRINTERSTATE_TITLE_VERSION => ZimAPI_getVersion(), PRINTERSTATE_TITLE_VERSION_N => ZimAPI_getVersion(TRUE), PRINTERSTATE_TITLE_TYPE => ZimAPI_getType(), PRINTERSTATE_TITLE_SERIAL => ZimAPI_getSerial(), PRINTERSTATE_TITLE_NB_EXTRUD => $CI->config->item('nb_extruder'), PRINTERSTATE_TITLE_VER_MARLIN => $version_marlin, PRINTERSTATE_TITLE_HOSTNAME => $hostname, ZIMAPI_TITLE_IP => $cr == ERROR_OK && isset($network_data[ZIMAPI_TITLE_IP]) ? $network_data[ZIMAPI_TITLE_IP] : 'N/A', ZIMAPI_TITLE_IPV6 => $cr == ERROR_OK && isset($network_data[ZIMAPI_TITLE_IPV6]) ? $network_data[ZIMAPI_TITLE_IPV6] : 'N/A');
    foreach ($platform_size as $key => $value) {
        $array_return[$key] = $value;
    }
    $cr = ZimAPI_getPrinterSSOName($name_sso);
    if ($cr == ERROR_OK && $name_sso != NULL) {
        $array_return[PRINTERSTATE_TITLE_SSO_NAME] = $name_sso;
    }
    return $array_return;
}
Exemple #6
0
function PrinterLog__logStats($array_stats = array())
{
    $json_data = array();
    $temp_filename = FALSE;
    $folder_path = NULL;
    $CI =& get_instance();
    // ignore invalid or empty input
    if (!is_array($array_stats) || count($array_stats) == 0) {
        return FALSE;
    }
    // return if stats is off
    if (FALSE == PrinterLog_getStats()) {
        return TRUE;
    }
    //TODO think if we take DNT into account or not (Do not track me)
    // 	if (isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] == 1) {
    // 		return TRUE;
    // 	}
    // treat required items: category and action
    if (isset($array_stats[PRINTERLOG_STATS_TITLE_CATEGORY]) && isset($array_stats[PRINTERLOG_STATS_TITLE_ACTION])) {
        $json_data[PRINTERLOG_STATS_TITLE_CATEGORY] = PRINTERLOG_STATS_TITLE_CATEGORY . '=' . $array_stats[PRINTERLOG_STATS_TITLE_CATEGORY];
        $json_data[PRINTERLOG_STATS_TITLE_ACTION] = PRINTERLOG_STATS_TITLE_ACTION . '=' . $array_stats[PRINTERLOG_STATS_TITLE_ACTION];
    } else {
        return FALSE;
    }
    // treat optional items: label and value
    if (isset($array_stats[PRINTERLOG_STATS_TITLE_LABEL])) {
        $item_data = $array_stats[PRINTERLOG_STATS_TITLE_LABEL];
        if (is_array($item_data)) {
            $item_data = json_encode($item_data);
        }
        $json_data[PRINTERLOG_STATS_TITLE_LABEL] = PRINTERLOG_STATS_TITLE_LABEL . '=' . $item_data;
    }
    if (isset($array_stats[PRINTERLOG_STATS_TITLE_VALUE])) {
        $json_data[PRINTERLOG_STATS_TITLE_VALUE] = PRINTERLOG_STATS_TITLE_VALUE . '=' . $array_stats[PRINTERLOG_STATS_TITLE_VALUE];
    }
    // add serial
    $CI->load->helper('zimapi');
    $json_data[PRINTERLOG_STATS_TITLE_SERIAL] = PRINTERLOG_STATS_TITLE_SERIAL . '=' . ZimAPI_getSerial();
    // generate temp curl json file
    $folder_path = $CI->config->item('temp') . PRINTERLOG_STATS_TEMPFILE_FOLDER;
    if (!file_exists($folder_path)) {
        mkdir($folder_path);
    }
    $temp_filename = tempnam($folder_path, PRINTERLOG_STATS_TEMPFILE_PREFIX);
    if ($temp_filename == FALSE || !file_exists($temp_filename)) {
        return FALSE;
    }
    $fp = fopen($temp_filename, 'w');
    if ($fp) {
        //TODO check if we need unescapse unicode
        // 		$CI->load->helper('json');
        // 		fwrite($fp, json_encode_unicode($json_data));
        fwrite($fp, json_encode($json_data));
        fclose($fp);
        chmod($temp_filename, 0777);
    } else {
        return FALSE;
    }
    exec($CI->config->item('siteutil') . PRINTERLOG_STATS_SITEUTILS_CMD . $temp_filename);
    return TRUE;
}
Exemple #7
0
 public function in_progress($ssid = NULL)
 {
     $template_data = array();
     $body_page = NULL;
     $hostname = NULL;
     $this->load->library('parser');
     $this->load->helper('zimapi');
     $this->lang->load('connection/master', $this->config->item('language'));
     $this->lang->load('connection/in_progress', $this->config->item('language'));
     if (ERROR_OK != ZimAPI_getHostname($hostname)) {
         $this->load->helper('printerlog');
         PrinterLog_logError('cannot get hostname', __FILE__, __LINE__);
     }
     $template_data = array('hostname' => $hostname, 'printersn' => ZimAPI_getSerial(), 'config_printer' => t('config_printer'), 'connect_error_msg' => t('connect_error_msg'), 'popup' => t('popup', $ssid ? urldecode($ssid) : "XXX"));
     $body_page = $this->parser->parse('connection/in_progress', $template_data, TRUE);
     $this->_generate_framePage($body_page);
     return;
 }