ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilWACToken.php
Go to the documentation of this file.
1<?php
2require_once('class.ilWACSignedPath.php');
3
11
12 const DEBUG = false;
18 protected static $SALT = '';
22 protected $session_id = '';
26 protected $timestamp = 0;
30 protected $ip = '';
34 protected $token = '';
38 protected $raw_token = '';
42 protected $path = '';
46 protected $id = '';
50 protected $client = '';
54 protected $ttl = 0;
55
56
64 public function __construct($path, $client, $timestamp = null, $ttl = null) {
65 $this->setClient($client);
66 $this->setPath($path);
67 $session_id = session_id();
68 $this->setSessionId($session_id ? $session_id : '-');
69 if (isset($_SERVER['REMOTE_ADDR'])) {
70 $this->setIp($_SERVER['REMOTE_ADDR']);
71 }
72 $this->setTimestamp($timestamp ? $timestamp : time());
74 $this->setTTL($ttl); // since we do not know the type at this poit we choose the shorter duration for security reasons
75 $this->generateToken();
76 $this->setId($this->getPath());
77 }
78
79
83 protected static function isDEBUG() {
85 }
86
87
88 public function generateToken() {
89 $this->initSalt();
90 $token = implode('-', array(
91 self::getSALT(),
92 $this->getClient(),
93 $this->getTimestamp(),
94 $this->getTTL(),
95 ));
96 $this->setRawToken($token);
97 $token = sha1($token);
98 $this->setToken($token);
99 }
100
101
105 protected function getSaltFilePath() {
106 $salt_file = './data/wacsalt.php';
107
108 return $salt_file;
109 }
110
111
112 protected function initSalt() {
113 if (self::getSALT()) {
114 return true;
115 }
116 $salt = null;
117 if (is_file($this->getSaltFilePath())) {
118 include($this->getSaltFilePath());
119 }
120 self::setSALT($salt);
121 if (!$salt) {
122 $this->generateSaltFile();
123 }
124 }
125
126
127 protected function generateSaltFile() {
128 if (is_file($this->getSaltFilePath())) {
129 unlink($this->getSaltFilePath());
130 }
131 $template = file_get_contents('./Services/WebAccessChecker/wacsalt.php.template');
132 $salt = md5(time() * rand(1000, 9999) . $this->getSaltFilePath());
133 self::setSALT($salt);
134 $template = str_replace('INSERT_SALT', $salt, $template);
135 if (is_writable(dirname($this->getSaltFilePath()))) {
136 file_put_contents($this->getSaltFilePath(), $template);
137 } else {
139 }
140 }
141
142
146 public function getSessionId() {
147 return $this->session_id;
148 }
149
150
154 public function setSessionId($session_id) {
155 $this->session_id = $session_id;
156 }
157
158
162 public function getTimestamp() {
163 return $this->timestamp;
164 }
165
166
170 public function setTimestamp($timestamp) {
171 $this->timestamp = $timestamp;
172 }
173
174
178 public function getIp() {
179 return $this->ip;
180 }
181
182
186 public function setIp($ip) {
187 $this->ip = $ip;
188 }
189
190
194 public function getToken() {
195 return $this->token;
196 }
197
198
202 public function setToken($token) {
203 $this->token = $token;
204 }
205
206
210 public function getPath() {
211 return $this->path;
212 }
213
214
218 public function setPath($path) {
219 $this->path = $path;
220 }
221
222
226 public function getId() {
227 return $this->id;
228 }
229
230
234 public function getHashedId() {
235 return md5($this->id);
236 }
237
238
242 public function setId($id) {
243 $this->id = $id;
244 }
245
246
250 public static function getSALT() {
251 return self::$SALT;
252 }
253
254
258 public static function setSALT($SALT) {
259 self::$SALT = $SALT;
260 }
261
262
266 public function getClient() {
267 return $this->client;
268 }
269
270
274 public function setClient($client) {
275 $this->client = $client;
276 }
277
278
282 public function getTTL() {
283 return $this->ttl;
284 }
285
286
290 public function setTTL($ttl) {
291 $this->ttl = $ttl;
292 }
293
294
298 public function getRawToken() {
299 return $this->raw_token;
300 }
301
302
306 public function setRawToken($raw_token) {
307 $this->raw_token = $raw_token;
308 }
309}
An exception for terminatinating execution or to throw for unit testing.
Class ilWACException.
static getTokenMaxLifetimeInSeconds()
Class ilWACToken.
static getSALT()
static isDEBUG()
setSessionId($session_id)
__construct($path, $client, $timestamp=null, $ttl=null)
ilWACToken constructor.
setRawToken($raw_token)
setTimestamp($timestamp)
setClient($client)
static setSALT($SALT)
const DEBUG
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']