1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
include_once($ariadne."/modules/mod_auth/default.php"); |
4
|
|
|
|
5
|
|
|
class mod_auth_radius extends mod_auth_default { |
6
|
|
|
|
7
|
|
|
function __construct($config) { |
8
|
|
|
$this->config = $config; |
|
|
|
|
9
|
|
|
} |
10
|
|
|
|
11
|
|
View Code Duplication |
function storeExternalUser($login, $userData) { |
|
|
|
|
12
|
|
|
global $AR, $store; |
13
|
|
|
// become admin for the moment |
14
|
|
|
$aLogin = $this->config["import_user_by"]; |
15
|
|
|
$AR->user = current($store->call("system.get.phtml", "", $store->find("/system/users/", "login.value='$aLogin' and object.implements='puser'"))); |
16
|
|
|
|
17
|
|
|
$user = $this->getUser($login); |
18
|
|
|
if ($user !== true) { |
19
|
|
|
$user_dir = $this->config["import_user_directory"]; |
20
|
|
|
$user_profile = $this->config["import_user_profile"]; |
21
|
|
|
$user_type = $this->config["import_user_type"]; |
22
|
|
|
if (!$user_type) { |
23
|
|
|
$user_type = "puser"; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
debug("ldAuthRadius: user ($login) didn't exist before: creating", "all"); |
27
|
|
|
$data = $userData; |
28
|
|
|
$data["arNewFilename"] = "$user_dir$login/"; |
29
|
|
|
$data["profile"] = $user_profile; |
30
|
|
|
$data["setowner"] = true; |
31
|
|
|
|
32
|
|
|
$user = $store->newobject( |
33
|
|
|
"$user_dir$login/", |
34
|
|
|
"$user_dir", |
35
|
|
|
"$user_type", |
36
|
|
|
new object); |
37
|
|
|
|
38
|
|
|
$user->arIsNewObject = true; |
39
|
|
|
$user->call('system.save.data.phtml', $data); |
40
|
|
|
|
41
|
|
|
return $user; |
42
|
|
|
} else { |
43
|
|
|
// $AR->user was set by getUser and contains the correct user now. |
44
|
|
|
return $AR->user; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
function authExternalUser($login, $password) { |
|
|
|
|
49
|
|
|
|
50
|
|
|
$res = radius_auth_open(); |
51
|
|
|
if (!radius_add_server($res, $this->config['radius_server'], $this->config['radius_port'], $this->config['sharedsecret'], 3, 3)) { |
52
|
|
|
debug('RadiusError:' . radius_strerror($res). "\n",'auth'); |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if (!radius_create_request($res, RADIUS_ACCESS_REQUEST)) { |
57
|
|
|
debug('RadiusError:' . radius_strerror($res). "\n",'auth'); |
58
|
|
|
return false; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
if (!radius_put_string($res, RADIUS_NAS_IDENTIFIER, isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost')) { |
62
|
|
|
debug('RadiusError:' . radius_strerror($res). "\n",'auth'); |
63
|
|
|
return false; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
View Code Duplication |
if (!radius_put_int($res, RADIUS_SERVICE_TYPE, RADIUS_FRAMED)) { |
67
|
|
|
debug('RadiusError:' . radius_strerror($res). "\n",'auth'); |
68
|
|
|
return false; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
View Code Duplication |
if (!radius_put_int($res, RADIUS_FRAMED_PROTOCOL, RADIUS_PPP)) { |
72
|
|
|
debug('RadiusError:' . radius_strerror($res). "\n",'auth'); |
73
|
|
|
return false; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
View Code Duplication |
if (!radius_put_string($res, RADIUS_CALLING_STATION_ID, isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : '127.0.0.1') == -1) { |
77
|
|
|
debug('RadiusError:' . radius_strerror($res). "\n",'auth'); |
78
|
|
|
return false; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
View Code Duplication |
if (!radius_put_string($res, RADIUS_USER_NAME, $login)) { |
82
|
|
|
debug('RadiusError:' . radius_strerror($res). "\n",'auth'); |
83
|
|
|
return false; |
84
|
|
|
} |
85
|
|
View Code Duplication |
if($password){ |
86
|
|
|
if (!radius_put_string($res, RADIUS_USER_PASSWORD, $password)) { |
87
|
|
|
debug('RadiusError:' . radius_strerror($res). "\n",'auth'); |
88
|
|
|
return false; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
View Code Duplication |
if (!radius_put_int($res, RADIUS_SERVICE_TYPE, RADIUS_FRAMED)) { |
93
|
|
|
debug('RadiusError:' . radius_strerror($res). "\n",'auth'); |
94
|
|
|
return false; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
View Code Duplication |
if (!radius_put_int($res, RADIUS_FRAMED_PROTOCOL, RADIUS_PPP)) { |
98
|
|
|
debug('RadiusError:' . radius_strerror($res). "\n",'auth'); |
99
|
|
|
return false; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$req = radius_send_request($res); |
103
|
|
View Code Duplication |
if (!$req) { |
104
|
|
|
debug('RadiusError:' . radius_strerror($res). "\n",'auth'); |
105
|
|
|
return false; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$user = false; |
109
|
|
|
switch($req) { |
110
|
|
|
case RADIUS_ACCESS_ACCEPT: |
111
|
|
|
$userData = Array(); |
112
|
|
|
$userData["name"] = $login; |
113
|
|
|
$userData["newpass1"] = '!'; |
114
|
|
|
$userData["newpass2"] = '!'; |
115
|
|
|
$user = $this->storeExternalUser($login, $userData); |
116
|
|
|
break; |
117
|
|
|
|
118
|
|
|
case RADIUS_ACCESS_REJECT: |
119
|
|
|
debug("RadiusError: Radius Request rejected\n",'auth'); |
120
|
|
|
break; |
121
|
|
|
|
122
|
|
|
default: |
123
|
|
|
debug("RadiusError: Unknown answer\n",'auth'); |
124
|
|
|
} |
125
|
|
|
return $user; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.