コード例 #1
0
ファイル: Remote.php プロジェクト: xamiro-dev/xamiro
 public function rename($mount, $filePath, $filename_new, $dest = null, &$errors)
 {
     $filename_new = XApp_Path_Utils::sanitizeEx(XApp_SystemTextEncoding::magicDequote($filename_new), XApp_Path_Utils::SANITIZE_HTML_STRICT);
     $filename_new = substr($filename_new, 0, xapp_get_option(self::NODENAME_MAX_LENGTH, $this));
     $old = $this->toRealPath($mount . DIRECTORY_SEPARATOR . $filePath);
     if (!is_writable($old)) {
         $errors[] = XAPP_TEXT_FORMATTED('FILE_NOT_WRITEABLE', array($old), 55100);
         return;
     }
     if ($dest == null) {
         $new = dirname($old) . "/" . $filename_new;
     } else {
         $new = $this->toRealPath($mount . DIRECTORY_SEPARATOR . $dest);
     }
     if ($filename_new == "" && $dest == null) {
         $errors[] = XAPP_TEXT_FORMATTED('DIRECTORY_NOT_WRITEABLE', array($old), 55100);
         return;
     }
     if (file_exists($new)) {
         $errors[] = XAPP_TEXT_FORMATTED('FILE_EXISTS', array($filename_new), 55100);
     }
     if (!file_exists($old)) {
         $errors[] = XAPP_TEXT_FORMATTED('CAN_NOT_FIND_FILE', array(basename($filePath)), 55100);
         return;
     }
     rename($old, $new);
 }
コード例 #2
0
ファイル: Json.php プロジェクト: xamiro-dev/xamiro
 public function write($data)
 {
     $pass = null;
     if (xapp_has_option(self::CONF_PASSWORD)) {
         $pass = xapp_get_option(self::CONF_PASSWORD);
     }
     return XApp_Utils_JSONUtils::write_json(xo_get(self::CONF_FILE, $this), $data, 'json', true, $pass);
 }
コード例 #3
0
ファイル: Utils.php プロジェクト: xamiro-dev/xamiro
 /**
  * Turns a xapp option into an instance, expects string
  *
  * @param null $key
  * @param null $mixed
  * @param null $default
  * @return mixed|null
  */
 function xo_as_instance($key = null, &$mixed = null, $default = null, $options)
 {
     if ($mixed == null) {
         $mixed = XApp_Options_Utils::optionCallee();
     }
     $opt = xapp_get_option($key, $mixed, $default);
     if (!empty($opt) && is_string($opt) && class_exists($opt)) {
         return new $opt($options);
     }
     return null;
 }
コード例 #4
0
ファイル: Store.php プロジェクト: xamiro-dev/xamiro
 public function getWriter()
 {
     if ($this->_writer) {
         return $this->_writer;
     }
     $writerClass = xapp_get_option(self::WRITER_CLASS, $this);
     if (class_exists($writerClass)) {
         $this->_writer = new $writerClass(xapp_get_options());
     }
     return $this->_writer;
 }
コード例 #5
0
ファイル: CIStore.php プロジェクト: xamiro-dev/xamiro
 public function write($data)
 {
     $path = xapp_get_option(self::CONF_FILE, $this);
     if (file_exists($path)) {
         $result = null;
         $pretty = true;
         if ($pretty) {
             $result = file_put_contents($path, Xapp_Util_Json::prettify($data), LOCK_EX);
         } else {
             $result = file_put_contents($path, $data, LOCK_EX);
         }
         if ($result !== false) {
             $result = null;
             return true;
         } else {
             throw new Xapp_Util_Json_Exception("unable to save to file: " . $path, 1690501);
         }
     }
     return $data;
 }
コード例 #6
0
ファイル: Raw.php プロジェクト: xamiro-dev/xamiro
 /**
  * executing requested service if found passing result from service invoking to response
  * or pass compile smd map to response if no service was called. if a callback was supplied
  * will wrap result into callback function
  *
  * @error 14706
  * @return void
  */
 protected function execute($call)
 {
     $get = $this->request()->getGet();
     $response = $this->response();
     try {
         $result = $this->invoke($call, $call[3]);
         $this->response()->skipHeader();
         if (array_key_exists(xapp_get_option(self::CALLBACK, $this), $get)) {
         } else {
             $result = $response->encode($result);
         }
         $response->body($result);
     } catch (Exception $e) {
         if (xapp_is_option(self::EXCEPTION_CALLBACK, $this)) {
             $e = call_user_func_array(xapp_get_option(self::EXCEPTION_CALLBACK, $this), array(&$e, $this, $call));
             if (!$e instanceof Exception) {
                 if (xapp_get_option(self::COMPLY_TO_JSONRPC_1_2, $this)) {
                     if (array_key_exists($e->getCode(), $this->codeMap)) {
                         xapp_set_option(Xapp_Rpc_Response::STATUS_CODE, $this->codeMap[$e->getCode()], $response);
                     } else {
                         xapp_set_option(Xapp_Rpc_Response::STATUS_CODE, 500, $response);
                     }
                 }
                 if (xapp_is_option(self::ERROR_CALLBACK, $this) && array_key_exists(xapp_get_option(self::ERROR_CALLBACK, $this), $get)) {
                     $e = $get[xapp_get_option(self::ERROR_CALLBACK, $this)] . '(' . $response->encode($e) . ')';
                 } else {
                     if (array_key_exists(xapp_get_option(self::CALLBACK, $this), $get)) {
                         $e = $get[xapp_get_option(self::CALLBACK, $this)] . '(' . $response->encode($e) . ')';
                     } else {
                         $e = $response->encode($e);
                     }
                 }
                 $response->body($e);
             }
         }
     }
 }
コード例 #7
0
ファイル: Error.php プロジェクト: xamiro-dev/xamiro
 /**
  * class destructor iterates through error stack an sorts all errors according to intended action
  * or target. since error have different severity level some errors need to be routed to specific
  * log writers only. therefore: the default implementation will route all errors to the designated
  * log writer. if the default log writers are overwritten than all errors are written to all registered
  * log writers at the same time - regardless of error log severity and mapped error action, e.g. only
  * mailing alert errors via email.
  *
  * @error 11605
  * @return void
  */
 public function __destruct()
 {
     $all = array();
     $mail = array();
     $file = array();
     $map = xapp_get_option(self::ACTION_MAP, $this);
     foreach ($this->stack as $k => $v) {
         if (!array_key_exists((int) $v->severity, $map)) {
             $v->severity = self::LOG;
         }
         if (array_key_exists((int) $v->severity, $map)) {
             $v->action = $map[(int) $v->severity];
         }
         if (isset($v->action) && !is_null($v->action)) {
             if (in_array($v->action, array(self::DUMP))) {
                 xapp_console($v->object, null, 'error');
             }
             if (in_array($v->action, array(self::LOG, self::LOG | self::MAIL))) {
                 $file[] = $v->message;
             }
             if (in_array($v->action, array(self::MAIL, self::LOG | self::MAIL))) {
                 $mail[] = $v->object;
             }
             $all[] = $v->object;
         }
     }
     if (xapp_is_option(self::WRITER, $this)) {
         $this->write($all);
     } else {
         if (sizeof($file) > 0) {
             $this->write($file, 'file');
         }
         if (sizeof($mail) > 0) {
             if (xapp_is_option(self::EMAIL, $this)) {
                 $this->write($mail, 'mail');
             }
         }
     }
 }
