Automatically calculate the filesystem path of the application and use
authorJoey Schulze <joey@infodrom.org>
Thu, 25 Feb 2010 16:18:02 +0000 (17:18 +0100)
committerJoey Schulze <joey@infodrom.org>
Thu, 25 Feb 2010 16:18:02 +0000 (17:18 +0100)
it for reading and including files later

ajax/ajax.php
lib/general.php
lib/login.php

index a709a03..57f35a3 100644 (file)
@@ -60,7 +60,7 @@ if (empty($_POST['source']))
   exit;
 
 connect_db();
   exit;
 
 connect_db();
-if (load_mask($_POST['source'], '../') === false) exit;
+if (load_mask($_POST['source']) === false) exit;
 
 $data = array('error' => 'Unknown function');
 
 
 $data = array('error' => 'Unknown function');
 
index fa250f8..278501e 100644 (file)
@@ -21,12 +21,12 @@ function sanitise_filename($file)
   return str_replace('./','x',$file);
 }
 
   return str_replace('./','x',$file);
 }
 
-function load_mask($name, $prefix = '')
+function load_mask($name)
 {
   global $mask;
 
   $name = sanitise_filename($name);
 {
   global $mask;
 
   $name = sanitise_filename($name);
-  $file = $prefix . 'masks/' . $name . '.php';
+  $file = $_SESSION['sys']['basedir'] . 'masks/' . $name . '.php';
 
   if (!file_exists($file))
     return false;
 
   if (!file_exists($file))
     return false;
index e45b4ec..35e6160 100644 (file)
@@ -17,11 +17,18 @@ function check_passwd()
 
   if ($sth === false) return false;
 
 
   if ($sth === false) return false;
 
+  if (substr($_SERVER['HTTP_REFERER'],-12) != '/?login=true'
+      || substr($_SERVER['SCRIPT_FILENAME'],-10) != '/index.php') {
+    error_log('Wrong referrer or wrong request uri');
+    return false;
+  }
+
   if ($row = pg_fetch_assoc($sth)) {
     $_SESSION['sys'] = array('uid' => $row['id'],
                             'login' => $row['login'],
                             'name' => $row['name'],
   if ($row = pg_fetch_assoc($sth)) {
     $_SESSION['sys'] = array('uid' => $row['id'],
                             'login' => $row['login'],
                             'name' => $row['name'],
-                            'email' => $row['email']);
+                            'email' => $row['email'],
+                            'basedir' => substr($_SERVER['SCRIPT_FILENAME'],0,-9));
     return true;
   }
 
     return true;
   }