BAOBAB
co_cobra_login.class.php
Go to the documentation of this file.
1 <?php
2 /***************************************************************************************************************************/
26 defined( 'LGV_ACCESS_CATCHER' ) or die ( 'Cannot Execute Directly' ); // Makes sure that this file is in the correct context.
27 
28 require_once(CO_Config::db_classes_class_dir().'/co_security_login.class.php');
29 require_once(dirname(__FILE__).'/co_login_manager.class.php');
30 
31 /***************************************************************************************************************************/
36 
37  /***********************************************************************************************************************/
38  /***********************/
42  public function __construct( $in_login_id = NULL,
43  $in_hashed_password = NULL,
44  $in_raw_password = NULL
45  ) {
46  parent::__construct($in_login_id, $in_hashed_password, $in_raw_password);
47 
48  $this->_special_first_time_security_exemption = true;
49  if (intval($this->id()) == intval(CO_Config::god_mode_id())) {
50  // God Mode is always forced to use the config password.
51  $this->context['hashed_password'] = bin2hex(openssl_random_pseudo_bytes(4)); // Just create a randomish junk password. It will never be used.
52  $this->instance_description = 'GOD MODE: '.(isset($this->name) && $this->name ? "$this->name (".$this->login_id.")" : "Unnamed Standard Login Node (".$this->login_id.")");
53  } else {
54  $this->instance_description = isset($this->name) && $this->name ? "$this->name (".$this->login_id.")" : "Unnamed Standard Login Node (".$this->login_id.")";
55  }
56  }
57 
58  /***********************/
68  public function set_personal_ids( $in_personal_ids = []
69  ) {
70  $personal_ids_temp = array_unique(array_map('intval', $in_personal_ids));
71  if (CO_Config::use_personal_tokens() && (NULL == $this->_personal_ids) && is_array($personal_ids_temp) && count($personal_ids_temp)) {
72  $personal_ids = [];
73  $my_ids = $this->_ids;
74  // None of the ids can be in the regular IDs, and will be removed from the set, if so.
75  // They also cannot be anyone else's personal ID, or anyone's login ID. Personal IDs can ONLY be regular (non-login) security objects.
76  foreach($personal_ids_temp as $id) {
77  // Make sure that we don't have this personal token in our regular ID array.
78  if (($key = array_search($id, $my_ids)) !== false) {
79  unset($my_ids[$key]);
80  }
81  if (!$this->get_access_object()->is_this_a_login_id($id) && (!$this->get_access_object()->is_this_a_personal_id($id) || in_array($id, $this->_personal_ids))) {
82  array_push($personal_ids, $id);
83  }
84  }
85  $this->_ids = $my_ids;
86  sort($personal_ids);
87  $this->_personal_ids = $personal_ids;
88 
89  $this->update_db();
90  } else { // If we are not NULL, then we kick the can down the road.
91  parent::set_personal_ids($in_personal_ids);
92  }
93 
94  return $this->_personal_ids;
95  }
96 
97  /***********************/
103  public function load_from_db($in_db_result) {
104  $ret = parent::load_from_db($in_db_result);
105 
106  if ($ret) {
107  $this->class_description = 'This is a security class for standard logins.';
108  if (intval($this->id()) == intval(CO_Config::god_mode_id())) {
109  // God Mode is always forced to use the config password.
110  $this->context['hashed_password'] = bin2hex(openssl_random_pseudo_bytes(4)); // Just create a randomish junk password. It will never be used.
111  $this->instance_description = 'GOD MODE: '.(isset($this->name) && $this->name ? "$this->name (".$this->login_id.")" : "Unnamed Standard Login Node (".$this->login_id.")");
112  } else {
113  $this->instance_description = isset($this->name) && $this->name ? "$this->name (".$this->login_id.")" : "Unnamed Standard Login Node (".$this->login_id.")";
114  }
115  }
116 
117  return $ret;
118  }
119 
120  /***********************/
127  public function security_exemption() {
128  $ret = $this->_special_first_time_security_exemption;
129  $this->_special_first_time_security_exemption = false;
130 
131  return $ret;
132  }
133 };
set_personal_ids( $in_personal_ids=[])
__construct( $in_login_id=NULL, $in_hashed_password=NULL, $in_raw_password=NULL)
load_from_db($in_db_result)