コード例 #8
0
ファイル: Bootstrap.php プロジェクト: xamiro-dev/xamiro
 public function setup()
 {
     /***
      * The very basic paths
      */
     if (!defined('XAPP_BASEDIR')) {
         define("XAPP_BASEDIR", xapp_get_option(self::BASEDIR, $this));
     }
     if (!defined('XAPP_LIB')) {
         define("XAPP_LIB", XAPP_BASEDIR . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR);
     }
     /***
      * Load utils
      */
     if (!class_exists('XApp_Service_Entry_Utils')) {
         include_once XAPP_BASEDIR . 'XApp_Service_Entry_Utils.php';
     }
     /***
      * Get run-time configuration, there is 'debug' and 'release'. For both cases there are
      * different resources to load.
      */
     $XAPP_RUN_TIME_CONFIGURATION = XApp_Service_Utils::_getKey('rtConfig', XApp_Service_Entry_Utils::getRunTimeConfiguration());
     /***
      * Now include all xapp stuff
      */
     //pull in parts of xapp core framework
     XApp_Service_Entry_Utils::includeXAppCore();
     //pull in registry of xapp core framework
     XApp_Service_Entry_Utils::includeXAppRegistry();
     //pull in parts of xapp json framework
     XApp_Service_Entry_Utils::includeXAppJSONStoreClasses();
     //pull in json utils (to read client app's resource configuration
     XApp_Service_Entry_Utils::includeXAppJSONTools();
     //some debugging tools
     XApp_Service_Entry_Utils::includeXAppDebugTools();
     //pull in legacy client app renderer
     xapp_import('xapp.app.Renderer');
     self::loadCommons();
     //pull in xapp commander renderer
     /*include_once(XAPP_BASEDIR . DIRECTORY_SEPARATOR . 'app'. DIRECTORY_SEPARATOR . 'Commander.php');*/
     //pull in xapp resource renderer
     include_once XAPP_BASEDIR . '/Resource/Renderer.php';
     //pull in xapp resource renderer
     xapp_import('xapp.commander.Resource.Renderer');
     //pull in xapp resource renderer
     xapp_import('xapp.Resource.Renderer');
     //pull in xide resource Renderer
     xapp_import('xapp.xide.Resource.Renderer');
     //pull in xide resource Renderer
     //xapp_import('xapp.xcf.Resource.Renderer');
     //pull in cms related resource renderer
     include_once XAPP_LIB . DIRECTORY_SEPARATOR . xapp_get_option(self::RESOURCE_RENDERER_PREFIX, $this) . DIRECTORY_SEPARATOR . 'ResourceRenderer.php';
     /***
      * Prepare resource renderer
      */
     //clients resource config path
     $XAPP_RESOURCE_CONFIG_PATH = '' . xapp_get_option(self::APPDIR, $this) . DIRECTORY_SEPARATOR;
     $XAPP_RESOURCE_CONFIG = xapp_get_option(self::XAPP_RESOURCE_CONFIG, $this);
     if (strlen($XAPP_RESOURCE_CONFIG)) {
         if ($XAPP_RUN_TIME_CONFIGURATION === 'debug') {
             $XAPP_RESOURCE_CONFIG_PATH .= 'lib' . DIRECTORY_SEPARATOR . xapp_get_option(self::APP_NAME, $this) . DIRECTORY_SEPARATOR . $XAPP_RESOURCE_CONFIG . xapp_get_option(self::RESOURCE_CONFIG_SUFFIX, $this) . '.json';
         } else {
             if ($XAPP_RUN_TIME_CONFIGURATION === 'release') {
                 $XAPP_RESOURCE_CONFIG_PATH .= DIRECTORY_SEPARATOR . xapp_get_option(self::APP_FOLDER, $this) . DIRECTORY_SEPARATOR . xapp_get_option(self::APP_NAME, $this) . DIRECTORY_SEPARATOR . $XAPP_RESOURCE_CONFIG . xapp_get_option(self::RESOURCE_CONFIG_SUFFIX, $this) . '.json';
             }
         }
     } else {
         if ($XAPP_RUN_TIME_CONFIGURATION === 'debug') {
             $XAPP_RESOURCE_CONFIG_PATH .= 'lib' . DIRECTORY_SEPARATOR . xapp_get_option(self::APP_NAME, $this) . DIRECTORY_SEPARATOR . 'resources-' . $XAPP_RUN_TIME_CONFIGURATION . xapp_get_option(self::RESOURCE_CONFIG_SUFFIX, $this) . '.json';
         } else {
             if ($XAPP_RUN_TIME_CONFIGURATION === 'release') {
                 $XAPP_RESOURCE_CONFIG_PATH .= DIRECTORY_SEPARATOR . xapp_get_option(self::APP_FOLDER, $this) . DIRECTORY_SEPARATOR . xapp_get_option(self::APP_NAME, $this) . DIRECTORY_SEPARATOR . 'resources-' . $XAPP_RUN_TIME_CONFIGURATION . xapp_get_option(self::RESOURCE_CONFIG_SUFFIX, $this) . '.json';
             }
         }
     }
     //error_log('$XAPP_RESOURCE_CONFIG ' . $XAPP_RESOURCE_CONFIG . "   =  " . $XAPP_RESOURCE_CONFIG_PATH);
     if (!file_exists($XAPP_RESOURCE_CONFIG_PATH)) {
         $this->log('have no core resources, ' . $XAPP_RESOURCE_CONFIG_PATH . ' doesnt exists');
         return null;
     }
     $resources = (object) XApp_Utils_JSONUtils::read_json($XAPP_RESOURCE_CONFIG_PATH, 'json', false, true);
     $pluginResources = null;
     /***
      * Load plugin resources
      */
     if (xapp_get_option(self::ALLOW_PLUGINS, $this) && xapp_get_option(self::PLUGIN_DIRECTORY, $this) && xapp_get_option(self::PLUGIN_DIRECTORY, $this)) {
         //pull in xapp plugin manager
         include_once XAPP_BASEDIR . '/commander/PluginManager.php';
         //pull in xapp commander plugin base class
         include_once XAPP_BASEDIR . '/commander/Plugin.php';
         //pull in RPC interface
         if (!class_exists('Xapp_Rpc_Interface_Callable')) {
             //pull in xapp commander plugin base class
             include_once XAPP_BASEDIR . '/Rpc/Interface/Callable.php';
         }
         $xComPluginManager = new XApp_Commander_PluginManager();
         $loadedPlugins = null;
         $plugins = $xComPluginManager->loadPlugins(xapp_get_option(self::PLUGIN_DIRECTORY, $this), xapp_get_option(self::PLUGIN_DIRECTORY, $this), xapp_get_option(self::PLUGIN_MASK, $this));
         $pluginResources = $this->getPluginResources($plugins, $XAPP_RUN_TIME_CONFIGURATION, $XAPP_RESOURCE_CONFIG);
     }
     //error_log('flags ' . json_encode(xapp_get_option(self::FLAGS, $this)));
     //now merge into app resources, filtered
     if ($pluginResources) {
         foreach ($pluginResources as $pluginResourceItems) {
             foreach ($pluginResourceItems as $pluginResource) {
                 $prohibited = explode(',', xapp_get_option(self::PROHIBITED_PLUGINS, $this));
                 if (property_exists($pluginResource, 'type') && property_exists($pluginResource, 'name')) {
                     //is plugin item
                     if (in_array('X' . $pluginResource->name, $prohibited)) {
                         continue;
                     } else {
                         array_push($resources->items, $pluginResource);
                     }
                 } else {
                     array_push($resources->items, $pluginResource);
                 }
             }
         }
     }
     $resourceRendererOptions = array(XApp_Resource_Renderer::DOC_ROOT => xapp_get_option(self::DOC_ROOT, $this), XApp_Resource_Renderer::DOC_ROOT_PATH => xapp_get_option(self::APPDIR, $this), XApp_Resource_Renderer::RESOURCES_DATA => $resources, XApp_Resource_Renderer::RENDER_DELEGATE => xapp_get_option(self::RENDER_DELEGATE, $this));
     $clz = xapp_get_option(self::RESOURCE_RENDERER_CLZ, $this);
     $xappResourceRenderer = new $clz($resourceRendererOptions);
     $xappResourceRenderer->registerDefault();
     if (xapp_has_option(self::RELATIVE_VARIABLES)) {
         $rVariables = xapp_get_option(self::RELATIVE_VARIABLES, $this);
         if ($rVariables != null && count($rVariables)) {
             foreach ($rVariables as $variable => $value) {
                 $xappResourceRenderer->registerRelative($variable, $value);
             }
         }
     }
     $XAPP_DOJO_PACKAGES = '[]';
     $XAPP_DOJO_PACKAGE_LOCATION_PREFIX = $xappResourceRenderer->resolveRelative('%PLUGIN_PACKAGE_ROOT_URL%');
     $javascriptPlugins = $xappResourceRenderer->getJavascriptPlugins();
     if ($javascriptPlugins && count($javascriptPlugins)) {
         if (XApp_Service_Entry_Utils::isDebug()) {
             $dojoPackages = array();
             $dojoPackagesStr = '[';
             $pIdx = 0;
             foreach ($javascriptPlugins as $plugin) {
                 if (!is_object($plugin)) {
                     continue;
                 }
                 if ($pIdx > 0) {
                     $dojoPackagesStr .= ",";
                 }
                 $dojoPackagesStr .= "{name:" . "'" . $plugin->name . "',";
                 if (property_exists($plugin, 'packageLocation')) {
                     $dojoPackagesStr .= "location:" . "'" . $plugin->packageLocation . "'}";
                 } else {
                     $dojoPackagesStr .= "location:" . "'" . $XAPP_DOJO_PACKAGE_LOCATION_PREFIX . $plugin->name . '/client/' . "'}";
                 }
                 if ($pIdx < count($javascriptPlugins) - 1) {
                     $dojoPackagesStr .= ',';
                 }
             }
             $dojoPackagesStr .= ']';
             $XAPP_DOJO_PACKAGES = $dojoPackagesStr;
         } else {
             $packageSuffix = "";
             $dojoPackages = array();
             array_push($dojoPackages, array('name' => 'dojo', 'location' => 'dojo'));
             array_push($dojoPackages, array('name' => 'dojox', 'location' => 'dojox'));
             array_push($dojoPackages, array('name' => 'dijit', 'location' => 'dijit'));
             array_push($dojoPackages, array('name' => 'cbtree', 'location' => 'cbtree'));
             array_push($dojoPackages, array('name' => 'xfile', 'location' => 'xfile'));
             array_push($dojoPackages, array('name' => 'xide', 'location' => 'xide'));
             array_push($dojoPackages, array('name' => 'xwordpress', 'location' => 'xwordpress'));
             array_push($dojoPackages, array('name' => 'xbox', 'location' => 'xbox'));
             array_push($dojoPackages, array('name' => 'xjoomla', 'location' => 'xjoomla'));
             foreach ($javascriptPlugins as $plugin) {
                 if (is_object($plugin)) {
                     if (property_exists($plugin, 'packageSuffix')) {
                         $packageSuffix = $plugin->{'packageSuffix'};
                     }
                     $packageLocation = $XAPP_DOJO_PACKAGE_LOCATION_PREFIX . $plugin->name . '/client/';
                     if (strlen($packageSuffix)) {
                         $packageLocation .= $packageSuffix . '/';
                     }
                     if (property_exists($plugin, 'packageLocation')) {
                         $packageLocation = $plugin->packageLocation;
                     }
                     array_push($dojoPackages, array('name' => $plugin->name, 'location' => $packageLocation));
                 }
             }
             $XAPP_DOJO_PACKAGES = json_encode($dojoPackages);
         }
         /****
          * Render plugin resources
          */
         $javaScriptHeaderStr = '';
         $javaScriptHeaderStr .= 'var xappPluginResources=';
         $javaScriptHeaderStr .= json_encode($javascriptPlugins) . ';';
         $javaScriptHeaderStr .= '';
         $xappResourceRenderer->registerRelative('XAPP_PLUGIN_RESOURCES', json_encode($javascriptPlugins));
         //important: get the resource variables before adding 'head' otherwise it breaks the JSON structure!
         $resourceVariables = (array) $xappResourceRenderer->registryToKeyValues(xapp_get_option(XApp_Resource_Renderer::RELATIVE_REGISTRY_NAMESPACE, $xappResourceRenderer));
         $resourceVariables['HTML_HEADER'] = array();
         $resourceVariables['XAPP_PLUGIN_RESOURCES'] = $javascriptPlugins;
         $resourceVariables['DOJOPACKAGES'] = array();
         $resourceVariables['XFILE_CONFIG_MIXIN'] = array();
         $resourceVariables['RESOURCE_VARIABLES'] = array();
         $xappResourceRenderer->registerRelative('RESOURCE_VARIABLES', Xapp_Util_Json::prettify(json_encode($resourceVariables, true)), LOCK_EX);
     }
     $xappResourceRenderer->registerRelative('DOJOPACKAGES', $XAPP_DOJO_PACKAGES);
     $pConfigDefault = $xappResourceRenderer->resolveRelative('%PACKAGE_CONFIG%');
     if (!strlen($pConfigDefault)) {
         $pConfigDefault = 'run-release-debug';
     }
     //error_log('$pConfigDefault ' .$pConfigDefault);
     $xappResourceRenderer->registerRelative('PACKAGE_CONFIG', XApp_Service_Utils::_getKey('pConfig', $pConfigDefault));
     /****
      * Build XApp-App-Renderer - Config
      */
     $opt = array(XApp_App_Commander::DOC_ROOT_PATH => xapp_get_option(self::APPDIR, $this), XApp_App_Commander::DOC_ROOT => xapp_get_option(self::DOC_ROOT, $this), XApp_App_Commander::APP_NAME => xapp_get_option(self::APP_NAME, $this), XApp_App_Commander::APP_FOLDER => xapp_get_option(self::APP_FOLDER, $this), XApp_App_Commander::CONFIG_NAME => $XAPP_RUN_TIME_CONFIGURATION, XApp_App_Commander::SERVICE_URL => xapp_get_option(self::SERVICE, $this), XApp_App_Commander::RESOURCE_RENDERER => $xappResourceRenderer);
     $xappAppRenderer = new XApp_App_Commander($opt);
     $this->appRenderer = $xappAppRenderer;
     $this->resourceRenderer = $xappResourceRenderer;
     return $xappAppRenderer;
 }
