| 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 | parent::checkUser($this->user_id); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | public function callXorg($path = null) { |
| 32 | if (is_null($path)) { |
| 33 | $path = $_SERVER['REQUEST_URI']; |
| 34 | } |
| 35 | $this->buildFromSession(); |
| 36 | if (@$_SESSION['auth-xorg']) { |
| 37 | return true; |
| 38 | } |
| 39 | $_SESSION["auth-x-challenge"] = md5(uniqid(rand(), 1)); |
| 40 | $url = "https://www.polytechnique.org/auth-groupex/utf8"; |
| 41 | $url .= "?session=" . session_id(); |
| 42 | $url .= "&challenge=" . $_SESSION["auth-x-challenge"]; |
| 43 | $url .= "&pass=" . md5($_SESSION["auth-x-challenge"] . XORG_AUTH_KEY); |
| 44 | $url .= "&url=http://murphy.m4x.org/~x2003bruneau/dotclear/auth/XorgReturn" . urlencode("?path=" . $path); |
| 45 | session_write_close(); |
| 46 | header("Location: $url"); |
| 47 | exit; |
| 48 | } |
| 49 | |
| 50 | private function acquireAdminRights() { |
| 51 | $this->forceSU = true; |
| 52 | } |
| 53 | |
| 54 | private function releaseAdminRights() { |
| 55 | $this->forceSU = false; |
| 56 | } |
| 57 | |
| 58 | private function createUser() { |
| 59 | global $core; |
| 60 | $this->acquireAdminRights(); |
| 61 | if (!$core->userExists($_SESSION['auth-xorg'])) { |
| 62 | $cur = new cursor($this->con, 'dc_user'); |
| 63 | $cur->user_id = $_SESSION['auth-xorg']; |
| 64 | $cur->user_pwd = md5(rand()); |
| 65 | $cur->user_lang = 'fr'; |
| 66 | $cur->user_name = $_SESSION['auth-xorg-nom']; |
| 67 | $cur->user_firstname = $_SESSION['auth-xorg-prenom']; |
| 68 | $cur->user_displayname = $cur->user_firstname . ' ' . $cur->user_name; |
| 69 | $cur->user_email = $_SESSION['auth-xorg'] . '@polytechnique.org'; |
| 70 | $cur->user_options = $core->userDefaults(); |
| 71 | $cur->user_default_blog = 'default'; // FIXME |
| 72 | $core->addUser($cur); |
| 73 | $core->setUserBlogPermissions($_SESSION['auth-xorg'], 'default', array('usage' => true, |
| 74 | 'contentadmin' => true, |
| 75 | 'admin' => true)); |
| 76 | } |
| 77 | $this->releaseAdminRights(); |
| 78 | } |
| 79 | |
| 80 | public function returnXorg() { |
| 81 | if (!isset($_GET['auth'])) { |
| 82 | return false; |
| 83 | } |
| 84 | $params = ''; |
| 85 | global $core; |
| 86 | $core->session->start(); |
| 87 | foreach($this->xorg_infos as $key => $val) { |
| 88 | if(!isset($_GET[$key])) { |
| 89 | return false; |
| 90 | } |
| 91 | $_SESSION['auth-xorg-' . $key] = $_GET[$key]; |
| 92 | $params .= $_GET[$key]; |
| 93 | } |
| 94 | if (md5('1' . $_SESSION['auth-x-challenge'] . XORG_AUTH_KEY . $params . '1') == $_GET['auth']) { |
| 95 | unset($_GET['auth']); |
| 96 | $_SESSION['sess_user_id'] = $_SESSION['auth-xorg'] = $_GET['forlife']; |
| 97 | $_SESSION['sess_browser_uid'] = http::browserUID(DC_MASTER_KEY); |
| 98 | $_SESSION['sess_blog_id'] = 'default'; |
| 99 | $this->createUser(); |
| 100 | header("Location: http://murphy.m4x.org" . $_GET['path']); |
| 101 | exit; |
| 102 | } |
| 103 | unset($_SESSION['auth-xorg']); |
| 104 | unset($_SESSION['sess_user_id']); |
| 105 | unset($_GET['auth']); |
| 106 | echo "Failed !!!"; |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | public function killSession() { |
| 111 | global $core; |
| 112 | $core->session->start(); |
| 113 | $core->session->destroy(); |
| 114 | header('Location: http://murphy.m4x.org/~x2003bruneau/dotclear/'); |
| 115 | exit; |
| 116 | } |
| 117 | |
| 118 | public function checkUser($user_id, $pwd = null, $user_key = null) { |
| 119 | return $this->callXorg(); |
| 120 | } |
| 121 | |
| 122 | public function check($permissions, $blog_id) { |
| 123 | $this->buildFromSession(); |
| 124 | return parent::check($permissions, $blog_id); |
| 125 | } |
| 126 | |
| 127 | public function allowPassChange() { |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | public function userID() { |
| 132 | $this->buildFromSession(); |
| 133 | return parent::userID(); |
| 134 | } |
| 135 | |
| 136 | public function getPermissions() { |
| 137 | $this->buildFromSession(); |
| 138 | return parent::getPermissions(); |
| 139 | } |
| 140 | |
| 141 | public function getInfo($n) { |
| 142 | $this->buildFromSession(); |
| 143 | return parent::getInfo($n); |
| 144 | } |
| 145 | |
| 146 | public function getOption($n) { |
| 147 | $this->buildFromSession(); |
| 148 | return parent::getOption($n); |
| 149 | } |
| 150 | |
| 151 | public function isSuperAdmin() { |
| 152 | return $this->forceSU || ($this->user_id == 'florent.bruneau.2003'); |
| 153 | } |
| 154 | |
| 155 | public function getOptions() { |
| 156 | $this->buildFromSession(); |
| 157 | return parent::getOptions(); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | ?> |