init.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /*
  3. Tiny Tiny RSS plugin for RADIUS authentication
  4. @author alsvartr (me@taughtbycats.ru)
  5. @copyright GPL2
  6. Requires php radius class (comes with plugin)
  7. Put the following options in config.php:
  8. define('RADIUS_AUTH_SERVER', 'radius_server_address');
  9. define('RADIUS_AUTH_SECRET', 'radius_shared_secret');
  10. Optional:
  11. //Default: 1812
  12. define('RADIUS_AUTH_PORT', radius_auth_port);
  13. */
  14. class Auth_Radius extends Plugin implements IAuthModule {
  15. private $link;
  16. private $host;
  17. private $base;
  18. private $debug;
  19. function about() {
  20. return array(0.1,
  21. "Authenticates against an RADIUS server (configured in config.php)",
  22. "alsvartr",
  23. true);
  24. }
  25. function init($host) {
  26. $this->link = $host->get_link();
  27. $this->host = $host;
  28. $this->base = new Auth_Base($this->link);
  29. $this->debug = FALSE;
  30. $host->add_hook($host::HOOK_AUTH_USER, $this);
  31. }
  32. private function _log($msg) {
  33. if ($this->debug) trigger_error($msg, E_USER_WARNING);
  34. }
  35. function authenticate($login, $password) {
  36. if (!require_once('php-radius/radius.php')) {
  37. $this->_log('Cannot require radius class files!');
  38. return FALSE;
  39. }
  40. if ($login && $password) {
  41. if ( (!defined('RADIUS_AUTH_SERVER')) OR (!defined('RADIUS_AUTH_SECRET')) ) {
  42. $this->_log('Could not parse RADIUS_AUTH_ options from config.php!');
  43. return FALSE;
  44. } elseif (!defined('RADIUS_AUTH_PORT'))
  45. define('RADIUS_AUTH_PORT', 1812);
  46. $radius = new Radius(RADIUS_AUTH_SERVER, RADIUS_AUTH_SECRET, '', 5, RADIUS_AUTH_PORT);
  47. $radius->SetNasIpAddress('1.2.3.4');
  48. $auth = $radius->AccessRequest($login, $password);
  49. if ($auth)
  50. return $this->base->auto_create_user($login);
  51. else {
  52. $this->_log('Radius authentication rejected!');
  53. return FALSE;
  54. }
  55. }
  56. return FALSE;
  57. }
  58. }
  59. ?>