ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilECSSettings.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 {
35  const ERROR_EXTRACT_SERIAL = 'ecs_error_extract_serial';
36  const ERROR_REQUIRED = 'fill_out_all_required_fields';
37  const ERROR_INVALID_IMPORT_ID = 'ecs_check_import_id';
38 
39  const DEFAULT_DURATION = 6;
40 
41 
42  const PROTOCOL_HTTP = 0;
43  const PROTOCOL_HTTPS = 1;
44 
45  protected static $instance = null;
46 
47  private $active = false;
48  private $server;
49  private $protocol;
50  private $port;
52  private $ca_cert_path;
53  private $key_path;
54  private $key_pathword;
55  private $polling;
56  private $import_id;
57  private $cert_serial;
58  private $global_role;
59  private $duration;
60 
61  private $user_recipients = array();
62  private $econtent_recipients = array();
63  private $approval_recipients = array();
64 
70  private function __construct()
71  {
72  $this->initStorage();
73  $this->read();
74  }
75 
83  public static function _getInstance()
84  {
85  if(self::$instance)
86  {
87  return self::$instance;
88  }
89  return self::$instance = new ilECSSettings();
90  }
91 
99  public function setEnabledStatus($a_status)
100  {
101  $this->active = $a_status;
102  }
103 
110  public function isEnabled()
111  {
112  return $this->active;
113  }
114 
122  public function setServer($a_server)
123  {
124  $this->server = $a_server;
125  }
126 
134  public function getServer()
135  {
136  return $this->server;
137  }
138 
145  public function getServerURI()
146  {
147  switch($this->getProtocol())
148  {
149  case self::PROTOCOL_HTTP:
150  $uri = 'http://';
151  break;
152 
153  case self::PROTOCOL_HTTPS:
154  $uri = 'https://';
155  break;
156  }
157  $uri .= $this->getServer().':'.$this->getPort();
158  return $uri;
159  }
160 
168  public function setProtocol($a_prot)
169  {
170  $this->protocol = $a_prot;
171  }
172 
179  public function getProtocol()
180  {
181  return $this->protocol;
182  }
183 
191  public function setPort($a_port)
192  {
193  $this->port = $a_port;
194  }
195 
203  public function getPort()
204  {
205  return $this->port;
206  }
207 
215  public function setPollingTime($a_time)
216  {
217  $this->polling = $a_time;
218  }
219 
226  public function getPollingTime()
227  {
228  return $this->polling;
229  }
230 
237  public function getPollingTimeSeconds()
238  {
239  return (int) ($this->polling % 60);
240  }
241 
248  public function getPollingTimeMinutes()
249  {
250  return (int) ($this->polling / 60);
251  }
252 
261  public function setPollingTimeMS($a_min,$a_sec)
262  {
263  $this->setPollingTime(60 * $a_min + $a_sec);
264  }
265 
273  public function setClientCertPath($a_path)
274  {
275  $this->client_cert_path = $a_path;
276  }
277 
283  public function getClientCertPath()
284  {
286  }
287 
295  public function setCACertPath($a_ca)
296  {
297  $this->ca_cert_path = $a_ca;
298  }
299 
306  public function getCACertPath()
307  {
308  return $this->ca_cert_path;
309  }
310 
317  public function getKeyPath()
318  {
319  return $this->key_path;
320  }
321 
329  public function setKeyPath($a_path)
330  {
331  $this->key_path = $a_path;
332  }
333 
340  public function getKeyPassword()
341  {
342  return $this->key_password;
343  }
344 
352  public function setKeyPassword($a_pass)
353  {
354  $this->key_password = $a_pass;
355  }
356 
364  public function setImportId($a_id)
365  {
366  $this->import_id = $a_id;
367  }
368 
374  public function getImportId()
375  {
376  return $this->import_id;
377  }
378 
386  public function setCertSerialNumber($a_cert_serial)
387  {
388  $this->cert_serial_number = $a_cert_serial;
389  }
390 
397  public function getCertSerialNumber()
398  {
399  return $this->cert_serial_number;
400  }
401 
408  public function getGlobalRole()
409  {
410  return $this->global_role;
411  }
412 
420  public function setGlobalRole($a_role_id)
421  {
422  $this->global_role = $a_role_id;
423  }
424 
432  public function setDuration($a_duration)
433  {
434  $this->duration = $a_duration;
435  }
436 
443  public function getDuration()
444  {
445  return $this->duration ? $this->duration : self::DEFAULT_DURATION;
446  }
447 
454  public function getUserRecipients()
455  {
456  return explode(',',$this->user_recipients);
457  }
458 
465  public function getUserRecipientsAsString()
466  {
467  return $this->user_recipients;
468  }
469 
477  public function setUserRecipients($a_logins)
478  {
479  $this->user_recipients = $a_logins;
480  }
481 
488  public function getEContentRecipients()
489  {
490  return explode(',',$this->econtent_recipients);
491  }
492 
500  {
502  }
503 
511  public function setEContentRecipients($a_logins)
512  {
513  $this->econtent_recipients = $a_logins;
514  }
515 
522  public function getApprovalRecipients()
523  {
524  return explode(',',$this->approval_recipients);
525  }
526 
535  {
537  }
538 
545  public function setApprovalRecipients($a_rcp)
546  {
547  $this->approval_recipients = $a_rcp;
548  }
549 
558  public function validate()
559  {
560  if(!$this->isEnabled())
561  {
562  return '';
563  }
564  if(!$this->getServer() or !$this->getPort() or !$this->getClientCertPath() or !$this->getCACertPath()
565  or !$this->getKeyPath() or !$this->getKeyPassword() or !$this->getPollingTime() or !$this->getImportId()
566  or !$this->getGlobalRole() or !$this->getDuration())
567  {
568  return self::ERROR_REQUIRED;
569  }
570 
571  // Check import id
572  if(!$this->fetchSerialID())
573  {
575  }
576  if(!$this->checkImportId())
577  {
579  }
580  return '';
581  }
582 
589  public function checkImportId()
590  {
591  global $ilObjDataCache,$tree;
592 
593  if(!$this->getImportId())
594  {
595  return false;
596  }
597  if($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($this->getImportId())) != 'cat')
598  {
599  return false;
600  }
601  if($tree->isDeleted($this->getImportId()))
602  {
603  return false;
604  }
605  return true;
606  }
607 
614  public function save()
615  {
616  $this->storage->set('active',(int) $this->isEnabled());
617  $this->storage->set('server',$this->getServer());
618  $this->storage->set('port',$this->getPort());
619  $this->storage->set('protocol',$this->getProtocol());
620  $this->storage->set('client_cert_path',$this->getClientCertPath());
621  $this->storage->set('ca_cert_path',$this->getCACertPath());
622  $this->storage->set('key_path',$this->getKeyPath());
623  $this->storage->set('key_password',$this->getKeyPassword());
624  $this->storage->set('import_id',$this->getImportId());
625  $this->storage->set('polling',$this->getPollingTime());
626  $this->storage->set('cert_serial',$this->getCertSerialNumber());
627  $this->storage->set('global_role',(int) $this->getGlobalRole());
628  $this->storage->set('user_rcp',$this->getUserRecipientsAsString());
629  $this->storage->set('econtent_rcp',$this->getEContentRecipientsAsString());
630  $this->storage->set('approval_rcp',$this->getApprovalRecipientsAsString());
631  $this->storage->set('duration',$this->getDuration());
632  }
633 
640  private function fetchSerialID()
641  {
642  global $ilLog;
643 
644  if(function_exists('openssl_x509_parse') and $cert = openssl_x509_parse('file://'.$this->getClientCertPath()))
645  {
646  if(isset($cert['serialNumber']) and $cert['serialNumber'])
647  {
648  $this->setCertSerialNumber($cert['serialNumber']);
649  $ilLog->write(__METHOD__.': Serial number is '.$cert['serialNumber']);
650  return true;
651  }
652  }
653 
654  if(!file_exists($this->getClientCertPath()) or !is_readable($this->getClientCertPath()))
655  {
656  return false;
657  }
658  $lines = file($this->getClientCertPath());
659  $found = false;
660  foreach($lines as $line)
661  {
662  if(strpos($line,'Serial Number:') !== false)
663  {
664  $found = true;
665  $serial_line = explode(':',$line);
666  $serial = (int) trim($serial_line[1]);
667  break;
668 
669  }
670  }
671  if($found)
672  {
673  $this->setCertSerialNumber($serial);
674  return true;
675  }
676  else
677  {
678  return false;
679  }
680  }
681 
682 
688  private function initStorage()
689  {
690  include_once('./Services/Administration/classes/class.ilSetting.php');
691  $this->storage = new ilSetting('ecs');
692  }
693 
699  private function read()
700  {
701  $this->setServer($this->storage->get('server'));
702  $this->setProtocol($this->storage->get('protocol'));
703  $this->setPort($this->storage->get('port'));
704  $this->setClientCertPath($this->storage->get('client_cert_path'));
705  $this->setCACertPath($this->storage->get('ca_cert_path'));
706  $this->setKeyPath($this->storage->get('key_path'));
707  $this->setKeyPassword($this->storage->get('key_password'));
708  $this->setPollingTime($this->storage->get('polling',128));
709  $this->setImportId($this->storage->get('import_id'));
710  $this->setEnabledStatus((int) $this->storage->get('active'));
711  $this->setCertSerialNumber($this->storage->get('cert_serial'));
712  $this->setGlobalRole($this->storage->get('global_role'));
713  $this->econtent_recipients = $this->storage->get('econtent_rcp');
714  $this->approval_recipients = $this->storage->get('approval_rcp');
715  $this->user_recipients = $this->storage->get('user_rcp');
716  $this->setDuration($this->storage->get('duration'));
717  }
718 }
719 ?>