diff --git a/classes/HTTPStatus.php b/classes/HTTPStatus.php index e062430684083149b82073019892bfb509eba988..705a9a4b95443b340832d7170e6591b69b04680e 100644 --- a/classes/HTTPStatus.php +++ b/classes/HTTPStatus.php @@ -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"); diff --git a/classes/modules/sessionModule.php b/classes/modules/sessionModule.php new file mode 100644 index 0000000000000000000000000000000000000000..bf2367e6e908c2b3552a15de546c0ff62b80aa7e --- /dev/null +++ b/classes/modules/sessionModule.php @@ -0,0 +1,83 @@ +<? +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; + } +} +?> diff --git a/common.inc.php b/common.inc.php index 95ea7bd75b1d8a7ba1c99c0ebc77def10f566827..fb075a4bcb7fd7fb5bd8d7e3687e9cb4b10b9e5f 100644 --- a/common.inc.php +++ b/common.inc.php @@ -60,14 +60,11 @@ $conf['modules'] = array(); $conf['modules']['directory'] = 'classes/modules/'; $conf['modules']['available'] = array('static','uri', 'type', 'service'); -<<<<<<< HEAD - //Uncomment next line to enable sessions //$conf['modules']['available'] = array('session', 'static','uri', 'type', 'service'); -======= + global $lodspk; ->>>>>>> 190d4897be9d90712085169270a6e105600063f5 include_once('settings.inc.php'); $conf['view']['standard']['baseUrl'] = $conf['basedir']; ?>