diff --git a/auth-ip/authenticate.php b/auth-ip/authenticate.php new file mode 100644 index 0000000..79261d2 --- /dev/null +++ b/auth-ip/authenticate.php @@ -0,0 +1,54 @@ += 7) { + $username = $_GET['token']; + } else if (isset($_GET['ddns']) && !empty($_GET['ddns']) && $_SERVER['REMOTE_ADDR'] === gethostbyname($_GET['ddns'])) { + $username = $_GET['ddns']; + } else { + $username = $_SERVER['REMOTE_ADDR']; + } + if ($acct = ClientAccount::lookupByUsername($username)) { + if (($client = new ClientSession(new EndUser($acct->getUser()))) + && $client->getId()) + return $client; + } + else { + // No such account. Attempt a lookup on the username + $users = parent::searchUsers($username); + if (!is_array($users)) + return; + + foreach ($users as $u) { + if (0 === strcasecmp($u['username'], $username) + || 0 === strcasecmp($u['email'], $username)) + // User information is valid + return new ClientCreateRequest($this, $username, $u); + } + } + } + } +} + +require_once(INCLUDE_DIR.'class.plugin.php'); +require_once('config.php'); +class IpAuthPlugin extends Plugin { + var $config_class = 'IpAuthConfig'; + + function bootstrap() { + $config = $this->getConfig(); + if ($config->get('auth-client')) + UserAuthenticationBackend::register('UserIpAuthentication'); + } +} diff --git a/auth-ip/config.php b/auth-ip/config.php new file mode 100644 index 0000000..fc8c4a6 --- /dev/null +++ b/auth-ip/config.php @@ -0,0 +1,45 @@ + new SectionBreakField(array( + 'label' => $__('Authentication Modes'), + 'hint' => $__('Authentication mode for clients. Clients + can be identified via their IP address.'), + )), + 'auth-client' => new BooleanField(array( + 'label' => $__('Client Authentication'), + 'default' => false, + 'configuration' => array( + 'desc' => $__('Enable IP authentication of clients') + ) + )), + ); + } + + function pre_save(&$config, &$errors) { + global $msg; + + list($__, $_N) = self::translate(); + if (!$errors) + $msg = $__('Configuration updated successfully'); + + return true; + } +} diff --git a/auth-ip/plugin.php b/auth-ip/plugin.php new file mode 100644 index 0000000..67e3473 --- /dev/null +++ b/auth-ip/plugin.php @@ -0,0 +1,11 @@ + 'auth:ip', # notrans + 'version' => '0.1', + 'name' => /* trans */ 'IP Authentication', + 'author' => 'Maximilian Weber', + 'description' => /* trans */ 'Allows user authentication based on IP addresses. osTicket will match the request IP address to usernames.', + 'url' => 'http://www.osticket.com/plugins/auth/ip', + 'plugin' => 'authenticate.php:IpAuthPlugin' +);