ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilWACToken Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilWACToken:

Public Member Functions

 __construct (string $path, string $client, int $timestamp=0, int $ttl=0)
 ilWACToken constructor. More...
 
 generateToken ()
 
 getSessionId ()
 
 setSessionId (string $session_id)
 
 getTimestamp ()
 
 setTimestamp (int $timestamp)
 
 getIp ()
 
 setIp (string $ip)
 
 getToken ()
 
 setToken (string $token)
 
 getPath ()
 
 setPath (string $path)
 
 getId ()
 
 getHashedId ()
 
 setId (string $id)
 
 getClient ()
 
 setClient (string $client)
 
 getTTL ()
 
 setTTL (int $ttl)
 
 getRawToken ()
 
 setRawToken (string $raw_token)
 

Static Public Member Functions

static getSALT ()
 
static setSALT (string $salt)
 

Protected Member Functions

 initSalt ()
 
 generateSaltFile ()
 

Protected Attributes

string $session_id = ''
 
int $timestamp = 0
 
string $ip = ''
 
string $token = ''
 
string $raw_token = ''
 
string $path = ''
 
string $id = ''
 
string $client = ''
 
int $ttl = 0
 

Static Protected Attributes

static string $SALT = ''
 

Private Attributes

const SALT_FILE_PATH = __DIR__ . '/../../../../public/data/wacsalt.php'
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Definition at line 19 of file class.ilWACToken.php.

Constructor & Destructor Documentation

◆ __construct()

ilWACToken::__construct ( string  $path,
string  $client,
int  $timestamp = 0,
int  $ttl = 0 
)

ilWACToken constructor.

Definition at line 40 of file class.ilWACToken.php.

References $_SERVER, $ttl, generateToken(), getPath(), ilWACSignedPath\getTokenMaxLifetimeInSeconds(), setClient(), setId(), setIp(), setPath(), setSessionId(), setTimestamp(), and setTTL().

45  {
46  $this->setClient($client);
47  $this->setPath($path);
48  $session_id = session_id();
49  $this->setSessionId($session_id ?: '-');
50  if (isset($_SERVER['REMOTE_ADDR'])) {
51  $this->setIp($_SERVER['REMOTE_ADDR']);
52  }
53  $this->setTimestamp($timestamp !== 0 ? $timestamp : time());
55  $this->setTTL($ttl); // since we do not know the type at this poit we choose the shorter duration for security reasons
56  $this->generateToken();
57  $this->setId($this->getPath());
58  }
setId(string $id)
setIp(string $ip)
setSessionId(string $session_id)
string $session_id
setPath(string $path)
setTimestamp(int $timestamp)
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
setTTL(int $ttl)
setClient(string $client)
static getTokenMaxLifetimeInSeconds()
+ Here is the call graph for this function:

Member Function Documentation

◆ generateSaltFile()

ilWACToken::generateSaltFile ( )
protected
Exceptions
ilWACException

Definition at line 98 of file class.ilWACToken.php.

References ilWACException\DATA_DIR_NON_WRITEABLE.

Referenced by initSalt().

98  : void
99  {
100  if (is_file(self::SALT_FILE_PATH)) {
101  unlink(self::SALT_FILE_PATH);
102  }
103  $template = file_get_contents(__DIR__ . '/../wacsalt.php.template');
104  $random = new \Random\Randomizer();
105  $salt = md5(time() * $random->getInt(1000, 9999) . self::SALT_FILE_PATH);
106  self::setSALT($salt);
107  $template = str_replace('INSERT_SALT', $salt, $template);
108  if (is_writable(dirname(self::SALT_FILE_PATH))) {
109  file_put_contents(self::SALT_FILE_PATH, $template);
110  } else {
111  throw new ilWACException(ilWACException::DATA_DIR_NON_WRITEABLE, self::SALT_FILE_PATH);
112  }
113  }
+ Here is the caller graph for this function:

◆ generateToken()

ilWACToken::generateToken ( )

Definition at line 61 of file class.ilWACToken.php.

References getClient(), getTimestamp(), getTTL(), initSalt(), setRawToken(), and setToken().

