Commit | Line | Data |
---|---|---|
3f6bc75f FB |
1 | <?php |
2 | ||
3f6bc75f | 3 | class xorgAuth extends dcAuth { |
1759942c FB |
4 | public $xorg_infos = array('forlife' => null, |
5 | 'prenom' => null, | |
6 | 'nom' => null); | |
7 | ||
e105d162 FB |
8 | public function __construct(&$core) { |
9 | parent::__construct($core); | |
10 | } | |
11 | ||
f33c2acf | 12 | public function buildFromSession() { |
e105d162 | 13 | global $core; |
001b27af | 14 | @header('Last-Modified:'); |
e105d162 FB |
15 | if (!isset($core) || !isset($core->session)) { |
16 | return; | |
17 | } | |
5a64dfac FB |
18 | if (!session_id()) { |
19 | $core->session->start(); | |
20 | } | |
001b27af FB |
21 | $user = @$_SESSION['auth-xorg']; |
22 | if ($user && is_null($this->xorg_infos['forlife'])) { | |
1759942c FB |
23 | foreach ($this->xorg_infos as $key => $val) { |
24 | $this->xorg_infos[$key] = $_SESSION['auth-xorg-' . $key]; | |
25 | } | |
001b27af | 26 | $this->user_id = $user; |
16237aee | 27 | parent::checkUser($this->user_id); |
f33c2acf FB |
28 | if (isset($core->blog)) { |
29 | $this->sudo(array($this, 'updateUserPerms')); | |
30 | } | |
1759942c FB |
31 | } |
32 | } | |
33 | ||
f33c2acf FB |
34 | public function createUser() { |
35 | global $core; | |
36 | if (!$core->userExists($_SESSION['auth-xorg'])) { | |
37 | $cur = new cursor($this->con, 'dc_user'); | |
38 | $cur->user_id = $_SESSION['auth-xorg']; | |
39 | $cur->user_pwd = md5(rand()); | |
40 | $cur->user_lang = 'fr'; | |
41 | $cur->user_name = $_SESSION['auth-xorg-nom']; | |
42 | $cur->user_firstname = $_SESSION['auth-xorg-prenom']; | |
43 | $cur->user_displayname = $cur->user_firstname . ' ' . $cur->user_name; | |
44 | $cur->user_email = $_SESSION['auth-xorg'] . '@polytechnique.org'; | |
45 | $cur->user_options = $core->userDefaults(); | |
46 | $cur->user_options['post_xorg_perms'] = 'public'; | |
47 | $cur->user_default_blog = 'default'; // FIXME | |
48 | $core->addUser($cur); | |
49 | } | |
50 | } | |
51 | ||
52 | private function updateUserPerms() { | |
53 | global $core; | |
54 | $core->setUserBlogPermissions($_SESSION['auth-xorg'], | |
55 | $core->blog->id, | |
56 | array('usage' => true, | |
57 | 'contentadmin' => true, | |
58 | 'admin' => true)); | |
59 | } | |
60 | ||
61 | ||
62 | /** Xorg SSO API */ | |
63 | ||
e105d162 FB |
64 | public function callXorg($path = null) { |
65 | if (is_null($path)) { | |
66 | $path = $_SERVER['REQUEST_URI']; | |
67 | } | |
68 | $this->buildFromSession(); | |
be74d9bd | 69 | if (@$_SESSION['auth-xorg']) { |
e105d162 | 70 | return true; |
be74d9bd | 71 | } |
9d447124 | 72 | global $core; |
5a64dfac FB |
73 | if (!session_id()) { |
74 | $core->session->start(); | |
001b27af | 75 | } |
be74d9bd FB |
76 | $_SESSION["auth-x-challenge"] = md5(uniqid(rand(), 1)); |
77 | $url = "https://www.polytechnique.org/auth-groupex/utf8"; | |
78 | $url .= "?session=" . session_id(); | |
79 | $url .= "&challenge=" . $_SESSION["auth-x-challenge"]; | |
80 | $url .= "&pass=" . md5($_SESSION["auth-x-challenge"] . XORG_AUTH_KEY); | |
9d447124 | 81 | $url .= "&url=" . urlencode($core->blog->url . "auth/XorgReturn?path=" . $path); |
be74d9bd FB |
82 | session_write_close(); |
83 | header("Location: $url"); | |
84 | exit; | |
85 | } | |
86 | ||
87 | public function returnXorg() { | |
88 | if (!isset($_GET['auth'])) { | |
89 | return false; | |
90 | } | |
91 | $params = ''; | |
e105d162 | 92 | global $core; |
001b27af FB |
93 | $_COOKIE[DC_SESSION_NAME] = $_GET['PHPSESSID']; |
94 | unset($_GET['PHPSESSID']); | |
fc802c03 | 95 | if (!session_id()) { |
5a64dfac FB |
96 | $core->session->start(); |
97 | } | |
be74d9bd FB |
98 | foreach($this->xorg_infos as $key => $val) { |
99 | if(!isset($_GET[$key])) { | |
100 | return false; | |
101 | } | |
102 | $_SESSION['auth-xorg-' . $key] = $_GET[$key]; | |
be74d9bd FB |
103 | $params .= $_GET[$key]; |
104 | } | |
105 | if (md5('1' . $_SESSION['auth-x-challenge'] . XORG_AUTH_KEY . $params . '1') == $_GET['auth']) { | |
106 | unset($_GET['auth']); | |
a1a69528 FB |
107 | $_SESSION['sess_user_id'] = $_SESSION['auth-xorg'] = $_GET['forlife']; |
108 | $_SESSION['sess_browser_uid'] = http::browserUID(DC_MASTER_KEY); | |
109 | $_SESSION['sess_blog_id'] = 'default'; | |
f33c2acf | 110 | $this->sudo(array($this, 'createUser')); |
001b27af | 111 | $path = $_GET['path']; |
c0556a51 | 112 | header("Location: http://murphy.m4x.org" . $_GET['path']); |
e105d162 | 113 | exit; |
be74d9bd | 114 | } |
a1a69528 FB |
115 | unset($_SESSION['auth-xorg']); |
116 | unset($_SESSION['sess_user_id']); | |
be74d9bd | 117 | unset($_GET['auth']); |
e105d162 | 118 | echo "Failed !!!"; |
be74d9bd FB |
119 | return false; |
120 | } | |
121 | ||
122 | public function killSession() { | |
e105d162 | 123 | global $core; |
5a64dfac FB |
124 | if (!session_id()) { |
125 | $core->session->start(); | |
126 | } | |
e105d162 | 127 | $core->session->destroy(); |
9d447124 | 128 | header('Location: ' . $core->blog->url); |
be74d9bd FB |
129 | exit; |
130 | } | |
a1a69528 | 131 | |
f33c2acf FB |
132 | |
133 | /** Dotclear dcAuth API */ | |
134 | ||
ccfabbd3 | 135 | public function checkUser($user_id, $pwd = null, $user_key = null) { |
16237aee | 136 | return $this->callXorg(); |
ccfabbd3 FB |
137 | } |
138 | ||
139 | public function check($permissions, $blog_id) { | |
140 | $this->buildFromSession(); | |
141 | return parent::check($permissions, $blog_id); | |
142 | } | |
143 | ||
0ff09dcb FB |
144 | public function checkPassword($pwd) { |
145 | $this->buildFromSession(); | |
146 | return !empty($this->user_id); | |
147 | } | |
148 | ||
a1a69528 FB |
149 | public function allowPassChange() { |
150 | return false; | |
151 | } | |
152 | ||
153 | public function userID() { | |
154 | $this->buildFromSession(); | |
ccfabbd3 | 155 | return parent::userID(); |
a1a69528 FB |
156 | } |
157 | ||
158 | public function getPermissions() { | |
ccfabbd3 FB |
159 | $this->buildFromSession(); |
160 | return parent::getPermissions(); | |
a1a69528 FB |
161 | } |
162 | ||
163 | public function getInfo($n) { | |
ccfabbd3 FB |
164 | $this->buildFromSession(); |
165 | return parent::getInfo($n); | |
abb4dd42 FB |
166 | } |
167 | ||
168 | public function getOption($n) { | |
ccfabbd3 FB |
169 | $this->buildFromSession(); |
170 | return parent::getOption($n); | |
a1a69528 | 171 | } |
5a64dfac | 172 | /* |
a1a69528 | 173 | public function isSuperAdmin() { |
f33c2acf | 174 | return parent::isSuperAdmin() || ($this->user_id == 'florent.bruneau.2003'); |
abb4dd42 | 175 | } |
5a64dfac | 176 | */ |
abb4dd42 | 177 | public function getOptions() { |
ccfabbd3 FB |
178 | $this->buildFromSession(); |
179 | return parent::getOptions(); | |
a1a69528 | 180 | } |
001b27af FB |
181 | |
182 | public function authForm() { | |
183 | global $core; | |
184 | $path = "http://murphy.m4x.org/~x2003bruneau/dotclear/"; | |
185 | return '<fieldset>'. | |
186 | '<p><a href="' . $path . 'auth/Xorg?path=/~x2003bruneau/dotclear/admin/index.php">Via Polytechnique.org</a></p>' . | |
187 | '<p><a href="' . $path . 'admin/auth.php">Via le formulaire</a></p>' . | |
188 | '</fieldset>'. | |
189 | '<p>'.__('You must accept cookies in order to use the private area.').'</p>'; | |
190 | } | |
3f6bc75f FB |
191 | } |
192 | ||
193 | ?> |