public function getProcessImage($api, $args)
 {
     $path = 'upload://tmp/';
     $image = new PMSEImageGenerator();
     $img = $image->get_image($args['record']);
     $file = new UploadStream();
     if (!$file->checkDir($path)) {
         $file->createDir($path);
     }
     $file_path = UploadFile::realpath($path) . '/' . $args['record'];
     imagepng($img, $file_path);
     imagedestroy($img);
 }
Example #2
0
 /**
  * Gets a single temporary file for rendering and removes it from filesystem.
  *
  * @param ServiceBase $api The service base
  * @param array $args Arguments array built by the service base
  */
 public function getTempImage($api, $args)
 {
     // Get the field
     if (empty($args['field'])) {
         // @TODO Localize this exception message
         throw new SugarApiExceptionMissingParameter('Field name is missing');
     }
     $field = $args['field'];
     // Get the bean
     $bean = BeanFactory::newBean($args['module']);
     // Handle ACL
     $this->verifyFieldAccess($bean, $field);
     $filepath = UploadStream::path("upload://tmp/") . $args['temp_id'];
     if (is_file($filepath)) {
         $filedata = getimagesize($filepath);
         $info = array('content-type' => $filedata['mime'], 'path' => $filepath);
         require_once "include/download_file.php";
         $dl = new DownloadFileApi($api);
         $dl->outputFile(false, $info);
         if (!empty($args['keep'])) {
             return;
         }
         register_shutdown_function(function () use($filepath) {
             if (is_file($filepath)) {
                 unlink($filepath);
             }
         });
     } else {
         throw new SugarApiExceptionInvalidParameter('File not found');
     }
 }
 public function run()
 {
     require_once 'ModuleInstall/PackageManager/PackageManager.php';
     $pm = new PackageManager();
     $packages = $pm->getinstalledPackages(array('module'));
     foreach ($packages as $pack) {
         if (strpos($pack['name'], 'SugarCRM Upgrader') !== false) {
             $uh = new UpgradeHistory();
             $uh->name = $pack['name'];
             $history = $uh->checkForExisting($uh);
             $this->filesToRemove[] = "custom/Extension/application/Ext/Include/{$history->id_name}.php";
             $history->delete();
             $this->fileToDelete($this->filesToRemove);
             $this->log("Useless files of {$pack['name']} v{$pack['version']} removed");
         }
     }
     foreach ($pm->getPackagesInStaging() as $pack) {
         if (strpos($pack['name'], 'SugarCRM Upgrader') !== false) {
             $file = UploadStream::getFSPath(hashToFile($pack['file']));
             $this->fileToDelete($file);
             foreach (array('manifest', 'icon') as $meta) {
                 $this->fileToDelete(pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME) . "-{$meta}.php");
             }
         }
     }
 }
 /**
  * Returns the filename for a temporary file
  *
  * @param  string $type string to prepend to the filename, typically to indicate the file's use
  * @return string filename
  */
 private static function _createFileName($type = self::FILE_MISCELLANEOUS)
 {
     global $current_user;
     $importdir = self::getImportDir();
     // ensure dir exists and writable
     UploadStream::ensureDir($importdir, true);
     return "{$importdir}/{$type}_{$current_user->id}.csv";
 }
 /**
  * A Static method to Build the display for the package manager
  *
  * @param String form1 - the form to display for manual downloading
  * @param String hidden_fields - the hidden fields related to downloading a package
  * @param String form_action - the form_action to be used when downloading from the server
  * @param String types - the types of objects we will request from the server
  * @param String active_form - the form to display first
  * @return String - a string of html which will be used to display the forms
  */
 function buildPackageDisplay($form1, $hidden_fields, $form_action, $types = array('module'), $active_form = 'form1', $install = false)
 {
     global $current_language, $app_strings;
     $app_strings = return_application_language($current_language);
     $ss = new Sugar_Smarty();
     $ss->assign('APP_STRINGS', $app_strings);
     $ss->assign('FORM_1_PLACE_HOLDER', $form1);
     $ss->assign('form_action', $form_action);
     $ss->assign('hidden_fields', $hidden_fields);
     $result = PackageManagerDisplay::getHeader();
     $isAlive = $result['isAlive'];
     $mi = new ModuleInstaller();
     $mi_errors = $mi->getErrors();
     $error_html = "";
     if (!empty($mi_errors)) {
         $error_html = "<div style='margin:0px 10px 10px 10px;'>";
         foreach ($mi_errors as $error) {
             $error_html .= "<font color='red'>" . $error . "</font><br>";
         }
         $error_html .= "</div>";
     }
     $tree = PackageManagerDisplay::buildTreeView('treeview', $isAlive);
     $tree->tree_style = 'vendor/ytree/TreeView/css/check/tree.css';
     $ss->assign('TREEHEADER', $tree->generate_header());
     $ss->assign('installation', $install ? 'true' : 'false');
     $mod_strings = return_module_language($current_language, "Administration");
     $ss->assign('MOD', $mod_strings);
     $ss->assign('module_load', 'true');
     if (UploadStream::getSuhosinStatus() == false) {
         $ss->assign('ERR_SUHOSIN', true);
     } else {
         $ss->assign('scripts', PackageManagerDisplay::getDisplayScript($install));
     }
     $show_login = false;
     //hiding install from sugar
     $ss->assign('MODULE_SELECTOR', PackageManagerDisplay::buildGridOutput($tree, $mod_strings, $isAlive, $show_login));
     $ss->assign('INSTALL_ERRORS', $error_html);
     $ss->assign('MOD', $mod_strings);
     $descItemsInstalled = $mod_strings['LBL_UW_DESC_MODULES_INSTALLED'];
     $ss->assign('INSTALLED_PACKAGES_HOLDER', PackageManagerDisplay::buildInstalledGrid($mod_strings, $types));
     $str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageForm.tpl');
     return $str;
 }
