function osTicketSession($ttl = 0)
 {
     $this->ttl = $ttl ?: ini_get('session.gc_maxlifetime') ?: SESSION_TTL;
     // Set osTicket specific session name.
     session_name('OSTSESSID');
     // Forced cleanup on shutdown
     register_shutdown_function('session_write_close');
     // Set session cleanup time to match TTL
     ini_set('session.gc_maxlifetime', $ttl);
     if (OsticketConfig::getDBVersion()) {
         return session_start();
     }
     # Cookies
     // Avoid setting a cookie domain without a dot, thanks
     // http://stackoverflow.com/a/1188145
     $domain = null;
     if (isset($_SERVER['HTTP_HOST']) && strpos($_SERVER['HTTP_HOST'], '.') !== false && !Validator::is_ip($_SERVER['HTTP_HOST'])) {
         // Remote port specification, as it will make an invalid domain
         list($domain) = explode(':', $_SERVER['HTTP_HOST']);
     }
     session_set_cookie_params($ttl, ROOT_PATH, $domain, osTicket::is_https());
     //Set handlers.
     session_set_save_handler(array(&$this, 'open'), array(&$this, 'close'), array(&$this, 'read'), array(&$this, 'write'), array(&$this, 'destroy'), array(&$this, 'gc'));
     //Start the session.
     session_start();
 }
示例#2
0
 function osTicketSession($ttl = 0)
 {
     $this->ttl = $ttl ?: ini_get('session.gc_maxlifetime') ?: SESSION_TTL;
     // Set osTicket specific session name.
     session_name('OSTSESSID');
     // Forced cleanup on shutdown
     register_shutdown_function('session_write_close');
     // Set session cleanup time to match TTL
     ini_set('session.gc_maxlifetime', $ttl);
     if (OsticketConfig::getDBVersion()) {
         return session_start();
     }
     # Cookies
     // Avoid setting a cookie domain without a dot, thanks
     // http://stackoverflow.com/a/1188145
     $domain = null;
     if (isset($_SERVER['HTTP_HOST']) && strpos($_SERVER['HTTP_HOST'], '.') !== false && !Validator::is_ip($_SERVER['HTTP_HOST'])) {
         // Remote port specification, as it will make an invalid domain
         list($domain) = explode(':', $_SERVER['HTTP_HOST']);
     }
     session_set_cookie_params($ttl, ROOT_PATH, $domain, osTicket::is_https());
     if (!defined('SESSION_BACKEND')) {
         define('SESSION_BACKEND', 'db');
     }
     try {
         $bk = SESSION_BACKEND;
         if (!class_exists(self::$backends[$bk])) {
             $bk = 'db';
         }
         $this->backend = new self::$backends[$bk]($this->ttl);
     } catch (Exception $x) {
         // Use the database for sessions
         trigger_error($x->getMessage(), E_USER_WARNING);
         $this->backend = new self::$backends['db']($this->ttl);
     }
     if ($this->backend instanceof SessionBackend) {
         // Set handlers.
         session_set_save_handler(array($this->backend, 'open'), array($this->backend, 'close'), array($this->backend, 'read'), array($this->backend, 'write'), array($this->backend, 'destroy'), array($this->backend, 'gc'));
     }
     // Start the session.
     session_start();
 }
