Skip to content
Snippets Groups Projects
Commit 7db5081f authored by alvaro's avatar alvaro
Browse files

Added session

parent 7dd5c0c6
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,12 @@ class HTTPStatus{
echo $uri."\n\n";
exit(0);
}
public static function send401($msg){
header("HTTP/1.0 401 Forbidden");
echo $msg;
exit(0);
}
public static function send404($uri){
header("HTTP/1.0 404 Not Found");
......
<?
require_once('abstractModule.php');
class SessionModule extends abstractModule{
//Session module
private $sessionUri = "session";
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;
Utils::send303($conf['basedir'], '');
}else{
Utils::send401("Authentication not valid.");
return true;
}
}
}else{
session_start();
if(isset($_SESSION['lodspk'])){
return false;
}else{
Utils::send303($conf['basedir'].$this->sessionUri, '');
return true;
}
}
}
public function execute($uri){
global $conf;
global $localUri;
global $uri;
global $acceptContentType;
global $endpoints;
global $lodspk;
global $firstResults;
return true;
}
private function showSessionForm(){
echo "<html>
<head>
<title>Login</title>
</head>
<body>
<form action='".$this->sessionUri."' method='POST'>
<input name='user' type='text' />
<input name='password' type='password' /><br/>
<input name='submit' type='submit' />
</form>
</body>
</html>";
exit(0);
}
private function validateAuthentication($data){
global $conf;
if(isset($conf['session']['user']) && isset($conf['session']['password'])){
if($data['user'] == $conf['session']['user'] && $data['password'] == $conf['session']['password']){
return true;
}
return false;
}
return false;
}
}
?>
......@@ -48,11 +48,22 @@ $conf['type']['priorities']['rdfs:Resource'] = -1;
//Debug
$conf['debug'] = false;
//Session module
//First version: really simple user/pass
$conf['session']['user'] = 'admin';
$conf['session']['password'] = 'admin';
//Modules: LODSPeaKr will try to match the requested URI
//using the modules in the following order
$conf['modules'] = array();
$conf['modules']['directory'] = 'classes/modules/';
$conf['modules']['available'] = array('static','uri', 'type', 'service');
//Uncomment next line to enable sessions
//$conf['modules']['available'] = array('session', 'static','uri', 'type', 'service');
global $lodspk;
include_once('settings.inc.php');
$conf['view']['standard']['baseUrl'] = $conf['basedir'];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment