]> wagnertech.de Git - timetracker.git/blobdiff - WEB-INF/lib/common.lib.php
Introduced IP based access control for groups.
[timetracker.git] / WEB-INF / lib / common.lib.php
index 69c38b731e63a867d6530c7d99faf96f1bd5f1e8..210ec41cd14cae02784ad85a65c04877f9e37f73 100644 (file)
@@ -339,9 +339,27 @@ function ttAccessAllowed($required_right)
     exit();
   }
 
+  // Check IP restriction, if set.
+  if ($user->allow_ip && !$user->can('override_allow_ip')) {
+    $access_allowed = false;
+    $user_ip = $_SERVER['REMOTE_ADDR'];
+    $allowed_ip_array = explode(',', $user->allow_ip);
+    foreach ($allowed_ip_array as $allowed_ip) {
+      $len = strlen($allowed_ip);
+      if (substr($user_ip, 0, $len) === $allowed_ip) {
+         $access_allowed = true;
+         break;
+      }
+    }
+    if (!$access_allowed) return false;
+  }
+
   // Check if user has the right.
-  if (in_array($required_right, $user->rights))
+  if (in_array($required_right, $user->rights)) {
+    import('ttUserHelper');
+    ttUserHelper::updateLastAccess();
     return true;
+  }
 
   return false;
 }