"Fossies" - the Fresh Open Source Software Archive

Member "OCSNG_UNIX_SERVER_2.6/ocsreports/plugins/main_sections/ms_teledeploy/ms_tele_package_new.php" (17 Apr 2019, 7548 Bytes) of package /linux/privat/OCSNG_UNIX_SERVER_2.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 /*
    3  * Copyright 2005-2016 OCSInventory-NG/OCSInventory-ocsreports contributors.
    4  * See the Contributors file for more details about them.
    5  *
    6  * This file is part of OCSInventory-NG/OCSInventory-ocsreports.
    7  *
    8  * OCSInventory-NG/OCSInventory-ocsreports is free software: you can redistribute
    9  * it and/or modify it under the terms of the GNU General Public License as
   10  * published by the Free Software Foundation, either version 2 of the License,
   11  * or (at your option) any later version.
   12  *
   13  * OCSInventory-NG/OCSInventory-ocsreports is distributed in the hope that it
   14  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
   15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16  * GNU General Public License for more details.
   17  *
   18  * You should have received a copy of the GNU General Public License
   19  * along with OCSInventory-NG/OCSInventory-ocsreports. if not, write to the
   20  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   21  * MA 02110-1301, USA.
   22  */
   23 require_once 'lib/package_functions.php';
   24 
   25 // Initialize the timestamp
   26 if (is_defined($_POST['TIMESTAMP']) && is_numeric($_POST['TIMESTAMP'])) {
   27     $timestamp = (integer) $_POST['TIMESTAMP'];
   28 } else {
   29     $timestamp = time();
   30 }
   31 
   32 // If the package hasn't been created, show the create package form
   33 if (!package_exists($timestamp)) {
   34     if (AJAX && isset($_FILES['FILE'])) {
   35         // Handle file upload
   36         $tmp_file = $_FILES['FILE']['tmp_name'];
   37 
   38         // Check for errors
   39         $error = null;
   40         $ext = null;
   41         switch ($_FILES['FILE']['error']) {
   42             case UPLOAD_ERR_OK:
   43                 // Check mime type and extension
   44                 $finfo = finfo_open(FILEINFO_MIME_TYPE);
   45                 $mime_type = finfo_file($finfo, $tmp_file);
   46                 finfo_close($finfo);
   47 
   48                 if ($mime_type == 'application/zip') {
   49                     $ext = '.zip';
   50                 } else if ($mime_type == 'application/x-gzip') {
   51                     $ext = '.tar.gz';
   52                 } else {
   53                     $error = 'Invalid file type (' . $mime_type . ')';
   54                 }
   55 
   56                 if (!$error && strtolower(substr($_FILES['FILE']['name'], -strlen($ext))) !== $ext) {
   57                     $error = 'Invalid file extension';
   58                 }
   59 
   60                 break;
   61             case UPLOAD_ERR_NO_FILE:
   62                 $error = 'No file sent';
   63                 break;
   64             case UPLOAD_ERR_INI_SIZE:
   65             case UPLOAD_ERR_FORM_SIZE:
   66                 $error = 'Exceeded file size limit';
   67                 break;
   68             default:
   69                 $error = 'Unknown error';
   70                 break;
   71         }
   72 
   73         if (!$error) {
   74             // Move the file in a tmp dir in its future download location
   75             $package_dir = get_download_root() . $timestamp;
   76 
   77             if (!file_exists($package_dir) && !mkdir($package_dir)) {
   78                 $error = 'Could not create dir ' . $package_dir . ', please fix your filesystem before trying again ';
   79                 // @TODO : buggy code
   80                 break;
   81             }
   82 
   83             $package_tmp_dir = $package_dir . '/tmp';
   84             if (!file_exists($package_tmp_dir) && !mkdir($package_tmp_dir)) {
   85                 $error = 'Could not create dir ' . $package_tmp_dir . ', please fix your filesystem before trying again ';
   86                 // @TODO : buggy code
   87                 break;
   88             }
   89 
   90             $package_tmp_file = $package_tmp_dir . '/package';
   91             if (!move_uploaded_file($tmp_file, $package_tmp_file)) {
   92                 $error = 'Could not create file ' . $package_tmp_file . ', please fix your filesystem before trying again ';
   93                 // @TODO : buggy code
   94                 break;
   95             }
   96 
   97             // Everything went well
   98             $size = filesize($package_tmp_file);
   99         }
  100 
  101         if ($error) {
  102             echo '{"status": "error", "message": "' . $error . '"}';
  103         } else {
  104             echo '{"status": "success", "type": "' . substr($ext, 1) . '", "size": "' . $size . '"}';
  105         }
  106 
  107         exit;
  108     } else {
  109         // Default values
  110         $form_data = array_merge(array(
  111             'NAME' => null,
  112             'DESCRIPTION' => null,
  113             'OS' => 'WINDOWS',
  114             'ACTION' => 'STORE',
  115             'ACTION_INPUT' => null,
  116             'DEPLOY_SPEED' => 'MIDDLE',
  117             'PRIORITY' => 5,
  118             'NB_FRAGS' => null,
  119             'NOTIFY_USER' => null,
  120             'NOTIFY_TEXT' => null,
  121             'NOTIFY_COUNTDOWN' => null,
  122             'NOTIFY_CAN_CANCEL' => null,
  123             'NOTIFY_CAN_DELAY' => null,
  124             'NEED_DONE_ACTION' => null,
  125             'NEED_DONE_ACTION_TEXT' => null,
  126             'REDISTRIB_USE' => null,
  127             'REDISTRIB_PRIORITY' => 5,
  128             'REDISTRIB_NB_FRAGS' => null,
  129             'DOWNLOAD_SERVER_DOCROOT' => get_redistrib_distant_download_root(),
  130                 ), $_POST);
  131 
  132         $form_data['TIMESTAMP'] = $timestamp;
  133 
  134         $errors = array();
  135         if (isset($_POST['create_package'])) {
  136             require_once 'lib/package_forms.php';
  137 
  138             // Perform validation
  139             $errors = validate_package_form($form_data, $_FILES);
  140 
  141             if (!$errors) {
  142                 require_once('require/function_telediff.php');
  143 
  144                 // Create package
  145                 $sql_details = array(
  146                     'document_root' => get_download_root(),
  147                     'timestamp' => $timestamp,
  148                     'nbfrags' => $form_data['NB_FRAGS'],
  149                     'name' => $form_data['NAME'],
  150                     'os' => $form_data['OS'],
  151                     'description' => $form_data['DESCRIPTION'],
  152                     'size' => 0, //$form_data['SIZE'],
  153                     'id_wk' => 0//$form_data['LIST_DDE_CREAT']
  154                 );
  155 
  156                 $info_details = array(
  157                     'PRI' => $form_data['PRIORITY'],
  158                     'ACT' => $form_data['ACTION'],
  159                     'DIGEST' => 'TODO', //$form_data['digest'],
  160                     'PROTO' => 'HTTP', //$protectedPost['PROTOCOLE'],
  161                     'DIGEST_ALGO' => 'MD5', //["digest_algo"],
  162                     'DIGEST_ENCODE' => 'HEXA', //$protectedPost["digest_encod"],
  163                     'PATH' => $form_data['ACTION_INPUT'],
  164                     'NAME' => $form_data['ACTION_INPUT'],
  165                     'COMMAND' => $form_data['ACTION_INPUT'],
  166                     'NOTIFY_USER' => $form_data['NOTIFY_USER'],
  167                     'NOTIFY_TEXT' => $form_data['NOTIFY_TEXT'],
  168                     'NOTIFY_COUNTDOWN' => $form_data['NOTIFY_COUNTDOWN'],
  169                     'NOTIFY_CAN_ABORT' => $form_data['NOTIFY_CAN_ABORT'],
  170                     'NOTIFY_CAN_DELAY' => $form_data['NOTIFY_CAN_DELAY'],
  171                     'NEED_DONE_ACTION' => $form_data['NEED_DONE_ACTION'],
  172                     'NEED_DONE_ACTION_TEXT' => $form_data['NEED_DONE_ACTION_TEXT'],
  173                     'GARDEFOU' => 'rien'
  174                 );
  175 
  176                 create_pack($sql_details, $info_details);
  177             }
  178         }
  179 
  180         if ($errors || !isset($_POST['create_package'])) {
  181             require_once 'views/package_form_view.php';
  182             show_package_form($form_data, $errors);
  183         }
  184     }
  185 }
  186 
  187 // If the package has been created, show the details of the package
  188 if (package_exists($timestamp)) {
  189     $form_data = array();
  190     $errors = array();
  191 
  192     require_once 'views/activate_form_view.php';
  193     show_activate_form($timestamp, $form_data, $errors);
  194 }
  195 ?>