예제 #1
0
 public static function send500($uri)
 {
     header("HTTP/1.0 500 Internal Server Error");
     $alt = "There was an internal error when processing " . $uri;
     echo HTTPStatus::_getContent("500", $alt);
     exit(0);
 }
예제 #2
0
 public function match($uri)
 {
     global $conf;
     global $localUri;
     global $lodspk;
     $method = ucwords($_SERVER['REQUEST_METHOD']);
     $uriSegment = str_replace($conf['basedir'], '', $localUri);
     //Check if looking for session validation
     if ($uriSegment === $this->sessionUri) {
         //GET will return the form
         if ($method == "GET") {
             $this->showSessionForm();
             return true;
         }
         //POST will take the data and validate it
         if ($method == "POST") {
             if ($this->validateAuthentication($_POST)) {
                 session_start();
                 $_SESSION['lodspk'] = 1;
                 HTTPStatus::send303($conf['basedir'], '');
                 return false;
             } else {
                 HTTPStatus::send401("Authentication not valid.");
                 return true;
             }
         }
     } else {
         session_start();
         if (isset($_SESSION['lodspk'])) {
             return false;
         } else {
             HTTPStatus::send303($conf['basedir'] . $this->sessionUri, '');
             return true;
         }
     }
 }
예제 #3
0
 public function execute($pair)
 {
     global $conf;
     global $localUri;
     global $uri;
     global $acceptContentType;
     global $endpoints;
     global $lodspk;
     global $results;
     global $firstResults;
     list($res, $page, $format) = $pair;
     //If resource is not the page, send a 303 to the document
     if ($res == $localUri) {
         HTTPStatus::send303($page, $acceptContentType);
     }
     $uri = $res;
     if ($conf['mirror_external_uris'] != false) {
         $localUri = preg_replace("|^" . $conf['ns']['local'] . "|", $conf['basedir'], $res);
     }
     $extension = Utils::getExtension($format);
     /*Redefine Content type based on the
      * dcterms:format for this page
      */
     $acceptContentType = $format;
     //Check if files for model and view exist
     $t = Queries::getClass($uri, $endpoints['local']);
     $obj = $this->getModelandView($t, $extension);
     $modelFile = $obj['modelFile'];
     $lodspk['model'] = $conf['model']['directory'];
     $viewFile = $obj['viewFile'];
     $lodspk['view'] = $obj['view']['directory'];
     if ($viewFile == null) {
         $lodspk['transform_select_query'] = true;
     }
     $lodspk['type'] = $modelFile;
     $lodspk['home'] = $conf['basedir'];
     $lodspk['baseUrl'] = $conf['basedir'];
     $lodspk['module'] = 'type';
     $lodspk['root'] = $conf['root'];
     $lodspk['contentType'] = $acceptContentType;
     $lodspk['ns'] = $conf['ns'];
     $lodspk['endpoint'] = $conf['endpoint'];
     $lodspk['view'] = $conf['view']['directory'];
     $lodspk['add_mirrored_uris'] = true;
     $lodspk['this']['value'] = $uri;
     $lodspk['this']['curie'] = Utils::uri2curie($uri);
     $lodspk['local']['value'] = $localUri;
     $lodspk['local']['curie'] = Utils::uri2curie($localUri);
     $lodspk['this']['extension'] = $extension;
     //chdir($conf['home'].$conf['model']['directory']);
     Utils::queryFile($modelFile, $endpoints['local'], $results, $firstResults);
     if (!$lodspk['resultRdf']) {
         $results = Utils::internalize($results);
         $firstAux = Utils::getfirstResults($results);
         //chdir($conf['home']);
         if (is_array($results)) {
             $resultsObj = Convert::array_to_object($results);
             $results = $resultsObj;
         } else {
             $resultsObj = $results;
         }
         $lodspk['firstResults'] = Convert::array_to_object($firstAux);
     } else {
         $resultsObj = $results;
     }
     //chdir($conf['home'].$conf['model']['directory']);
     Utils::processDocument($viewFile, $lodspk, $resultsObj);
 }