示例#3
0
#!/usr/bin/php -q
<?php 
/*********************************************************************
    pipe.php

    Converts piped emails to ticket. Just local - remote must use /api/tickets.email

    Peter Rotich <*****@*****.**>
    Copyright (c)  2006-2013 osTicket
    http://www.osticket.com

    Released under the GNU General Public License WITHOUT ANY WARRANTY.
    See LICENSE.TXT for details.

    vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
ini_set('memory_limit', '256M');
//The concern here is having enough mem for emails with attachments.
@chdir(realpath(dirname(__FILE__)) . '/');
//Change dir.
require 'api.inc.php';
//Only local piping supported via pipe.php
if (!osTicket::is_cli()) {
    die('pipe.php only supports local piping - use http -> api/tickets.email');
}
require_once INCLUDE_DIR . 'api.tickets.php';
PipeApiController::process();
示例#4
0
define('EQUIPMENT_TICKET_VIEW', TABLE_PREFIX . 'EquipmentTicketView');
define('EQUIPMENT_SEARCH_VIEW', TABLE_PREFIX . 'EquipmentSearchView');
define('EQUIPMENT_FORM_VIEW', TABLE_PREFIX . 'EquipmentFormView');
define('EQUIPMENT_DELETE_TRIGGER', TABLE_PREFIX . 'equipment_ADEL');
define('EQUIPMENT_INSERT_TRIGGER', TABLE_PREFIX . 'equipment_AINS');
define('EQUIPMENT_UPDATE_TRIGGER', TABLE_PREFIX . 'equipment_AUPD');
define('STATUS_INSERT_TRIGGER', TABLE_PREFIX . 'equipment_status_AINS');
define('STATUS_UPDATE_TRIGGER', TABLE_PREFIX . 'equipment_status_AUPD');
define('STATUS_DELETE_TRIGGER', TABLE_PREFIX . 'equipment_status_ADEL');
define('EVENT_DELETE_TRIGGER', TABLE_PREFIX . 'ticket_event_AINS');
define('EVENT_UPDATE_TRIGGER', TABLE_PREFIX . 'ticket_event_AUPD');
define('CREATE_FORM_FIELDS_PROCEEDURE', TABLE_PREFIX . 'CreateEquipmentFormFields');
define('COPY_FORM_ENTRY_PROCEEDURE', TABLE_PREFIX . 'Equipment_Copy_Form_Entry');
define('REOPEN_TICKET_PROCEEDURE', TABLE_PREFIX . 'Equipment_Reopen_Ticket');
define('CRON_PROCEEDURE', TABLE_PREFIX . 'EquipmentCronProc');
define('OST_WEB_ROOT', osTicket::get_root_path(__DIR__));
define('EQUIPMENT_WEB_ROOT', OST_WEB_ROOT . 'scp/dispatcher.php/equipment/');
define('OST_ROOT', INCLUDE_DIR . '../');
define('PLUGINS_ROOT', INCLUDE_DIR . 'plugins/');
define('EQUIPMENT_PLUGIN_ROOT', __DIR__ . '/');
define('EQUIPMENT_INCLUDE_DIR', EQUIPMENT_PLUGIN_ROOT . 'include/');
define('EQUIPMENT_MODEL_DIR', EQUIPMENT_INCLUDE_DIR . 'model/');
define('EQUIPMENT_CONTROLLER_DIR', EQUIPMENT_INCLUDE_DIR . 'controller/');
define('EQUIPMENT_APP_DIR', EQUIPMENT_PLUGIN_ROOT . 'app/');
define('EQUIPMENT_ASSETS_DIR', EQUIPMENT_PLUGIN_ROOT . 'assets/');
define('EQUIPMENT_VENDOR_DIR', EQUIPMENT_PLUGIN_ROOT . 'vendor/');
define('EQUIPMENT_VIEWS_DIR', EQUIPMENT_PLUGIN_ROOT . 'views/');
define('EQUIPMENT_STAFFINC_DIR', EQUIPMENT_INCLUDE_DIR . 'staff/');
define('EQUIPMENT_CLIENTINC_DIR', EQUIPMENT_INCLUDE_DIR . 'client/');
require_once EQUIPMENT_VENDOR_DIR . 'autoload.php';
spl_autoload_register(array('EquipmentPlugin', 'autoload'));
示例#5
0
文件: file.php 项目: gizur/osticket
 function run($args, $options)
 {
     Bootstrap::connect();
     osTicket::start();
     switch ($args['action']) {
         case 'backends':
             // List configured backends
             foreach (FileStorageBackend::allRegistered() as $char => $bk) {
                 print "{$char} -- {$bk::$desc} ({$bk})\n";
             }
             break;
         case 'list':
             // List files matching criteria
             // ORM would be nice!
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             foreach ($files as $f) {
                 printf("% 5d %s % 8d %s % 16s %s\n", $f->id, $f->bk, $f->size, $f->created, $f->type, $f->name);
                 if ($f->attrs) {
                     printf("        %s\n", $f->attrs);
                 }
             }
             break;
         case 'dump':
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             if ($files->count() != 1) {
                 $this->fail('Criteria must select exactly 1 file');
             }
             if (($f = AttachmentFile::lookup($files[0]->id)) && ($bk = $f->open())) {
                 $bk->passthru();
             }
             break;
         case 'load':
             // Load file content from STDIN
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             if ($files->count() != 1) {
                 $this->fail('Criteria must select exactly 1 file');
             }
             $f = AttachmentFile::lookup($files[0]->id);
             try {
                 if ($bk = $f->open()) {
                     $bk->unlink();
                 }
             } catch (Exception $e) {
             }
             if ($options['to']) {
                 $bk = FileStorageBackend::lookup($options['to'], $f);
             } else {
                 // Use the system default
                 $bk = AttachmentFile::getBackendForFile($f);
             }
             $type = false;
             $signature = '';
             $finfo = new finfo(FILEINFO_MIME_TYPE);
             if ($options['file'] && $options['file'] != '-') {
                 if (!file_exists($options['file'])) {
                     $this->fail($options['file'] . ': Cannot open file');
                 }
                 if (!$bk->upload($options['file'])) {
                     $this->fail('Unable to upload file contents to backend');
                 }
                 $type = $finfo->file($options['file']);
                 list(, $signature) = AttachmentFile::_getKeyAndHash($options['file'], true);
             } else {
                 $stream = fopen('php://stdin', 'rb');
                 while ($block = fread($stream, $bk->getBlockSize())) {
                     if (!$bk->write($block)) {
                         $this->fail('Unable to send file contents to backend');
                     }
                     if (!$type) {
                         $type = $finfo->buffer($block);
                     }
                 }
                 if (!$bk->flush()) {
                     $this->fail('Unable to commit file contents to backend');
                 }
             }
             // TODO: Update file metadata
             $sql = 'UPDATE ' . FILE_TABLE . ' SET bk=' . db_input($bk->getBkChar()) . ', created=CURRENT_TIMESTAMP' . ', type=' . db_input($type) . ', signature=' . db_input($signature) . ' WHERE id=' . db_input($f->getId());
             if (!db_query($sql) || db_affected_rows() != 1) {
                 $this->fail('Unable to update file metadata');
             }
             $this->stdout->write("Successfully saved contents\n");
             break;
         case 'migrate':
             if (!$options['to']) {
                 $this->fail('Please specify a target backend for migration');
             }
             if (!FileStorageBackend::isRegistered($options['to'])) {
                 $this->fail('Target backend is not installed. See `backends` action');
             }
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             $count = 0;
             foreach ($files as $m) {
                 $f = AttachmentFile::lookup($m->id);
                 if ($f->getBackend() == $options['to']) {
                     continue;
                 }
                 if ($options['verbose']) {
                     $this->stdout->write('Migrating ' . $m->name . "\n");
                 }
                 try {
                     if (!$f->migrate($options['to'])) {
                         $this->stderr->write('Unable to migrate ' . $m->name . "\n");
                     } else {
                         $count++;
                     }
                 } catch (IOException $e) {
                     $this->stderr->write('IOError: ' . $e->getMessage());
                 }
             }
             $this->stdout->write("Migrated {$count} files\n");
             break;
             /**
              * export
              *
              * Export file contents to a stream file. The format of the stream
              * will be a continuous stream of file information in the following
              * format:
              *
              * AFIL<meta-length><data-length><meta><data>EOF\x1c
              *
              * Where
              *   A              is the version code of the export
              *   "FIL"          is the literal text 'FIL'
              *   meta-length    is 'V' packed header length (bytes)
              *   data-length    is 'V' packed data length (bytes)
              *   meta           is the %file record, php serialized
              *   data           is the raw content of the file
              *   "EOF"          is the literal text 'EOF'
              *   \x1c           is an ASCII 0x1c byte (file separator)
              *
              * Options:
              * --file       File to which to direct the stream output, default
              *              is stdout
              */
         /**
          * export
          *
          * Export file contents to a stream file. The format of the stream
          * will be a continuous stream of file information in the following
          * format:
          *
          * AFIL<meta-length><data-length><meta><data>EOF\x1c
          *
          * Where
          *   A              is the version code of the export
          *   "FIL"          is the literal text 'FIL'
          *   meta-length    is 'V' packed header length (bytes)
          *   data-length    is 'V' packed data length (bytes)
          *   meta           is the %file record, php serialized
          *   data           is the raw content of the file
          *   "EOF"          is the literal text 'EOF'
          *   \x1c           is an ASCII 0x1c byte (file separator)
          *
          * Options:
          * --file       File to which to direct the stream output, default
          *              is stdout
          */
         case 'export':
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             if (!$options['file'] || $options['file'] == '-') {
                 $options['file'] = 'php://stdout';
             }
             if (!($stream = fopen($options['file'], 'wb'))) {
                 $this->fail($options['file'] . ': Unable to open file for export stream');
             }
             foreach ($files as $m) {
                 $f = AttachmentFile::lookup($m->id);
                 if ($options['verbose']) {
                     $this->stderr->write($m->name . "\n");
                 }
                 // TODO: Log %attachment and %ticket_attachment entries
                 $info = array('file' => $f->getInfo());
                 $header = serialize($info);
                 fwrite($stream, 'AFIL' . pack('VV', strlen($header), $f->getSize()));
                 fwrite($stream, $header);
                 $FS = $f->open();
                 while ($block = $FS->read()) {
                     fwrite($stream, $block);
                 }
                 fwrite($stream, "EOF");
             }
             fclose($stream);
             break;
             /**
              * import
              *
              * Import a collection of file contents exported by the `export`.
              * See the export function above for details about the stream
              * format.
              *
              * Options:
              * --file       File from which to read the export stream, default
              *              is stdin
              * --to         Backend to receive the contents (@see `backends`)
              * --verbose    Show file names while importing
              */
         /**
          * import
          *
          * Import a collection of file contents exported by the `export`.
          * See the export function above for details about the stream
          * format.
          *
          * Options:
          * --file       File from which to read the export stream, default
          *              is stdin
          * --to         Backend to receive the contents (@see `backends`)
          * --verbose    Show file names while importing
          */
         case 'import':
             if (!$options['file'] || $options['file'] == '-') {
                 $options['file'] = 'php://stdin';
             }
             if (!($stream = fopen($options['file'], 'rb'))) {
                 $this->fail($options['file'] . ': Unable to open import stream');
             }
             while (true) {
                 // Read the file header
                 // struct file_data_header {
                 //   char[4] marker; // Four chars, 'AFIL'
                 //   int     lenMeta;
                 //   int     lenData;
                 // };
                 if (!($header = fread($stream, 12))) {
                     break;
                 }
                 // EOF
                 list(, $mark, $hlen, $dlen) = unpack('V3', $header);
                 // AFIL written as little-endian 4-byte int is 0x4c4946xx (LIFA),
                 // where 'A' is the version code of the export
                 $version = $mark & 0xff;
                 if ($mark >> 8 != 0x4c4946) {
                     $this->fail('Bad file record');
                 }
                 // Read the header
                 $header = fread($stream, $hlen);
                 if (strlen($header) != $hlen) {
                     $this->fail('Short read getting header info');
                 }
                 $header = unserialize($header);
                 if (!$header) {
                     $this->fail('Unable to decipher file header');
                 }
                 // Find or create the file record
                 $finfo = $header['file'];
                 // TODO: Consider the $version code
                 $f = AttachmentFile::lookup($finfo['id']);
                 if ($f) {
                     // Verify file information
                     if ($f->getSize() != $finfo['size'] || $f->getSignature() != $finfo['signature']) {
                         $this->fail(sprintf('%s: File data does not match existing file record', $finfo['name']));
                     }
                     // Drop existing file contents, if any
                     try {
                         if ($bk = $f->open()) {
                             $bk->unlink();
                         }
                     } catch (Exception $e) {
                     }
                 } else {
                     $fm = FileModel::create($finfo);
                     if (!$fm->save() || !($f = AttachmentFile::lookup($fm->id))) {
                         $this->fail(sprintf('%s: Unable to create new file record', $finfo['name']));
                     }
                 }
                 // Determine the backend to recieve the file contents
                 if ($options['to']) {
                     $bk = FileStorageBackend::lookup($options['to'], $f);
                 } else {
                     $bk = AttachmentFile::getBackendForFile($f);
                 }
                 if ($options['verbose']) {
                     $this->stdout->write('Importing ' . $f->getName() . "\n");
                 }
                 // Write file contents to the backend
                 $md5 = hash_init('md5');
                 $sha1 = hash_init('sha1');
                 $written = 0;
                 // Handle exceptions by dropping imported file contents and
                 // then returning the error to the error output stream.
                 try {
                     while ($dlen > 0) {
                         $read_size = min($dlen, $bk->getBlockSize());
                         $contents = '';
                         // reading from the stream will likely return an amount of
                         // data different from the backend requested block size. Loop
                         // until $read_size bytes are recieved.
                         while ($read_size > 0 && ($block = fread($stream, $read_size))) {
                             $contents .= $block;
                             $read_size -= strlen($block);
                         }
                         if ($read_size != 0) {
                             // short read
                             throw new Exception(sprintf('%s: Some contents are missing from the stream', $f->getName()));
                         }
                         // Calculate MD5 and SHA1 hashes of the file to verify
                         // contents after successfully written to backend
                         if (!$bk->write($contents)) {
                             throw new Exception('Unable to send file contents to backend');
                         }
                         hash_update($md5, $contents);
                         hash_update($sha1, $contents);
                         $dlen -= strlen($contents);
                         $written += strlen($contents);
                     }
                     // Some backends cannot handle flush() without a
                     // corresponding write() call.
                     if ($written && !$bk->flush()) {
                         throw new Exception('Unable to commit file contents to backend');
                     }
                     // Check the signature hash
                     if ($finfo['signature']) {
                         $md5 = base64_encode(hash_final($md5, true));
                         $sha1 = base64_encode(hash_final($sha1, true));
                         $sig = str_replace(array('=', '+', '/'), array('', '-', '_'), substr($sha1, 0, 16) . substr($md5, 0, 16));
                         if ($sig != $finfo['signature']) {
                             throw new Exception(sprintf('%s: Signature verification failed', $f->getName()));
                         }
                     }
                     // Update file to record current backend
                     $sql = 'UPDATE ' . FILE_TABLE . ' SET bk=' . db_input($bk->getBkChar()) . ' WHERE id=' . db_input($f->getId());
                     if (!db_query($sql) || db_affected_rows() != 1) {
                         return false;
                     }
                 } catch (Exception $ex) {
                     if ($bk) {
                         $bk->unlink();
                     }
                     $this->fail($ex->getMessage());
                 }
                 // Read file record footer
                 $footer = fread($stream, 4);
                 if (strlen($footer) != 4) {
                     $this->fail('Unable to read file EOF marker');
                 }
                 list(, $footer) = unpack('N', $footer);
                 // Footer should be EOF\x1c as an int
                 if ($footer != 0x454f461c) {
                     $this->fail('Incorrect file EOF marker');
                 }
             }
             break;
         case 'zip':
             // Create a temporary ZIP file
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             if (!$options['file']) {
                 $this->fail('Please specify zip file with `-f`');
             }
             $zip = new ZipArchive();
             if (true !== ($reason = $zip->open($options['file'], ZipArchive::CREATE))) {
                 $this->fail($reason . ': Unable to create zip file');
             }
             foreach ($files as $m) {
                 $f = AttachmentFile::lookup($m->id);
                 if ($options['verbose']) {
                     $this->stderr->write($m->name . "\n");
                 }
                 $name = Format::encode(sprintf('%d-%s', $f->getId(), $f->getName()), 'utf-8', 'cp437');
                 $zip->addFromString($name, $f->getData());
             }
             $zip->close();
             break;
         case 'expunge':
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             foreach ($files as $m) {
                 // Drop associated attachment links
                 $m->tickets->expunge();
                 $f = AttachmentFile::lookup($m->id);
                 // Drop file contents
                 if ($bk = $f->open()) {
                     $bk->unlink();
                 }
                 // Drop file record
                 $f->delete();
             }
     }
 }