コード例 #9
0
ファイル: Autoloader.php プロジェクト: xamiro-dev/xamiro
 /**
  * autoload function registered with autoload handler loads class by looking for class in preloaded class map loaded
  * by Xapp_Autoloader::preload.
  *
  * @error 01706
  * @param null|string $class expects class to load
  * @return bool
  */
 public function load($class = null)
 {
     $file = null;
     if ($class !== null && !empty($class)) {
         $class = strtolower(trim((string) $class));
         if (strpos($class, xapp_get_option(self::NS_SEPARATOR, $this)) !== false) {
             $class = trim($class, xapp_get_option(self::NS_SEPARATOR, $this));
             $class = str_replace(xapp_get_option(self::NS_SEPARATOR, $this), xapp_get_option(self::PATH_SEPARATOR, $this), $class);
         }
         if ((bool) xapp_get_option(self::XAPP_ONLY)) {
             if (strpos($class, 'Xapp_') === false) {
                 return true;
             }
         }
         if (empty($this->_classes)) {
             $this->preload();
         }
         foreach ($this->_dirs as $k => $v) {
             if (isset($this->_classes[$k]) && array_key_exists($class, $this->_classes[$k])) {
                 $file = $this->_classes[$k][$class];
                 break;
             }
             if (isset($this->_classes[$k]) && array_key_exists("xapp_ext_{$class}", $this->_classes[$k])) {
                 $file = $this->_classes[$k]["xapp_ext_{$class}"];
                 break;
             }
         }
         if ($file !== null && is_file($file)) {
             require_once $file;
             @clearstatcache();
             return true;
         }
     }
     return false;
 }
コード例 #10
0
ファイル: Service.php プロジェクト: xamiro-dev/xamiro
 /**
  * @return array
  * @throws Xapp_XFile_Exception
  */
 public function put()
 {
     xapp_import('xapp.Path.Utils');
     xapp_import('xapp.Utils.SystemTextEncoding');
     $vars = array_merge($_GET, $_POST);
     $dstIn = '/';
     $mount = '/';
     if (array_key_exists('dstDir', $vars)) {
         $dstIn = XApp_Path_Utils::decodeSecureMagic($vars['dstDir']);
     }
     if (array_key_exists('mount', $vars)) {
         $mount = preg_replace('@[/\\\\]@', '', XApp_Path_Utils::decodeSecureMagic($vars['mount']));
     }
     if ($dstIn === '.') {
         $dstIn = '/';
     }
     $vfs = $this->getFileSystem($mount);
     $destination = $vfs->toRealPath(XApp_Path_Utils::normalizePath($mount . DIRECTORY_SEPARATOR . $dstIn));
     $errors = array();
     if (!$this->isLocal($mount, $this->getFSResources())) {
         return $this->putRemote($mount, $destination);
     }
     //writable check
     if (!is_writable($destination)) {
         throw new Xapp_XFile_Exception(XAPP_TEXT_FORMATTED('DIRECTORY_NOT_WRITEABLE', array($destination), 55100));
     }
     //parse files
     $fileVars = $_FILES;
     foreach ($fileVars as $boxName => $boxData) {
         if (substr($boxName, 0, 9) != "userfile_") {
             continue;
         }
         $err = self::parseFileDataErrors($boxData);
         if ($err != null) {
             $errorMessage = $err[1];
             $errors[] = XAPP_TEXT_FORMATTED('Error with upload %s', array($errorMessage));
             continue;
         }
         //basic sanitize
         $userfile_name = $boxData["name"];
         $userfile_name = XApp_Path_Utils::sanitizeEx(XApp_SystemTextEncoding::fromPostedFileName($userfile_name), XApp_Path_Utils::SANITIZE_HTML_STRICT);
         $userfile_name = substr($userfile_name, 0, 128);
         //rename if needed!
         $autorename = xapp_get_option(self::AUTO_RENAME);
         if ($autorename) {
             $userfile_name = self::autoRenameForDest($destination, $userfile_name);
         }
         /***
          * file extension check
          */
         $ext = pathinfo(strtolower($userfile_name), PATHINFO_EXTENSION);
         $allowable = explode(',', xapp_get_option(self::UPLOAD_EXTENSIONS, $this));
         if ($ext == '' || $ext == false || !in_array($ext, $allowable)) {
             $errors[] = XAPP_TEXT_FORMATTED('UPLOAD_EXTENSIONS_NOT_ALLOWED', array($userfile_name, $ext));
             xapp_clog('file not allowed');
             continue;
         }
         try {
             //no need anymore
             if (file_exists($destination . "/" . $userfile_name)) {
             }
         } catch (Exception $e) {
             $errorMessage = $e->getMessage();
             $errors[] = XAPP_TEXT_FORMATTED('UPLOAD_UNKOWN_ERROR', array($userfile_name, $errorMessage));
             break;
         }
         if (isset($boxData["input_upload"])) {
             try {
                 $input = fopen("php://input", "r");
                 $output = fopen("{$destination}/" . $userfile_name, "w");
                 $sizeRead = 0;
                 while ($sizeRead < intval($boxData["size"])) {
                     $chunk = fread($input, 4096);
                     $sizeRead += strlen($chunk);
                     fwrite($output, $chunk, strlen($chunk));
                 }
                 fclose($input);
                 fclose($output);
             } catch (Exception $e) {
                 $errorMessage = $e->getMessage();
                 $errors[] = XAPP_TEXT_FORMATTED('UPLOAD_UNKOWN_ERROR', array($userfile_name, $errorMessage));
                 break;
             }
         } else {
             $result = @move_uploaded_file($boxData["tmp_name"], "{$destination}/" . $userfile_name);
             if (!$result) {
                 $realPath = $destination . DIRECTORY_SEPARATOR . $userfile_name;
                 $result = move_uploaded_file($boxData["tmp_name"], $realPath);
             }
             if (!$result) {
                 $errors[] = XAPP_TEXT_FORMATTED('UPLOAD_UNKOWN_ERROR', array($userfile_name));
                 break;
             }
         }
     }
     return $errors;
 }
