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