Referenced by __construct(), and ilWACTokenTest\testTokenGeneration().

61  : void
62  {
63  $this->initSalt();
64  $token = implode('-', [
65  self::getSALT(),
66  $this->getClient(),
67  $this->getTimestamp(),
68  $this->getTTL(),
69  ]);
70  $this->setRawToken($token);
71  $token = sha1($token);
72  $this->setToken($token);
73  }
setRawToken(string $raw_token)
setToken(string $token)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getClient()

ilWACToken::getClient ( )

Definition at line 206 of file class.ilWACToken.php.

References $client.

Referenced by generateToken().

206  : string
207  {
208  return $this->client;
209  }
+ Here is the caller graph for this function:

◆ getHashedId()

ilWACToken::getHashedId ( )

Definition at line 182 of file class.ilWACToken.php.

182  : string
183  {
184  return md5($this->id);
185  }

◆ getId()

ilWACToken::getId ( )

Definition at line 176 of file class.ilWACToken.php.

References $id.

176  : string
177  {
178  return $this->id;
179  }

◆ getIp()

ilWACToken::getIp ( )

Definition at line 140 of file class.ilWACToken.php.

References $ip.

140  : string
141  {
142  return $this->ip;
143  }

◆ getPath()

ilWACToken::getPath ( )

Definition at line 164 of file class.ilWACToken.php.

References $path.

Referenced by __construct().

164  : string
165  {
166  return $this->path;
167  }
+ Here is the caller graph for this function:

◆ getRawToken()

ilWACToken::getRawToken ( )

Definition at line 230 of file class.ilWACToken.php.

References $raw_token.

230  : string
231  {
232  return $this->raw_token;
233  }

◆ getSALT()

static ilWACToken::getSALT ( )
static

Definition at line 194 of file class.ilWACToken.php.

Referenced by ilWACTokenTest\testTokenGeneration().

194  : string
195  {
196  return self::$SALT;
197  }
+ Here is the caller graph for this function:

◆ getSessionId()

ilWACToken::getSessionId ( )

Definition at line 116 of file class.ilWACToken.php.

References $session_id.

116  : string
117  {
118  return $this->session_id;
119  }
string $session_id

◆ getTimestamp()

ilWACToken::getTimestamp ( )

Definition at line 128 of file class.ilWACToken.php.

References $timestamp.

Referenced by generateToken().

128  : int
129  {
130  return $this->timestamp;
131  }
+ Here is the caller graph for this function:

◆ getToken()

ilWACToken::getToken ( )

Definition at line 152 of file class.ilWACToken.php.

References $token.

152  : string
153  {
154  return $this->token;
155  }

◆ getTTL()

ilWACToken::getTTL ( )

Definition at line 218 of file class.ilWACToken.php.

References $ttl.

Referenced by generateToken().

218  : int
219  {
220  return $this->ttl;
221  }
+ Here is the caller graph for this function:

◆ initSalt()

ilWACToken::initSalt ( )
protected

Definition at line 76 of file class.ilWACToken.php.

References generateSaltFile().

Referenced by generateToken().

