/** * Constructor of a file or folder * * @param string $path The absolute path must be suplied * @throws Exception */ public function __construct($path) { // \GO::debug("FS construct $path"); if (empty($path)) { throw new \Exception("Path may not be empty in Base"); } //normalize path slashes if (\GO\Base\Util\Common::isWindows()) { $path = str_replace('\\', '/', $path); } if (!self::checkPathInput($path)) { throw new \Exception("The supplied path '{$path}' was invalid"); } $parent = dirname($path); if ($parent != '/') { $this->path = $parent; } else { $this->path = ''; } $this->path .= '/' . self::utf8Basename($path); }
public function encode($xml, $output = false) { file_put_contents($this->_xmlFile, $xml); if (\GO\Base\Util\Common::isWindows()) { $cmd = \GO::config()->cmd_xml2wbxml . ' -o ' . $this->_wbxmlFile . ' ' . $this->_xmlFile; } else { $cmd = \GO::config()->cmd_xml2wbxml . ' -o ' . $this->_wbxmlFile . ' ' . $this->_xmlFile . ' 2>/dev/null'; } exec($cmd); if (!file_exists($this->_wbxmlFile)) { throw new \Exception('xml2wbxml conversion failed'); } if ($output) { readfile($this->_wbxmlFile); } else { $wbxml = trim(file_get_contents($this->_wbxmlFile)); } //remove temp files unlink($this->_wbxmlFile); unlink($this->_xmlFile); return $output ? true : $wbxml; }
/** * Create a ZIP archive encoded in CP850 so that Windows will understand * foreign characters * * @param File $archiveFile * @param Folder $workingFolder * @param Base[] $sources * @param boolean $utf8 Set to true to use UTF8 encoding. This is not supported by Windows explorer. * @throws Exception */ public static function create(File $archiveFile, Folder $workingFolder, $sources, $utf8 = false) { if (class_exists("\\ZipArchive") && !$utf8) { \GO::debug("Using PHP ZipArchive"); $zip = new \ZipArchive(); $zip->open($archiveFile->path(), \ZipArchive::CREATE); for ($i = 0; $i < count($sources); $i++) { if ($sources[$i]->isFolder()) { self::_zipDir($sources[$i], $zip, str_replace($workingFolder->path() . '/', '', $sources[$i]->path()) . '/'); } else { $name = str_replace($workingFolder->path() . '/', '', $sources[$i]->path()); $name = @iconv('UTF-8', 'CP850//TRANSLIT', $name); \GO::debug("Add file: " . $sources[$i]->path()); $zip->addFile($sources[$i]->path(), $name); } } if (!$zip->close() || !$archiveFile->exists()) { throw new \Exception($zip->getStatusString()); } else { return true; } } else { \GO::debug("Using zip exec"); if (!\GO\Base\Util\Common::isWindows()) { putenv('LANG=en_US.UTF-8'); } chdir($workingFolder->path()); $cmdSources = array(); for ($i = 0; $i < count($sources); $i++) { $cmdSources[$i] = escapeshellarg(str_replace($workingFolder->path() . '/', '', $sources[$i]->path())); } $cmd = \GO::config()->cmd_zip . ' -r ' . escapeshellarg($archiveFile->path()) . ' ' . implode(' ', $cmdSources); exec($cmd, $output, $ret); if ($ret != 0 || !$archiveFile->exists()) { throw new \Exception('Command failed: ' . $cmd . "<br /><br />" . implode("<br />", $output)); } return true; } }
private function _launchBatchSend($mailing_id) { $mailing = \GO\Addressbook\Model\SentMailing::model()->findByPk($mailing_id); if (!$mailing) { throw new \Exception("Mailing not found!\n"); } $joinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addRawCondition('t.id', 'a.account_id'); $findParams = \GO\Base\Db\FindParams::newInstance()->single()->join(\GO\Email\Model\Alias::model()->tableName(), $joinCriteria, 'a')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('id', $mailing->alias_id, '=', 'a')); $account = \GO\Email\Model\Account::model()->find($findParams); $pwdParam = ''; if ($account && !empty(\GO::session()->values['emailModule']['smtpPasswords'][$account->id])) { $mailing->temp_pass = \GO::session()->values['emailModule']['smtpPasswords'][$account->id]; $mailing->save(); $pwdParam = '--smtp_password='******'emailModule']['smtpPasswords'][$account->id]; } $log = \GO::config()->file_storage_path . 'log/mailings/'; if (!is_dir($log)) { mkdir($log, 0755, true); } $log .= $mailing_id . '.log'; $cmd = \GO::config()->cmd_php . ' ' . \GO::config()->root_path . 'groupofficecli.php -r=addressbook/sentMailing/batchSend -c="' . \GO::config()->get_config_file() . '" --mailing_id=' . $mailing_id . ' ' . $pwdParam . ' >> ' . $log; if (!\GO\Base\Util\Common::isWindows()) { $cmd .= ' 2>&1 &'; } file_put_contents($log, \GO\Base\Util\Date::get_timestamp(time()) . "\r\n" . $cmd . "\r\n\r\n", FILE_APPEND); if (\GO\Base\Util\Common::isWindows()) { pclose(popen("start /B " . $cmd, "r")); } else { exec($cmd, $outputarr, $returnvar); \GO::debug('===== CMD ====='); \GO::debug($cmd); \GO::debug('===== OUTPUT ARR ====='); \GO::debug(var_export($outputarr, true)); \GO::debug('===== RETURN VAR ====='); \GO::debug(var_export($returnvar, true)); } }
/** * Constructor. Initialises all public variables. * * @access public * @return void */ function __construct() { $config = array(); $this->root_path = str_replace('\\', '/', dirname(dirname(dirname(__FILE__)))) . '/'; //suppress error for open_basedir warnings etc if (@file_exists('/etc/groupoffice/globalconfig.inc.php')) { require '/etc/groupoffice/globalconfig.inc.php'; } $config_file = $this->get_config_file(); if ($config_file) { include $config_file; } foreach ($config as $key => $value) { $this->{$key} = $value; } // if($this->info_log=="") // $this->info_log =$this->file_storage_path.'log/info.log'; //this can be used in some cases where you don't want the dynamically //determined full URL. This is done in set_full_url below. $this->orig_full_url = $this->full_url; $this->orig_tmpdir = $this->tmpdir; if (empty($this->db_user)) { //Detect some default values for installation if root_path is not set yet $this->host = dirname($_SERVER['PHP_SELF']); if (basename($this->host) == 'install') { $this->host = dirname($this->host); } if (substr($this->host, -1) != '/') { $this->host .= '/'; } $this->db_host = 'localhost'; if (Util\Common::isWindows()) { $this->file_storage_path = substr($this->root_path, 0, 3) . 'groupoffice/'; $this->tmpdir = substr($this->root_path, 0, 3) . 'temp'; $this->cmd_zip = $this->root_path . 'controls/win32/zip.exe'; $this->cmd_unzip = $this->root_path . 'controls/win32/unzip.exe'; $this->cmd_xml2wbxml = $this->root_path . 'controls/win32/libwbxml/xml2wbxml.exe'; $this->cmd_wbxml2xml = $this->root_path . 'controls/win32/libwbxml/wbxml2xml.exe'; $this->convert_utf8_filenames_to_ascii = true; } if (empty($config['tmpdir']) && function_exists('sys_get_temp_dir')) { $this->tmpdir = rtrim(str_replace('\\', '/', sys_get_temp_dir()), '/') . '/groupoffice/'; } $this->default_timezone = @date_default_timezone_get(); //suppress warning if using system tz $lc = localeconv(); $this->default_currency = empty($lc['currency_symbol']) ? '€' : $lc['currency_symbol']; $this->default_decimal_separator = empty($lc['decimal_point']) ? '.' : $lc['decimal_point']; $this->default_thousands_separator = $this->default_decimal_separator == '.' ? ',' : '.'; //$lc['thousands_sep']; } // // path to classes // $this->class_path = $this->root_path.$this->class_path.'/'; // // // path to themes // $this->theme_path = $this->root_path.$this->theme_path.'/'; // // // URL to themes // $this->theme_url = $this->host.$this->theme_url.'/'; // // // path to controls // $this->control_path = $this->root_path.$this->control_path.'/'; // // // url to controls // $this->control_url = $this->host.$this->control_url.'/'; // // // path to modules // $this->module_path = $this->root_path.$this->module_path.'/'; // // // url to user configuration apps // $this->configuration_url = $this->host.$this->configuration_url.'/'; if ($this->debug) { $this->debug_log = true; } // if($this->debug_log){// || $this->log_slow_requests) { // // list ($usec, $sec) = explode(" ", microtime()); // $this->loadstart = ((float) $usec + (float) $sec); // //// $dat = getrusage(); //// define('PHP_TUSAGE', microtime(true)); //// define('PHP_RUSAGE', $dat["ru_utime.tv_sec"]*1e6+$dat["ru_utime.tv_usec"]); // } // if(is_string($this->file_create_mode)) { // $this->file_create_mode=octdec($this->file_create_mode); // } // // if(is_string($this->folder_create_mode)) { // $this->folder_create_mode=octdec($this->folder_create_mode); // } if ($this->debug_log) { $this->log = true; } $this->set_full_url(); if (!$this->support_link && $this->isProVersion()) { $this->support_link = "https://www.group-office.com/support"; } /* * Check if the noreply_email variable is set in the config.php file. * If it is not set, then use noreply@ {webmaster_email domain name} * When the webmaster email is not set, then this will be noreply@example.com */ if (empty($this->noreply_email)) { $wmdomain = 'example.com'; if (!empty($this->webmaster_email)) { $extractedEmail = explode('@', $this->webmaster_email); if (isset($extractedEmail[1])) { $wmdomain = $extractedEmail[1]; } } $this->noreply_email = 'noreply@' . $wmdomain; } }
protected function actionDecompress($params) { if (!\GO\Base\Util\Common::isWindows()) { putenv('LANG=en_US.UTF-8'); } $sources = json_decode($params['decompress_sources'], true); $workingFolder = \GO\Files\Model\Folder::model()->findByPk($params['working_folder_id']); $workingPath = \GO::config()->file_storage_path . $workingFolder->path; chdir($workingPath); while ($filePath = array_shift($sources)) { $file = new \GO\Base\Fs\File(\GO::config()->file_storage_path . $filePath); switch (strtolower($file->extension())) { case 'zip': $folder = \GO\Base\Fs\Folder::tempFolder(uniqid()); if (class_exists("\\ZipArchive")) { $zip = new \ZipArchive(); $zip->open($file->path()); $zip->extractTo($folder->path()); $this->_convertZipEncoding($folder); } else { chdir($folder->path()); $cmd = \GO::config()->cmd_unzip . ' -n ' . escapeshellarg($file->path()); exec($cmd, $output, $ret); if ($ret != 0) { throw new \Exception("Could not decompress\n" . implode("\n", $output)); } } $items = $folder->ls(); foreach ($items as $item) { $item->move(new \GO\Base\Fs\Folder($workingPath)); } $folder->delete(); break; case 'gz': case 'tgz': $cmd = \GO::config()->cmd_tar . ' zxf ' . escapeshellarg($file->path()); exec($cmd, $output, $ret); if ($ret != 0) { throw new \Exception("Could not decompress\n" . implode("\n", $output)); } break; case 'tar': $cmd = \GO::config()->cmd_tar . ' xf ' . escapeshellarg($file->path()); exec($cmd, $output, $ret); if ($ret != 0) { throw new \Exception("Could not decompress\n" . implode("\n", $output)); } break; } } $workingFolder->syncFilesystem(true); return array('success' => true); }
<?php /****************************************************************************/ /* */ /* YOU MAY WISH TO MODIFY OR REMOVE THE FOLLOWING LINES WHICH SET DEFAULTS */ /* */ /****************************************************************************/ $preferences = Swift_Preferences::getInstance(); // Sets the default charset so that setCharset() is not needed elsewhere $preferences->setCharset('utf-8'); if (\GO\Base\Util\Common::isWindows()) { $preferences->setTempDir(GO::config()->tmpdir)->setCacheType('array'); } else { $preferences->setTempDir(GO::config()->tmpdir)->setCacheType('disk'); } // this should only be done when Swiftmailer won't use the native QP content encoder // see mime_deps.php if (version_compare(phpversion(), '5.4.7', '<')) { $preferences->setQPDotEscape(\GO::config()->swift_qp_dot_escape); }