ILIAS  release_8 Revision v8.23
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 = './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 Class ilWACToken

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
1.0.0

Definition at line 24 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 42 of file class.ilWACToken.php.

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

47  {
48  $this->setClient($client);
49  $this->setPath($path);
50  $session_id = session_id();
51  $this->setSessionId($session_id ?: '-');
52  if (isset($_SERVER['REMOTE_ADDR'])) {
53  $this->setIp($_SERVER['REMOTE_ADDR']);
54  }
55  $this->setTimestamp($timestamp !== 0 ? $timestamp : time());
57  $this->setTTL($ttl); // since we do not know the type at this poit we choose the shorter duration for security reasons
58  $this->generateToken();
59  $this->setId($this->getPath());
60  }
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:10
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 100 of file class.ilWACToken.php.

References ilWACException\DATA_DIR_NON_WRITEABLE.

Referenced by initSalt().

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

◆ generateToken()

ilWACToken::generateToken ( )

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

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

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

63  : void
64  {
65  $this->initSalt();
66  $token = implode('-', array(
67  self::getSALT(),
68  $this->getClient(),
69  $this->getTimestamp(),
70  $this->getTTL(),
71  ));
72  $this->setRawToken($token);
73  $token = sha1($token);
74  $this->setToken($token);
75  }
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 208 of file class.ilWACToken.php.

References $client.

Referenced by generateToken().

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

◆ getHashedId()

ilWACToken::getHashedId ( )

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

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

◆ getId()

ilWACToken::getId ( )

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

References $id.

178  : string
179  {
180  return $this->id;
181  }

◆ getIp()

ilWACToken::getIp ( )

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

References $ip.

142  : string
143  {
144  return $this->ip;
145  }

◆ getPath()

ilWACToken::getPath ( )

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

References $path.

Referenced by __construct().

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

◆ getRawToken()

ilWACToken::getRawToken ( )

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

References $raw_token.

232  : string
233  {
234  return $this->raw_token;
235  }

◆ getSALT()

static ilWACToken::getSALT ( )
static

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

Referenced by ilWACTokenTest\testTokenGeneration().

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

◆ getSessionId()

ilWACToken::getSessionId ( )

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

References $session_id.

118  : string
119  {
120  return $this->session_id;
121  }
string $session_id

◆ getTimestamp()

ilWACToken::getTimestamp ( )

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

References $timestamp.

Referenced by generateToken().

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

◆ getToken()

ilWACToken::getToken ( )

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

References $token.

154  : string
155  {
156  return $this->token;
157  }

◆ getTTL()

ilWACToken::getTTL ( )

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

References $ttl.

Referenced by generateToken().

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

◆ initSalt()

ilWACToken::initSalt ( )
protected

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

References generateSaltFile().

Referenced by generateToken().

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

◆ setClient()

ilWACToken::setClient ( string  $client)

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

References $client.

Referenced by __construct().

214  : void
215  {
216  $this->client = $client;
217  }
+ Here is the caller graph for this function:

◆ setId()

ilWACToken::setId ( string  $id)

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

References $id.

Referenced by __construct().

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

◆ setIp()

ilWACToken::setIp ( string  $ip)

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

References $ip.

Referenced by __construct().

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

◆ setPath()

ilWACToken::setPath ( string  $path)

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

References $path.

Referenced by __construct().

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

◆ setRawToken()

ilWACToken::setRawToken ( string  $raw_token)

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

References $raw_token.

Referenced by generateToken().

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

◆ setSALT()

static ilWACToken::setSALT ( string  $salt)
static

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

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

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

◆ setSessionId()

ilWACToken::setSessionId ( string  $session_id)

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

References $session_id.

Referenced by __construct().

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

◆ setTimestamp()

ilWACToken::setTimestamp ( int  $timestamp)

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

References $timestamp.

Referenced by __construct().

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

◆ setToken()

ilWACToken::setToken ( string  $token)

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

References $token.

Referenced by generateToken().

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

◆ setTTL()

ilWACToken::setTTL ( int  $ttl)

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

References $ttl.

Referenced by __construct().

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

Field Documentation

◆ $client

string ilWACToken::$client = ''
protected

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

Referenced by getClient(), and setClient().

◆ $id

string ilWACToken::$id = ''
protected

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

Referenced by getId(), and setId().

◆ $ip

string ilWACToken::$ip = ''
protected

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

Referenced by getIp(), and setIp().

◆ $path

string ilWACToken::$path = ''
protected

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

Referenced by getPath(), and setPath().

◆ $raw_token

string ilWACToken::$raw_token = ''
protected

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

Referenced by getRawToken(), and setRawToken().

◆ $SALT

string ilWACToken::$SALT = ''
staticprotected

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

◆ $session_id

string ilWACToken::$session_id = ''
protected

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

Referenced by getSessionId(), and setSessionId().

◆ $timestamp

int ilWACToken::$timestamp = 0
protected

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

Referenced by getTimestamp(), and setTimestamp().

◆ $token

string ilWACToken::$token = ''
protected

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

Referenced by getToken(), and setToken().

◆ $ttl

int ilWACToken::$ttl = 0
protected

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

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

◆ SALT_FILE_PATH

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

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


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