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