Exemple #1
0
 /**
  * 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);
 }
Exemple #2
0
function echo_errorlog()
{
    $_errorLogPath = M3_Util_Settings::getPhpErrorLogPathName();
    if ($_errorLogPath) {
        if (get_request_param("clearerrorlog")) {
            if (!M3_Util_File::truncateFile($_errorLogPath)) {
                echo "<i>Count not truncate error log [{$_errorLogPath}]</i>";
            }
        }
        echo <<<EOL1
        <h2 align="center">{$_errorLogPath}</h2>
        <table align="center"><tr><td>
        <form action="index.php">
           <input type="hidden" name="show" value="errorlog"/>
           <input type="hidden" name="clearerrorlog" value="true"/>
           <input type="submit" value="Clear"/>
        </form>
        </td></tr></table>
EOL1;
        echo "<pre>";
        echo htmlentities(file_get_contents($_errorLogPath));
        echo "</pre>";
    } else {
        echo "Cannot determine where the error log is";
    }
}
 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;
 }
Exemple #4
0
 /**
  * Returns the installation directory of the Ringside Server itself.
  * 
  * @return string the pathname of the install directory
  */
 public static function getRingsideServerInstallDir()
 {
     // when in production, build.info file should always exist at the root install dir;
     // use build.info as our primary search file since we know we'll never have more than one.
     // if that isn't found, we must be in dev mode; let's hunt for the LocalSettings.php
     // which should also be in the root install dir. There may be more than one in other
     // directories, but I think we usually only have one at the root dir.  Because I'm
     // not sure if this will change in the future, that's why I key on build.info first.
     $_file = M3_Util_File::findFileInIncludePath('build.info');
     if (!$_file) {
         $_file = M3_Util_File::findFileInIncludePath('LocalSettings.php');
         if (!$_file) {
             throw Exception("Missing both build.info and LocalSettings.php! Can't find install dir");
         }
     }
     $_installDir = dirname(realpath($_file));
     return $_installDir;
 }
