Public Attributes | |
$valid | |
This will be true, if the instance is "valid" (has at least an initialized "data" database). More... | |
$error | |
If there was an error, it will be held here. More... | |
$class_description | |
This is a brief textual description of the class. More... | |
$version | |
This will contain the BADGER Version. More... | |
Protected Attributes | |
$_data_db_object | |
This is the instance of the class representing the "data" database. This will always be instantiated. More... | |
$_security_db_object | |
This is the instance of the class representing the "scurity" database. This may not be instantiated, if there is no login. More... | |
$_login_id | |
This is an integer, containing the security DB ID of the logged-in user. It will be NULL for no login. More... | |
This is the principal interface class for BADGER. To use BADGER, you instantiate this class with a login (or no login), and the instance handles all the database setup and permission-setting in the background.
You then use this class as your database interface. No SQL or DB commands. It's all functions, and it should all go through this class or instances of records that it supplies. You do not interface with the databases. This is a functional interface.
This class is designed to be specialized and subclassed. In it's "pure" form, it is extremely generic.
BADGER consists of two databases: The "data" database, and the "security" database. These do not have any database-level relations. They can both be set up on different servers, and could even be different SQL databases, as the schemas are very simple, and we use PDO to access them.
The databases are crazy simple. Each consists of one table, with only a single schema table. Much of the specialization is done through subclasses.
Each database record has a classname stored. This is used to instantiate the appropriate class to interpret that record.
Security is tinfoil. Not only are there two databases, with the ability to encapsulate the security database in a hardened server, but each login is given an ACL, and that ACL determines what it can see or modify.
Each record has one code for reading, and one code for writing. If the code is not available in the logged-in user's ACL, then that user can't see the data, or modify it. This is enforced at the SQL level. The system will not even read in records that don't match the security key.
You set up BADGER with a config file, which implements a static class with some basic parameters for use in the system. For security, it's a good idea to locate the config file outside the HTTP tree.
You include the config file in whatever context is your main context, and include this file after that. You should define the "LGV_ACCESS_CATCHER" define to "1", so this file will run. This file will take care of other access tokens as necessary.
Definition at line 81 of file co_access.class.php.
CO_Access::__construct | ( | $in_login_id = NULL , |
|
$in_hashed_password = NULL , |
|||
$in_raw_password = NULL , |
|||
$in_api_key = NULL |
|||
) |
The constructor.
$in_login_id | The login ID |
$in_hashed_password | The password, crypt-hashed |
$in_raw_password | The password, cleartext. |
$in_api_key | An API key, for REST. |
Reimplemented in CO_Chameleon.
Definition at line 97 of file co_access.class.php.
References CO_Lang_Common\$pdo_error_code_failed_to_open_data_db, CO_Lang_Common\$pdo_error_code_failed_to_open_security_db, CO_Lang_Common\$pdo_error_code_invalid_login, CO_Lang\$pdo_error_desc_failed_to_open_data_db, CO_Lang\$pdo_error_desc_failed_to_open_security_db, CO_Lang\$pdo_error_desc_invalid_login, CO_Lang\$pdo_error_name_failed_to_open_data_db, CO_Lang\$pdo_error_name_failed_to_open_security_db, CO_Lang\$pdo_error_name_invalid_login, and __BADGER_VERSION__.
CO_Access::add_personal_token_from_current_login | ( | $in_to_id, | |
$in_id | |||
) |
This adds a personal token from one ID's pool, to the regular ID pool of another ID.
$in_to_id | The ID of the object we are affecting. |
$in_id | The ID (personal token) to be added. |
Definition at line 331 of file co_access.class.php.
References get_personal_security_ids().
CO_Access::can_i_see_this_data_record | ( | $in_id | ) |
This returns true, if the current user at least has read access to the Data DB record whose ID is provided..
This is "security safe," so that means that if the user does not have rights to the row, or the row does not exist, they will get false.
$in_id | This is the ID of the record to check. |
Definition at line 778 of file co_access.class.php.
CO_Access::can_i_see_this_security_record | ( | $in_id | ) |
This returns true, if the current user at least has read access to the Security DB record whose ID is provided..
This is "security safe," so that means that if the user does not have rights to the row, or the row does not exist, they will get false.
$in_id | This is the ID of the record to check. |
Definition at line 798 of file co_access.class.php.
CO_Access::check_login_exists | ( | $in_login_id | ) |
$in_login_id | The integer login ID to check |
Definition at line 521 of file co_access.class.php.
References security_db_available().
Referenced by check_user_exists().
CO_Access::check_login_exists_by_login_string | ( | $in_login_id_string | ) |
$in_login_id_string | The string login ID to check |
Definition at line 549 of file co_access.class.php.
References security_db_available().
CO_Access::check_user_exists | ( | $in_login_id | ) |
$in_login_id | The integer login ID to check |
Definition at line 583 of file co_access.class.php.
References check_login_exists().
CO_Access::delete_data_record | ( | $id | ) |
This is a "security-safe" method for deleting a record by its ID.
$id | The integer ID of the record to be deleted. |
Definition at line 1005 of file co_access.class.php.
CO_Access::generic_search | ( | $in_search_parameters = NULL , |
|
$or_search = false , |
|||
$page_size = 0 , |
|||
$initial_page = 0 , |
|||
$and_writeable = false , |
|||
$count_only = false , |
|||
$ids_only = false |
|||
) |
This is a "generic" data database search. It can be called from external user contexts, and allows a fairly generalized search of the "data" database. Sorting will be done for the "owner" and "location" values. "owner" will be sorted by the ID of the returned records, and "location" will be by distance from the center.
It is "security-safe."
$in_search_parameters | This is an associative array of terms to define the search. The keys should be:
|
You can specify an array for any one of the values, which allows you to do an OR search for those values ($or_search does not apply. It is only for the combination of main values). If you add an element called 'use_like' ('use_like' => 1) to the end of 'access_class', 'name' or one of the 'tags', then you can use SQL-style "wildcards" (%) in your matches. If you have 'use_like', and put just a single wildcard in quotes (''), then you are saying "not-empty." NOTE: Although this is an optional parameter, failing to provide anything could return the entire readable database.
$or_search | If true, then the search is very wide (OR), as opposed to narrow (AND), by default. If you specify a location, then that will always be AND, but the other fields can be OR. |
$page_size | If specified with a 1-based integer, this denotes the size of a "page" of results. NOTE: This is only applicable to MySQL or Postgres, and will be ignored if the DB is not MySQL or Postgres. |
$initial_page | This is ignored unless $page_size is greater than 0. If so, then this 0-based index will specify which page of results to return. |
$and_writeable | If true, then we only want records we can modify. |
$count_only | If true (default is false), then only a single integer will be returned, with the count of items that fit the search. |
$ids_only | If true (default is false), then the return array will consist only of integers (the object IDs). If $count_only is true, this is ignored. |
Definition at line 1026 of file co_access.class.php.
Referenced by CO_Chameleon\get_all_collections_for_element(), CO_Chameleon\get_object_for_key(), CO_Chameleon\get_user_from_login(), CO_Chameleon\get_value_for_key(), and CO_Chameleon\set_value_for_key().
CO_Access::get_all_data_readable_records | ( | $open_only = false , |
|
$in_this_id = NULL |
|||
) |
This returns every readable (by this user) item from the "data" database.
$open_only | If true, then we will look for ONLY records with a NULL or 0 read_security_id |
$in_this_id | If we are in "god mode," we can look for particular IDs. In that case, this would be the integer ID of the login to check. |
Definition at line 816 of file co_access.class.php.
CO_Access::get_all_data_writeable_records | ( | $in_this_id = NULL | ) |
This returns every writeable (by this user) item from the "data" database.
$in_this_id | If we are in "god mode," we can look for particular IDs. In that case, this would be the integer ID of the login to check. |
Definition at line 835 of file co_access.class.php.
CO_Access::get_all_login_objects | ( | $and_write = false | ) |
This is a security-vetted search for all login objects (visible to the current user).
$and_write | If true, then we only want ones we have write access to. |
Definition at line 1077 of file co_access.class.php.
CO_Access::get_all_login_objects_with_access | ( | $in_security_token, | |
$and_write = false |
|||
) |
You give a security ID, and you will get all login objects that have that token in their list (or are of that ID).
This is restricted to use security vetting, so only logins visible to the current login.
$in_security_token | An integer, with the requested security token. |
$and_write | If true, then we only want ones we have write access to. |
Reimplemented in CO_Chameleon.
Definition at line 1104 of file co_access.class.php.
CO_Access::get_all_personal_ids_except_for_id | ( | $in_id = 0 | ) |
This returns just the "personal" IDs for ALL logins, EXCEPT for the given ID.
This should only be called from the ID fetcher in the access class, as it does not do a security predicate.
$in_id | The integer ID of the row we want exempted. If not specified, then all IDs are returned. |
Definition at line 276 of file co_access.class.php.
CO_Access::get_all_security_readable_records | ( | $in_this_id = NULL | ) |
This returns every readable (by this user) item from the "security" database.
$in_this_id | If we are in "god mode," we can look for particular IDs. In that case, this would be the integer ID of the login to check. |
Definition at line 937 of file co_access.class.php.
CO_Access::get_all_security_writeable_records | ( | $in_this_id = NULL | ) |
This returns every writeable (by this user) item from the "security" database.
$in_this_id | If we are in "god mode," we can look for particular IDs. In that case, this would be the integer ID of the login to check. |
Definition at line 960 of file co_access.class.php.
CO_Access::get_all_tokens | ( | ) |
This is a special "God-only" search for all available tokens. If not in "God" mode, you get NULL.
Definition at line 1092 of file co_access.class.php.
CO_Access::get_all_user_objects_with_access | ( | $in_security_token | ) |
You give a security ID, and you will get all user objects that have a login wih that token in their list (or are of that ID).
This is restricted to use security vetting, so only users visible to the current login.
$in_security_token | An integer, with the requested security token. |
Reimplemented in CO_Chameleon.
Definition at line 1122 of file co_access.class.php.
CO_Access::get_available_tokens | ( | $no_personal = false | ) |
This is pretty much the same as above, except with the God Mode, you get all the security tokens instead of -1.
$no_personal | This is optional. If we DO NOT want personal tokens included, this should be set to true. Default is false (include personal tokens). |
Definition at line 404 of file co_access.class.php.
References get_login_id(), and god_mode().
CO_Access::get_data_access_class_by_id | ( | $in_id | ) |
This returns the access class for the given ID for the Data Database.
This is "security safe," so that means that if the user does not have rights to the row, they will get NULL.
$in_id | This is the ID of the record to fetch. |
Definition at line 740 of file co_access.class.php.
CO_Access::get_lang | ( | $in_login_id = NULL | ) |
$in_login_id | The integer login ID to check. If not-NULL, then the ID of a login instance. It must be one that the current user can see. |
Reimplemented in CO_Chameleon.
Definition at line 495 of file co_access.class.php.
References $lang, and get_login_item().
CO_Access::get_login_id | ( | $in_login_id = NULL | ) |
$in_login_id | The integer login ID to check. If not-NULL, then the ID of a login instance. It must be one that the current user can see. |
Definition at line 448 of file co_access.class.php.
References $_login_id, and get_single_security_record_by_id().
Referenced by get_available_tokens(), get_login_item(), get_personal_security_ids(), get_security_ids(), CO_Chameleon\get_user_from_login(), and make_new_blank_record().
CO_Access::get_login_item | ( | $in_login_id = NULL | ) |
This returns the actual security DB login item for the requested user (or the current logged-in user).
The response is subject to standard security vetting, so there is a possibility that nothing will be returned, when there is an existing login at that ID.
$in_login_id | The integer login ID to check. If not-NULL, then the ID of a login instance. It must be one that the current user can see. |
Definition at line 476 of file co_access.class.php.
References get_login_id(), and get_single_security_record_by_id().
Referenced by get_lang(), CO_Chameleon\get_lang(), get_remaining_time(), and CO_Chameleon\test_access().
CO_Access::get_login_item_by_login_string | ( | $in_login_id_string | ) |
$in_login_id_string | The string login ID to check |
Definition at line 568 of file co_access.class.php.
References security_db_available().
CO_Access::get_logins_that_have_any_of_my_ids | ( | ) |
This returns IDs that have our personal IDs.
Definition at line 375 of file co_access.class.php.
CO_Access::get_logins_with_personal_ids | ( | ) |
This returns IDs that have personal IDs. This only works for the God admin.
Definition at line 295 of file co_access.class.php.
CO_Access::get_multiple_data_records_by_id | ( | $in_id_array | ) |
This method queries the "data" databse for multiple records, given a list of IDs.
The records will not be returned if the user does not have read permission for them.
$in_id_array | An array of integers, with the item IDs. |
Definition at line 698 of file co_access.class.php.
Referenced by get_single_data_record_by_id().
CO_Access::get_multiple_security_records_by_id | ( | $in_id_array | ) |
This method queries the "security" databse for multiple records, given a list of IDs.
The records will not be returned if the user does not have read permission for them.
$in_id_array | An array of integer IDs. |
Definition at line 895 of file co_access.class.php.
Referenced by get_single_security_record_by_id().
CO_Access::get_personal_security_ids | ( | ) |
This fetches the list of the "personal" security tokens the currently logged-in user has available. This will reload any non-God Mode IDs before fetching the IDs, in order to spike privilege escalation. If they have God Mode, then you're pretty much screwed, anyway.
Definition at line 251 of file co_access.class.php.
References get_login_id().
Referenced by add_personal_token_from_current_login(), and remove_personal_token_from_this_login().
CO_Access::get_remaining_time | ( | $in_login_id = NULL | ) |
$in_login_id | The integer login ID to check. If not-NULL, then the ID of a login instance. It must be one that the current user can see. |
Definition at line 540 of file co_access.class.php.
References get_login_item().
CO_Access::get_security_access_class_by_id | ( | $in_id | ) |
This returns the access class for the given ID for the Security Database.
This is "security safe," so that means that if the user does not have rights to the row, they will get NULL.
$in_id | This is the ID of the record to fetch. |
Definition at line 759 of file co_access.class.php.
CO_Access::get_security_ids | ( | $no_personal = false | ) |
This fetches the list of security tokens the currently logged-in user has available. This will reload any non-God Mode IDs before fetching the IDs, in order to spike privilege escalation. If they have God Mode, then you're pretty much screwed, anyway.
$no_personal | This is optional. If we DO NOT want personal tokens included, this should be set to true. Default is false (include personal tokens). |
Reimplemented in CO_Chameleon.
Definition at line 220 of file co_access.class.php.
References get_login_id(), and god_mode().
Referenced by i_have_this_token().
CO_Access::get_single_data_record_by_id | ( | $in_id | ) |
This is a "security-safe" method for fetching a single record from the "data" database, by its ID.
$in_id | The integer ID of the record to fetch. |
Definition at line 720 of file co_access.class.php.
References get_multiple_data_records_by_id().
CO_Access::get_single_security_record_by_id | ( | $in_id | ) |
This is a "security-safe" method for fetching a single record from the "security" database, by its ID.
$in_id | The integer ID to check. |
Definition at line 918 of file co_access.class.php.
References get_multiple_security_records_by_id().
Referenced by get_login_id(), and get_login_item().
CO_Access::god_mode | ( | ) |
Definition at line 512 of file co_access.class.php.
Referenced by CO_Chameleon\fetch_backup(), get_available_tokens(), get_security_ids(), and i_have_this_token().
CO_Access::i_have_this_token | ( | $in_token_to_test | ) |
Tests a token, to see if the current user has it.
$in_token_to_test | The token we are checking out |
Definition at line 866 of file co_access.class.php.
References get_security_ids(), god_mode(), and security_db_available().
CO_Access::is_this_a_login_id | ( | $in_id | ) |
This checks an ID, to see if it is a login ID.
$in_id | The ID we are checking. Must be greater than 1. |
Definition at line 385 of file co_access.class.php.
CO_Access::is_this_a_personal_id | ( | $in_id | ) |
This checks an ID, to see if it is a personal ID.
$in_id | The ID we are checking. Must be greater than 1. |
Definition at line 312 of file co_access.class.php.
CO_Access::item_exists | ( | $in_id, | |
$in_visibility_test = false |
|||
) |
This is a very "raw" function that simply checks to see if any item exists for a given integer ID.
This deliberately does not pass security vetting, so we're careful. It's meant to be used by collection classes for garbage collection.
$in_id | The integer ID of the item. |
$in_visibility_test | If true (default is false), then this will return false, even if the item exists, but cannot be seen by this user. |
Definition at line 206 of file co_access.class.php.
CO_Access::main_db_available | ( | ) |
Definition at line 440 of file co_access.class.php.
References $_data_db_object.
CO_Access::make_new_blank_record | ( | $in_classname | ) |
This method instantiates a new, default instance of a class.
The instance does not reflect a database entity until it has had its update_db() method called.
$in_classname | This is the name of the class to instantiate. |
Definition at line 605 of file co_access.class.php.
References CO_Lang_Common\$access_error_code_class_file_not_found, CO_Lang_Common\$access_error_code_class_not_created, CO_Lang_Common\$access_error_code_user_not_authorized, CO_Lang\$access_error_desc_class_file_not_found, CO_Lang\$access_error_desc_class_not_created, CO_Lang\$access_error_desc_user_not_authorized, CO_Lang\$access_error_name_class_file_not_found, CO_Lang\$access_error_name_class_not_created, CO_Lang\$access_error_name_user_not_authorized, and get_login_id().
Referenced by CO_Chameleon\set_value_for_key().
CO_Access::remove_personal_token_from_this_login | ( | $in_to_id, | |
$in_id | |||
) |
This removes a token that is owned by one ID, from another ID.
$in_to_id | The ID of the object we are affecting. |
$in_id | The ID (personal token) to be removed. |
Definition at line 353 of file co_access.class.php.
References get_personal_security_ids().
CO_Access::security_db_available | ( | ) |
Definition at line 856 of file co_access.class.php.
References $_security_db_object.
Referenced by check_login_exists(), check_login_exists_by_login_string(), get_login_item_by_login_string(), i_have_this_token(), CO_Chameleon\set_value_for_key(), and CO_Chameleon\test_access().
CO_Access::write_data_record | ( | $params_associative_array | ) |
This writes a data record to the "data" database, based on an associative array of elements.
This is security-safe.
This should generally not be called by user contexts.
$params_associative_array | This is an associative array that has the values, keyed by the database column IDs. |
Definition at line 987 of file co_access.class.php.
|
protected |
This is the instance of the class representing the "data" database. This will always be instantiated.
Definition at line 82 of file co_access.class.php.
Referenced by main_db_available().
|
protected |
This is an integer, containing the security DB ID of the logged-in user. It will be NULL for no login.
Definition at line 84 of file co_access.class.php.
Referenced by get_login_id().
|
protected |
This is the instance of the class representing the "scurity" database. This may not be instantiated, if there is no login.
Definition at line 83 of file co_access.class.php.
Referenced by security_db_available().
CO_Access::$class_description |
This is a brief textual description of the class.
Definition at line 88 of file co_access.class.php.
CO_Access::$error |
If there was an error, it will be held here.
Definition at line 87 of file co_access.class.php.
CO_Access::$valid |
This will be true, if the instance is "valid" (has at least an initialized "data" database).
Definition at line 86 of file co_access.class.php.
CO_Access::$version |
This will contain the BADGER Version.
Definition at line 90 of file co_access.class.php.