示例#6
0
define('TICKET_EVENT_TABLE', TABLE_PREFIX . 'ticket_event');
define('TICKET_EMAIL_INFO_TABLE', TABLE_PREFIX . 'ticket_email_info');
define('EMAIL_TABLE', TABLE_PREFIX . 'email');
define('EMAIL_TEMPLATE_TABLE', TABLE_PREFIX . 'email_template');
define('EMAIL_FILTER_TABLE', TABLE_PREFIX . 'email_filter');
define('EMAIL_FILTER_RULE_TABLE', TABLE_PREFIX . 'email_filter_rule');
define('BANLIST_TABLE', TABLE_PREFIX . 'email_banlist');
//Not in use anymore....as of v 1.7
define('SLA_TABLE', TABLE_PREFIX . 'sla');
define('API_KEY_TABLE', TABLE_PREFIX . 'api_key');
define('TIMEZONE_TABLE', TABLE_PREFIX . 'timezone');
#Connect to the DB && get configuration from database
$ferror = null;
if (!db_connect(DBHOST, DBUSER, DBPASS) || !db_select_database(DBNAME)) {
    $ferror = 'Unable to connect to the database';
} elseif (!($ost = osTicket::start(1)) || !($cfg = $ost->getConfig())) {
    $ferror = 'Unable to load config info from DB. Get tech support.';
}
if ($ferror) {
    //Fatal error
    //try alerting admin using email in config file
    $msg = $ferror . "\n\n" . THISPAGE;
    Mailer::sendmail(ADMIN_EMAIL, 'osTicket Fatal Error', $msg, sprintf('"osTicket Alerts"<%s>', ADMIN_EMAIL));
    //Display generic error to the user
    die("<b>Fatal Error:</b> Contact system administrator.");
    exit;
}
//Init
$session = $ost->getSession();
//System defaults we might want to make global//
#pagenation default - user can overwrite it!
示例#7
0
//Shown on admin panel
define('GIT_VERSION', '$git');
//Path separator
if (!defined('PATH_SEPARATOR')) {
    if (strpos($_ENV['OS'], 'Win') !== false || !strcasecmp(substr(PHP_OS, 0, 3), 'WIN')) {
        define('PATH_SEPARATOR', ';');
    } else {
        define('PATH_SEPARATOR', ':');
    }
    //Linux
}
//Set include paths. Overwrite the default paths.
ini_set('include_path', './' . PATH_SEPARATOR . INCLUDE_DIR . PATH_SEPARATOR . PEAR_DIR);
require INCLUDE_DIR . 'class.osticket.php';
require INCLUDE_DIR . 'class.misc.php';
require INCLUDE_DIR . 'class.http.php';
// Determine the path in the URI used as the base of the osTicket
// installation
if (!defined('ROOT_PATH') && ($rp = osTicket::get_root_path(dirname(__FILE__)))) {
    define('ROOT_PATH', rtrim($rp, '/') . '/');
}
Bootstrap::init();
#CURRENT EXECUTING SCRIPT.
define('THISPAGE', Misc::currentURL());
define('DEFAULT_MAX_FILE_UPLOADS', ini_get('max_file_uploads') ? ini_get('max_file_uploads') : 5);
define('DEFAULT_PRIORITY_ID', 1);
#Global override
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    // Take the left-most item for X-Forwarded-For
    $_SERVER['REMOTE_ADDR'] = trim(array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])));
}
示例#8
0
 function run($args, $options)
 {
     Bootstrap::connect();
     osTicket::start();
     switch ($args['action']) {
         case 'backends':
             // List configured backends
             foreach (FileStorageBackend::allRegistered() as $char => $bk) {
                 print "{$char} -- {$bk::$desc} ({$bk})\n";
             }
             break;
         case 'list':
             // List files matching criteria
             // ORM would be nice!
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             foreach ($files as $f) {
                 printf("% 5d %s % 8d %s % 16s %s\n", $f->id, $f->bk, $f->size, $f->created, $f->type, $f->name);
                 if ($f->attrs) {
                     printf("        %s\n", $f->attrs);
                 }
             }
             break;
         case 'dump':
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             if ($files->count() != 1) {
                 $this->fail('Criteria must select exactly 1 file');
             }
             if (($f = AttachmentFile::lookup($files[0]->id)) && ($bk = $f->open())) {
                 $bk->passthru();
             }
             break;
         case 'load':
             // Load file content from STDIN
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             if ($files->count() != 1) {
                 $this->fail('Criteria must select exactly 1 file');
             }
             $f = AttachmentFile::lookup($files[0]->id);
             try {
                 if ($bk = $f->open()) {
                     $bk->unlink();
                 }
             } catch (Exception $e) {
             }
             if ($options['to']) {
                 $bk = FileStorageBackend::lookup($options['to'], $f);
             } else {
                 // Use the system default
                 $bk = AttachmentFile::getBackendForFile($f);
             }
             $type = false;
             $signature = '';
             $finfo = new finfo(FILEINFO_MIME_TYPE);
             if ($options['file'] && $options['file'] != '-') {
                 if (!file_exists($options['file'])) {
                     $this->fail($options['file'] . ': Cannot open file');
                 }
                 if (!$bk->upload($options['file'])) {
                     $this->fail('Unable to upload file contents to backend');
                 }
                 $type = $finfo->file($options['file']);
                 list(, $signature) = AttachmentFile::_getKeyAndHash($options['file'], true);
             } else {
                 $stream = fopen('php://stdin', 'rb');
                 while ($block = fread($stream, $bk->getBlockSize())) {
                     if (!$bk->write($block)) {
                         $this->fail('Unable to send file contents to backend');
                     }
                     if (!$type) {
                         $type = $finfo->buffer($block);
                     }
                 }
                 if (!$bk->flush()) {
                     $this->fail('Unable to commit file contents to backend');
                 }
             }
             // TODO: Update file metadata
             $sql = 'UPDATE ' . FILE_TABLE . ' SET bk=' . db_input($bk->getBkChar()) . ', created=CURRENT_TIMESTAMP' . ', type=' . db_input($type) . ', signature=' . db_input($signature) . ' WHERE id=' . db_input($f->getId());
             if (!db_query($sql) || db_affected_rows() != 1) {
                 $this->fail('Unable to update file metadata');
             }
             $this->stdout->write("Successfully saved contents\n");
             break;
         case 'migrate':
             if (!$options['to']) {
                 $this->fail('Please specify a target backend for migration');
             }
             if (!FileStorageBackend::isRegistered($options['to'])) {
                 $this->fail('Target backend is not installed. See `backends` action');
             }
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             $count = 0;
             foreach ($files as $m) {
                 $f = AttachmentFile::lookup($m->id);
                 if ($f->getBackend() == $options['to']) {
                     continue;
                 }
                 if ($options['verbose']) {
                     $this->stdout->write('Migrating ' . $m->name . "\n");
                 }
                 try {
                     if (!$f->migrate($options['to'])) {
                         $this->stderr->write('Unable to migrate ' . $m->name . "\n");
                     } else {
                         $count++;
                     }
                 } catch (IOException $e) {
                     $this->stderr->write('IOError: ' . $e->getMessage());
                 }
             }
             $this->stdout->write("Migrated {$count} files\n");
             break;
         case 'export':
             // Create a temporary ZIP file
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             if (!$options['file']) {
                 $this->fail('Please specify zip file with `-f`');
             }
             $zip = new ZipArchive();
             if (true !== ($reason = $zip->open($options['file'], ZipArchive::CREATE))) {
                 $this->fail($reason . ': Unable to create zip file');
             }
             $manifest = array();
             foreach ($files as $m) {
                 $f = AttachmentFile::lookup($m->id);
                 $zip->addFromString($f->getId(), $f->getData());
                 $zip->setCommentName($f->getId(), $f->getName());
                 // TODO: Log %attachment and %ticket_attachment entries
                 $info = array('file' => $f->getInfo());
                 foreach ($m->tickets as $t) {
                     $info['tickets'][] = $t->ht;
                 }
                 $manifest[$f->getId()] = $info;
             }
             $zip->addFromString('MANIFEST', serialize($manifest));
             $zip->close();
             break;
         case 'expunge':
             // Create a temporary ZIP file
             $files = FileModel::objects();
             $this->_applyCriteria($options, $files);
             foreach ($files as $f) {
                 $f->tickets->expunge();
                 $f->unlink() && $f->delete();
             }
     }
 }
