ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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.

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 }
static getTokenMaxLifetimeInSeconds()
string $session_id
setPath(string $path)
setIp(string $ip)
setSessionId(string $session_id)
setId(string $id)
setTimestamp(int $timestamp)
setTTL(int $ttl)
setClient(string $client)
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26

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

+ 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.

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 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static setSALT(string $salt)

References ilWACException\DATA_DIR_NON_WRITEABLE, and setSALT().

Referenced by initSalt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generateToken()

ilWACToken::generateToken ( )

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

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 }
setToken(string $token)
setRawToken(string $raw_token)

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

Referenced by __construct().

+ 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.

206 : string
207 {
208 return $this->client;
209 }

References $client.

Referenced by generateToken().

+ 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.

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

References $id.

◆ getIp()

ilWACToken::getIp ( )

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

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

References $ip.

◆ getPath()

ilWACToken::getPath ( )

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

164 : string
165 {
166 return $this->path;
167 }

References $path.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ getRawToken()

ilWACToken::getRawToken ( )

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

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

References $raw_token.

◆ getSALT()

static ilWACToken::getSALT ( )
static

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

194 : string
195 {
196 return self::$SALT;
197 }
static string $SALT

References $SALT.

Referenced by ilWACTokenTest\testTokenGeneration().

+ Here is the caller graph for this function:

◆ getSessionId()

ilWACToken::getSessionId ( )

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

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

References $session_id.

◆ getTimestamp()

ilWACToken::getTimestamp ( )

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

128 : int
129 {
130 return $this->timestamp;
131 }

References $timestamp.

Referenced by generateToken().

+ Here is the caller graph for this function:

◆ getToken()

ilWACToken::getToken ( )

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

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

References $token.

◆ getTTL()

ilWACToken::getTTL ( )

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

218 : int
219 {
220 return $this->ttl;
221 }

References $ttl.

Referenced by generateToken().

+ Here is the caller graph for this function:

◆ initSalt()

ilWACToken::initSalt ( )
protected

@noRector

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

76 : void
77 {
78 if (self::getSALT() !== '' && self::getSALT() !== '0') {
79 return;
80 }
81 $salt = '';
82 if (is_file(self::SALT_FILE_PATH)) {
85 self::setSALT($salt);
86 }
87
88 if (strcmp($salt, '') === 0) {
89 $this->generateSaltFile();
90 $this->initSalt();
91 }
92 }
const SALT_FILE_PATH

References generateSaltFile(), initSalt(), SALT_FILE_PATH, and setSALT().

Referenced by generateToken(), and initSalt().

+ 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.

212 : void
213 {
214 $this->client = $client;
215 }

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

Referenced by __construct().

+ 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.

188 : void
189 {
190 $this->id = $id;
191 }

References $id.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setIp()

ilWACToken::setIp ( string  $ip)

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

146 : void
147 {
148 $this->ip = $ip;
149 }

References $ip.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setPath()

ilWACToken::setPath ( string  $path)

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

170 : void
171 {
172 $this->path = $path;
173 }

References $path.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRawToken()

ilWACToken::setRawToken ( string  $raw_token)

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

236 : void
237 {
238 $this->raw_token = $raw_token;
239 }

References $raw_token.

Referenced by generateToken().

+ Here is the caller graph for this function:

◆ setSALT()

static ilWACToken::setSALT ( string  $salt)
static

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

200 : void
201 {
202 self::$SALT = $salt;
203 }

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

+ Here is the caller graph for this function:

◆ setSessionId()

ilWACToken::setSessionId ( string  $session_id)

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

122 : void
123 {
124 $this->session_id = $session_id;
125 }

References $session_id.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setTimestamp()

ilWACToken::setTimestamp ( int  $timestamp)

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

134 : void
135 {
136 $this->timestamp = $timestamp;
137 }

References $timestamp.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setToken()

ilWACToken::setToken ( string  $token)

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

158 : void
159 {
160 $this->token = $token;
161 }

References $token.

Referenced by generateToken().

+ Here is the caller graph for this function:

◆ setTTL()

ilWACToken::setTTL ( int  $ttl)

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

224 : void
225 {
226 $this->ttl = $ttl;
227 }

References $ttl.

Referenced by __construct().

+ 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.

Referenced by getSALT().

◆ $session_id

string ilWACToken::$session_id = ''
protected

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

Referenced by __construct(), getSessionId(), and setSessionId().

◆ $timestamp

int ilWACToken::$timestamp = 0
protected

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

Referenced by __construct(), getTimestamp(), and setTimestamp().

◆ $token

string ilWACToken::$token = ''
protected

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

Referenced by generateToken(), 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.

Referenced by initSalt().


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