예제 #4
0
 public function execute($service)
 {
     global $conf;
     global $localUri;
     global $uri;
     global $acceptContentType;
     global $endpoints;
     global $lodspk;
     global $firstResults;
     global $results;
     $context = array();
     $context['contentType'] = $acceptContentType;
     $context['endpoints'] = $endpoints;
     //$f = $this->getFunction($localUri);
     $params = array();
     $params = $this->getParams($localUri);
     //$params[] = $context;
     //$acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']);
     $extension = Utils::getExtension($acceptContentType);
     $args = array();
     list($modelFile, $viewFile) = $service;
     try {
         $prefixHeader = array();
         for ($i = 0; $i < sizeof($params); $i++) {
             if ($conf['mirror_external_uris'] != false) {
                 $altUri = Utils::curie2uri($params[$i]);
                 $altUri = preg_replace("|^" . $conf['basedir'] . "|", $conf['ns']['local'], $altUri);
                 $params[$i] = Utils::uri2curie($altUri);
             }
         }
         $segmentConnector = "";
         for ($i = 0; $i < sizeof($params); $i++) {
             Utils::curie2uri($params[$i]);
             //echo $params[$i]." ".Utils::curie2uri($params[$i]);exit(0);
             $auxPrefix = Utils::getPrefix($params[$i]);
             if ($auxPrefix['ns'] != NULL) {
                 $prefixHeader[] = $auxPrefix;
             }
             $args["arg" . $i] = $params[$i];
             $args["all"] .= $segmentConnector . $params[$i];
             if ($segmentConnector == "") {
                 $segmentConnector = "/";
             }
         }
         $results['params'] = $params;
         $lodspk['home'] = $conf['basedir'];
         $lodspk['baseUrl'] = $conf['basedir'];
         $lodspk['module'] = 'service';
         $lodspk['root'] = $conf['root'];
         $lodspk['contentType'] = $acceptContentType;
         $lodspk['ns'] = $conf['ns'];
         $lodspk['this']['value'] = $uri;
         $lodspk['this']['curie'] = Utils::uri2curie($uri);
         $lodspk['local']['value'] = $localUri;
         $lodspk['local']['curie'] = Utils::uri2curie($localUri);
         $lodspk['contentType'] = $acceptContentType;
         $lodspk['endpoint'] = $conf['endpoint'];
         $lodspk['type'] = $modelFile;
         $lodspk['header'] = $prefixHeader;
         $lodspk['args'] = $args;
         $lodspk['add_mirrored_uris'] = false;
         $lodspk['baseUrl'] = $conf['basedir'];
         $lodspk['this']['value'] = $uri;
         if ($viewFile == null) {
             $lodspk['transform_select_query'] = true;
         }
         //  chdir($lodspk['model']);
         Utils::queryFile($modelFile, $endpoints['local'], $results, $firstResults);
         if (!$lodspk['resultRdf']) {
             $results = Utils::internalize($results);
             $firstAux = Utils::getfirstResults($results);
             //  	chdir($conf['home']);
             if (is_array($results)) {
                 $resultsObj = Convert::array_to_object($results);
                 $results = $resultsObj;
             } else {
                 $resultsObj = $results;
             }
             $lodspk['firstResults'] = Convert::array_to_object($firstAux);
         } else {
             $resultsObj = $results;
         }
         //Need to redefine viewFile as 'local' i.e., inside service.foo/ so I can load files with the relative path correctly
         //$viewFile = $extension.".template";
         //chdir($conf['home']);
         Utils::processDocument($viewFile, $lodspk, $results);
     } catch (Exception $ex) {
         echo $ex->getMessage();
         if ($conf['debug']) {
             Logging::log($ex->getMessage(), E_ERROR);
         }
         HTTPStatus::send500($uri);
     }
 }