示例#9
0
 function start()
 {
     if (!($ost = new osTicket())) {
         return null;
     }
     //Set default time zone... user/staff settting will override it (on login).
     $_SESSION['TZ_OFFSET'] = $ost->getConfig()->getTZoffset();
     $_SESSION['TZ_DST'] = $ost->getConfig()->observeDaylightSaving();
     // Bootstrap installed plugins
     $ost->plugins->bootstrap();
     return $ost;
 }
示例#10
0
 function start()
 {
     // Prep basic translation support
     Internationalization::bootstrap();
     if (!($ost = new osTicket())) {
         return null;
     }
     //Set default time zone... user/staff settting will override it (on login).
     $_SESSION['TZ_OFFSET'] = $ost->getConfig()->getTZoffset();
     $_SESSION['TZ_DST'] = $ost->getConfig()->observeDaylightSaving();
     // Bootstrap installed plugins
     $ost->plugins->bootstrap();
     // Mirror content updates to the search backend
     $ost->searcher = new SearchInterface();
     return $ost;
 }
示例#11
0
 function start($configId)
 {
     if (!$configId || !($ost = new osTicket($configId)) || $ost->getConfigId() != $configId) {
         return null;
     }
     //Set default time zone... user/staff settting will overwrite it (on login).
     $_SESSION['TZ_OFFSET'] = $ost->getConfig()->getTZoffset();
     $_SESSION['TZ_DST'] = $ost->getConfig()->observeDaylightSaving();
     return $ost;
 }