コード例 #11
0
ファイル: Bootstrap.php プロジェクト: xamiro-dev/xamiro
 public function setup()
 {
     $this->loadMin();
     /***
      * Get run-time configuration, there is 'debug' and 'release'. For both cases there are
      * different resources to load.
      */
     $XAPP_RUN_TIME_CONFIGURATION = XApp_Service_Entry_Utils::getRunTimeConfiguration();
     /***
      * Now include all xapp stuff
      */
     //pull in registry of xapp core framework
     XApp_Service_Entry_Utils::includeXAppRegistry();
     //pull in parts of xapp json framework
     self::loadXAppJSONStoreClasses();
     //pull in json utils (to read client app's resource configuration
     self::loadJSONTools();
     //some debugging tools
     self::loadDebuggingTools();
     //pull in legacy client app renderer
     xapp_import('xapp.app.Renderer');
     //pull in xapp resource renderer
     xapp_import('xapp.Resource.Renderer');
     //pull in custom resource Renderer
     xapp_import('xapp.xide.Resource.Renderer');
     /***
      * Prepare resource renderer
      */
     //clients resource config path
     $XAPP_RESOURCE_CONFIG_PATH = '' . xapp_get_option(self::APPDIR, $this) . DIRECTORY_SEPARATOR;
     if ($XAPP_RUN_TIME_CONFIGURATION === 'debug') {
         $XAPP_RESOURCE_CONFIG_PATH .= 'lib' . DIRECTORY_SEPARATOR . xapp_get_option(self::APP_NAME, $this) . DIRECTORY_SEPARATOR . 'resources-' . $XAPP_RUN_TIME_CONFIGURATION . xapp_get_option(self::RESOURCE_CONFIG_SUFFIX, $this) . '.json';
     } else {
         if ($XAPP_RUN_TIME_CONFIGURATION === 'release') {
             $XAPP_RESOURCE_CONFIG_PATH .= DIRECTORY_SEPARATOR . xapp_get_option(self::APP_FOLDER, $this) . DIRECTORY_SEPARATOR . xapp_get_option(self::APP_NAME, $this) . DIRECTORY_SEPARATOR . 'resources-' . $XAPP_RUN_TIME_CONFIGURATION . xapp_get_option(self::RESOURCE_CONFIG_SUFFIX, $this) . '.json';
         }
     }
     if (!file_exists($XAPP_RESOURCE_CONFIG_PATH)) {
         $this->log('have no client resource configuration at ' . $XAPP_RESOURCE_CONFIG_PATH . ', aborting');
     }
     //load resource configuration
     $resources = (object) XApp_Utils_JSONUtils::read_json($XAPP_RESOURCE_CONFIG_PATH, 'json', false, true);
     $pluginResources = null;
     $resourceRendererOptions = array(XApp_Resource_Renderer::DOC_ROOT => xapp_get_option(self::DOC_ROOT, $this), XApp_Resource_Renderer::DOC_ROOT_PATH => xapp_get_option(self::APPDIR, $this), XApp_Resource_Renderer::RESOURCES_DATA => $resources);
     $clz = xapp_get_option(self::RESOURCE_RENDERER_CLZ, $this);
     $xappResourceRenderer = new $clz($resourceRendererOptions);
     $xappResourceRenderer->registerDefault();
     if (xapp_has_option(self::RELATIVE_VARIABLES)) {
         $rVariables = xapp_get_option(self::RELATIVE_VARIABLES, $this);
         foreach ($rVariables as $variable => $value) {
             $xappResourceRenderer->registerRelative($variable, $value);
         }
     }
     //determine Dojo package paths and store them as JSON serialized resource variable
     $XAPP_DOJO_PACKAGE_LOCATION_PREFIX = $xappResourceRenderer->resolveRelative('%PLUGIN_PACKAGE_ROOT_URL%');
     $javascriptPlugins = $xappResourceRenderer->getJavascriptPlugins();
     $dojoPackages = $this->getDojoPackages($XAPP_DOJO_PACKAGE_LOCATION_PREFIX, $javascriptPlugins, XApp_Service_Entry_Utils::isDebug());
     $xappResourceRenderer->registerRelative('XAPP_PLUGIN_RESOURCES', $dojoPackages['plugins']);
     $xappResourceRenderer->registerRelative('DOJOPACKAGES', $dojoPackages['packages']);
     /****
      * Build XApp-App-Renderer - Config
      */
     $opt = array(XApp_App_Renderer::DOC_ROOT_PATH => xapp_get_option(self::APPDIR, $this), XApp_App_Renderer::DOC_ROOT => xapp_get_option(self::DOC_ROOT, $this), XApp_App_Renderer::APP_NAME => xapp_get_option(self::APP_NAME, $this), XApp_App_Renderer::APP_FOLDER => xapp_get_option(self::APP_FOLDER, $this), XApp_App_Renderer::CONFIG_NAME => $XAPP_RUN_TIME_CONFIGURATION, XApp_App_Renderer::SERVICE_URL => xapp_get_option(self::SERVICE, $this), XApp_App_Renderer::RESOURCE_RENDERER => $xappResourceRenderer);
     $this->appRenderer = new XApp_App_Renderer($opt);
     $this->resourceRenderer = xo_get(XApp_App_Renderer::RESOURCE_RENDERER, $this->appRenderer);
 }
コード例 #12
0
ファイル: Apc.php プロジェクト: xamiro-dev/xamiro
 /**
  * remove cache key returning boolean value
  *
  * @error 16205
  * @param string $key expects the cache key name as string
  * @return bool
  */
 public function forget($key)
 {
     return (bool) apc_delete(xapp_get_option(self::KEY_PREFIX, $this) . $key);
 }
コード例 #13
0
ファイル: Json.php プロジェクト: xamiro-dev/xamiro
 /**
  * compile service part of smd schema
  *
  * @error 14806
  * @param XO $obj expects reference variable of schema object
  * @return void
  */
 protected function compileService(&$obj)
 {
     $tmp = array();
     $separator = xapp_get_option(self::CLASS_METHOD_SEPARATOR, $this);
     if (xapp_is_option(self::SERVICE_OVER_GET, $this)) {
         foreach ($this->map() as $key => $val) {
             if (is_array($val)) {
                 foreach ($val as $k => $v) {
                     $v->transport = 'POST';
                     if (xapp_is_option(self::METHOD_TARGET, $this)) {
                         $v->target = $this->getTarget("{$key}.{$k}");
                     }
                     $tmp[$key . $separator . $k] = $v;
                 }
             } else {
                 $val->transport = 'POST';
                 if (xapp_is_option(self::METHOD_TARGET, $this)) {
                     $val->target = $this->getTarget($key);
                 }
                 $tmp[$key] = $val;
             }
         }
     } else {
         foreach ($this->map() as $key => $val) {
             if (is_array($val)) {
                 foreach ($val as $k => $v) {
                     $v->transport = 'POST';
                     $v->target = $this->getTarget();
                     $tmp[$key . $separator . $k] = $v;
                 }
             } else {
                 $val->transport = 'POST';
                 if (xapp_is_option(self::METHOD_TARGET, $this)) {
                     $val->target = $this->getTarget();
                 }
                 $tmp[$key] = $val;
             }
         }
     }
     $obj->services = $tmp;
 }
コード例 #14
0
ファイル: Plugin.php プロジェクト: xamiro-dev/xamiro
 /**
  * IPugin interface impl.
  *
  * setup() must be called before load
  *
  * @error 15404
  * @return integer Returns error code due to the initialization.
  */
 function setup()
 {
     //extract service configuration
     $this->serviceConfig = xapp_get_option(self::SERVICE_CONF, $this);
     //logging
     if (xapp_is_option(self::LOGGING_CONF, $this) && $this->serviceConfig) {
         $logConfig = xapp_get_option(self::SERVICE_CONF);
         if ($logConfig && $logConfig[XC_CONF_LOGGER] != null) {
             $this->logger = $logConfig[XC_CONF_LOGGER];
         } else {
             //setup logger
         }
     }
     //cache
     if (xapp_is_option(self::CACHE_CONF, $this) && $this->serviceConfig) {
         $cacheConfig = xapp_get_option(self::CACHE_CONF);
         if ($cacheConfig) {
             $this->cache = Xapp_Cache::instance($this->CACHE_NS, "file", array(Xapp_Cache_Driver_File::PATH => xapp_get_option(XC_CONF_CACHE_PATH, $this->serviceConfig), Xapp_Cache_Driver_File::CACHE_EXTENSION => $this->CACHE_NS, Xapp_Cache_Driver_File::DEFAULT_EXPIRATION => 200));
         }
     }
 }
コード例 #15
0
ファイル: Response.php プロジェクト: xamiro-dev/xamiro
 /**
  * flush headers by setting default header content type, length and charset and
  * all registered custom headers in class options or set via the header method
  *
  * @error 14511
  * @return void
  */
 protected function flushHeader()
 {
     if (!$this->_headerSent) {
         $charset = xapp_get_option(self::CHARSET, $this);
         $contentType = xapp_get_option(self::CONTENT_TYPE, $this);
         $statusCode = xapp_get_option(self::STATUS_CODE, $this);
         header("Content-Type: {$contentType}; charset={$charset}", true, (int) $statusCode);
         if (ob_get_contents() === '') {
             header("Content-Length: " . strlen($this->body()));
         }
         foreach ($this->_header as $h) {
             header(trim($h->name, ' :') . ': ' . $h->value, $h->replace, $h->code);
         }
         $this->_headerSent = true;
     }
 }
