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