Example #6
0
 /**
  * Constructor
  *
  * @param string $filename
  * @param string $delimiter
  * @param string $enclosure
  * @param bool   $deleteFile
  * @param bool   $checkUploadPath
  * @param int    $rowsCount
  */
 public function __construct($filename, $delimiter = ',', $enclosure = '', $deleteFile = true, $checkUploadPath = true, $rowsCount = 0)
 {
     if (!is_file($filename) || !is_readable($filename)) {
         return false;
     }
     if ($checkUploadPath && UploadStream::path($filename) == null) {
         $GLOBALS['log']->fatal("ImportFile detected attempt to access to the following file not within the sugar upload dir: {$filename}");
         return null;
     }
     // turn on auto-detection of line endings to fix bug #10770
     ini_set('auto_detect_line_endings', '1');
     $this->_fp = sugar_fopen($filename, 'r');
     $this->_sourcename = $filename;
     $this->_deleteFile = $deleteFile;
     $this->_delimiter = empty($delimiter) ? ',' : $delimiter;
     if ($this->_delimiter == '\\t') {
         $this->_delimiter = "\t";
     }
     $this->_enclosure = empty($enclosure) ? '' : trim($enclosure);
     // Autodetect does setFpAfterBOM()
     $this->_encoding = $this->autoDetectCharacterSet();
     $this->_rowsCount = $rowsCount;
 }
Example #7
0
/**
 * Get UW directories
 * Provides compatibility with both 6.3 and pre-6.3 setup
 */