コード例 #16
0
ファイル: Jsonp.php プロジェクト: xamiro-dev/xamiro
 /**
  * compile service part of smd schema overwriting parent json compile method
  *
  * @error 14903
  * @param XO $obj expects reference variable of schema object
  * @return void
  */
 protected function compileService(&$obj)
 {
     $tmp = array();
     $separator = xapp_get_option(self::CLASS_METHOD_SEPARATOR, $this);
     foreach ($this->map() as $key => $val) {
         if (is_array($val)) {
             foreach ($val as $k => $v) {
                 $v->transport = 'GET';
                 $v->target = $this->getTarget($key . $separator . $k);
                 $tmp[$k] = $v;
             }
         } else {
             $val->transport = 'GET';
             $val->target = $this->getTarget($key);
             $tmp[$key] = $val;
         }
     }
     $obj->service = $tmp;
 }
コード例 #17
0
ファイル: StoreBase.php プロジェクト: xamiro-dev/xamiro
 public function set($section, $path = '.', $searchQuery = null, $value = null, $decodeValue = true)
 {
     $dataAll = $this->read();
     $userData = null;
     if ($dataAll) {
         $primKey = xapp_get_option(self::PRIMARY_KEY, $this);
         if (!property_exists($dataAll, $primKey)) {
             $dataAll->{$primKey} = new stdClass();
         }
         $userData = $dataAll->{$primKey};
     }
     if (!property_exists($userData, $section)) {
         $userData->{$section} = array();
     }
     $storeData = json_encode($userData);
     $store = new Xapp_Util_Json_Query($storeData);
     $value = is_string($value) ? json_decode($value) : $value;
     if ($decodeValue === false && (is_array($value) || is_object($value))) {
         $value = json_encode($value, true);
     }
     if (!$value) {
         return false;
     }
     $success = false;
     $stdQuery = null;
     if ($searchQuery) {
         $stdQuery = $this->toStdQuery(is_string($searchQuery) ? json_decode($searchQuery, true) : $searchQuery);
         $queryResult = $store->query($path, $stdQuery)->get();
         if ($queryResult != null && count($queryResult) == 1) {
             $queryResult[0]->{xapp_get_option(self::DATA_PROPERTY, $this)} = $value;
             $success = true;
         } else {
             return false;
         }
     } else {
         if (is_array($userData->{$section})) {
             $found = null;
             $dataProp = xapp_get_option(self::DATA_PROPERTY, $this);
             foreach ($userData->{$section} as $item) {
                 if (property_exists($item, xapp_get_option(self::ID_PROPERTY, $this))) {
                     $found = $item;
                     break;
                 }
             }
             $value = (object) $value;
             if (is_string($value->{$dataProp})) {
                 $value->{$dataProp} = json_decode($value->{$dataProp});
             }
             if ($found) {
                 $userData->{$section}[0]->{$dataProp} = $value->{$dataProp};
             } else {
                 $userData->{$section}[] = $value;
                 //implicit
             }
             $dataAll->{$primKey} = $userData;
             $this->write(json_encode($dataAll));
         }
     }
     if ($success) {
         $dataAll->{$primKey} = $store->getObject();
         $this->write(json_encode($dataAll));
         return true;
     }
     return false;
 }
コード例 #18
0
ファイル: Jsonp.php プロジェクト: xamiro-dev/xamiro
 /**
  * flush exception as json error object encapsulated in js callback or custom error callback function if supplied
  *
  * @error 14708
  * @param Exception $error expects the exception to flush
  */
 public function error(Exception $error)
 {
     $get = $this->request()->getGet();
     $response = $this->response();
     if (xapp_get_option(self::COMPLY_TO_JSONRPC_1_2, $this)) {
         if (array_key_exists($error->getCode(), $this->codeMap)) {
             xapp_set_option(Xapp_Rpc_Response::STATUS_CODE, $this->codeMap[$error->getCode()], $response);
         } else {
             xapp_set_option(Xapp_Rpc_Response::STATUS_CODE, 500, $response);
         }
     }
     $error = $this->compileError($error);
     if (xapp_is_option(self::ERROR_CALLBACK, $this) && array_key_exists(xapp_get_option(self::ERROR_CALLBACK, $this), $get)) {
         $error = $get[xapp_get_option(self::ERROR_CALLBACK, $this)] . '(' . $response->encode($error) . ')';
     } else {
         if (array_key_exists(xapp_get_option(self::CALLBACK, $this), $get)) {
             $error = $get[xapp_get_option(self::CALLBACK, $this)] . '(' . $response->encode($error) . ')';
         } else {
             $error = $response->encode($error);
         }
     }
     $response->body($error);
     $this->flush();
 }
コード例 #19
0
ファイル: Gateway.php プロジェクト: xamiro-dev/xamiro
 /**
  * run gateway validating all options and handle request by server first by calling server setup method
  * then handle and finally tearing down the server instance. nothing will happen unless this function is called!
  *
  * @error 14016
  * @return void
  */
 public final function run()
 {
     xapp_debug('rpc gateway running', 'rpc');
     xapp_event('xapp.rpc.gateway.run', array(&$this));
     $this->server()->setup();
     if ($this->server()->hasCalls()) {
         if (xapp_get_option(self::VALIDATE, $this)) {
             foreach (xapp_get_options($this) as $k => $v) {
                 $this->validate($k, $v);
             }
         }
     }
     $this->server()->handle();
     $this->server()->teardown();
     xapp_debug('rpc gateway shutting down', 'rpc');
 }
コード例 #20
0
ファイル: Profiler.php プロジェクト: xamiro-dev/xamiro
 /**
  * dump profiler data using Xapp_Debug dump method flushing all profiler data to empty it
  *
  * @error 15207
  * @return void
  */
 public function dump()
 {
     $separator = xapp_get_option(self::STRING_SEPARATOR, $this);
     if (!empty($this->_data)) {
         foreach ($this->_data as $key => $val) {
             Xapp_Debug::dump("{$key}:");
             foreach ($val as $k => $v) {
                 Xapp_Debug::dump('... ' . implode($separator, array_slice($v, 1)));
             }
         }
     }
     $this->_data = array();
 }
コード例 #21
0
ファイル: Bootstrap.php プロジェクト: xamiro-dev/xamiro
 public function isLoggedIn()
 {
     $flags = xapp_get_option(self::FLAGS);
     if ($this->testFlag(XAPP_BOOTSTRAP_NEEDS_AUTHENTICATION, $flags) && xapp_get_option(self::USER_CONF, $this)) {
         self::loadJSONTools();
         self::loadXAppJSONStoreClasses();
         xapp_import('xapp.Store.Json.Json');
         $userMgr = new XApp_UserManager(array(XApp_UserManager::STORE_CONF => array(XApp_Store_JSON::CONF_FILE => xapp_get_option(self::USER_CONF, $this))));
         $userMgr->init();
         $userMgr->initSessionStorage();
         $result = $userMgr->isLoggedIn();
         return $result;
     }
     return true;
 }
コード例 #22
0
ファイル: Renderer.php プロジェクト: xamiro-dev/xamiro
 public function renderResources()
 {
     $resourceRenderer = xapp_get_option(self::RESOURCE_RENDERER, $this);
     if ($resourceRenderer) {
         return $resourceRenderer->render();
     }
     return '';
 }
コード例 #23
0
ファイル: Utils.php プロジェクト: xamiro-dev/xamiro
 /**
  *
  * Check all validation methods provided into options
  *
  *
  * @param $options
  * @param $error
  * @param $success
  */
 public static function check($options, &$error, &$success)
 {
     if (xapp_get_option(self::VALIDATE, $options)) {
         foreach (xapp_get_options($options) as $k => $v) {
             self::validate($k, $v, $options, $error, $success);
         }
     }
 }
コード例 #24
0
ファイル: Memcached.php プロジェクト: xamiro-dev/xamiro
 /**
  * remove cache key returning boolean value
  *
  * @error 15805
  * @param string $key expects the cache key name as string
  * @return bool
  */
 public function forget($key)
 {
     if ($this->has($key)) {
         return $this->_memcached->delete(xapp_get_option(self::KEY_PREFIX, $this) . (string) $key);
     } else {
         return false;
     }
 }