예제 #5
0
 public static function getUnMirroredUri($uri)
 {
     global $conf;
     $localUri = $uri;
     if (is_bool($conf['mirror_external_uris'])) {
         $localUri = preg_replace("|^" . $conf['ns']['local'] . "|", $conf['basedir'], $uri);
     } elseif (is_string($conf['mirror_external_uris'])) {
         $localUri = preg_replace("|^" . $conf['mirror_external_uris'] . "|", $conf['basedir'], $uri);
     } elseif (is_array($conf['mirror_external_uris'])) {
         //Instead of doing expensive regex, jsut use str_replace
         foreach ($conf['mirror_external_uris'] as $k => $v) {
             if (strlen(str_replace($v, "", $uri)) != strlen($uri)) {
                 $fragment = $k == "" ? $k : $k . "/";
                 $localUri = preg_replace("|^" . $v . "|", $conf['basedir'] . $fragment, $uri);
                 break;
             }
         }
     } else {
         HTTPStatus::send500("Error in mirroring configuration");
         exit(1);
     }
     return $localUri;
 }
예제 #6
0
 protected function addFile($params)
 {
     $path = "components/" . implode("/", array_slice($params, 1));
     $basicContent = "SELECT * WHERE{\n      ?s ?p ?o\n    }LIMIT 10";
     if (strpos($path, ".template") !== FALSE) {
         //It is not a query, but a template
         $basicContent = "<!DOCTYPE html>\n<html>\n  <head>\n    <meta http-equiv='Content-type' content='text/html; charset=utf-8'>\n  </head>\n  <body>\n  </body>\n</html>";
     }
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         if (sizeof($params) < 3) {
             HTTPStatus::send404();
             exit(0);
         }
         $return_var = 0;
         if (file_exists($path)) {
             echo json_encode(array('success' => false));
             return;
         }
         $dirpath = $path;
         $dirArray = explode("/", $path);
         array_pop($dirArray);
         $dirpath = implode("/", $dirArray);
         if (!is_dir($dirpath)) {
             $oldumask = umask(0);
             $return_var = mkdir($dirpath, 0755, true);
             umask($oldumask);
             if ($return_var === FALSE) {
                 HTTPStatus::send500("mkdir " . var_export($return_var, true) . " " . $dirpath);
             }
         }
         $return_var = file_put_contents($path, $basicContent);
         //echo $return_var;exit(0);
         if ($return_var === FALSE) {
             HTTPStatus::send500("file_puts_content " . var_export($return_var, true) . " " . $path);
         } else {
             echo json_encode(array('success' => true, 'return' => $return_var));
         }
     } else {
         HTTPStatus::send406();
         exit(0);
     }
 }
