]> projects.mako.cc - scuttle/blobdiff - services/userservice.php
updated readme with information on a series of bugs I know exist
[scuttle] / services / userservice.php
index a2709fbd10123715c3b86cf661d25f9ca90700d9..a4fdbb7ed0dc1f024c5c4e7b6d2688f186bab1cb 100644 (file)
@@ -19,9 +19,9 @@ class UserService {
   var $tablename;
   var $sessionkey;
   var $cookiekey;
-  var $cookietime = 1209600; // 2 weeks
+  var $cookietime = 63072000; // 2 years
 
-    function UserService(&$db) {
+    function __construct(&$db) {
         $this->db =& $db;
         $this->tablename = $GLOBALS['tableprefix'] .'users';
         $this->sessionkey = $GLOBALS['cookieprefix'] .'-currentuserid';
@@ -41,7 +41,7 @@ class UserService {
         if(!empty($host)) {
             @exec("nslookup -type=$type $host", $output);
             while(list($k, $line) = each($output)) {
-                if(eregi("^$host", $line)) {
+                if(preg_match("/^$host/i", $line)) {   //eregi("^$host", $line)
                     return true;
                 }
             }
@@ -63,6 +63,15 @@ class UserService {
             return false;
     }
 
+    function _in_regex_array($value, $array) {
+      foreach ($array as $key => $pattern) {
+        if (preg_match($pattern, $value)) {
+          return TRUE;
+        }
+      }
+      return FALSE;
+    }
+
     function _randompassword() {
         $password = mt_rand(1, 99999999);
         $password = substr(md5($password), mt_rand(0, 19), mt_rand(6, 12));
@@ -123,7 +132,7 @@ class UserService {
         if (isset($_SESSION[$this->getSessionKey()])) {
             return $_SESSION[$this->getSessionKey()];
         } else if (isset($_COOKIE[$this->getCookieKey()])) {
-            $cook = split(':', $_COOKIE[$this->getCookieKey()]);
+            $cook = explode(':', $_COOKIE[$this->getCookieKey()]); //split(':', $_COOKIE[$this->getCookieKey()]);
             //cookie looks like this: 'id:md5(username+password)'
             $query = 'SELECT * FROM '. $this->getTableName() .
                      ' WHERE MD5(CONCAT('.$this->getFieldName('username') .
@@ -325,6 +334,29 @@ class UserService {
             return false;
     }
 
+    function isBlockedEmail($email) {
+      // Check whitelist
+      $whitelist = $GLOBALS['email_whitelist'];
+      if (!is_null($whitelist) && is_array($whitelist)) {
+        if (!$this->_in_regex_array($email, $whitelist)) {
+          // Not in whitelist -> blocked
+          return TRUE;
+        }
+      }
+
+      // Check blacklist
+      $blacklist = $GLOBALS['email_blacklist'];
+      if (!is_null($blacklist) && is_array($blacklist)) {
+        if ($this->_in_regex_array($email, $blacklist)) {
+          // In blacklist -> blocked
+          return TRUE;
+        }
+      }
+
+      // Not blocked
+      return FALSE;
+    }
+
     function isReserved($username) {
         if (in_array($username, $GLOBALS['reservedusers'])) {
             return true;

Benjamin Mako Hill || Want to submit a patch?