コード例 #25
0
ファイル: Query.php プロジェクト: xamiro-dev/xamiro
 /**
  * search and find objects by path and optional query parameters. the first parameter expects the object
  * to be searched. the second parameter a search path with delimiter style like "root.0" or "." or "" to search
  * from root element. the third parameter expects an array with query filter chain elements, each value a query
  * filter with {key}{operator}{value} syntax e.g. key=1. the following operators are supported:
  *
  * !%   = not like (expecting word to match)
  * %    = like (expecting word to match)
  * !->  = not in (expecting comma separated value list)
  * ->   = in (expecting comma separated value list)
  * !<>  = not between (expecting two values, min and max comma separated)
  * <>   = between (expecting two values, min and max comma separated)
  * *    = any value that is not null or empty string
  * ==   = equal and of same data type
  * !==  = not equal and of same data type
  * !=   = not equal
  * >=   = greater than equal
  * <=   = lesser than equal
  * =    = equal
  * >    = greater
  * <    = lesser
  *
  * regex patterns are also allowed and need to be passed like key=/pattern/
  * reference to other keys and their value are also allowed and need to passed like key={otherkey}
  *
  * the fourth optional parameter when set will return either the first or last object if passed as "last" or
  * "first" or will return the result untouched resulting in either array or object to be returned. the result is
  * return as reference and can be manipulated outside this method which changes will be reflected in the passed object.
  * that way this function is not only a search function but also a means to change object values. will either
  * return boolean false or throw result exception if static option THROW_EXCEPTION is set to true.
  *
  * @error 16715
  * @param object $object expects the object to search
  * @param string $path expects the optional search path as outlined above
  * @param array $query expects the optional query filter chain as explained above
  * @param null|string $result_flag expects optional result flag "first" or "last"
  * @param null|mixed $parent stores optional parent element as reference
  * @return array|bool|mixed
  * @throws Xapp_Result_Exception
  */
 public static function &find($object, $path, array $query = null, $result_flag = null, &$parent = null)
 {
     $class = get_class();
     $return = false;
     //xapp_dumpObject($query,'std query');
     if ($result_flag !== null) {
         $result_flag = strtolower(trim((string) $result_flag));
     }
     if ($query === null) {
         return self::retrieve($object, $path);
     } else {
         if (($object =& self::retrieve($object, $path)) !== false) {
             $result = array();
             if (sizeof($query) > 1) {
                 foreach ($query as $q) {
                     $parent = $object;
                     $result = self::execute($object, $q);
                     if (!empty($result)) {
                         $object =& $result;
                     } else {
                         if (xapp_get_option(self::THROW_EXCEPTION, $class)) {
                             throw new Xapp_Result_Exception("no result found for query", 1671501);
                         } else {
                             return $return;
                         }
                     }
                 }
                 if ($result_flag === 'first') {
                     return $result[0];
                 } else {
                     if ($result_flag === 'last') {
                         return $result[sizeof($result) - 1];
                     } else {
                         return $result;
                     }
                 }
             } else {
                 $result = array();
                 self::execute($object, $query[0], $result);
                 if (!empty($result)) {
                     if ($result_flag === 'first') {
                         return $result[0];
                     } else {
                         if ($result_flag === 'last') {
                             return $result[sizeof($result) - 1];
                         } else {
                             return $result;
                         }
                     }
                 } else {
                     if (xapp_get_option(self::THROW_EXCEPTION, $class)) {
                         throw new Xapp_Result_Exception(_("no result found for query"), 1671501);
                     } else {
                         return $return;
                     }
                 }
             }
         }
     }
     if (xapp_get_option(self::THROW_EXCEPTION, $class)) {
         throw new Xapp_Result_Exception(_("no result found for query"), 1671501);
     } else {
         return $return;
     }
 }
コード例 #26
0
ファイル: Base.php プロジェクト: xamiro-dev/xamiro
 public function getResource($name, $enabledOnly = true)
 {
     $resourceData = xapp_get_option(self::RESOURCES_DATA, $this);
     $nameIn = '' . str_replace('/', '', $name);
     if ($resourceData !== null) {
         $resourceItem = (array) xapp_object_find($resourceData, '.items', array('class=' . 'cmx.types.Resource', 'name=' . $nameIn, 'type=' . XAPP_RESOURCE_TYPE_FILE_PROXY, 'enabled=' . $enabledOnly));
         if (count($resourceItem) && is_object($resourceItem[0])) {
             return $resourceItem[0];
         }
     }
     return null;
 }
コード例 #27
0
ファイル: Scope.php プロジェクト: xamiro-dev/xamiro
 private function _replaceScopeVariables($str, $vars)
 {
     $result = '' . $str;
     $variableDelimiter = xapp_get_option(self::SCOPE_VARIABLE_DELIMITER, $this);
     $userVars = (array) $vars;
     if ($userVars) {
         $_keys = array();
         $_values = array();
         foreach ($userVars as $key => $value) {
             array_push($_keys, $variableDelimiter . $key . $variableDelimiter);
             array_push($_values, $value);
         }
         $result = str_replace($_keys, $_values, $result);
     }
     return $result;
 }
コード例 #28
0
ファイル: VariableMixin.php プロジェクト: xamiro-dev/xamiro
 public function getResource($name, $enabledOnly = true)
 {
     $resourceData = xapp_get_option(self::RESOURCES_DATA, $this);
     if ($resourceData !== null) {
         $resourceItem = (array) xapp_object_find($resourceData, '.items', array('class=' . 'cmx.types.Resource', 'name=' . $name, 'type=' . xo_get(self::RESOURCES_TYPE, $this), 'enabled=' . $enabledOnly));
         if (count($resourceItem) && is_object($resourceItem[0])) {
             return $resourceItem[0];
         }
     }
     return null;
 }
