26 defined(
'LGV_ACCESS_CATCHER' ) or die ( 'Cannot Execute Directly' );
30 require_once(CO_Config::chameleon_main_class_dir().'/co_chameleon.class.php');
32 if ( !defined('LGV_LANG_CATCHER') ) {
33 define(
'LGV_LANG_CATCHER', 1);
36 require_once(CO_Config::cobra_lang_class_dir().
'/common.inc.php');
63 if (isset($in_chameleon_instance)
65 && $in_chameleon_instance->security_db_available()
66 && ($in_chameleon_instance->god_mode() || ($in_chameleon_instance->get_login_item() instanceof
CO_Login_Manager))) {
67 $ret =
new CO_Cobra($in_chameleon_instance);
68 } elseif (isset($in_chameleon_instance) && ($in_chameleon_instance instanceof
CO_Chameleon)) {
90 $this->_chameleon_instance = $in_chameleon_instance;
105 $manager = $this->_chameleon_instance->get_login_item();
106 if ($this->_chameleon_instance->god_mode() || ($manager instanceof
CO_Login_Manager)) {
107 $new_token = $this->_chameleon_instance->make_new_blank_record(
'CO_Security_ID');
108 if (isset($new_token) && ($new_token instanceof
CO_Security_ID)) {
109 $new_id = $new_token->id();
110 if (!$this->_chameleon_instance->error) {
113 $this->error = $this->_chameleon_instance->error;
139 for ($index = 0; $index < $in_count; $index++) {
154 $in_is_login_manager =
false
157 $working_login = $this->_chameleon_instance->get_login_item_by_login_string($in_login_id);
158 $manager = $this->_chameleon_instance->get_login_item();
160 if ($working_login && $working_login->user_can_write() && ($manager instanceof
CO_Login_Manager || $manager->
is_god())) {
162 if (($in_is_login_manager && !$working_login->is_manager()) || (!$in_is_login_manager && $working_login->is_manager())) {
163 $className = $in_is_login_manager ?
'CO_Login_Manager' :
'CO_Cobra_Login';
167 $new_login_object = $this->_chameleon_instance->make_new_blank_record($className);
169 if (isset($new_login_object) && ($new_login_object instanceof
CO_Cobra_Login)) {
170 $original_login_id = $working_login->id();
171 $original_ids = $working_login->ids();
172 if (!isset($original_ids)) {
176 array_push($original_ids, $original_login_id);
177 $original_ids = array_unique($original_ids);
179 asort($original_ids);
181 $new_login_object->login_id = $working_login->login_id;
182 $new_login_object->name = $working_login->name;
183 $new_login_object->context = $working_login->context;
184 $new_login_object->set_ids($original_ids);
187 if ($working_login->delete_from_db()) {
188 if ($new_login_object->update_db()) {
189 $new_id = $new_login_object->id();
190 if (method_exists($manager,
'add_new_login_id')) {
191 $manager->add_new_login_id($new_id);
193 $new_login_object->read_security_id = $new_id;
194 $new_login_object->write_security_id = $new_id;
195 if ($new_login_object->update_db()) {
196 $user_object->write_security_id = $new_id;
197 $user_object->set_login($new_id);
198 if ($user_object->update_db()) {
199 $ret = $new_login_object;
201 $this->error = $user_object->error;
204 $this->error = $new_login_object->error;
207 $this->error = $new_login_object->error;
210 $this->error = $working_login->error;
227 $in_cleartext_password,
228 $in_create_this_many_personal_ids = 0,
229 $in_security_token_ids = NULL,
230 $in_is_login_manager =
false
234 if (isset($in_login_id) && !$this->_chameleon_instance->check_login_exists_by_login_string($in_login_id)) {
235 $manager = $this->_chameleon_instance->get_login_item();
237 $use_these_ids = Array();
239 if (isset($in_security_token_ids) && is_array($in_security_token_ids) && count($in_security_token_ids)) {
242 foreach ($in_security_token_ids as $id) {
243 if (in_array($id, $my_ids)) {
244 array_push($use_these_ids, $id);
250 $className = $in_is_login_manager ?
'CO_Login_Manager' :
'CO_Cobra_Login';
252 $new_login_object = $this->_chameleon_instance->make_new_blank_record($className);
254 if (isset($new_login_object) && ($new_login_object instanceof
CO_Cobra_Login)) {
255 $new_login_object->login_id = $in_login_id;
256 if (strlen($in_cleartext_password) >= CO_Config::$min_pw_len) {
257 $new_login_object->context[
'hashed_password'] = password_hash($in_cleartext_password, PASSWORD_DEFAULT);
259 if (!$new_login_object->update_db()) {
260 $this->error = $new_login_object->error;
261 $new_login_object->delete_from_db();
262 $new_login_object = NULL;
264 $new_id = $new_login_object->id();
265 if (method_exists($manager,
'add_new_login_id')) {
266 $manager->add_new_login_id($new_id);
268 if ($new_login_object->set_read_security_id($new_id)) {
269 if ($new_login_object->set_write_security_id($new_id)) {
271 foreach ($use_these_ids as $id) {
272 if (in_array($id, $my_ids) && ($id != $new_id)) {
273 array_push($new_ids, $id);
277 if ($new_login_object->set_ids($new_ids)) {
278 if (CO_Config::use_personal_tokens() && (0 < $in_create_this_many_personal_ids)) {
280 $new_login_object->set_personal_ids($new_personal_ids);
281 if (!$new_login_object->error) {
282 $ret = $new_login_object;
284 $this->error = $new_login_object->error;
285 $new_login_object->delete_from_db();
286 $new_login_object = NULL;
290 $ret = $new_login_object;
292 $this->error = $new_login_object->error;
293 $new_login_object->delete_from_db();
294 $new_login_object = NULL;
297 $this->error = $new_login_object->error;
298 $new_login_object->delete_from_db();
299 $new_login_object = NULL;
302 $this->error = $new_login_object->error;
303 $new_login_object->delete_from_db();
304 $new_login_object = NULL;
308 $new_login_object->delete_from_db();
309 $new_login_object = NULL;
315 if (isset($this->_chameleon_instance->error)) {
316 $this->error = $this->_chameleon_instance->error;
329 } elseif (isset($in_login_id)) {
355 return $this->_chameleon_instance->get_security_ids();
369 $in_personal_ids = []
371 $target = $this->_chameleon_instance->get_login_item($in_login_id);
372 if (CO_Config::use_personal_tokens() && ($target instanceof
CO_Security_Login) && $this->_chameleon_instance->god_mode()) {
373 return $target->set_personal_ids($in_personal_ids);
388 if ($this->_chameleon_instance->god_mode() || ($this->_chameleon_instance->get_login_item() instanceof
CO_Login_Manager)) {
389 $user = $this->_chameleon_instance->make_new_blank_record(
'CO_User_Collection');
392 if (!isset($user->error)) {
393 $user->set_read_security_id(1);
394 $user->set_write_security_id($this->_chameleon_instance->get_login_item()->id());
395 if (isset($user->error)) {
396 $this->error = $user->error;
397 $user->delete_from_db();
401 $this->error = $user->error;
402 $user->delete_from_db();
410 } elseif (!($this->_chameleon_instance->get_login_item() instanceof
CO_Login_Manager)) {
431 if (isset($in_login_id) && $in_login_id) {
432 $ret = $this->_chameleon_instance->get_login_item_by_login_string($in_login_id);
434 $this->error = $this->_chameleon_instance->error;
449 $in_make_user_if_necessary =
false
451 $user = $this->_chameleon_instance->get_user_from_login($in_login_id);
452 if (!$user && $in_make_user_if_necessary && ($this->_chameleon_instance->god_mode() || ($this->_chameleon_instance->get_login_item() instanceof
CO_Login_Manager))) {
453 if (isset($in_login_id) && (0 < intval($in_login_id))) {
454 $login_id = intval($in_login_id);
457 if (isset($in_login_id) && (0 < intval($in_login_id))) {
458 $login_item = $this->_chameleon_instance->get_login_item($in_login_id);
461 if (!$this->_chameleon_instance->check_user_exists($in_login_id)) {
465 $user->set_login($in_login_id);
466 if (isset($user->error)) {
467 $this->error = $user->error;
468 $user->delete_from_db();
471 $user->set_write_security_id($in_login_id);
472 if (isset($user->error)) {
473 $this->error = $user->error;
474 $user->delete_from_db();
498 } elseif (!($this->_chameleon_instance->get_login_item() instanceof
CO_Login_Manager)) {
515 $in_cleartext_password,
516 $in_create_this_many_personal_ids = 0
518 return $this->
_create_new_login($in_login_id, $in_cleartext_password, $in_create_this_many_personal_ids);
529 $in_cleartext_password,
530 $in_create_this_many_personal_ids = 0
532 return $this->
_create_new_login($in_login_id, $in_cleartext_password, $in_create_this_many_personal_ids, NULL,
true);
544 $in_is_login_manager =
false
558 $also_delete_user =
false
564 if ($cobra_login_instance) {
565 $cobra_user_instance = NULL;
567 if ($also_delete_user) {
571 $ret = $cobra_login_instance->delete_from_db();
573 if ($ret && $cobra_user_instance) {
574 $ret = $cobra_user_instance->delete_from_db();
587 $in_login_integer_id = NULL
589 if (!$this->_chameleon_instance->god_mode()) {
591 $in_login_integer_id = 0;
593 $in_login_id = trim(strval($in_login_id));
596 $in_login_integer_id = intval($in_login_integer_id);
598 $item = $this->_chameleon_instance->get_login_item_by_login_string($in_login_id);
600 $in_login_integer_id = $item->id();
607 $results = $this->_chameleon_instance->get_all_login_objects($and_write);
608 if (isset($results) && is_array($results) && count($results)) {
609 foreach ($results as $result) {
610 if (!$in_login_integer_id || ($in_login_integer_id == $result->id())) {
611 $id_list[] = $result->id();
612 foreach ($result->ids() as $id) {
613 if (($id != CO_Config::god_mode_id()) || (($id == CO_Config::god_mode_id()) && ($in_login_integer_id == CO_Config::god_mode_id()))) {
621 $id_list = array_unique($id_list);
623 foreach ($id_list as $id) {
624 $object = $this->_chameleon_instance->get_single_security_record_by_id($id);
629 if (1 < count($ret)) {
631 usort($ret,
function ($a, $b) {
632 if ($a->id() == $b->id()) {
636 if ($a->id() < $b->id()) {
660 $id = intval($in_test_target->read_security_id);
663 $ret = $this->_chameleon_instance->get_all_login_objects_with_access($id);
664 if (!isset($ret) || !is_array($ret) || !count($ret)) {
667 } elseif (0 == $id) {
684 $non_managers_only =
false
693 $id = intval($in_test_target->write_security_id);
696 $ret = $this->_chameleon_instance->get_all_login_objects_with_access($id,
true);
698 if (($in_test_target instanceof
CO_Security_Login) && isset($ret) && is_array($ret) && $non_managers_only) {
700 foreach ($ret as $login) {
702 $ret_temp[] = $login;
706 if (count($ret_temp)) {
711 } elseif (!isset($ret) || !is_array($ret) || !count($ret)) {
714 } elseif (0 == $id) {
733 $manager = $this->_chameleon_instance->get_login_item();
734 if ($this->_chameleon_instance->god_mode() || ($manager instanceof
CO_Login_Manager)) {
735 $new_token = $this->_chameleon_instance->make_new_blank_record(
'CO_Security_ID');
736 if (isset($new_token) && ($new_token instanceof
CO_Security_ID)) {
737 $new_id = $new_token->id();
738 if ($this->_chameleon_instance->god_mode() || $manager->add_new_login_id($new_id)) {
741 $new_token->delete_from_db();
if(!defined( 'LGV_LANG_CATCHER'))
_create_this_many_personal_ids($in_count)
_convert_login( $in_login_id, $in_is_login_manager=false)
who_can_modify( $in_test_target, $non_managers_only=false)
who_can_see( $in_test_target)
get_login_instance( $in_login_id)
$version
The version indicator.
delete_login( $in_login_id, $also_delete_user=false)
set_personal_ids( $in_login_id, $in_personal_ids=[])
create_new_manager_login( $in_login_id, $in_cleartext_password, $in_create_this_many_personal_ids=0)
convert_login( $in_login_id, $in_is_login_manager=false)
create_new_standard_login( $in_login_id, $in_cleartext_password, $in_create_this_many_personal_ids=0)
static make_cobra($in_chameleon_instance)
__construct( $in_chameleon_instance=NULL)
get_user_from_login( $in_login_id=NULL, $in_make_user_if_necessary=false)
_create_new_login( $in_login_id, $in_cleartext_password, $in_create_this_many_personal_ids=0, $in_security_token_ids=NULL, $in_is_login_manager=false)
$_chameleon_instance
This is the CHAMELEON instance that is associated with this COBRA instance.
get_all_logins( $and_write=false, $in_login_id=NULL, $in_login_integer_id=NULL)
static $cobra_error_code_user_already_exists
static $cobra_error_code_invalid_chameleon
static $cobra_error_code_token_id_not_set
static $cobra_error_code_login_unavailable
static $cobra_error_code_login_error
static $cobra_error_code_instance_failed_to_initialize
static $cobra_error_code_password_too_short
static $cobra_error_code_token_instance_failed_to_initialize
static $cobra_error_code_user_not_authorized
static $cobra_error_desc_user_not_authorized
static $cobra_error_name_token_instance_failed_to_initialize
static $cobra_error_name_login_error
static $cobra_error_name_user_not_authorized
static $cobra_error_desc_invalid_chameleon
static $cobra_error_name_token_id_not_set
static $cobra_error_name_user_already_exists
static $cobra_error_name_password_too_short
static $cobra_error_desc_instance_failed_to_initialize
static $cobra_error_name_login_unavailable
static $cobra_error_desc_login_unavailable
static $cobra_error_desc_password_too_short
static $cobra_error_name_instance_failed_to_initialize
static $cobra_error_desc_user_already_exists
static $cobra_error_desc_login_error
static $cobra_error_desc_user_not_authorized_instance
static $cobra_error_name_invalid_chameleon
static $cobra_error_desc_token_id_not_set
static $cobra_error_desc_token_instance_failed_to_initialize
This class provides a general error report, with file, method and error information.