예제 #7
0
파일: index.php 프로젝트: narock/lodspeakr
$uri = $conf['basedir'] . $_GET['q'];
$localUri = $uri;
if ($uri == $conf['basedir']) {
    header('Location: ' . $conf['root']);
    exit(0);
}
//Configure external URIs if necessary
$localUri = $conf['basedir'] . $_GET['q'];
$uri = Utils::getMirroredUri($localUri);
//Modules
foreach ($conf['modules']['available'] as $i) {
    $className = $i . 'Module';
    $currentModule = $conf['modules']['directory'] . $className . '.php';
    if (!is_file($currentModule)) {
        HTTPStatus::send500("<br/>Can't load or error in module <tt>" . $currentModule . "</tt>");
        exit(1);
    }
    require_once $currentModule;
    $module = new $className();
    $matching = $module->match($uri);
    if ($matching != FALSE) {
        $module->execute($matching);
        if ($conf['logfile'] != null) {
            fwrite($conf['logfile'], "]}");
            fclose($conf['logfile']);
        }
        exit(0);
    }
}
HTTPStatus::send404($uri);
예제 #8
0
 public function execute($p)
 {
     global $conf;
     global $localUri;
     global $uri;
     global $acceptContentType;
     global $endpoints;
     global $lodspk;
     global $results;
     global $firstResults;
     $res = $p['res'];
     $page = $p['page'];
     $format = $p['format'];
     $modelFile = $p['modelFile'];
     $viewFile = $p['viewFile'];
     $uri = $res;
     $curie = Utils::uri2curie($res);
     //If resource is not the page, send a 303 to the document
     if ($res == $localUri) {
         HTTPStatus::send303($page, $acceptContentType);
     }
     $uri = $res;
     if ($conf['mirror_external_uris'] != false) {
         $localUri = preg_replace("|^" . $conf['ns']['local'] . "|", $conf['basedir'], $res);
     }
     $extension = Utils::getExtension($format);
     /*Redefine Content type based on the
      * dcterms:format for this page
      */
     $acceptContentType = $format;
     $curie = Utils::uri2curie($uri);
     if ($modelFile == NULL) {
         return;
     }
     //$lodspk = $conf['view']['standard'];
     $lodspk['type'] = $modelFile;
     $lodspk['home'] = $conf['basedir'];
     $lodspk['module'] = 'uri';
     $lodspk['add_mirrored_uris'] = true;
     $lodspk['this']['value'] = $uri;
     $lodspk['this']['curie'] = Utils::uri2curie($uri);
     $lodspk['local']['value'] = $localUri;
     $lodspk['local']['curie'] = Utils::uri2curie($localUri);
     $lodspk['contentType'] = $acceptContentType;
     $lodspk['model'] = $conf['model']['directory'];
     $lodspk['view'] = $conf['view']['directory'];
     $lodspk['ns'] = $conf['ns'];
     //chdir($conf['home'].$conf['model']['directory']);
     Utils::queryFile($modelFile, $endpoints['local'], $results, $firstResults);
     if (!$lodspk['resultRdf']) {
         $results = Utils::internalize($results);
         $firstAux = Utils::getfirstResults($results);
         chdir($conf['home']);
         if (is_array($results)) {
             $resultsObj = Convert::array_to_object($results);
             $results = $resultsObj;
         } else {
             $resultsObj = $results;
         }
         $lodspk['firstResults'] = Convert::array_to_object($firstAux);
     } else {
         $resultsObj = $results;
     }
     //chdir($conf['home']);
     if ($conf['debug']) {
         Logging::log("Using template " . $viewFile);
     }
     Utils::processDocument($viewFile, $lodspk, $resultsObj);
 }
