/** *@name pdftk *@brief Validate with xmlint (external tool) an xml file using the schema (XML|DTD|XSD|RNG|SCH) *@access public *@note This function will call pdftk/pdftk.exe like this: * pdftk form.pdf fill_form data.fdf output out.pdf flatten * (pdftk form.filled.pdf output out.pdf flatten is not supported) * * If the input FDF file includes Rich Text formatted data in * addition to plain text, then the Rich Text data is packed * into the form fields as well as the plain text. Pdftk also * sets a flag that cues Acrobat/Reader to generate new field * appearances based on the Rich Text data. That way, when the * user opens the PDF, the viewer will create the Rich Text * fields on the spot. If the user's PDF viewer does not sup- * port Rich Text, then the user will see the plain text data * instead. If you flatten this form before Acrobat has a * chance to create (and save) new field appearances, then the * plain text field data is what you'll see. * *@internal Wrapper to call pdftk, a shell command, in background. *@param String pdf_file absolute pathname to a pdf form file *@param String fdf_file absolute pathname to a pdf data file *@param String settings * * Output modes 'compress', 'uncompress', 'flatten' ..(see pdftk --help) *@return Array an associative array with two keys: * Boolean success a flag , if positive meaning the process is a success * String return the path to the pdf generated or the error message **/ function pdftk($pdf_file, $fdf_file, $settings) { //------------------------------------------ $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); $output_modes = $settings['output_modes']; $security = $settings['security']; $cwd = '/tmp'; $env = array('misc_options' => 'aeiou'); $err = ''; $success = 0; if (is_windows()) { $cmd = "pdftk.exe"; //For windows } else { $cmd = "pdftk"; //For linux and mac } $dircmd = fix_path(dirname(__FILE__)); if (file_exists("{$dircmd}/{$cmd}")) { $pdf_out = FPDM_CACHE . "pdf_flatten.pdf"; $cmdline = "{$dircmd}/{$cmd} \"{$pdf_file}\" fill_form \"{$fdf_file}\" output \"{$pdf_out}\" {$output_modes} {$security}"; //direct to ouptut //echo htmlentities("$cmdline , $descriptorspec, $cwd, $env"); if (PHP5_ENGINE) { // Php5 $process = proc_open($cmdline, $descriptorspec, $pipes, $cwd, $env); } else { //Php4 $process = proc_open($cmdline, $descriptorspec, $pipes); } if (is_resource($process)) { if (PHP5_ENGINE) { $err = stream_get_contents($pipes[2]); } else { //Php4 $err = ""; while ($str = fgets($pipes[2], 4096)) { $err .= "{$str}\n"; } } fclose($pipes[2]); //Its important to close the pipes before proc_close call to avoid dead locks $return_value = proc_close($process); } else { $err = "No more resource to execute the command"; } } else { $err = "Sorry but pdftk binary is not provided / Cette fonctionnalite requiere pdftk non fourni ici<ol>"; $err .= "<li>download it from / telecharger ce dernier a partir de <br><blockquote><a href=\"http://www.pdflabs.com/docs/install-pdftk/\">pdflabs</a></blockquote>"; $err .= "<li>copy the executable in this directory / Copier l'executable dans<br><blockquote><b>{$dircmd}</b></blockquote>"; $err .= "<li>set \$cmd to match binary name in / configurer \$cmd pour qu'il corresponde dans le fichier<br><blockquote><b>" . __FILE__ . "</b></blockquote></ol>"; } if ($err) { $ret = array("success" => false, "return" => $err); } else { $ret = array("success" => true, "return" => $pdf_out); } return $ret; }
public function testAssertWritable() { $fs = new Filesystem(); if (!is_windows()) { $this->assertEquals('/tmp', $fs->assertFolderWritable('/tmp')); } else { $this->assertTrue(true); } }
function load_extension($ext_name) { if (is_windows()) { $loaded = @dl($ext_name . '.dll'); } else { $loaded = @dl($ext_name . '.so'); } return $loaded; }
public function setUp() { if (is_windows()) { $this->markTestSkipped('Skipping on Windows'); } $this->_filename = realpath(dirname(__FILE__) . '/../../../cache/') . 'file_utils_override' . mt_rand() . '.txt'; touch($this->_filename); $this->_old_default_permissions = $GLOBALS['sugar_config']['default_permissions']; $GLOBALS['sugar_config']['default_permissions'] = array('dir_mode' => 0777, 'file_mode' => 0660, 'user' => $this->_getCurrentUser(), 'group' => $this->_getCurrentGroup()); }
function mkdir_recursive($path, $check_is_parent_dir = false) { if (sugar_is_dir($path, 'instance')) { return true; } if (sugar_is_file($path, 'instance')) { if (!empty($GLOBALS['log'])) { $GLOBALS['log']->fatal("ERROR: mkdir_recursive(): argument {$path} is already a file."); } return false; } //make variables with file paths $pathcmp = $path = rtrim(clean_path($path), '/'); $basecmp = $base = rtrim(clean_path(getcwd()), '/'); if (is_windows()) { //make path variable lower case for comparison in windows $pathcmp = strtolower($path); $basecmp = strtolower($base); } if ($basecmp == $pathcmp) { return true; } $base .= "/"; if (strncmp($pathcmp, $basecmp, strlen($basecmp)) == 0) { /* strip current path prefix */ $path = substr($path, strlen($base)); } $thePath = ''; $dirStructure = explode("/", $path); if ($dirStructure[0] == '') { // absolute path $base = '/'; array_shift($dirStructure); } if (is_windows()) { if (strlen($dirStructure[0]) == 2 && $dirStructure[0][1] == ':') { /* C: prefix */ $base = array_shift($dirStructure) . "\\"; } elseif ($dirStructure[0][0] . $dirStructure[0][1] == "\\\\") { /* UNC absolute path */ $base = array_shift($dirStructure) . "\\" . array_shift($dirStructure) . "\\"; // we won't try to mkdir UNC share name } } foreach ($dirStructure as $dirPath) { $thePath .= $dirPath . "/"; $mkPath = $base . $thePath; if (!is_dir($mkPath)) { if (!sugar_mkdir($mkPath)) { return false; } } } return true; }
function show_prompt() { $user = trim($_SESSION['user']); $host = trim($_SESSION['host']); $path = trim($_SESSION['path']); if (is_windows()) { echo "{$user}@{$host}<{$path}>"; } else { echo "{$user}@{$host}:{$path}" . '$'; } }
/** * Convert all \ to / in path, remove multiple '/'s and '/./' * @param string $path * @return string */ function clean_path($path) { // clean directory/file path with a functional equivalent $appendpath = ''; if (is_windows() && strlen($path) >= 2 && $path[0] . $path[1] == "\\\\") { $path = substr($path, 2); $appendpath = "\\\\"; } $path = str_replace("\\", "/", $path); $path = str_replace("//", "/", $path); $path = str_replace("/./", "/", $path); return $appendpath . $path; }
function dns_cname($domain) { if (is_windows()) { $url = "http://opencdn.sinaapp.com/dns.php?domain={$domain}&type=CNAME"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $content = curl_exec($ch); curl_close($ch); return json_decode($content, true); } else { return dns_get_record($domain, DNS_CNAME); } }
/** * Checks if the given path is a valid destination for package files * * @param string $path * @return bool */ function isValidCopyPath($path) { $path = str_replace('\\', '/', $path); // check if path is absolute if ($path === '' || $path[0] === '/') { return false; } // additionally check if path starts with a drive letter for Windows if (is_windows() && preg_match('/^[a-z]:/i', $path)) { return false; } // check if path contains reference to parent directory if (preg_match('/(^|\\/)\\.\\.(\\/|$)/', $path)) { return false; } return true; }
public function isSchedulerSet($api, array $args) { global $sugar_flavor; // if it's CE, always show scheduler data if ($sugar_flavor != 'CE' && AddonBoilerplate_Helper::is_ondemand_instance() === true) { return array('ondemand' => true, 'scheduler_ran' => '', 'is_windows' => '', 'realpath' => ''); } $scheduler_ran = false; $instructions = ''; $scheduler = BeanFactory::getBean('Schedulers'); $scheduler_list = $scheduler->get_list('', 'last_run is not null'); if (!empty($scheduler_list) && $scheduler_list['row_count'] > 0) { $scheduler_ran = true; } if (!isset($_SERVER['Path'])) { $_SERVER['Path'] = getenv('Path'); } return array('ondemand' => false, 'scheduler_ran' => $scheduler_ran, 'is_windows' => is_windows(), 'realpath' => SUGAR_PATH); }
* Reserved. Contributor(s): ______________________________________.. * *******************************************************************************/ logThis('[At systemCheck.php]'); $stop = false; // flag to prevent going to next step /////////////////////////////////////////////////////////////////////////////// //// FILE CHECKS logThis('Starting file permission check...'); $filesNotWritable = array(); $filesNWPerms = array(); // add directories here that should be skipped when doing file permissions checks (cache/upload is the nasty one) $skipDirs = array($sugar_config['upload_dir'], '.svn'); $files = uwFindAllFiles(getcwd(), array(), true, $skipDirs); $i = 0; $filesOut = "\n\t<a href='javascript:void(0); toggleNwFiles(\"filesNw\");'>{$mod_strings['LBL_UW_SHOW_NW_FILES']}</a>\n\t<div id='filesNw' style='display:none;'>\n\t<table cellpadding='3' cellspacing='0' border='0'>\n\t<tr>\n\t\t<th align='left'>{$mod_strings['LBL_UW_FILE']}</th>\n\t\t<th align='left'>{$mod_strings['LBL_UW_FILE_PERMS']}</th>\n\t\t<th align='left'>{$mod_strings['LBL_UW_FILE_OWNER']}</th>\n\t\t<th align='left'>{$mod_strings['LBL_UW_FILE_GROUP']}</th>\n\t</tr>"; $isWindows = is_windows(); foreach ($files as $file) { if ($isWindows) { if (!is_writable_windows($file)) { logThis('WINDOWS: File [' . $file . '] not readable - saving for display'); // don't warn yet - we're going to use this to check against replacement files $filesNotWritable[$i] = $file; $filesNWPerms[$i] = substr(sprintf('%o', fileperms($file)), -4); $filesOut .= "<tr>" . "<td><span class='error'>{$file}</span></td>" . "<td>{$filesNWPerms[$i]}</td>" . "<td>" . $mod_strings['ERR_UW_CANNOT_DETERMINE_USER'] . "</td>" . "<td>" . $mod_strings['ERR_UW_CANNOT_DETERMINE_GROUP'] . "</td>" . "</tr>"; } } else { if (!is_writable($file)) { logThis('File [' . $file . '] not writable - saving for display'); // don't warn yet - we're going to use this to check against replacement files $filesNotWritable[$i] = $file; $filesNWPerms[$i] = substr(sprintf('%o', fileperms($file)), -4);
?> </ol> <?php } ?> </div> <div class="chunk"> <p class="footnote"><strong>NOTE</strong>: Passing this test does not guarantee that the AWS SDK for PHP will run on your web server — it only ensures that the requirements have been addressed.</p> </div> </div> </div> <?php if (!is_windows()) { ?> <script type="text/javascript" charset="utf-8"> reqwest('<?php echo pathinfo(__FILE__, PATHINFO_BASENAME); ?> ?ssl_check', function(resp) { $sslCheck = document.getElementById('ssl_check'); $sslCheck.innerHTML = ''; $sslCheck.innerHTML = '<code>' + resp + '</code>'; }); </script> <?php } ?>
function quietechorun($e) { // enclose in "" on Windows for PHP < 5.3 if (is_windows() && phpversion() < '5.3') { $e = '"' . $e . '"'; } passthru($e); }
} if (!isset($sugar_config['cache_dir'])) { $sugar_config['cache_dir'] = $sugar_config_defaults['cache_dir']; } if (!isset($sugar_config['site_url'])) { $sugar_config['site_url'] = $_SESSION['setup_site_url']; } if (!isset($sugar_config['translation_string_prefix'])) { $sugar_config['translation_string_prefix'] = $sugar_config_defaults['translation_string_prefix']; } $mod_strings_scheduler = return_module_language($GLOBALS['current_language'], 'Schedulers'); $error = ''; if (!isset($_SERVER['Path'])) { $_SERVER['Path'] = getenv('Path'); } if (is_windows()) { if (isset($_SERVER['Path']) && !empty($_SERVER['Path'])) { // IIS IUSR_xxx may not have access to Path or it is not set if (!strpos($_SERVER['Path'], 'php')) { // $error = '<em>'.$mod_strings_scheduler['LBL_NO_PHP_CLI'].'</em>'; } } $cronString = ' <tr> <td align="left" colspan="2"> <font color="red"> ' . $mod_strings_scheduler['LBL_CRON_WINDOWS_DESC'] . '<br> </font> cd ' . realpath('./') . '<br> php.exe -f cron.php <br>' . $error . '
function find_temp_dir() { global $path_to_site, $img_dir; if (is_windows()) { $guess = array(txpath . DS . 'tmp', getenv('TMP'), getenv('TEMP'), getenv('SystemRoot') . DS . 'Temp', 'C:' . DS . 'Temp', $path_to_site . DS . $img_dir); foreach ($guess as $k => $v) { if (empty($v)) { unset($guess[$k]); } } } else { $guess = array(txpath . DS . 'tmp', '', DS . 'tmp', $path_to_site . DS . $img_dir); } foreach ($guess as $dir) { $tf = @tempnam($dir, 'txp_'); if ($tf) { $tf = realpath($tf); } if ($tf and file_exists($tf)) { unlink($tf); return dirname($tf); } } return false; }
/** * Sends an email, wrapping PHP's mail() function. * ALL emails sent by b2evolution must be sent through this function (for consistency and for logging) * * {@link $current_locale} will be used to set the charset. * * Note: we use a single \n as line ending, though it does not comply to {@link http://www.faqs.org/rfcs/rfc2822 RFC2822}, but seems to be safer, * because some mail transfer agents replace \n by \r\n automatically. * * @todo Unit testing with "nice addresses" This gets broken over and over again. * * @param string Recipient email address. * @param string Recipient name. * @param string Subject of the mail * @param string The message text * @param string From address, being added to headers (we'll prevent injections); see {@link http://securephp.damonkohler.com/index.php/Email_Injection}. * Defaults to {@link GeneralSettings::get('notification_sender_email') } if NULL. * @param string From name. * @param array Additional headers ( headername => value ). Take care of injection! * @param integer User ID * @return boolean True if mail could be sent (not necessarily delivered!), false if not - (return value of {@link mail()}) */ function send_mail($to, $to_name, $subject, $message, $from = NULL, $from_name = NULL, $headers = array(), $user_ID = NULL) { global $servertimenow; // Stop a request from the blocked IP addresses antispam_block_ip(); global $debug, $app_name, $app_version, $current_locale, $current_charset, $evo_charset, $locales, $Debuglog, $Settings, $demo_mode, $sendmail_additional_params; // Memorize email address $to_email_address = $to; $NL = "\r\n"; if ($demo_mode) { // Debug mode restriction: Sending email in debug mode is not allowed return false; } if (!is_array($headers)) { // Make sure $headers is an array $headers = array($headers); } if (empty($from)) { $from = user_get_notification_sender($user_ID, 'email'); } if (empty($from_name)) { $from_name = user_get_notification_sender($user_ID, 'name'); } $return_path = $Settings->get('notification_return_path'); // Add real name into $from... if (!is_windows()) { // fplanque: Windows XP, Apache 1.3, PHP 4.4, MS SMTP : will not accept "nice" addresses. if (!empty($to_name)) { $to = '"' . mail_encode_header_string($to_name) . '" <' . $to . '>'; } if (!empty($from_name)) { $from = '"' . mail_encode_header_string($from_name) . '" <' . $from . '>'; } } $from = mail_sanitize_header_string($from, true); // From has to go into headers $headers['From'] = $from; if (!empty($return_path)) { // Set a return path $headers['Return-Path'] = $return_path; } // echo 'sending email to: ['.htmlspecialchars($to).'] from ['.htmlspecialchars($from).']'; $clear_subject = $subject; $subject = mail_encode_header_string($subject); $message = str_replace(array("\r\n", "\r"), $NL, $message); // Convert encoding of message (from internal encoding to the one of the message): // fp> why do we actually convert to $current_charset? // dh> I do not remember. Appears to make sense sending it unconverted in $evo_charset. // asimo> converting the message creates wrong output, no need for conversion, however this needs further investigation // $message = convert_charset( $message, $current_charset, $evo_charset ); if (!isset($headers['Content-Type'])) { // Specify charset and content-type of email $headers['Content-Type'] = 'text/plain; charset=' . $current_charset; } $headers['MIME-Version'] = '1.0'; $headers['Date'] = gmdate('r', $servertimenow); // ADDITIONAL HEADERS: $headers['X-Mailer'] = $app_name . ' ' . $app_version . ' - PHP/' . phpversion(); $ip_list = implode(',', get_ip_list()); if (!empty($ip_list)) { // Add X-Remote_Addr param only if its value is not empty $headers['X-Remote-Addr'] = $ip_list; } // COMPACT HEADERS: $headerstring = ''; reset($headers); while (list($lKey, $lValue) = each($headers)) { // Add additional headers $headerstring .= $lKey . ': ' . $lValue . $NL; } // Set an additional parameter for the return path: if (!empty($sendmail_additional_params)) { $additional_parameters = str_replace(array('$from-address$', '$return-address$'), array($from, empty($return_path) ? $from : $return_path), $sendmail_additional_params); } else { $additional_parameters = ''; } if (mail_is_blocked($to_email_address)) { // Check if the email address is blocked $Debuglog->add('Sending mail to «' . htmlspecialchars($to_email_address) . '» FAILED, because this email marked with spam or permanent errors.', 'error'); mail_log($user_ID, $to_email_address, $clear_subject, $message, $headerstring, 'blocked'); return false; } // SEND MESSAGE: if ($debug > 1) { // We agree to die for debugging... if (!mail($to, $subject, $message, $headerstring, $additional_parameters)) { mail_log($user_ID, $to_email_address, $clear_subject, $message, $headerstring, 'error'); debug_die('Sending mail from «' . htmlspecialchars($from) . '» to «' . htmlspecialchars($to) . '», Subject «' . htmlspecialchars($subject) . '» FAILED.'); } } else { // Soft debugging only.... if (!@mail($to, $subject, $message, $headerstring, $additional_parameters)) { $Debuglog->add('Sending mail from «' . htmlspecialchars($from) . '» to «' . htmlspecialchars($to) . '», Subject «' . htmlspecialchars($subject) . '» FAILED.', 'error'); mail_log($user_ID, $to_email_address, $clear_subject, $message, $headerstring, 'error'); return false; } } $Debuglog->add('Sent mail from «' . htmlspecialchars($from) . '» to «' . htmlspecialchars($to) . '», Subject «' . htmlspecialchars($subject) . '».'); mail_log($user_ID, $to_email_address, $clear_subject, $message, $headerstring, 'ok'); return true; }
function failure($s = 'No ') { return is_windows() ? $s : "[1;37m[41m " . $s . " [0m"; }
function displayCronInstructions() { global $mod_strings; global $sugar_config; $error = ''; if (!isset($_SERVER['Path'])) { $_SERVER['Path'] = getenv('Path'); } if (is_windows()) { if (isset($_SERVER['Path']) && !empty($_SERVER['Path'])) { // IIS IUSR_xxx may not have access to Path or it is not set if (!strpos($_SERVER['Path'], 'php')) { // $error = '<em>'.$mod_strings['LBL_NO_PHP_CLI'].'</em>'; } } } else { if (isset($_SERVER['Path']) && !empty($_SERVER['Path'])) { // some Linux servers do not make this available if (!strpos($_SERVER['PATH'], 'php')) { // $error = '<em>'.$mod_strings['LBL_NO_PHP_CLI'].'</em>'; } } } if (is_windows()) { echo '<br>'; echo ' <table cellpadding="0" cellspacing="0" width="100%" border="0" class="list view"> <tr height="20"> <th><slot> ' . $mod_strings['LBL_CRON_INSTRUCTIONS_WINDOWS'] . ' </slot></th> </tr> <tr class="evenListRowS1"> <td scope="row" valign="top" width="70%"><slot> ' . $mod_strings['LBL_CRON_WINDOWS_DESC'] . '<br> <b>cd ' . realpath('./') . '<br> php.exe -f cron.php</b> </slot></td> </tr> </table>'; } else { echo '<br>'; echo ' <table cellpadding="0" cellspacing="0" width="100%" border="0" class="list view"> <tr height="20"> <th><slot> ' . $mod_strings['LBL_CRON_INSTRUCTIONS_LINUX'] . ' </slot></th> </tr> <tr> <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#fdfdfd" width="70%"><slot> ' . $mod_strings['LBL_CRON_LINUX_DESC'] . '<br> <b>* * * * * cd ' . realpath('./') . '; php -f cron.php > /dev/null 2>&1</b> <br>' . $error . ' </slot></td> </tr> </table>'; } }
<?php /* $HeadURL: $ $LastChangedRevision: $ */ $old_level = error_reporting(E_ALL ^ E_NOTICE); define('TXP_DEBUG', 0); define('SPAM', -1); define('MODERATE', 0); define('VISIBLE', 1); define('RELOAD', -99); define('RPC_SERVER', 'http://rpc.textpattern.com'); define('LEAVE_TEXT_UNTOUCHED', 0); define('USE_TEXTILE', 1); define('CONVERT_LINEBREAKS', 2); if (defined('DIRECTORY_SEPARATOR')) { define('DS', DIRECTORY_SEPARATOR); } else { define('DS', is_windows() ? '\\' : '/'); } error_reporting($old_level); unset($old_level);
function stdapi_registry_set_value($req, &$pkt) { if (is_windows() and is_callable('reg_open_key')) { global $registry_handles; my_print("doing stdapi_registry_set_value"); $key_id_tlv = packet_get_tlv($req, TLV_TYPE_ROOT_KEY); $key_id = $key_id_tlv['value']; } else { return ERROR_FAILURE; } }
/** * creates a file's name for preparation for saving * @return string */ function create_stored_filename() { global $sugar_config; if (!$this->use_soap) { $stored_file_name = $_FILES[$this->field_name]['name']; $this->original_file_name = $stored_file_name; /** * cn: bug 8056 - windows filesystems and IIS do not like utf8. we are forced to urlencode() to ensure that * the file is linkable from the browser. this will stay broken until we move to a db-storage system */ if (is_windows()) { // create a non UTF-8 name encoding // 176 + 36 char guid = windows' maximum filename length $end = strlen($stored_file_name) > 176 ? 176 : strlen($stored_file_name); $stored_file_name = substr($stored_file_name, 0, $end); $this->original_file_name = $_FILES[$this->field_name]['name']; } $stored_file_name = str_replace("\\", "", $stored_file_name); } else { $stored_file_name = $this->stored_file_name; $this->original_file_name = $stored_file_name; } $this->file_ext = pathinfo($stored_file_name, PATHINFO_EXTENSION); // cn: bug 6347 - fix file extension detection foreach ($sugar_config['upload_badext'] as $badExt) { if (strtolower($this->file_ext) == strtolower($badExt)) { $stored_file_name .= ".txt"; $this->file_ext = "txt"; break; // no need to look for more } } return $stored_file_name; }
function core_machine_id($req, &$pkt) { my_print("doing core_machine_id"); if (is_callable('gethostname')) { # introduced in 5.3 $machine_id = gethostname(); } else { $machine_id = php_uname('n'); } $serial = ""; if (is_windows()) { # It's dirty, but there's not really a nicer way of doing this on windows. Make sure # it's lowercase as this is what the other meterpreters use. $output = strtolower(shell_exec("vol %SYSTEMDRIVE%")); $serial = preg_replace('/.*serial number is ([a-z0-9]{4}-[a-z0-9]{4}).*/s', '$1', $output); } else { $serial = get_hdd_label(); } packet_add_tlv($pkt, create_tlv(TLV_TYPE_MACHINE_ID, $serial . ":" . $machine_id)); return ERROR_SUCCESS; }
/** * checks files for permissions * @param array files Array of files with absolute paths * @return string result of check */ function checkFiles($files, $echo = false) { global $mod_strings; $filesNotWritable = array(); $i = 0; $filesOut = "\n\t\t<a href='javascript:void(0); toggleNwFiles(\"filesNw\");'>{$mod_strings['LBL_UW_SHOW_NW_FILES']}</a>\n\t\t<div id='filesNw' style='display:none;'>\n\t\t<table cellpadding='3' cellspacing='0' border='0'>\n\t\t<tr>\n\t\t\t<th align='left'>{$mod_strings['LBL_UW_FILE']}</th>\n\t\t\t<th align='left'>{$mod_strings['LBL_UW_FILE_PERMS']}</th>\n\t\t\t<th align='left'>{$mod_strings['LBL_UW_FILE_OWNER']}</th>\n\t\t\t<th align='left'>{$mod_strings['LBL_UW_FILE_GROUP']}</th>\n\t\t</tr>"; $isWindows = is_windows(); foreach ($files as $file) { if ($isWindows) { if (!is_writable_windows($file)) { logThis('WINDOWS: File [' . $file . '] not readable - saving for display'); // don't warn yet - we're going to use this to check against replacement files // aw: commented out; it's a hack to allow upgrade wizard to continue on windows... will fix later /*$filesNotWritable[$i] = $file; $filesNWPerms[$i] = substr(sprintf('%o',fileperms($file)), -4); $filesOut .= "<tr>". "<td><span class='error'>{$file}</span></td>". "<td>{$filesNWPerms[$i]}</td>". "<td>".$mod_strings['ERR_UW_CANNOT_DETERMINE_USER']."</td>". "<td>".$mod_strings['ERR_UW_CANNOT_DETERMINE_GROUP']."</td>". "</tr>";*/ } } else { if (!is_writable($file)) { logThis('File [' . $file . '] not writable - saving for display'); // don't warn yet - we're going to use this to check against replacement files $filesNotWritable[$i] = $file; $filesNWPerms[$i] = substr(sprintf('%o', fileperms($file)), -4); $owner = posix_getpwuid(fileowner($file)); $group = posix_getgrgid(filegroup($file)); $filesOut .= "<tr>" . "<td><span class='error'>{$file}</span></td>" . "<td>{$filesNWPerms[$i]}</td>" . "<td>" . $owner['name'] . "</td>" . "<td>" . $group['name'] . "</td>" . "</tr>"; } } $i++; } $filesOut .= '</table></div>'; // not a stop error $errors['files']['filesNotWritable'] = count($filesNotWritable) > 0 ? true : false; if (count($filesNotWritable) < 1) { $filesOut = "{$mod_strings['LBL_UW_FILE_NO_ERRORS']}"; } return $filesOut; }
/** * * Wrap calls to proc_close(proc_open()) and call hook * so plugins can take part in process :) * * args: * $cmd program to run * next args are passed as $cmd command line * * e.g.: proc_run("ls","-la","/tmp"); * * $cmd and string args are surrounded with "" */ function proc_run($cmd) { $a = get_app(); $args = func_get_args(); $newargs = array(); if (!count($args)) { return; } // expand any arrays foreach ($args as $arg) { if (is_array($arg)) { foreach ($arg as $n) { $newargs[] = $n; } } else { $newargs[] = $arg; } } $args = $newargs; $arr = array('args' => $args, 'run_cmd' => true); call_hooks("proc_run", $arr); if (!$arr['run_cmd']) { return; } if (count($args) && $args[0] === 'php') { $args[0] = x($a->config, 'system') && x($a->config['system'], 'php_path') && strlen($a->config['system']['php_path']) ? $a->config['system']['php_path'] : 'php'; } for ($x = 0; $x < count($args); $x++) { $args[$x] = escapeshellarg($args[$x]); } $cmdline = implode($args, " "); if (is_windows()) { $cwd = getcwd(); $cmd = "cmd /c start \"title\" /D \"{$cwd}\" /b {$cmdline}"; proc_close(proc_open($cmd, array(), $foo)); } else { proc_close(proc_open($cmdline . " &", array(), $foo)); } }
/** * verifyAttachment * * @param array $pParamHash * @param array $pFile * @param array $pKey * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure * @deprecated deprecated since version 2.1.0-beta */ function verifyAttachment(&$pParamHash, $pFile, $pKey) { //deprecated( "This method has been replaced by a method in LibertyMime. Please try to migrate your code." ); global $gBitSystem, $gBitUser, $gLibertySystem; if (!empty($pFile) && !empty($pFile['size'])) { if (empty($pParamHash['storage_guid'])) { // only file format storage available at present $pParamHash['storage_guid'] = $storageGuid = PLUGIN_GUID_BIT_FILES; } else { $storageGuid = $pParamHash['storage_guid']; } if (!empty($pFile['size'])) { $this->extractMetaData($pParamHash, $pFile); // meta data may be stupid and have stuffed title with all spaces if (!empty($pParamHash['title'])) { $pParamHash['title'] = trim($pParamHash['title']); } // let's add a default title if (empty($pParamHash['title']) && !empty($pFile['name'])) { if (preg_match('/^[A-Z]:\\\\/', $pFile['name'])) { // MSIE shit file names if passthrough via gigaupload, etc. // basename will not work - see http://us3.php.net/manual/en/function.basename.php $tmp = preg_split("#[\\\\]#", $pFile['name']); $defaultName = $tmp[count($tmp) - 1]; } elseif (strpos('.', $pFile['name'])) { list($defaultName, $ext) = explode('.', $pFile['name']); } else { $defaultName = $pFile['name']; } $pParamHash['title'] = str_replace('_', ' ', substr($defaultName, 0, strrpos($defaultName, '.'))); } if (!is_windows()) { list($pFile['name'], $pFile['type']) = $gBitSystem->verifyFileExtension($pFile['tmp_name'], $pFile['name']); } else { //$pFile['type'] = $gBitSystem->verifyMimeType( $pFile['tmp_name'] ); } // clean out crap that can make life difficult in server maintenance $cleanedBaseName = preg_replace('/[&\\%:\\/\\\\]/', '', substr($pFile['name'], 0, strrpos($pFile['name'], '.'))); $pFile['dest_base_name'] = $cleanedBaseName; $pFile['source_file'] = $pFile['tmp_name']; // lowercase all file extensions $pFile['name'] = $cleanedBaseName . strtolower(substr($pFile['name'], strrpos($pFile['name'], '.'))); if (!isset($pParamHash['STORAGE'][$storageGuid])) { $pParamHash['STORAGE'][$storageGuid] = array(); } $pParamHash['STORAGE'][$storageGuid][$pKey] = array('upload' => &$pFile); } } }
/** * * Wrap calls to proc_close(proc_open()) and call hook * so plugins can take part in process :) * * args: * $cmd program to run * next args are passed as $cmd command line * * e.g.: proc_run("ls","-la","/tmp"); * * $cmd and string args are surrounded with "" */ function proc_run() { $args = func_get_args(); $newargs = array(); if (!count($args)) { return; } $args = flatten_array_recursive($args); $arr = array('args' => $args, 'run_cmd' => true); call_hooks('proc_run', $arr); if (!$arr['run_cmd']) { return; } if (count($args) && $args[0] === 'php') { $args[0] = x(App::$config, 'system') && x(App::$config['system'], 'php_path') && strlen(App::$config['system']['php_path']) ? App::$config['system']['php_path'] : 'php'; } // redirect proc_run statements of legacy daemon processes to the newer Daemon Master object class // We will keep this interface until everybody has transitioned. (2016-05-20) if (strstr($args[1], 'include/')) { // convert 'include/foo.php' to 'Foo' $orig = substr(ucfirst(substr($args[1], 8)), 0, -4); logger('proc_run_redirect: ' . $orig); if (file_exists('Zotlabs/Daemon/' . $orig . '.php')) { array_shift($args); // daemons are all run by php, pop it off the top of the array $args[0] = $orig; // replace with the new daemon name logger('Redirecting old proc_run interface: ' . print_r($args, true), LOGGER_DEBUG, LOG_DEBUG); \Zotlabs\Daemon\Master::Summon($args); // summon the daemon return; } } $args = array_map('escapeshellarg', $args); $cmdline = implode($args, " "); if (is_windows()) { $cwd = getcwd(); $cmd = "cmd /c start \"title\" /D \"{$cwd}\" /b {$cmdline}"; proc_close(proc_open($cmd, array(), $foo)); } else { if (get_config('system', 'use_proc_open')) { proc_close(proc_open($cmdline . " &", array(), $foo)); } else { exec($cmdline . ' > /dev/null &'); } } }
function slash() { return is_windows() ? '\\' : '/'; }
/** * @brief Checks the PHP environment. * * @param[in,out] string &$phpath * @param[out] array &$checks */ function check_php(&$phpath, &$checks) { $help = ''; if (strlen($phpath)) { $passed = file_exists($phpath); } else { if (is_windows()) { $phpath = trim(shell_exec('where php')); } else { $phpath = trim(shell_exec('which php')); } $passed = strlen($phpath); } if (!$passed) { $help .= t('Could not find a command line version of PHP in the web server PATH.') . EOL; $help .= t('If you don\'t have a command line version of PHP installed on server, you will not be able to run background polling via cron.') . EOL; $help .= EOL . EOL; $tpl = get_markup_template('field_input.tpl'); $help .= replace_macros($tpl, array('$field' => array('phpath', t('PHP executable path'), $phpath, t('Enter full path to php executable. You can leave this blank to continue the installation.')))); $phpath = ''; } check_add($checks, t('Command line PHP') . ($passed ? " (<tt>{$phpath}</tt>)" : ""), $passed, false, $help); if ($passed) { $str = autoname(8); $cmd = "{$phpath} install/testargs.php {$str}"; $result = trim(shell_exec($cmd)); $passed2 = $result == $str; $help = ''; if (!$passed2) { $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.') . EOL; $help .= t('This is required for message delivery to work.'); } check_add($checks, t('PHP register_argc_argv'), $passed, true, $help); } }
/** * checks files for permissions * @param array files Array of files with absolute paths * @return string result of check */ function systemCheckJsonCheckFiles($persistence) { global $mod_strings; global $persistence; $filesNotWritable = array(); $i = 0; $filesOut = "\n\t\t<a href='javascript:void(0); toggleNwFiles(\"filesNw\");'>{$mod_strings['LBL_UW_SHOW_NW_FILES']}</a>\n\t\t<div id='filesNw' style='display:none;'>\n\t\t<table cellpadding='3' cellspacing='0' border='0'>\n\t\t<tr>\n\t\t\t<th align='left'>{$mod_strings['LBL_UW_FILE']}</th>\n\t\t\t<th align='left'>{$mod_strings['LBL_UW_FILE_PERMS']}</th>\n\t\t\t<th align='left'>{$mod_strings['LBL_UW_FILE_OWNER']}</th>\n\t\t\t<th align='left'>{$mod_strings['LBL_UW_FILE_GROUP']}</th>\n\t\t</tr>"; $isWindows = is_windows(); foreach ($persistence['files_to_check'] as $file) { // while($file = array_pop($persistence['files_to_check'])) { // admin deletes a bad file mid-check: if (!file_exists($file)) { continue; } if ($isWindows) { if (!is_writable_windows($file)) { logThis('WINDOWS: File [' . $file . '] not readable - saving for display'); // don't warn yet - we're going to use this to check against replacement files $filesNotWritable[$i] = $file; $filesNWPerms[$i] = substr(sprintf('%o', fileperms($file)), -4); $filesOut .= "<tr>" . "<td valign='top'><span class='error'>{$file}</span></td>" . "<td valign='top'>{$filesNWPerms[$i]}</td>" . "<td valign='top'>" . $mod_strings['ERR_UW_CANNOT_DETERMINE_USER'] . "</td>" . "<td valign='top'>" . $mod_strings['ERR_UW_CANNOT_DETERMINE_GROUP'] . "</td>" . "</tr>"; } } else { if (!is_writable($file)) { logThis('File [' . $file . '] not writable - saving for display'); // don't warn yet - we're going to use this to check against replacement files $filesNotWritable[$i] = $file; $filesNWPerms[$i] = substr(sprintf('%o', fileperms($file)), -4); $owner = posix_getpwuid(fileowner($file)); $group = posix_getgrgid(filegroup($file)); $filesOut .= "<tr>" . "<td valign='top'><span class='error'>{$file}</span></td>" . "<td valign='top'>{$filesNWPerms[$i]}</td>" . "<td valign='top'>" . $owner['name'] . "</td>" . "<td valign='top'>" . $group['name'] . "</td>" . "</tr>"; } } $i++; } $filesOut .= '</table></div>'; // not a stop error $persistence['filesNotWritable'] = count($filesNotWritable) > 0 ? true : false; if (count($filesNotWritable) < 1) { $filesOut = "{$mod_strings['LBL_UW_FILE_NO_ERRORS']}"; $persistence['step']['systemCheck'] = 'success'; } echo $filesOut; return $persistence; }
/** * get_mode * * Will check to see if there is a default mode defined in the config file, otherwise return the * $mode given as input * * @param int $mode - the mode being passed by the calling function. This value will be overridden by a value * defined in the config file. * @return int - the mode either found in the config file or passed in via the input parameter */ function get_mode($key = 'dir_mode', $mode = null) { if (!is_int($mode)) { $mode = (int) $mode; } if (!class_exists('SugarConfig', true)) { require 'include/SugarObjects/SugarConfig.php'; } if (!is_windows()) { $conf_inst = SugarConfig::getInstance(); $mode = $conf_inst->get('default_permissions.' . $key, $mode); } return $mode; }