/** * Returns an array containing information on an API. * * @return array info on an API */ public function execute() { $_apiNamePieces = explode('.', $this->apiName); $_apiNamespace = $_apiNamePieces[0]; $_apiPkg = $_apiNamePieces[1]; $_apiShortName = $_apiNamePieces[2]; $_apiClassFile = ucfirst($_apiPkg) . ucfirst($_apiShortName) . '.php'; // we need to scan the rest locations so we can get the full path info $_restLocations = M3_Util_Settings::getRestLocations(); $_deployedApiLocations = M3_Util_Settings::getDeployedApiLocations(); $_foundPathname = null; foreach ($_restLocations as $_restLocation) { foreach ($_deployedApiLocations as $_deployedApiLocation) { $_dir = M3_Util_File::buildPathName($_restLocation, $_deployedApiLocation); $_pathname = M3_Util_File::buildPathName($_dir, $_apiClassFile); if (file_exists($_pathname)) { $_foundPathname = $_pathname; break; } } if (!is_null($_foundPathname)) { break; } } $_info = array(); if (!is_null($_foundPathname)) { $_info['api_name'] = $this->apiName; $_info['pathname'] = $_foundPathname; } return array('api' => $_info); }
public function validateRequest() { $this->pathname = $this->getRequiredApiParam("pathname"); $this->useIncludePath = $this->getApiParam("useIncludePath"); // not allowed to look for files in parent directories if (preg_match("/\\.\\./", $this->pathname)) { throw new OpenFBAPIException("Illegal pathname has been rejected"); } if (isset($this->useIncludePath) && $this->useIncludePath == "true") { $this->pathname = M3_Util_File::findFileInIncludePath($this->pathname); } else { $_installDir = M3_Util_Settings::getRingsideServerInstallDir(); $this->pathname = M3_Util_File::buildPathName($_installDir, $this->pathname); } if (!file_exists($this->pathname)) { throw new OpenFBAPIException("File [{$this->pathname}] does not exist"); } // don't process request for any content larger than 1MB $_size = filesize($this->pathname); if ($_size >= M3_Util_Settings::getMaxSizeAllowedOperationGetFileContent()) { throw new OpenFBAPIException("File [{$this->pathname}] is too large [{$_size}]"); } return; }
/** * We only store MD5 hashs of queries in the metrics file so limit the size of that file. * We store the real query string in a file whose name is the MD5 of the query. * This creates that MD5 file if it does not yet exist. * * @return this returns the MD5 of the query, or "" if $query is empty */ private function createQueryMD5File($query) { if (empty($query)) { return ""; } $_md5 = md5($query); // first see if we haven't seen this query yet if (!isset($this->md5FilesCreated[$_md5])) { // now see if the file isn't created yet $_pathname = M3_Util_File::buildPathName($this->dataDirectory, $_md5 . ".md5"); if (!file_exists($_pathname)) { M3_Util_File::lockAndAppendFile($_pathname, $query); } $this->md5FilesCreated[$_md5] = true; } return $_md5; }