コード例 #29
0
ファイル: App.php プロジェクト: xamiro-dev/xamiro
function xapp_commander_render_app($XAPP_BASE_DIRECTORY, $XAPP_APP_NAME, $XAPP_CLIENT_DIRECTORY, $REPOSITORY_ROOT, $REPOSITORY_START_PATH, $UPLOAD_EXTENSIONS, $XFILE_CONFIG, $XAPP_JQUERY_THEME = 'dot-luv', $XAPP_SITE_URL, $XAPP_PLUGIN_URL, $FILE_STORE_URL, $XAPP_AUTH_DELEGATE, $XAPP_AUTH_PREFIX, $XAPP_AUTH_SUFFIX, $XAPP_LOG_DIR, $PROHIBITED_PLUGINS, $RESOURCE_PREFIX, $RESOURCE_RENDERER, $RESOURCE_CONFIG_PREFIX, $RENDER_DELEGATE, $ALLOW_IP, $DENY_IP, $ALLOW_HOST, $DENY_HOST, $RPC_TARGET, $RPC_URL, $STORE_CLASS, $STORE_FILE, $XAPP_SALT_KEY, $RELATIVE_VARIABLES, $_DEBUG, $XAPP_COMPONENTS, $XAPP_RESOURCE_CONFIG, $XAPP_BOOTSTRAP_OVERRIDE)
{
    $_REQUEST_TYPE = XApp_Service_Entry_Utils::getServiceType();
    $XAPP_USER_CONFIG_PATH = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Users.php';
    $_IS_RPC = $_REQUEST_TYPE == XApp_Service_Entry_Utils::LOGIN || $_REQUEST_TYPE == XApp_Service_Entry_Utils::SMD_CALL || $_REQUEST_TYPE == XApp_Service_Entry_Utils::SMD_GET || $_REQUEST_TYPE == XApp_Service_Entry_Utils::UPLOAD || $_REQUEST_TYPE == XApp_Service_Entry_Utils::DOWNLOAD;
    if ($_IS_RPC) {
        /***
         * Ajax - calls go through here too! In case its RPC, we do here the 1st security pass, further checks are done in XFile.php in conjunction with the Joomla-Component-Parameters
         */
        switch (XApp_Service_Entry_Utils::getServiceType()) {
            /***
             * JSON-RPC-2.0 call
             */
            case XApp_Service_Entry_Utils::SMD_CALL:
                $operation = XApp_Service_Entry_Utils::getXCommanderOperation();
                $authorized = $XAPP_AUTH_DELEGATE::authorize($XAPP_AUTH_PREFIX . $operation, $XAPP_AUTH_SUFFIX);
                if (!$authorized) {
                    die(XApp_Service_Entry_Utils::toRPCErrorStd(1, XAPP_TEXT('AUTHORIZATION_ERROR')));
                }
                break;
                /***
                 * JSON-RPC-2.0 Service Introspection. You can see the full RPC class by opening http://localhost/joomla251/administrator/index.php?option=com_xappcommander&view=rpc
                 */
            /***
             * JSON-RPC-2.0 Service Introspection. You can see the full RPC class by opening http://localhost/joomla251/administrator/index.php?option=com_xappcommander&view=rpc
             */
            case XApp_Service_Entry_Utils::SMD_GET:
                break;
                /***
                 * Upload request. This is only a general check. More specific checks are done in the XFile RPC service class.
                 */
            /***
             * Upload request. This is only a general check. More specific checks are done in the XFile RPC service class.
             */
            case XApp_Service_Entry_Utils::UPLOAD:
                $authorized = $XAPP_AUTH_DELEGATE::authorize($XAPP_AUTH_PREFIX . XC_OPERATION_UPLOAD_STR, $XAPP_AUTH_SUFFIX);
                if (!$authorized) {
                    die(XApp_Service_Entry_Utils::toRPCError(1, XAPP_TEXT('AUTHORIZATION_ERROR')));
                }
                break;
                /***
                 * Download request. This is only a general check. More specific checks are done in the XFile RPC service class. The $UPLOAD_EXTENSIONS must be set here.
                 */
            /***
             * Download request. This is only a general check. More specific checks are done in the XFile RPC service class. The $UPLOAD_EXTENSIONS must be set here.
             */
            case XApp_Service_Entry_Utils::DOWNLOAD:
                $authorized = $XAPP_AUTH_DELEGATE::authorize($XAPP_AUTH_PREFIX . XC_OPERATION_DOWNLOAD_STR, $XAPP_AUTH_SUFFIX);
                if (!$authorized) {
                    die(XAPP_TEXT('AUTHORIZATION_ERROR'));
                }
                break;
                /***
                 * CBTree is in charge to enumerate files in directories. It has its own security checks.
                 * @todo
                 */
            /***
             * CBTree is in charge to enumerate files in directories. It has its own security checks.
             * @todo
             */
            case XApp_Service_Entry_Utils::CBTREE:
                break;
        }
        /***
         * Now authorize RPC router, further security checks are done in xapp/RPC/Gateway and other files, requiring signed client requests and all
         * client actions need to be enabled by the component's ACL settings.
         */
        define('_XAPP_AUTH_DONE_', true);
        /***
         * 2nd pass and final RPC rendering
         */
        switch (XApp_Service_Entry_Utils::getServiceType()) {
            case XApp_Service_Entry_Utils::LOGIN:
            case XApp_Service_Entry_Utils::SMD_CALL:
            case XApp_Service_Entry_Utils::SMD_GET:
            case XApp_Service_Entry_Utils::UPLOAD:
            case XApp_Service_Entry_Utils::DOWNLOAD:
                xapp_import('xapp.Service.Service');
                xapp_import('xapp.commander.Directory.Service');
                xapp_import('xapp.VFS.Base');
                xapp_import('xapp.VFS.Local');
                xapp_import('xapp.Option.Utils');
                xapp_import('xapp.Directory.Utils');
                xapp_import("xapp.xide.Models.User");
                xapp_import('xapp.xide.Controller.UserManager');
                xapp_import('xapp.xide.Controller.UserService');
                xapp_import('xapp.Store.Json.Json');
                xapp_import('xapp.Resource.Service');
                xapp_import('xapp.Resource.ResourceManager');
                xapp_import('xapp.xide.Logging.Service');
                xapp_import('xapp.xide.Logging.LogManager');
                $XAPP_VFS_CONFIG_PATH = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vfs.php';
                if (!file_exists($XAPP_VFS_CONFIG_PATH)) {
                    die('Have no vfs config at ' . dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vfs.php');
                }
                $XAPP_USER_CONFIG_PATH = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Users.php';
                $XIDE_LOG_PATH = realpath(XAPP_BASEDIR . '..' . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR . 'all.log');
                if (!$XIDE_LOG_PATH) {
                    $XIDE_LOG_PATH = '';
                }
                $REPOSITORY_ROOT = str_replace('administrator', '', $REPOSITORY_ROOT);
                //no idea why
                if ($REPOSITORY_START_PATH != null) {
                    $REPOSITORY_ROOT .= DIRECTORY_SEPARATOR . $REPOSITORY_START_PATH . DIRECTORY_SEPARATOR;
                    //
                }
                if ($UPLOAD_EXTENSIONS == null) {
                    $UPLOAD_EXTENSIONS = 'bmp,csv,doc,gif,ico,jpg,jpeg,odg,odp,ods,odt,pdf,png,ppt,swf,txt,xcf,xls';
                }
                $authDelegate = new $XAPP_AUTH_DELEGATE();
                //$SYSTEM_ROOT = realpath('/PMaster/') . DIRECTORY_SEPARATOR;
                Xapp_Rpc_Gateway::setSalt($XAPP_SALT_KEY);
                $isDirectoryService = strpos(XApp_Service_Entry_Utils::getSMDMethod(), 'Directory_Service.ls') !== false;
                $bootStrapFlags = null;
                if ($isDirectoryService) {
                    $bootStrapFlags = array(XAPP_BOOTSTRAP_SETUP_XAPP, XAPP_BOOTSTRAP_SETUP_RPC, XAPP_BOOTSTRAP_SETUP_STORE, XAPP_BOOTSTRAP_SETUP_GATEWAY, XAPP_BOOTSTRAP_SETUP_SERVICES, XAPP_BOOTSTRAP_NEEDS_AUTHENTICATION);
                } else {
                    $bootStrapFlags = array(XAPP_BOOTSTRAP_LOAD_PLUGIN_RESOURCES, XAPP_BOOTSTRAP_REGISTER_SERVER_PLUGINS, XAPP_BOOTSTRAP_SETUP_XAPP, XAPP_BOOTSTRAP_SETUP_RPC, XAPP_BOOTSTRAP_SETUP_STORE, XAPP_BOOTSTRAP_SETUP_GATEWAY, XAPP_BOOTSTRAP_SETUP_SERVICES, XAPP_BOOTSTRAP_NEEDS_AUTHENTICATION);
                }
                $services = null;
                if ($isDirectoryService) {
                    $services = array(XApp_Service::factory('XCOM_Directory_Service', array(XApp_Directory_Service::REPOSITORY_ROOT => $REPOSITORY_ROOT . DIRECTORY_SEPARATOR, XApp_Directory_Service::FILE_SYSTEM => 'XApp_VFS_Local', XApp_Directory_Service::VFS_CONFIG_PATH => $XAPP_VFS_CONFIG_PATH, XApp_Directory_Service::FILE_SYSTEM_CONF => array(XApp_VFS_Base::ABSOLUTE_VARIABLES => array('root' => $REPOSITORY_ROOT . DIRECTORY_SEPARATOR), XApp_VFS_Base::RELATIVE_VARIABLES => array()), XApp_Directory_Service::UPLOAD_EXTENSIONS => $UPLOAD_EXTENSIONS)));
                } else {
                    $services = array(XApp_Service::factory('XCOM_Directory_Service', array(XApp_Directory_Service::REPOSITORY_ROOT => $REPOSITORY_ROOT . DIRECTORY_SEPARATOR, XApp_Directory_Service::FILE_SYSTEM => 'XApp_VFS_Local', XApp_Directory_Service::VFS_CONFIG_PATH => $XAPP_VFS_CONFIG_PATH, XApp_Directory_Service::FILE_SYSTEM_CONF => array(XApp_VFS_Base::ABSOLUTE_VARIABLES => array('root' => $REPOSITORY_ROOT . DIRECTORY_SEPARATOR), XApp_VFS_Base::RELATIVE_VARIABLES => array()), XApp_Directory_Service::UPLOAD_EXTENSIONS => $UPLOAD_EXTENSIONS)), XApp_Service::factoryEx('XApp_Resource_Service', array(XApp_Service::MANAGED_CLASS => 'XApp_ResourceManager', XApp_Service::MANAGED_CLASS_OPTIONS => array(XApp_ResourceManager::STORE_CONF => array(XApp_Store_JSON::CONF_FILE => $XAPP_VFS_CONFIG_PATH)))), XApp_Service::factoryEx('XApp_XIDE_Controller_UserService', array(XApp_Service::MANAGED_CLASS_OPTIONS => array(XApp_UserManager::STORE_CONF => array(XApp_Store_JSON::CONF_FILE => $XAPP_USER_CONFIG_PATH)))), XApp_Service::factoryEx('XIDE_Log_Service', array(XApp_Service::MANAGED_CLASS => 'XIDE_Log_Manager', XApp_Service::MANAGED_CLASS_OPTIONS => array(XIDE_Log_Manager::LOG_PATH => $XIDE_LOG_PATH))));
                }
                /**
                 * Register workbench service
                 */
                if (isset($XAPP_COMPONENTS['xideve']) && $XAPP_COMPONENTS['xideve']) {
                    xapp_import('xapp.xide.Workbench.Service');
                    xapp_import('xapp.xide.Directory.Service');
                    xapp_import("xapp.xide.Models.User");
                    $user = new XApp_User();
                    $user->setName('A');
                    $services[] = XApp_Service::factory('xapp.xide.Workbench.Service', array(XApp_XIDE_Workbench_Service::WORKBENCH_USER => $user, XApp_XIDE_Workbench_Service::WORKBENCH_DIRECTORY => realpath(XAPP_BASEDIR . '/../user/A/ws/workspace/'), XApp_XIDE_Workbench_Service::SITE_CONFIG_DIRECTORY => realpath(XAPP_BASEDIR . '/xide/Workbench/siteconfig/')));
                }
                /***
                 * Build bootstrap config for the RPC service
                 */
                $opt = array(XApp_Commander_Bootstrap::BASEDIR => XAPP_BASEDIR, XApp_Commander_Bootstrap::APP_NAME => 'xfile', XApp_Commander_Bootstrap::APP_FOLDER => $XAPP_APP_NAME, XApp_Commander_Bootstrap::RESOURCE_CONFIG_SUFFIX => '', XApp_Commander_Bootstrap::RESOURCE_RENDERER_PREFIX => $RESOURCE_PREFIX, XApp_Commander_Bootstrap::RESOURCE_RENDERER_CLZ => $RESOURCE_RENDERER, XApp_Commander_Bootstrap::PLUGIN_DIRECTORY => XAPP_BASEDIR . DIRECTORY_SEPARATOR . 'commander' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR, XApp_Commander_Bootstrap::PLUGIN_MASK => 'XCOM', XApp_Commander_Bootstrap::ALLOW_PLUGINS => $authDelegate->authorize(XC_OPERATION_PLUGINS_STR), XApp_Commander_Bootstrap::PROHIBITED_PLUGINS => $PROHIBITED_PLUGINS, XApp_Commander_Bootstrap::FLAGS => $bootStrapFlags, XApp_Commander_Bootstrap::AUTH_DELEGATE => $authDelegate, XApp_Commander_Bootstrap::RPC_TARGET => $RPC_TARGET, XApp_Commander_Bootstrap::SIGNING_KEY => md5($authDelegate->getUserName()), XApp_Commander_Bootstrap::SIGNING_TOKEN => md5($authDelegate->getToken()), XApp_Commander_Bootstrap::SIGNED_SERVICE_TYPES => array(XAPP_SERVICE_TYPE_SMD_CALL, XAPP_SERVICE_TYPE_DOWNLOAD, XAPP_SERVICE_TYPE_SMD_GET), XApp_Commander_Bootstrap::GATEWAY_CONF => array(Xapp_Rpc_Gateway::ALLOW_IP => $ALLOW_IP, Xapp_Rpc_Gateway::DENY_IP => $DENY_IP, Xapp_Rpc_Gateway::ALLOW_HOST => $ALLOW_HOST, Xapp_Rpc_Gateway::DENY_HOST => $DENY_HOST, Xapp_Rpc_Gateway::OMIT_ERROR => false), XApp_Commander_Bootstrap::LOGGING_FLAGS => array(XAPP_LOG_SHARED_LOGGER_PLUGINS, XAPP_LOG_XFILE_OPERATIONS), XApp_Commander_Bootstrap::LOGGING_CONF => array(Xapp_Log::PATH => $XAPP_LOG_DIR, Xapp_Log::EXTENSION => 'log', Xapp_Log::NAME => $XAPP_AUTH_SUFFIX), XApp_Commander_Bootstrap::XAPP_CONF => array(XAPP_CONF_DEBUG_MODE => null, XAPP_CONF_AUTOLOAD => false, XAPP_CONF_DEV_MODE => $_DEBUG, XAPP_CONF_HANDLE_BUFFER => !XApp_Service_Entry_Utils::isDownload(), XAPP_CONF_HANDLE_SHUTDOWN => false, XAPP_CONF_HTTP_GZIP => !XApp_Service_Entry_Utils::isDownload(), XAPP_CONF_CONSOLE => $_DEBUG ? XApp_Service_Entry_Utils::getConsoleType() : false, XAPP_CONF_HANDLE_ERROR => false, XAPP_CONF_HANDLE_EXCEPTION => false), XApp_Commander_Bootstrap::STORE_CONF => array(XApp_Store::READER_CLASS => $STORE_CLASS, XApp_Store::WRITER_CLASS => $STORE_CLASS, XApp_Store::PRIMARY_KEY => trim(preg_replace('/\\s+/', '', $authDelegate->getUserName())), XApp_Store::IDENTIFIER => $XAPP_AUTH_SUFFIX, XApp_Store::CONF_FILE => $STORE_FILE), XApp_Commander_Bootstrap::SERIVCE_CONF => $services, XApp_Commander_Bootstrap::USER_CONF => $XAPP_USER_CONFIG_PATH);
                if ($XAPP_BOOTSTRAP_OVERRIDE) {
                    $opt = array_merge_recursive((array) $opt, (array) $XAPP_BOOTSTRAP_OVERRIDE);
                }
                $xappBootrapper = XApp_Commander_Bootstrap::instance($opt);
                $xappBootrapper->setupService();
                //tear down here
                break;
                //over and out
        }
        exit;
    }
    /*******************************************************************************************/
    /*  Its not RPC, render UX                                                                 */
    /*******************************************************************************************/
    //Setup paths, variables and shit
    $XAPP_SERVICE_URL = $RPC_URL;
    $XAPP_APP_URL = $XAPP_SITE_URL . '/client/src';
    $XAPP_PLUGIN_URL = '' . $XAPP_PLUGIN_URL;
    $XAPP_SERVICE_URL_FULL = $XAPP_SITE_URL . '/' . $RPC_URL;
    $XAPP_RELATIVE_VARIABLES = array('APP_URL' => $XAPP_APP_URL, 'SITEURL' => $XAPP_SITE_URL, 'XCOM_ROOT' => $XAPP_PLUGIN_URL, 'FILE_SERVICE' => $XAPP_SERVICE_URL, 'XFILE_CONFIG_MIXIN' => $XFILE_CONFIG, 'FILES_STORE_URL' => $FILE_STORE_URL, 'FILE_SERVICE_FULL' => $XAPP_SERVICE_URL_FULL, 'XCOM_PLUGINS_WEB_URL' => $XAPP_PLUGIN_URL . '/', 'RPC_SIGNATURE_TOKEN' => md5($XAPP_AUTH_DELEGATE->getToken()), 'RPC_USER_VALUE' => md5($XAPP_AUTH_DELEGATE->getUserName()), 'RPC_URL' => $RPC_URL, 'REPO_URL' => $XAPP_SITE_URL . '/' . $REPOSITORY_START_PATH, 'PLUGIN_PACKAGE_ROOT_URL' => $XAPP_PLUGIN_URL, 'JQUERY_THEME' => $XAPP_JQUERY_THEME, 'INDEX' => xapp_fix_index(), 'XIDEVE_DOJO_BASE_URL' => $XAPP_APP_URL . '/lib/dojo', 'XIDEVE_DOJO_URL' => $XAPP_APP_URL . '/lib/dojo/dojo.js', 'XIDEVE_LIB_ROOT' => $XAPP_APP_URL . '/lib/');
    if ($RELATIVE_VARIABLES) {
        $XAPP_RELATIVE_VARIABLES = array_merge($XAPP_RELATIVE_VARIABLES, $RELATIVE_VARIABLES);
    }
    /***
     * Setup xapp commander bootstrap
     */
    $options = array(XApp_Commander_Bootstrap::RESOURCE_RENDERER_PREFIX => $RESOURCE_PREFIX, XApp_Commander_Bootstrap::RESOURCE_CONFIG_SUFFIX => $RESOURCE_CONFIG_PREFIX, XApp_Commander_Bootstrap::BASEDIR => XAPP_BASEDIR, XApp_Commander_Bootstrap::DOC_ROOT => $XAPP_APP_URL, XApp_Commander_Bootstrap::APP_NAME => $XAPP_APP_NAME, XApp_Commander_Bootstrap::APP_FOLDER => 'xfile', XApp_Commander_Bootstrap::APPDIR => $XAPP_CLIENT_DIRECTORY, XApp_Commander_Bootstrap::SERVICE => $XAPP_SERVICE_URL, XApp_Commander_Bootstrap::PLUGIN_MASK => 'XCOM', XApp_Commander_Bootstrap::RENDER_DELEGATE => $RENDER_DELEGATE, XApp_Commander_Bootstrap::RESOURCE_RENDERER_CLZ => $RESOURCE_RENDERER, XApp_Commander_Bootstrap::ALLOW_PLUGINS => $XAPP_AUTH_DELEGATE::authorize($XAPP_AUTH_PREFIX . XC_OPERATION_PLUGINS_STR, $XAPP_AUTH_SUFFIX), XApp_Commander_Bootstrap::PLUGIN_DIRECTORY => XAPP_BASEDIR . DIRECTORY_SEPARATOR . 'commander' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR, XApp_Commander_Bootstrap::PROHIBITED_PLUGINS => $PROHIBITED_PLUGINS, XApp_Commander_Bootstrap::RELATIVE_VARIABLES => $XAPP_RELATIVE_VARIABLES, XApp_Commander_Bootstrap::FLAGS => array(XAPP_BOOTSTRAP_NEEDS_AUTHENTICATION), XApp_Commander_Bootstrap::USER_CONF => $XAPP_USER_CONFIG_PATH, XApp_Commander_Bootstrap::XAPP_RESOURCE_CONFIG => $XAPP_RESOURCE_CONFIG);
    if ($XAPP_BOOTSTRAP_OVERRIDE) {
        $options = array_merge_recursive((array) $options, (array) $XAPP_BOOTSTRAP_OVERRIDE);
    }
    //create bootstrap
    $xappBootrapper = new XApp_Commander_Bootstrap($options);
    //do the bootstrap
    $xappCommanderRenderer = $xappBootrapper->setup();
    //extract resource renderer
    $xappResourceRender = xapp_get_option(XApp_App_Commander::RESOURCE_RENDERER, $xappCommanderRenderer);
    $result = array('renderer' => $xappCommanderRenderer, 'resourceRender' => $xappResourceRender, 'bootstrap' => $xappBootrapper);
    return $result;
}
コード例 #30
0
ファイル: Json.php プロジェクト: xamiro-dev/xamiro
 /**
  * sets version to response data according to rpc version or if dojo compatible always under
  * parameter "version". will always cast to string for compare version function
  *
  * @error 15103
  * @param int|string $version expects the version to compare
  * @return void
  */
 public function setVersion($version)
 {
     if (xapp_get_option(self::DOJO_COMPATIBLE, $this)) {
         $this->set('version', $version);
     } else {
         if (version_compare((string) $version, '2.0', '>=')) {
             $this->set('jsonrpc', $version);
         } else {
             $this->set('version', $version);
         }
     }
 }