Build the permissions...
[dotclear.git] / class.xorg.auth.php
1 <?php
2
3 require_once dirname(__FILE__) . '/../../inc/core/class.dc.auth.php';
4
5 class xorgAuth extends dcAuth {
6 private $forceSU = false;
7
8 public $xorg_infos = array('forlife' => null,
9 'prenom' => null,
10 'nom' => null);
11
12 public function __construct(&$core) {
13 parent::__construct($core);
14 }
15
16 private function buildFromSession() {
17 global $core;
18 if (!isset($core) || !isset($core->session)) {
19 return;
20 }
21 $core->session->start();
22 if (@$_SESSION['auth-xorg'] && is_null($this->xorg_infos['forlife'])) {
23 foreach ($this->xorg_infos as $key => $val) {
24 $this->xorg_infos[$key] = $_SESSION['auth-xorg-' . $key];
25 }
26 $this->user_id = $_SESSION['auth-xorg'];
27 }
28 }
29
30 public function checkUser($user_id, $pwd = null, $user_key = null) {
31 return $this->callXorg() && $user_id == $this->user_id;
32 // echo "checking auth for " . $user_id;
33 // return parent::checkUser($user_id, $pwd, $user_key);
34 }
35
36 public function check($permissions, $blog_id) {
37 $this->buildFromSession();
38 return true;
39 // echo "Checking right to view $permissions on $blog_id";
40 // return parent::check($permissions, $blog_id);
41 }
42
43 public function callXorg($path = null) {
44 if (is_null($path)) {
45 $path = $_SERVER['REQUEST_URI'];
46 }
47 $this->buildFromSession();
48 if (@$_SESSION['auth-xorg']) {
49 return true;
50 }
51 $_SESSION["auth-x-challenge"] = md5(uniqid(rand(), 1));
52 $url = "https://www.polytechnique.org/auth-groupex/utf8";
53 $url .= "?session=" . session_id();
54 $url .= "&challenge=" . $_SESSION["auth-x-challenge"];
55 $url .= "&pass=" . md5($_SESSION["auth-x-challenge"] . XORG_AUTH_KEY);
56 $url .= "&url=http://murphy.m4x.org/~x2003bruneau/dotclear/auth/XorgReturn" . urlencode("?path=" . $path);
57 session_write_close();
58 header("Location: $url");
59 exit;
60 }
61
62 private function acquireAdminRights() {
63 $this->forceSU = true;
64 }
65
66 private function releaseAdminRights() {
67 $this->forceSU = false;
68 }
69
70 private function createUser() {
71 global $core;
72 $this->acquireAdminRights();
73 if (!$core->userExists($_SESSION['auth-xorg'])) {
74 $cur = new cursor($this->con, 'dc_user');
75 $cur->user_id = $_SESSION['auth-xorg'];
76 $cur->user_pwd = md5(rand());
77 $cur->user_lang = 'fr';
78 $cur->user_name = $_SESSION['auth-xorg-nom'];
79 $cur->user_firstname = $_SESSION['auth-xorg-prenom'];
80 $cur->user_email = $_SESSION['auth-xorg'] . '@polytechnique.org';
81 $cur->user_options = $core->userDefaults();
82 $cur->user_default_blog = 'default'; // FIXME
83 $core->addUser($cur);
84 $core->setUserBlogPermissions($_SESSION['auth-xorg'], 'default', array('usage' => true,
85 'contentadmin' => true,
86 'admin' => true));
87 }
88 $this->releaseAdminRights();
89 }
90
91 public function returnXorg() {
92 if (!isset($_GET['auth'])) {
93 return false;
94 }
95 $params = '';
96 global $core;
97 $core->session->start();
98 foreach($this->xorg_infos as $key => $val) {
99 if(!isset($_GET[$key])) {
100 return false;
101 }
102 $_SESSION['auth-xorg-' . $key] = $_GET[$key];
103 $params .= $_GET[$key];
104 }
105 if (md5('1' . $_SESSION['auth-x-challenge'] . XORG_AUTH_KEY . $params . '1') == $_GET['auth']) {
106 unset($_GET['auth']);
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';
110 $this->createUser();
111 header("Location: http://murphy.m4x.org" . $_GET['path']);
112 exit;
113 }
114 unset($_SESSION['auth-xorg']);
115 unset($_SESSION['sess_user_id']);
116 unset($_GET['auth']);
117 echo "Failed !!!";
118 return false;
119 }
120
121 public function killSession() {
122 global $core;
123 $core->session->start();
124 $core->session->destroy();
125 header('Location: http://murphy.m4x.org/~x2003bruneau/dotclear/');
126 exit;
127 }
128
129 public function allowPassChange() {
130 return false;
131 }
132
133 public function userID() {
134 $this->buildFromSession();
135 return $this->user_id;
136 }
137
138 public function getPermissions() {
139 return array('default' => array('name' => 'My first blog',
140 'url' => 'http://murphy.m4x.org/~x2003bruneau/dotclear/',
141 'permissions' => array('usage' => true,
142 'contentadmin' => true,
143 'admin' => true)));
144 }
145
146 public function getInfo($n) {
147 switch ($n) {
148 case 'user_lang':
149 return "fr";
150 case 'user_default_blog':
151 return 'default';
152 case 'user_post_status':
153 return 1;
154 case 'user_tz':
155 return 'UTC';
156 case 'user_name':
157 return $this->xorg_infos['nom'];
158 case 'user_firstname':
159 return $this->xorg_infos['prenom'];
160 case 'user_displayname':
161 return $this->xorg_infos['prenom'] . ' ' . $this->xorg_infos['nom'];
162 case 'user_email':
163 return $this->user_id . '@polytechnique.org';
164 case 'user_url':
165 return null;
166 }
167 echo "info $n ";
168 return null;
169 }
170
171 public function getOption($n) {
172 $options = $this->getOptions();
173 if (isset($options[$n])) {
174 return $options[$n];
175 }
176 echo "option $n ";
177 return null;
178 }
179
180 public function isSuperAdmin() {
181 return $this->forceSU || ($this->user_id == 'florent.bruneau.2003');
182 }
183
184 public function getOptions() {
185 return array('edit_size' => 24,
186 'enable_wysiwyg' => true,
187 'post_format' => 'wiki');
188 }
189 }
190
191 ?>