예제 #9
0
 public function run()
 {
     set_time_limit(0);
     error_reporting(E_ERROR);
     if (is_file(FILE)) {
         echo "There is an existing " . FILE . " file on this installation. Please remove it before importing a new one";
         exit(0);
     }
     if (!isset($_GET['import']) && !isset($_POST['importtext'])) {
         $this->showInterface();
         exit(0);
     }
     if (!is_writable('.')) {
         echo 'The webserver needs write permissions in "lodspeakr/" "lodspeakr/models/" and "lodspeakr/views/" dirs to import settings.';
         exit(0);
     }
     echo $this->external_basedir;
     include_once 'lib/arc2/ARC2.php';
     $parser = ARC2::getTurtleParser();
     if (isset($_GET['import'])) {
         $parser->parse($_GET['import']);
         $this->external_basedir = str_replace('export', '', $_GET['import']);
     } elseif (isset($_POST['importtext'])) {
         $parser->parse(RDF, $_POST['importtext']);
     } else {
         HTTPStatus::send500();
         exit(0);
     }
     $triples = $parser->getTriples();
     $appArr = $this->search($triples, null, RDF . 'type', LS . 'Application');
     if (!(sizeof($appArr) > 0)) {
         echo "I can't find an application from the URL given";
         exit(0);
     }
     $app = $appArr[0]['s'];
     $this->external_basedir = $app;
     $compArr = $this->search($triples, null, SKOS . 'broader', $app);
     $content = "<?\n\$conf['debug'] = false;\n\$conf['mirror_external_uris'] = true;\n\n";
     $this->basedir = preg_replace('/import$/', '', !empty($_SERVER['HTTPS']) ? "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
     //$arr = explode("lodspeakr/benegesserit", $this->basedir);
     //$this->basedir = $arr[0];
     $content .= "\$conf['basedir'] = \"{$this->basedir}\";\n";
     $content .= "\$conf['parentApp'] = \"{$app}\";\n";
     $pwd = getcwd();
     $content .= "\$conf['home'] = \"{$pwd}/\";\n";
     //App params
     $q = $this->search($triples, $app, LS . 'usedParameter', null);
     $appParams = array();
     foreach ($q as $p) {
         $param = $p['o'];
         $labelArr = $this->search($triples, $param, RDFS . 'label', null);
         $label = $labelArr[0]['o'];
         $format = $this->search($triples, $param, DC . 'hasFormat', null);
         $cntArr = $this->search($triples, $format[0]['o'], CNT . 'chars', null);
         $cnt = $cntArr[0]['o'];
         $appParams[$label] = $cnt;
     }
     foreach ($appParams as $k => $v) {
         $content .= "\$conf['{$k}'] = \"{$v}\";\n";
     }
     $content .= "/*ATTENTION: By default this application is available to\n * be exported and copied (its configuration)\n * by others. If you do not want that, \n * turn the next option as false\n */ \n\$conf['export'] = true;\n\n";
     //Components
     foreach ($compArr as $v) {
         $component = $v['s'];
         $componentTypeArr = $this->search($triples, $component, RDF . 'type', null);
         $compType = $componentTypeArr[0]['o'];
         $params = array();
         $q = $this->search($triples, $component, LS . 'usedParameter', null);
         foreach ($q as $p) {
             $param = $p['o'];
             $labelArr = $this->search($triples, $param, RDFS . 'label', null);
             $label = $labelArr[0]['o'];
             $format = $this->search($triples, $param, DC . 'hasFormat', null);
             $cntArr = $this->search($triples, $format[0]['o'], CNT . 'chars', null);
             $cnt = $cntArr[0]['o'];
             $params[$label] = $cnt;
         }
         $inputs = array();
         $q = $this->search($triples, $component, LS . 'usedInput', null);
         foreach ($q as $p) {
             $param = $p['o'];
             $labelArr = $this->search($triples, $param, RDFS . 'label', null);
             if (sizeof($labelArr) > 0) {
                 $label = $labelArr[0]['o'];
                 $format = $this->search($triples, $param, DC . 'hasFormat', null);
                 $cntArr = $this->search($triples, $format[0]['o'], CNT . 'chars', null);
                 $cnt = $cntArr[0]['o'];
                 $inputs[$label] = $cnt;
             }
         }
         if ($compType == LS . "LodspeakrEndpointManagerComponent") {
             $content .= $this->createEndpoints($params);
         } elseif ($compType == LS . "LodspeakrNamespaceManagerComponent") {
             $content .= $this->createNamespaces($params);
         } elseif ($compType == LS . "LodspeakrSparqlEndpointRetriever") {
             $this->createModels($inputs);
         } elseif ($compType == LS . "LodspeakrStaticElementsComponent") {
             $this->createStatics($inputs);
         } elseif ($compType == LS . "LodspeakrVisualComponent") {
             $this->createViews($inputs);
         } else {
             if ($conf['debug']) {
                 Logging::log("Component '{$component}' (of type {$compType}) not supported", E_USER_WARNING);
             }
         }
     }
     $content .= "?>\n";
     try {
         $fh = fopen(FILE, 'a');
         fwrite($fh, $content);
         fclose($fh);
     } catch (Exception $e) {
         echo 'Caught exception while writing settings: ', $e->getMessage(), "\n";
         exit(1);
     }
     $this->showFinishing();
 }