Exemple #5
0
 public function testFilePage()
 {
     $filename = M3_Util_File::getTempDir() . "/FileTestCase2.txt";
     @unlink($filename);
     // purge any old one that might be hanging out
     $this->assertFileNotExists($filename);
     // see that we can get an empty page
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl());
     $this->assertEquals(0, $pageList->getTotalSize());
     $this->assertEquals(0, count($pageList->getData()));
     // file with 1 line
     $line1 = "first line\n";
     M3_Util_File::lockAndAppendFile($filename, $line1);
     $this->assertEquals(1, M3_Util_File::getNumberOfLines($filename));
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(0, 1));
     // page size is just enough
     $this->assertEquals(1, $pageList->getTotalSize());
     $data = $pageList->getData();
     $this->assertEquals(1, count($data));
     $this->assertEquals($line1, array_shift($data));
     $this->assertEquals(0, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(1, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(0, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(0, $pageList->getPageControl()->getEndRow());
     // file with 2 lines
     $line2 = "second line\n";
     M3_Util_File::lockAndAppendFile($filename, $line2);
     $this->assertEquals(2, M3_Util_File::getNumberOfLines($filename));
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(0, 5));
     // page size is larger than needed
     $this->assertEquals(2, $pageList->getTotalSize(), "total size should have given the full number of rows in file");
     $data = $pageList->getData();
     $this->assertEquals(2, count($data));
     $this->assertEquals($line1, $data[0]);
     $this->assertEquals($line2, $data[1]);
     $this->assertEquals(0, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(5, $pageList->getPageControl()->getPageSize());
     // page size is 5 still, even though we only have 2 rows
     $this->assertEquals(0, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(4, $pageList->getPageControl()->getEndRow());
     // let's page our 2-rows into two 1-row pages
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(0, 1));
     // first page
     $this->assertEquals(2, $pageList->getTotalSize(), "total number of rows should be 2, even though we only have 1 page worth");
     $data = $pageList->getData();
     $this->assertEquals(1, count($data));
     // our page control should have limited this to 1
     $this->assertEquals($line1, $data[0]);
     $this->assertEquals(0, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(1, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(0, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(0, $pageList->getPageControl()->getEndRow());
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(1, 1));
     // second page
     $this->assertEquals(2, $pageList->getTotalSize(), "Total number of rows should be 2, even though we only have 1 page worth.");
     $data = $pageList->getData();
     $this->assertEquals(1, count($data));
     // our page control should have limited this to 1
     $this->assertEquals($line2, $data[0]);
     // first row in the page is the second overall row
     $this->assertEquals(1, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(1, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(1, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(1, $pageList->getPageControl()->getEndRow());
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(2, 1));
     // third page (non-existent)
     $this->assertEquals(2, $pageList->getTotalSize(), "empty page, but we still should say how many total rows there are");
     $data = $pageList->getData();
     $this->assertEquals(0, count($data));
     $this->assertEquals(2, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(1, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(2, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(2, $pageList->getPageControl()->getEndRow());
     // let's page our 2-rows into two 1-row pages again, but explicitly indicate that we know total size is 2
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(0, 1), 2);
     // first page
     $this->assertEquals(2, $pageList->getTotalSize(), "total number of rows should be 2, even though we only have 1 page worth..");
     $data = $pageList->getData();
     $this->assertEquals(1, count($data));
     // our page control should have limited this to 1
     $this->assertEquals($line1, $data[0]);
     $this->assertEquals(0, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(1, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(0, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(0, $pageList->getPageControl()->getEndRow());
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(1, 1), 2);
     // second page
     $this->assertEquals(2, $pageList->getTotalSize(), "Total number of rows should be 2, even though we only have 1 page worth..");
     $data = $pageList->getData();
     $this->assertEquals(1, count($data));
     // our page control should have limited this to 1
     $this->assertEquals($line2, $data[0]);
     // first row in the page is the second overall row
     $this->assertEquals(1, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(1, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(1, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(1, $pageList->getPageControl()->getEndRow());
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(2, 1), 2);
     // third page (non-existent)
     $this->assertEquals(2, $pageList->getTotalSize(), "empty page, but we still should say how many total rows there are");
     $data = $pageList->getData();
     $this->assertEquals(0, count($data));
     $this->assertEquals(2, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(1, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(2, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(2, $pageList->getPageControl()->getEndRow());
     // file with 6 lines
     $line3 = "third line\n";
     $line4 = "fourth line\n";
     $line5 = "fifth line\n";
     $line6 = "sixth line\n";
     M3_Util_File::lockAndAppendFile($filename, $line3);
     M3_Util_File::lockAndAppendFile($filename, $line4);
     M3_Util_File::lockAndAppendFile($filename, $line5);
     M3_Util_File::lockAndAppendFile($filename, $line6);
     $this->assertEquals(6, M3_Util_File::getNumberOfLines($filename));
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(0, 10));
     // page size is larger than needed
     $this->assertEquals(6, $pageList->getTotalSize(), "total size should have given the full number of rows in file");
     $data = $pageList->getData();
     $this->assertEquals(6, count($data));
     $this->assertEquals($line1, $data[0]);
     $this->assertEquals($line2, $data[1]);
     $this->assertEquals($line3, $data[2]);
     $this->assertEquals($line4, $data[3]);
     $this->assertEquals($line5, $data[4]);
     $this->assertEquals($line6, $data[5]);
     $this->assertEquals(0, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(10, $pageList->getPageControl()->getPageSize());
     // page size is 10 still, even though we only have 6 rows
     $this->assertEquals(0, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(9, $pageList->getPageControl()->getEndRow());
     // let's page our 6-rows into two 3-row pages
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(0, 3));
     // first page
     $this->assertEquals(6, $pageList->getTotalSize(), "total number of rows should be 6, even though we only have 1 page worth");
     $data = $pageList->getData();
     $this->assertEquals(3, count($data), "our page control should have limited this to 3");
     $this->assertEquals($line1, $data[0]);
     $this->assertEquals($line2, $data[1]);
     $this->assertEquals($line3, $data[2]);
     $this->assertEquals(0, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(3, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(0, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(2, $pageList->getPageControl()->getEndRow());
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(1, 3));
     // second page
     $this->assertEquals(6, $pageList->getTotalSize(), "Total number of rows should be 6, even though we only have 1 page worth.");
     $data = $pageList->getData();
     $this->assertEquals(3, count($data), "Our page control should have limited this to 3.");
     $this->assertEquals($line4, $data[0], "first row in the page should be the fourth overall row");
     $this->assertEquals($line5, $data[1], "second row in the page should be the fifth overall row");
     $this->assertEquals($line6, $data[2], "third row in the page should be the sixth overall row");
     $this->assertEquals(1, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(3, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(3, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(5, $pageList->getPageControl()->getEndRow());
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(2, 3));
     // third page (non-existent)
     $this->assertEquals(6, $pageList->getTotalSize(), "empty page, but we still should say how many total rows there are");
     $data = $pageList->getData();
     $this->assertEquals(0, count($data));
     $this->assertEquals(2, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(3, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(6, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(8, $pageList->getPageControl()->getEndRow());
     // let's page our 6-rows into two 3-row pages again, but explicitly indicate that we know total size is 6
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(0, 3), 6);
     // first page
     $this->assertEquals(6, $pageList->getTotalSize(), "total number of rows should be 6, even though we only have 1 page worth");
     $data = $pageList->getData();
     $this->assertEquals(3, count($data), "our page control should have limited this to 3");
     $this->assertEquals($line1, $data[0]);
     $this->assertEquals($line2, $data[1]);
     $this->assertEquals($line3, $data[2]);
     $this->assertEquals(0, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(3, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(0, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(2, $pageList->getPageControl()->getEndRow());
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(1, 3), 6);
     // second page
     $this->assertEquals(6, $pageList->getTotalSize(), "Total number of rows should be 6, even though we only have 1 page worth.");
     $data = $pageList->getData();
     $this->assertEquals(3, count($data), "Our page control should have limited this to 3.");
     $this->assertEquals($line4, $data[0], "first row in the page should be the fourth overall row");
     $this->assertEquals($line5, $data[1], "second row in the page should be the fifth overall row");
     $this->assertEquals($line6, $data[2], "third row in the page should be the sixth overall row");
     $this->assertEquals(1, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(3, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(3, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(5, $pageList->getPageControl()->getEndRow());
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(2, 3), 6);
     // third page (non-existent)
     $this->assertEquals(6, $pageList->getTotalSize(), "empty page, but we still should say how many total rows there are");
     $data = $pageList->getData();
     $this->assertEquals(0, count($data));
     $this->assertEquals(2, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(3, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(6, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(8, $pageList->getPageControl()->getEndRow());
     // let's page our 6-rows into three 2-row pages
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(0, 2));
     // first page
     $this->assertEquals(6, $pageList->getTotalSize(), "total number of rows should be 6, even though we only have 1 page worth");
     $data = $pageList->getData();
     $this->assertEquals(2, count($data), "our page control should have limited this to 2");
     $this->assertEquals($line1, $data[0]);
     $this->assertEquals($line2, $data[1]);
     $this->assertEquals(0, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(2, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(0, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(1, $pageList->getPageControl()->getEndRow());
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(1, 2));
     // second page
     $this->assertEquals(6, $pageList->getTotalSize(), "Total number of rows should be 6, even though we only have 1 page worth.");
     $data = $pageList->getData();
     $this->assertEquals(2, count($data), "Our page control should have limited this to 2.");
     $this->assertEquals($line3, $data[0], "first row in the page should be the third overall row");
     $this->assertEquals($line4, $data[1], "second row in the page should be the fourth overall row");
     $this->assertEquals(1, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(2, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(2, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(3, $pageList->getPageControl()->getEndRow());
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(2, 2));
     // third page
     $this->assertEquals(6, $pageList->getTotalSize(), "Total number of rows should be 6, even though we only have 1 page worth..");
     $data = $pageList->getData();
     $this->assertEquals(2, count($data), "Our page control should have limited this to 2.");
     $this->assertEquals($line5, $data[0], "first row in the page should be the fifth overall row");
     $this->assertEquals($line6, $data[1], "second row in the page should be the sixth overall row");
     $this->assertEquals(2, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(2, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(4, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(5, $pageList->getPageControl()->getEndRow());
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl(3, 2));
     // fourth page (non-existent)
     $this->assertEquals(6, $pageList->getTotalSize(), "empty page, but we still should say how many total rows there are");
     $data = $pageList->getData();
     $this->assertEquals(0, count($data));
     $this->assertEquals(3, $pageList->getPageControl()->getPageNumber());
     $this->assertEquals(2, $pageList->getPageControl()->getPageSize());
     $this->assertEquals(6, $pageList->getPageControl()->getStartRow());
     $this->assertEquals(7, $pageList->getPageControl()->getEndRow());
     // test our truncate file function, and see that it really empties the file
     M3_Util_File::truncateFile($filename);
     $pageList = M3_Util_File::getFilePage($filename, new M3_Paging_PageControl());
     $this->assertEquals(0, $pageList->getTotalSize());
     $this->assertEquals(0, count($pageList->getData()));
     unlink($filename);
 }
 /**
  * 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;
 }