function getUWDirs()
{
    if (!class_exists('UploadStream')) {
        // we're still running the old code
        global $sugar_config;
        return array($sugar_config['upload_dir'] . "/upgrades", $sugar_config['cache_dir'] . "upload/upgrades/temp");
    } else {
        if (!in_array("upload", stream_get_wrappers())) {
            UploadStream::register();
            // just in case file was copied, but not run
        }
        return array("upload://upgrades", sugar_cached("upgrades/temp"));
    }
}
Example #8
0
require_once 'modules/Trackers/BreadCrumbStack.php';
require_once 'modules/Trackers/Tracker.php';
require_once 'modules/Trackers/TrackerManager.php';
require_once 'modules/ACL/ACLController.php';
require_once 'modules/Administration/Administration.php';
require_once 'modules/Administration/updater_utils.php';
require_once 'modules/Users/User.php';
require_once 'modules/Users/authentication/AuthenticationController.php';
require_once 'include/utils/LogicHook.php';
require_once 'include/SugarTheme/SugarTheme.php';
require_once 'include/MVC/SugarModule.php';
require_once 'include/SugarCache/SugarCache.php';
require 'modules/Currencies/Currency.php';
require_once 'include/MVC/SugarApplication.php';
require_once 'include/upload_file.php';
UploadStream::register();
//
//SugarApplication::startSession();
///////////////////////////////////////////////////////////////////////////////
////    Handle loading and instantiation of various Sugar* class
if (!defined('SUGAR_PATH')) {
    define('SUGAR_PATH', realpath(dirname(__FILE__) . '/..'));
}
require_once 'include/SugarObjects/SugarRegistry.php';
if (empty($GLOBALS['installing'])) {
    ///////////////////////////////////////////////////////////////////////////////
    ////	SETTING DEFAULT VAR VALUES
    $GLOBALS['log'] = LoggerManager::getLogger();
    $error_notice = '';
    $use_current_user_login = false;
    // Allow for the session information to be passed via the URL for printing.
Example #9
0
 public function url_stat($path, $flags)
 {
     $this->init();
     // because of php bug not calling stream ctor
     if (file_exists(parent::getFSPath($path))) {
         return parent::url_stat($path, $flags);
     }
     $stat = $this->callS3("url_stat", func_get_args());
     if (empty($stat['size'])) {
         return false;
     }
     return $stat;
 }
Example #10
0
 /**
  * Get upload directory
  * @return string
  */
 public static function getDir()
 {
     if (empty(self::$upload_dir)) {
         self::$upload_dir = rtrim($GLOBALS['sugar_config']['upload_dir'], '/\\');
         if (empty(self::$upload_dir)) {
             self::$upload_dir = "upload";
         }
         if (!file_exists(self::$upload_dir)) {
             sugar_mkdir(self::$upload_dir, 0755, true);
         }
     }
     return self::$upload_dir;
 }
Example #11
0
global $sugar_config;
$supportedExtensions = array('jpg', 'png', 'jpeg');
$json = getJSONobj();
$rmdir = true;
$returnArray = array();
if ($json->decode(html_entity_decode($_REQUEST['forQuotes']))) {
    $returnArray['forQuotes'] = "quotes";
} else {
    $returnArray['forQuotes'] = "company";
}
$upload_ok = false;
if (isset($_FILES['file_1'])) {
    $upload = new UploadFile('file_1');
    if ($upload->confirm_upload()) {
        $dir = "upload://cache/images";
        UploadStream::ensureDir($dir);
        $file_name = $dir . "/" . $upload->get_stored_file_name();
        if ($upload->final_move($file_name)) {
            $upload_ok = true;
        }
    }
}
if (!$upload_ok) {
    $returnArray['data'] = 'not_recognize';
    echo $json->encode($returnArray);
    sugar_cleanup();
    exit;
}
if (file_exists($file_name) && is_file($file_name)) {
    $returnArray['path'] = substr($file_name, 9);
    // strip upload prefix
 /**
  * A Static method to Build the display for the package manager
  *
  * @param String form1 - the form to display for manual downloading
  * @param String hidden_fields - the hidden fields related to downloading a package
  * @param String form_action - the form_action to be used when downloading from the server
  * @param String types - the types of objects we will request from the server
  * @param String active_form - the form to display first
  * @return String - a string of html which will be used to display the forms
  */
 static function buildPackageDisplay($form1, $hidden_fields, $form_action, $types = array('module'), $active_form = 'form1', $install = false)
 {
     global $current_language;
     $mod_strings = return_module_language($current_language, "Administration");
     global $app_strings;
     global $sugar_version, $sugar_config;
     $app_strings = return_application_language($current_language);
     $ss = new Sugar_Smarty();
     $ss->assign('APP_STRINGS', $app_strings);
     $ss->assign('FORM_1_PLACE_HOLDER', $form1);
     $ss->assign('form_action', $form_action);
     $ss->assign('hidden_fields', $hidden_fields);
     $result = PackageManagerDisplay::getHeader();
     $header_text = $result['text'];
     $isAlive = $result['isAlive'];
     $show_login = $result['show_login'];
     $mi_errors = ModuleInstaller::getErrors();
     $error_html = "";
     if (!empty($mi_errors)) {
         $error_html = "<tr><td><span>";
         foreach ($mi_errors as $error) {
             $error_html .= "<font color='red'>" . $error . "</font><br>";
         }
         $error_html .= "</span></td></tr>";
     }
     $form2 = "<table  class='tabForm' width='100%'  cellpadding='0' cellspacing='0' width='100%' border='0'>";
     $form2 .= $error_html;
     if (!$isAlive) {
         $form2 .= "<tr><td><span id='span_display_html'>" . $header_text . "</span></td></tr>";
     }
     $form2 .= "</table>";
     $tree = null;
     //if($isAlive){
     $tree = PackageManagerDisplay::buildTreeView('treeview', $isAlive);
     $tree->tree_style = 'include/ytree/TreeView/css/check/tree.css';
     $ss->assign('TREEHEADER', $tree->generate_header());
     //}
     //$form2 .= PackageManagerDisplay::buildLoginPanel($mod_strings);
     $form2 .= "<table  class='tabForm' cellpadding='0' cellspacing='0' width='100%' border='0'>";
     $form2 .= "<tr><td></td><td align='left'>";
     if ($isAlive) {
         $form2 .= "<input type='button' id='modifCredentialsBtn' class='button' onClick='PackageManager.showLoginDialog(true);' value='" . $mod_strings['LBL_MODIFY_CREDENTIALS'] . "'>";
     } else {
         $form2 .= "<input type='button' id='modifCredentialsBtn' class='button' onClick='PackageManager.showLoginDialog(true);' value='" . $mod_strings['LBL_MODIFY_CREDENTIALS'] . "'style='display:none;'>";
     }
     $form2 .= "</td><td align='left'><div id='workingStatusDiv' style='display:none;'>" . SugarThemeRegistry::current()->getImage("sqsWait", "border='0' align='bottom'", null, null, '.gif', "Loading") . "</div></td><td align='right'>";
     if ($isAlive) {
         $form2 .= "<slot><a class=\"listViewTdToolsS1\" id='href_animate' onClick=\"PackageManager.toggleDiv('span_animate_server_div', 'catview');\"><span id='span_animate_server_div'><img src='" . SugarThemeRegistry::current()->getImageURL('basic_search.gif') . "' width='8' height='8' border='0'>&nbsp;Collapse</span></a></slot>";
     } else {
         $form2 .= "<slot><a class=\"listViewTdToolsS1\" id='href_animate' onClick=\"PackageManager.toggleDiv('span_animate_server_div', 'catview');\"><span id='span_animate_server_div' style='display:none;'><img src='" . SugarThemeRegistry::current()->getImageURL('basic_search.gif') . "' width='8' height='8' border='0'>&nbsp;Collapse</span></a></slot>";
     }
     $form2 .= "</td></tr></table>";
     $form2 = '';
     //Commenting out the form as part of sugar depot hiding.
     $ss->assign('installation', $install ? 'true' : 'false');
     $mod_strings = return_module_language($current_language, "Administration");
     $ss->assign('MOD', $mod_strings);
     $ss->assign('module_load', 'true');
     if (UploadStream::getSuhosinStatus() == false) {
         $ss->assign('ERR_SUHOSIN', true);
     } else {
         $ss->assign('scripts', PackageManagerDisplay::getDisplayScript($install));
     }
     $show_login = false;
     //hiding install from sugar
     $ss->assign('MODULE_SELECTOR', PackageManagerDisplay::buildGridOutput($tree, $mod_strings, $isAlive, $show_login));
     $ss->assign('FORM_2_PLACE_HOLDER', $form2);
     $ss->assign('MOD', $mod_strings);
     $descItemsInstalled = $mod_strings['LBL_UW_DESC_MODULES_INSTALLED'];
     $ss->assign('INSTALLED_PACKAGES_HOLDER', PackageManagerDisplay::buildInstalledGrid($mod_strings, $types));
     $str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageForm.tpl');
     return $str;
 }
Example #13
0
 /**
  * Moves temporary files associated with the bean from the temporary folder
  * to the upload folder.
  *
  * @param array $args The request arguments.
  * @param SugarBean $bean The bean associated with the file.
  * @throws SugarApiExceptionInvalidParameter If the file mime types differ
  *   from $imageFileMimeTypes.
  */
 protected function moveTemporaryFiles($args, SugarBean $bean)
 {
     require_once 'include/upload_file.php';
     require_once 'include/SugarFields/SugarFieldHandler.php';
     $fileFields = $bean->getFieldDefinitions('type', array('file', 'image'));
     $sfh = new SugarFieldHandler();
     // FIXME This path should be changed with BR-1955.
     $basepath = UploadStream::path('upload://tmp/');
     $configDir = SugarConfig::getInstance()->get('upload_dir', 'upload');
     foreach ($fileFields as $fieldName => $def) {
         if (empty($args[$fieldName . '_guid'])) {
             continue;
         }
         $this->verifyFieldAccess($bean, $fieldName);
         $filepath = $basepath . $args[$fieldName . '_guid'];
         if (!is_file($filepath)) {
             continue;
         }
         if ($def['type'] === 'image') {
             $filename = $args[$fieldName . '_guid'];
             $bean->{$fieldName} = $filename;
         } else {
             // FIXME Image verification and mime type updating
             // should not be duplicated from SugarFieldFile.
             // SC-3338 is tracking this.
             require_once 'include/utils/file_utils.php';
             $filename = $bean->id;
             $mimeType = get_file_mime_type($filepath, 'application/octet-stream');
             $sf = $sfh->getSugarField($def['type']);
             $extension = pathinfo($fieldName, PATHINFO_EXTENSION);
             if (in_array($mimeType, $sf::$imageFileMimeTypes) && !verify_image_file($filepath)) {
                 throw new SugarApiExceptionInvalidParameter(string_format($GLOBALS['app_strings']['LBL_UPLOAD_IMAGE_FILE_NOT_SUPPORTED'], array($extension)));
             }
             $bean->file_mime_type = $mimeType;
             $bean->file_ext = $extension;
         }
         $destination = rtrim($configDir, '/\\') . '/' . $filename;
         // FIXME BR-1956 will address having multiple files
         // associated with a record.
         rename($filepath, $destination);
     }
 }
Example #14
0
$supportedExtensions = array('jpg', 'png', 'jpeg');
$json = getJSONobj();
$rmdir = true;
$returnArray = array();
if ($json->decode(html_entity_decode($_REQUEST['forQuotes']))) {
    $returnArray['forQuotes'] = "quotes";
} else {
    $returnArray['forQuotes'] = "company";
}
$upload_ok = false;
$upload_path = 'tmp_logo_' . $returnArray['forQuotes'] . '_upload';
if (isset($_FILES['file_1'])) {
    $upload = new UploadFile('file_1');
    if ($upload->confirm_upload()) {
        $upload_dir = 'upload://' . $upload_path;
        UploadStream::ensureDir($upload_dir);
        $file_name = $upload_dir . "/" . $upload->get_stored_file_name();
        if ($upload->final_move($file_name)) {
            $upload_ok = true;
        }
    }
}
if (!$upload_ok) {
    $returnArray['data'] = 'not_recognize';
    echo $json->encode($returnArray);
    sugar_cleanup(true);
}
if (file_exists($file_name) && is_file($file_name)) {
    $encoded_file_name = rawurlencode($upload->get_stored_file_name());
    $returnArray['path'] = $upload_path . '/' . $encoded_file_name;
    $returnArray['url'] = 'cache/images/' . $encoded_file_name;
Example #15
0
}
if ($upload_max_filesize_bytes > constant('SUGARCRM_MIN_UPLOAD_MAX_FILESIZE_BYTES')) {
    $fileMaxStatus = "{$mod_strings['LBL_CHECKSYS_OK']}</font>";
} else {
    $fileMaxStatus = "<span class='stop'><b>{$mod_strings['ERR_UPLOAD_MAX_FILESIZE']}</font></b></span>";
}
$envString .= '<p><b>' . $mod_strings['LBL_UPLOAD_MAX_FILESIZE_TITLE'] . '</b> ' . $fileMaxStatus . '</p>';
//CHECK Sprite support
if (function_exists('imagecreatetruecolor')) {
    $spriteSupportStatus = "{$mod_strings['LBL_CHECKSYS_OK']}</font>";
} else {
    $spriteSupportStatus = "<span class='stop'><b>{$mod_strings['ERROR_SPRITE_SUPPORT']}</b></span>";
}
$envString .= '<p><b>' . $mod_strings['LBL_SPRITE_SUPPORT'] . '</b> ' . $spriteSupportStatus . '</p>';
// Suhosin allow to use upload://
if (UploadStream::getSuhosinStatus() == true || strpos(ini_get('suhosin.perdir'), 'e') !== false && strpos($_SERVER["SERVER_SOFTWARE"], 'Microsoft-IIS') === false) {
    $suhosinStatus = "{$mod_strings['LBL_CHECKSYS_OK']}";
} else {
    $suhosinStatus = "<span class='stop'><b>{$app_strings['ERR_SUHOSIN']}</b></span>";
}
$envString .= "<p><b>{$mod_strings['LBL_STREAM']} (" . UploadStream::STREAM_NAME . "://)</b> " . $suhosinStatus . "</p>";
// PHP.ini
$phpIniLocation = get_cfg_var("cfg_file_path");
$envString .= '<p><b>' . $mod_strings['LBL_CHECKSYS_PHP_INI'] . '</b> ' . $phpIniLocation . '</p>';
$out = <<<EOQ

<div id="syscred">

EOQ;
$out .= $envString;
$out .= <<<EOQ
Example #16
0
 /**
  * Register the stream
  */
 public function register()
 {
     if (isset($GLOBALS['sugar_config']['upload_wrapper_class'])) {
         SugarAutoLoader::requireWithCustom("include/{$GLOBALS['sugar_config']['upload_wrapper_class']}.php");
         if (class_exists($GLOBALS['sugar_config']['upload_wrapper_class'])) {
             self::$wrapper_class = $GLOBALS['sugar_config']['upload_wrapper_class'];
         } else {
             self::$wrapper_class = __CLASS__;
         }
     } else {
         self::$wrapper_class = __CLASS__;
     }
     stream_register_wrapper(self::STREAM_NAME, self::$wrapper_class);
     self::$instance = new self::$wrapper_class();
 }