ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ExpiryDate.php
Go to the documentation of this file.
1 <?php
2 
24 
25  private $warndaysbefore = 0;
26  private $netid_attr = NULL;
27  private $expirydate_attr = NULL;
28  private $date_format = 'd.m.Y';
29 
30 
37  public function __construct($config, $reserved) {
38  parent::__construct($config, $reserved);
39 
40  assert('is_array($config)');
41 
42  if (array_key_exists('warndaysbefore', $config)) {
43  $this->warndaysbefore = $config['warndaysbefore'];
44  if (!is_string($this->warndaysbefore)) {
45  throw new Exception('Invalid value for number of days given to expirycheck::ExpiryDate filter.');
46  }
47  }
48 
49  if (array_key_exists('netid_attr', $config)) {
50  $this->netid_attr = $config['netid_attr'];
51  if (!is_string($this->netid_attr)) {
52  throw new Exception('Invalid attribute name given as eduPersonPrincipalName to expirycheck::ExpiryDate filter.');
53  }
54  }
55 
56  if (array_key_exists('expirydate_attr', $config)) {
57  $this->expirydate_attr = $config['expirydate_attr'];
58  if (!is_string($this->expirydate_attr)) {
59  throw new Exception('Invalid attribute name given as schacExpiryDate to expirycheck::ExpiryDate filter.');
60  }
61  }
62 
63  if (array_key_exists('date_format', $config)) {
64  $this->date_format = $config['date_format'];
65  if (!is_string($this->date_format)) {
66  throw new Exception('Invalid date format given to expirycheck::ExpiryDate filter.');
67  }
68  }
69  }
70 
78  public function shWarning(&$state, $expireOnDate, $warndaysbefore) {
79  $now = time();
80  $end = $expireOnDate;
81 
82  if ($expireOnDate >= $now) {
83  $days = (int)(($end - $now) / (24*60*60));
84  if ($days <= $warndaysbefore) {
85  $state['daysleft'] = $days;
86  return true;
87  }
88  }
89  return false;
90  }
91 
98  public function checkDate($expireOnDate) {
99  $now = time();
100  $end = $expireOnDate;
101 
102  if ($now <= $end) {
103  return true;
104  } else {
105  return false;
106  }
107 
108  }
109 
115  public function process(&$state) {
116  /*
117  * UTC format: 20090527080352Z
118  */
119  $netId = $state['Attributes'][$this->netid_attr][0];
120  $expireOnDate = strtotime($state['Attributes'][$this->expirydate_attr][0]);
121 
122  if (self::shWarning($state, $expireOnDate, $this->warndaysbefore)) {
123  assert('is_array($state)');
124  if (isset($state['isPassive']) && $state['isPassive'] === TRUE) {
125  // We have a passive request. Skip the warning.
126  return;
127  }
128 
129  SimpleSAML\Logger::warning('expirycheck: NetID ' . $netId .
130  ' is about to expire!');
131 
132  // Save state and redirect
133  $state['expireOnDate'] = date($this->date_format, $expireOnDate);
134  $state['netId'] = $netId;
135  $id = SimpleSAML_Auth_State::saveState($state, 'expirywarning:about2expire');
136  $url = SimpleSAML\Module::getModuleURL('expirycheck/about2expire.php');
138  }
139 
140  if (!self::checkDate($expireOnDate)) {
141  SimpleSAML\Logger::error('expirycheck: NetID ' . $netId .
142  ' has expired [' . date($this->date_format, $expireOnDate) . ']. Access denied!');
144 
145  /* Save state and redirect. */
146  $state['expireOnDate'] = date($this->date_format, $expireOnDate);
147  $state['netId'] = $netId;
148  $id = SimpleSAML_Auth_State::saveState($state, 'expirywarning:expired');
149  $url = SimpleSAML\Module::getModuleURL('expirycheck/expired.php');
151 
152  }
153  }
154 
155 
156 }
shWarning(&$state, $expireOnDate, $warndaysbefore)
Show expirational warning if remaining days is equal or under defined $warndaysbefore.
Definition: ExpiryDate.php:78
$end
Definition: saml1-acs.php:18
if(!array_key_exists('StateId', $_REQUEST)) $id
static redirectTrustedURL($url, $parameters=array())
This function redirects to the specified URL without performing any security checks.
Definition: HTTP.php:962
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
Definition: Module.php:303
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
static warning($string)
Definition: Logger.php:179
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
static error($string)
Definition: Logger.php:168
Create styles array
The data for the language used.
$globalConfig
__construct($config, $reserved)
Initialize this filter.
Definition: ExpiryDate.php:37
checkDate($expireOnDate)
Check if given date is older than today.
Definition: ExpiryDate.php:98
$url
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static saveState(&$state, $stage, $rawId=false)
Save the state.
Definition: State.php:194
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.