76  : void
77  {
78  if (self::getSALT() !== '' && self::getSALT() !== '0') {
79  return;
80  }
81  $salt = '';
82  if (is_file(self::SALT_FILE_PATH)) {
84  require self::SALT_FILE_PATH;
85  self::setSALT($salt);
86  }
87 
88  if (strcmp($salt, '') === 0) {
89  $this->generateSaltFile();
90  $this->initSalt();
91  }
92  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setClient()

ilWACToken::setClient ( string  $client)

Definition at line 212 of file class.ilWACToken.php.

References $client, and ILIAS\UI\examples\Progress\Bar\client().

Referenced by __construct().

212  : void
213  {
214  $this->client = $client;
215  }
client()
description: > This example shows how a Progress Bar can be rendered and used on the client...
Definition: client.php:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setId()

ilWACToken::setId ( string  $id)

Definition at line 188 of file class.ilWACToken.php.

References $id.

Referenced by __construct().

188  : void
189  {
190  $this->id = $id;
191  }
+ Here is the caller graph for this function:

◆ setIp()

ilWACToken::setIp ( string  $ip)

Definition at line 146 of file class.ilWACToken.php.

References $ip.

Referenced by __construct().

146  : void
147  {
148  $this->ip = $ip;
149  }
+ Here is the caller graph for this function:

◆ setPath()

ilWACToken::setPath ( string  $path)

Definition at line 170 of file class.ilWACToken.php.

References $path.

Referenced by __construct().

170  : void
171  {
172  $this->path = $path;
173  }
+ Here is the caller graph for this function:

◆ setRawToken()

ilWACToken::setRawToken ( string  $raw_token)

Definition at line 236 of file class.ilWACToken.php.

References $raw_token.

Referenced by generateToken().

236  : void
237  {
238  $this->raw_token = $raw_token;
239  }
+ Here is the caller graph for this function:

◆ setSALT()

static ilWACToken::setSALT ( string  $salt)
static

Definition at line 200 of file class.ilWACToken.php.

Referenced by ilWACCheckingInstanceTest\setUp(), and ilWACTokenTest\setUp().

200  : void
201  {
202  self::$SALT = $salt;
203  }
+ Here is the caller graph for this function:

◆ setSessionId()

ilWACToken::setSessionId ( string  $session_id)

Definition at line 122 of file class.ilWACToken.php.

References $session_id.

Referenced by __construct().

122  : void
123  {
124  $this->session_id = $session_id;
125  }
string $session_id
+ Here is the caller graph for this function:

◆ setTimestamp()

ilWACToken::setTimestamp ( int  $timestamp)

Definition at line 134 of file class.ilWACToken.php.

References $timestamp.

Referenced by __construct().

134  : void
135  {
136  $this->timestamp = $timestamp;
137  }
+ Here is the caller graph for this function:

◆ setToken()

ilWACToken::setToken ( string  $token)

Definition at line 158 of file class.ilWACToken.php.

References $token.

Referenced by generateToken().

158  : void
159  {
160  $this->token = $token;
161  }
+ Here is the caller graph for this function:

◆ setTTL()

ilWACToken::setTTL ( int  $ttl)

Definition at line 224 of file class.ilWACToken.php.

References $ttl.

Referenced by __construct().

224  : void
225  {
226  $this->ttl = $ttl;
227  }
+ Here is the caller graph for this function:

Field Documentation

◆ $client

string ilWACToken::$client = ''
protected

Definition at line 33 of file class.ilWACToken.php.

Referenced by getClient(), and setClient().

◆ $id

string ilWACToken::$id = ''
protected

Definition at line 32 of file class.ilWACToken.php.

Referenced by getId(), and setId().

◆ $ip

string ilWACToken::$ip = ''
protected

Definition at line 28 of file class.ilWACToken.php.

Referenced by getIp(), and setIp().

◆ $path

string ilWACToken::$path = ''
protected

Definition at line 31 of file class.ilWACToken.php.

Referenced by getPath(), and setPath().

◆ $raw_token

string ilWACToken::$raw_token = ''
protected

Definition at line 30 of file class.ilWACToken.php.

Referenced by getRawToken(), and setRawToken().

◆ $SALT

string ilWACToken::$SALT = ''
staticprotected

Definition at line 25 of file class.ilWACToken.php.

◆ $session_id

string ilWACToken::$session_id = ''
protected

Definition at line 26 of file class.ilWACToken.php.

Referenced by getSessionId(), and setSessionId().

◆ $timestamp

int ilWACToken::$timestamp = 0
protected

Definition at line 27 of file class.ilWACToken.php.

Referenced by getTimestamp(), and setTimestamp().

◆ $token

string ilWACToken::$token = ''
protected

Definition at line 29 of file class.ilWACToken.php.

Referenced by getToken(), and setToken().

◆ $ttl

int ilWACToken::$ttl = 0
protected

Definition at line 34 of file class.ilWACToken.php.

Referenced by __construct(), getTTL(), and setTTL().

◆ SALT_FILE_PATH

const ilWACToken::SALT_FILE_PATH = __DIR__ . '/../../../../public/data/wacsalt.php'
private

Definition at line 24 of file class.ilWACToken.php.


The documentation for this class was generated from the following file: