27 defined(
'LGV_BASALT_CATCHER' ) or die ( 'Cannot Execute Directly' );
31 if (!defined('LGV_ACCESS_CATCHER')) {
32 define(
'LGV_ACCESS_CATCHER', 1);
35 if ( !defined(
'LGV_ANDISOL_CATCHER') ) {
36 define(
'LGV_ANDISOL_CATCHER', 1);
39 require_once(CO_Config::andisol_main_class_dir().
'/co_andisol.class.php');
40 require_once(CO_Config::main_class_dir().
'/a_co_basalt_plugin.class.php');
42 if ( !defined(
'LGV_LANG_CATCHER') ) {
43 define(
'LGV_LANG_CATCHER', 1);
46 require_once(CO_Config::lang_class_dir().
'/common.inc.php');
48 define(
'_PLUGIN_NAME_',
'baseline');
83 $in_text_data = explode(
"\n", $in_text_data);
84 if (isset($in_text_data) && is_array($in_text_data) && (1 < count($in_text_data))) {
85 $keys = str_getcsv(array_shift($in_text_data));
86 foreach ($in_text_data as $row) {
87 $row_temp = str_getcsv($row);
89 foreach ($row_temp as $element) {
90 if ((
'"NULL"' == $element) || (
'NULL' == $element) || (
"'NULL'" == $element) || !trim($element)) {
96 if (count($row) == count($keys)) {
97 $row = array_combine($keys, $row);
102 header(
'HTTP/1.1 400 Invalid Bulk Data');
116 $empty_array = array_fill(0, count($in_header_row),
'NULL');
117 $template = array_combine($in_header_row, $empty_array);
120 foreach ($in_line as $key => $value) {
121 if (!trim($value) || (
'api_key' == $key)) {
125 $needs_quotes = preg_match(
'|[\s",]|', $value);
126 $value = str_replace(
"'",
"''", $value);
127 $value = str_replace(
'"',
'""', $value);
128 $value = str_replace(
'\\""',
'""', $value);
129 $value = str_replace(
'\\\\',
'\\', $value);
131 $value =
"\"$value\"";
135 $template[$key] = $value;
139 echo(implode(
',', $template).
"\n");
150 $paths = isset($_SERVER[
'PATH_INFO']) ? explode(
"/", substr($_SERVER[
'PATH_INFO'], 1)) : [];
151 $query = isset($_SERVER[
'QUERY_STRING']) ? $_SERVER[
'QUERY_STRING'] : NULL;
156 $this->_response_type = NULL;
157 $this->_plugin_selector = NULL;
159 $this->_request_type = strtoupper(trim($_SERVER[
'REQUEST_METHOD']));
162 if ((1 < count($paths)) || (isset($paths[0]) && ((
'use_auth_params' == $paths[0]) || (
'login' == $paths[0]) || (
'logout' == $paths[0])))) {
163 $response_type = strtolower(trim($paths[0]));
165 if (
'use_auth_params' == $response_type) {
166 $this->_path = Array(
'use_auth_params');
167 } elseif (
'login' == $response_type) {
168 $query = explode(
'&', $query);
169 $this->_path = Array(
'login');
170 if (isset($query) && is_array($query) && (2 == count($query))) {
173 foreach ($query as $param) {
178 $parts = explode(
'=', $param, 2);
179 if (1 < count($parts)) {
180 $key = trim($parts[0]);
181 $value = trim($parts[1]);
185 if (!isset($value) || !$value) {
190 $vars_final[$key] = $value;
193 $this->_vars = $vars_final;
195 header(
'HTTP/1.1 403 Unauthorized Login');
198 } elseif (
'logout' == $response_type) {
199 $this->_path = Array(
'logout');
202 if ((
'json' == $response_type) || (
'xml' == $response_type) || (
'xsd' == $response_type) || (
'csv' == $response_type)) {
205 $this->_response_type = $response_type;
207 $plugin_selector = strtolower(trim($paths[0]));
213 $this->_plugin_selector = $plugin_selector;
218 $this->_path = array_filter(array_map(
'trim', $paths),
function($i){
return '' != $i;});
221 $query = explode(
'&', $query);
223 if (isset($query) && is_array($query) && count($query)) {
224 foreach ($query as $param) {
229 $parts = explode(
'=', $param, 2);
230 if (1 < count($parts)) {
231 $key = trim($parts[0]);
232 $value = urldecode(trim($parts[1]));
236 if (!isset($value)) {
241 $vars_final[$key] = $value;
248 if (!isset($vars_final[
'remove_payload'])) {
250 if (
'POST' == $this->_request_type) {
251 if (isset($_FILES[
'payload']) && (!isset($_FILES[
'payload'][
'error']) || is_array($_FILES[
'payload'][
'error']))) {
252 header(
'HTTP/1.1 400 '.print_r($_FILES[
'payload'][
'error'],
true));
254 } elseif (isset($_FILES[
'payload'])) {
255 $file_data = file_get_contents($_FILES[
'payload'][
'tmp_name']);
257 } elseif (
'PUT' == $this->_request_type) {
259 $put_data = fopen(
'php://input',
'r');
260 if (isset($put_data) && $put_data) {
261 while ($data = fread($put_data, 2048)) {
269 if (isset($file_data) && $file_data) {
270 $vars_final[
'payload'] = base64_decode($file_data);
271 } elseif (isset ($vars_final[
'payload'])) {
273 if (base64_encode(base64_decode($vars_final[
'payload'])) == $vars_final[
'payload']) {
274 $vars_final[
'payload'] = base64_decode($vars_final[
'payload']);
279 $this->_vars = $vars_final;
281 header(
'HTTP/1.1 400 Unsupported or Missing Plugin');
285 header(
'HTTP/1.1 400 Improper Return Type');
290 header(
'HTTP/1.1 400 Missing Path Components');
305 if (isset($this->_andisol_instance) && ($this->_andisol_instance instanceof
CO_Andisol) && $this->_andisol_instance->valid()) {
306 if (
'baseline' == $this->_plugin_selector) {
307 if ((
'GET' == $this->_request_type) || (
'POST' == $this->_request_type)) {
308 $result = $this->
process_command($this->_andisol_instance, $this->_request_type, $this->_response_type, $this->_path, $this->_vars);
310 $header =
'HTTP/1.1 400 Incorrect HTTP Request Method';
314 $plugin_filename =
'co_'.$this->_plugin_selector.
'_basalt_plugin.class.php';
315 $plugin_classname =
'CO_'.$this->_plugin_selector.
'_Basalt_Plugin';
316 $plugin_dirs = CO_Config::plugin_dirs();
319 foreach ($plugin_dirs as $plugin_dir) {
320 if (isset($plugin_dir) && is_dir($plugin_dir)) {
322 foreach (
new DirectoryIterator($plugin_dir) as $fileInfo) {
323 if ($plugin_filename == $fileInfo->getBasename()) {
324 $plugin_file = $fileInfo->getPathname();
332 require_once($plugin_file);
333 $plugin_instance =
new $plugin_classname();
335 $result = $plugin_instance->process_command($this->_andisol_instance, $this->_request_type, $this->_response_type, $this->_path, $this->_vars);
337 header(
'HTTP/1.1 400 Unsupported or Missing Plugin');
341 header(
'HTTP/1.1 400 Unsupported or Missing Plugin');
346 switch ($this->_response_type) {
349 $header .=
'Content-Type: text/xml';
353 $header .=
'Content-Type: application/json';
357 $header =
'HTTP/1.1 400 Improper Return Type';
361 if (isset($this->_andisol_instance) && ($this->_andisol_instance instanceof
CO_Andisol)) {
362 $this->error = $this->_andisol_instance->error;
364 $header =
'HTTP/1.1 401 Unauthorized API Key';
366 $header =
'HTTP/1.1 408 API Key Timeout';
368 $header =
'HTTP/1.1 400 General Error';
371 $header =
'HTTP/1.1 400 General Error';
379 $ob_stat = ob_get_status();
381 if (is_array($ob_stat) && isset($ob_stat[
'level']) && 0 < $ob_stat[
'level']) {
388 if ( zlib_get_coding_type() ===
false )
390 $handler =
"ob_gzhandler";
396 if (is_array($result)) {
397 foreach ($result as $element) {
422 if ($in_andisol_instance->logged_in()) {
423 if ((
'GET' == $in_http_method) && !isset($in_query[
'types']) && (!isset($in_path) || !is_array($in_path) || !count($in_path))) {
424 $ret = [
'tokens' => $in_andisol_instance->get_available_tokens()];
425 } elseif ((
'GET' == $in_http_method) && isset($in_query[
'types'])) {
426 $tokens = $in_andisol_instance->get_available_tokens();
427 $personal_login_array = [];
431 if ($in_andisol_instance->god()) {
432 $personal_login_array = $in_andisol_instance->get_logins_with_personal_ids();
434 $personal_login_array = [$in_andisol_instance->current_login()->id() => $in_andisol_instance->get_personal_security_ids()];
437 foreach ($tokens as $token) {
440 foreach ($personal_login_array as $key => $ids) {
441 if (in_array($token, $ids)) {
447 $temp_ret = [
'id' => $token];
449 $temp_ret[
'type'] =
'personal';
450 if ($in_andisol_instance->god()) {
451 $temp_ret[
'login_id'] = $id;
453 } elseif ($in_andisol_instance->is_this_a_personal_id($token)) {
454 $temp_ret[
'type'] =
'assigned';
455 } elseif ($in_andisol_instance->is_this_a_login_id($token) && $in_andisol_instance->god()) {
456 $temp_ret[
'type'] =
'login';
458 $temp_ret[
'type'] =
'token';
461 $ret_temp[] = $temp_ret;
463 $ret[
'tokens'] = $ret_temp;
464 } elseif ((
'GET' == $in_http_method) && isset($in_query[
'count_access_to']) && (isset($in_path) && is_array($in_path) && count($in_path))) {
465 $ids = array_map(
'trim', explode(
',', $in_path[0]));
466 $ids = array_map(
'trim', $ids);
467 $ids = array_map(
'intval', $ids);
468 $ids = array_unique($ids);
470 foreach ($ids as $single_id) {
471 if (1 < $single_id) {
472 array_push($retTemp, [
'token' => intval($single_id),
'access' => $in_andisol_instance->count_all_login_objects_with_access(intval($single_id))]);
475 $ret = [
'count_access_to' => $retTemp];
476 } elseif ((
'POST' == $in_http_method) && $in_andisol_instance->manager()) {
477 $ret = [
'tokens' => [$in_andisol_instance->make_security_token()]];
479 header(
'HTTP/1.1 403 Unauthorized Command');
483 header(
'HTTP/1.1 403 Unauthorized Command');
501 if ($in_andisol_instance->god()) {
502 $ret = [
'serverinfo' => []];
508 $ret[
'serverinfo'][
'security_db_type'] = CO_Config::$sec_db_type;
509 $ret[
'serverinfo'][
'data_db_type'] = CO_Config::$data_db_type;
511 $ret[
'serverinfo'][
'min_pw_length'] = intval(CO_Config::$min_pw_len);
512 $ret[
'serverinfo'][
'regular_timeout_in_seconds'] = intval(CO_Config::$session_timeout_in_seconds);
513 $ret[
'serverinfo'][
'god_timeout_in_seconds'] = intval(CO_Config::$god_session_timeout_in_seconds);
514 $ret[
'serverinfo'][
'block_repeated_logins'] = CO_Config::$block_logins_for_valid_api_key ? true :
false;
515 $ret[
'serverinfo'][
'block_differing_ip_address'] = CO_Config::$api_key_includes_ip_address ? true :
false;
516 $ret[
'serverinfo'][
'ssl_requirement_level'] = intval(CO_Config::$ssl_requirement_level);
517 $ret[
'serverinfo'][
'google_api_key'] = CO_Config::$google_api_key;
518 $ret[
'serverinfo'][
'allow_address_lookup'] = CO_Config::$allow_address_lookup ? true :
false;
519 $ret[
'serverinfo'][
'allow_general_address_lookup'] = CO_Config::$allow_general_address_lookup ? true :
false;
520 $ret[
'serverinfo'][
'default_region_bias'] = CO_Config::$default_region_bias;
522 header(
'HTTP/1.1 403 Unauthorized Command');
539 if ( isset ($in_path[0]) ) {
540 $login_id_list = array_map(
'intval', array_map(
'trim', explode(
',', $in_path[0])));
542 $login_id_list = [$in_andisol_instance->current_login()->id()];
544 if ( 0 < count($login_id_list) ) {
547 foreach ($login_id_list as $id) {
548 $time = floatval($in_andisol_instance->get_remaining_time($id));
550 if ( (-1 == $time) || (0 < $time) ) {
551 $ret[
"remaining_time"][] = [
"id" => $id,
"time" => $time];
555 if ( 0 < count($ret) ) {
560 header(
'HTTP/1.1 403 Unable to Determine Time');
579 if ((
'GET' == $in_http_method) && (!isset($in_command) || !$in_command)) {
580 $ret = Array(
'plugins' => CO_Config::plugin_names());
581 array_unshift($ret[
'plugins'], $this->
plugin_name());
582 } elseif ( (
'GET' == $in_http_method) && (
'ping' == $in_command) ) {
584 } elseif ((
'POST' == $in_http_method) && $this->_andisol_instance->god() && (
'bulk-loader' == $in_command) && CO_Config::$enable_bulk_upload) {
586 } elseif (
'tokens' == $in_command) {
588 } elseif ((
'serverinfo' == $in_command) && $in_andisol_instance->god()) {
590 } elseif ((
'backup' == $in_command) && $in_andisol_instance->god() && (
'GET' == $in_http_method)) {
592 } elseif ((
'handlers' == $in_command) && isset($in_path[0]) && trim($in_path[0])) {
593 $id_list = explode(
',', trim($in_path[0]));
594 $id_list = array_map(
'intval', $id_list);
596 foreach ($id_list as $id) {
598 $class_name = $in_andisol_instance->get_data_access_class_by_id($id);
602 $ret[$handler][] = $id;
607 } elseif ((
'visibility' == $in_command) && $in_andisol_instance->logged_in()) {
608 if (
'token' == trim($in_path[0])) {
609 $token = intval(trim($in_path[1]));
610 if ((0 <= $token) && $in_andisol_instance->i_have_this_token($token)) {
611 if (isset($in_query[
'users'])) {
612 $objects = $in_andisol_instance->get_all_user_objects_with_access($token);
613 if (count($objects)) {
614 $ret[
'token'][
'token'] = $token;
615 $ret[
'token'][
'user_ids'] = array_map(
function($item){
return intval($item->id()); }, $objects);
618 $objects = $in_andisol_instance->get_all_login_objects_with_access($token);
619 if (count($objects)) {
620 $ret[
'token'][
'token'] = $token;
621 $ret[
'token'][
'login_ids'] = array_map(
function($item){
return intval($item->id()); }, $objects);
625 header(
'HTTP/1.1 400 Invalid Token');
629 $id = intval(trim($in_path[0]));
631 if ((1 < $id) && $in_andisol_instance->can_i_see_this_data_record($id)) {
632 $record = $in_andisol_instance->get_single_data_record_by_id($id);
635 $read_login_records = $in_andisol_instance->get_all_login_objects_with_access($record->read_security_id);
636 $write_login_records = $in_andisol_instance->get_all_login_objects_with_access($record->write_security_id);
637 $ret[
'id'][
'id'] = $id;
638 $ret[
'id'][
'writeable'] = $record->user_can_write();
639 $read_login_records = array_map(
function($item){
return intval($item->id()); }, $read_login_records);
640 $write_login_records = array_map(
function($item){
return intval($item->id()); }, $write_login_records);
642 if (count($write_login_records)) {
643 foreach ($write_login_records as $id) {
644 if (!in_array($id, $read_login_records)) {
645 $read_login_records[] = $id;
649 sort($write_login_records);
650 sort($read_login_records);
653 if (count($read_login_records)) {
654 $ret[
'id'][
'read_login_ids'] = $read_login_records;
657 if (count($write_login_records)) {
658 $ret[
'id'][
'write_login_ids'] = $write_login_records;
662 header(
'HTTP/1.1 400 Invalid ID');
666 } elseif (
'version' == $in_command) {
668 } elseif (
'search' == $in_command) {
670 $radius = isset($in_query) && is_array($in_query) && isset($in_query[
'search_radius']) && (0.0 < floatval($in_query[
'search_radius'])) ? floatval($in_query[
'search_radius']) : NULL;
671 $longitude = isset($in_query) && is_array($in_query) && isset($in_query[
'search_longitude']) ? floatval($in_query[
'search_longitude']) : NULL;
672 $latitude = isset($in_query) && is_array($in_query) && isset($in_query[
'search_latitude']) ? floatval($in_query[
'search_latitude']) : NULL;
674 $search_page_size = isset($in_query) && is_array($in_query) && isset($in_query[
'search_page_size']) ? abs(intval($in_query[
'search_page_size'])) : 0;
675 $search_page_number = isset($in_query) && is_array($in_query) && isset($in_query[
'search_page_number']) ? abs(intval($in_query[
'search_page_number'])) : 0;
676 $writeable = isset($in_query) && is_array($in_query) && isset($in_query[
'writeable']);
677 $search_name = isset($in_query) && is_array($in_query) && isset($in_query[
'search_name']) ? trim($in_query[
'search_name']) : NULL;
681 if (isset($radius) && (0 < $radius) && isset($longitude) && isset($latitude)) {
682 $location_search = Array(
'radius' => $radius,
'longitude' => $longitude,
'latitude' => $latitude);
683 $search_array[
'location'] = $location_search;
686 if (isset($search_name)) {
687 $search_array[
'name'] = Array($search_name,
'use_like' => 1);
694 for ($tag = 0; $tag < 10; $tag++) {
695 $tag_string =
'search_tag'.$tag;
696 $tag_value = isset($in_query) && is_array($in_query) && isset($in_query[$tag_string]) ? trim($in_query[$tag_string]) : NULL;
697 if ($tag_value !== NULL) {
700 $tags[] = $tag_value;
705 $search_array[
'tags'] = $tags;
706 $search_array[
'tags'][
'use_like'] = 1;
709 $object_list = $in_andisol_instance->generic_search($search_array,
false, $search_page_size, $search_page_number, $writeable);
711 if (isset($object_list) && is_array($object_list) && count($object_list)) {
712 foreach ($object_list as $instance) {
713 $class_name = get_class($instance);
717 $ret[$handler][] = $instance->id();
722 if (isset($location_search)) {
723 $ret[
'search_location'] = $location_search;
737 set_time_limit(3600);
740 if ($in_andisol_instance->god()) {
741 $backup = $in_andisol_instance->fetch_backup();
743 if (isset($backup) && is_array($backup) && (2 == count($backup)) && isset($backup[
'security']) && is_array($backup[
'security']) && count($backup[
'security']) && isset($backup[
'data']) && is_array($backup[
'data']) && count($backup[
'data'])) {
744 $header_row = [
'id',
'api_key',
'login_id',
'access_class',
'last_access',
'read_security_id',
'write_security_id',
'object_name',
'access_class_context',
'owner',
'longitude',
'latitude',
'tag0',
'tag1',
'tag2',
'tag3',
'tag4',
'tag5',
'tag6',
'tag7',
'tag8',
'tag9',
'ids',
'payload'];
745 header(
'Content-Type: text/csv');
746 echo(implode(
',', $header_row).
"\n");
747 foreach ($backup[
'security'] as $line) {
750 foreach ($backup[
'data'] as $line) {
755 header(
'HTTP/1.1 500 Internal Server Error');
759 header(
'HTTP/1.1 403 Unauthorized User');
776 set_time_limit(3600);
779 if ($this->_andisol_instance->god() && CO_Config::$enable_bulk_upload) {
780 if (
'POST' == $this->_request_type) {
781 if (isset($_FILES[
'payload']) && (!isset($_FILES[
'payload'][
'error']) || is_array($_FILES[
'payload'][
'error']))) {
782 header(
'HTTP/1.1 400 '.print_r($_FILES[
'payload'][
'error'],
true));
784 } elseif (isset($_FILES[
'payload'])) {
785 $file_data = base64_decode(file_get_contents($_FILES[
'payload'][
'tmp_name']));
788 if (isset($csv_data) && is_array($csv_data) && count($csv_data)) {
789 $ret = [
'bulk_upload' => []];
796 foreach ($csv_data as $row) {
797 $in_id = intval($row[
'id']);
798 $row_result = [
'input_id' => $in_id];
802 $security_ids[$in_id] = intval($new_record->id());
804 $data_ids[$in_id] = intval($new_record->id());
807 $records[] = $new_record;
808 $row_result[
'access_class'] = get_class($new_record);
809 $row_result[
'output_id'] = $new_record->id();
810 $ret[
'bulk_upload'][] = $row_result;
814 foreach ($records as $object) {
815 if (method_exists($object,
'ids')) {
816 $ids = $object->ids();
817 if (isset($ids) && is_array($ids) && count($ids)) {
820 foreach ($ids as $id) {
822 if (isset($security_ids[$id]) && (1 < $security_ids[$id])) {
823 $new_ids[] = $security_ids[$id];
828 $object->set_ids($new_ids);
832 if (method_exists($object,
'owner_id')) {
833 $id = $object->owner_id();
834 if (isset($data_ids[$id]) && (1 < $data_ids[$id])) {
835 $object->set_owner_id(intval($data_ids[$id]));
839 $context = $object->context;
841 if (method_exists($object,
'children_ids')) {
842 $old_ids = $object->children_ids(
true);
843 if (isset($old_ids) && is_array($old_ids) && count($old_ids)) {
844 $object->deleteAllChildren();
846 foreach ($old_ids as $id) {
847 if (isset($data_ids[$id]) && (1 < $data_ids[$id])) {
848 $new_ids[] = intval($data_ids[$id]);
852 if (isset($new_ids) && is_array($new_ids) && count($new_ids)) {
853 if (!$object->set_children_ids($new_ids)) {
854 header(
'HTTP/1.1 500 Internal Server Error');
862 $old_id = intval($object->tags()[0]);
863 $new_id = $security_ids[$old_id];
866 $object->set_tag(0, $new_id);
870 $read = $object->read_security_id;
873 $read = $security_ids[$read];
877 $object->set_read_security_id($read);
878 if (0 < $object->write_security_id) {
879 $object->set_write_security_id($security_ids[$object->write_security_id]);
881 $object->set_write_security_id(-1);
884 if (!$object->clear_batch_mode()) {
885 header(
'HTTP/1.1 500 Internal Server Error');
890 header(
'HTTP/1.1 400 Invalid Bulk Data');
895 header(
'HTTP/1.1 400 Improper HTTP Method');
899 header(
'HTTP/1.1 403 Unauthorized User');
910 $access_class = $in_row_data[
'access_class'];
913 if ($this->_andisol_instance->check_login_exists_by_login_string($in_row_data[
'login_id'])) {
914 $in_row_data[
'login_id'] .=
'-copy';
917 $new_record = $this->_andisol_instance->make_new_blank_record($access_class);
919 if (isset($new_record) && ($new_record instanceof $access_class)) {
920 $in_row_data[
'id'] = $new_record->id();
921 $new_record->set_batch_mode();
922 $new_record->load_from_db($in_row_data);
923 if (!$new_record->update_db()) {
924 header(
'HTTP/1.1 500 Internal Server Error');
929 header(
'HTTP/1.1 400 Invalid Bulk Data');
941 return $this->
_process_xsd(dirname(__FILE__).
'/schema.xsd');
955 $this->_andisol_instance = NULL;
958 $https = ((!empty($_SERVER[
'HTTPS']) && (($_SERVER[
'HTTPS'] !==
'off') || (intval($_SERVER[
'SERVER_PORT']) == 443)))) ? true :
false;
959 if ((CO_CONFIG_HTTPS_ALL > CO_Config::$ssl_requirement_level) || $https) {
962 if ((1 == count($this->_path)) && (
'use_auth_params' == $this->_path[0])) {
963 exit(
'cgi' == substr(php_sapi_name(), 0, 3) ?
'1' :
'0');
965 } elseif ((1 == count($this->_path)) && (
'login' == $this->_path[0])) {
966 if (isset($this->_vars) && isset($this->_vars[
'login_id']) && isset($this->_vars[
'password'])) {
968 if ($https || (CO_CONFIG_HTTPS_OFF == CO_Config::$ssl_requirement_level)) {
969 $login_id = $this->_vars[
'login_id'];
970 $password = $this->_vars[
'password'];
973 if (method_exists(
'CO_Config',
'call_login_validator_function')) {
974 if (!CO_Config::call_login_validator_function($login_id, $password, $_SERVER)) {
975 header(
'HTTP/1.1 403 Unauthorized Login');
981 $andisol_instance =
new CO_Andisol($login_id,
'', $password);
983 if (isset($andisol_instance) && ($andisol_instance instanceof
CO_Andisol) && $andisol_instance->logged_in()) {
984 if (method_exists(
'CO_Config',
'call_log_handler_function')) {
985 CO_Config::call_log_handler_function($andisol_instance, $_SERVER);
987 $login_item = $andisol_instance->get_login_item();
991 $api_key = $login_item->get_api_key();
993 if (isset($api_key)) {
996 header(
'HTTP/1.1 403 Unauthorized Login');
999 header(
'HTTP/1.1 403 Unauthorized Login');
1002 header(
'HTTP/1.1 403 Unauthorized Login');
1005 header(
'HTTP/1.1 401 SSL Connection Required');
1008 header(
'HTTP/1.1 401 Credentials Required');
1012 } elseif ((1 == count($this->_path)) && (
'logout' == $this->_path[0])) {
1013 $server_secret = isset($_SERVER[
'PHP_AUTH_USER']) ? $_SERVER[
'PHP_AUTH_USER'] : NULL;
1014 $api_key = isset($_SERVER[
'PHP_AUTH_PW']) ? $_SERVER[
'PHP_AUTH_PW'] : NULL;
1016 if (!$server_secret || !$api_key) {
1017 $auth = explode(
'&', $_SERVER[
'QUERY_STRING']);
1018 foreach ($auth as $query) {
1019 $exp = explode(
'=', $query);
1020 if (
'login_server_secret' == $exp[0]) {
1021 $server_secret = trim($exp[1]);
1022 } elseif (
'login_api_key' == $exp[0]) {
1023 $api_key = trim($exp[1]);
1029 if ($https || (CO_CONFIG_HTTPS_LOGGED_IN_ONLY > CO_Config::$ssl_requirement_level)) {
1031 if(!(isset($api_key) && $api_key && ($server_secret == Co_Config::server_secret()))) {
1032 header(
'HTTP/1.1 403 Cannot Logout Without Valid Credentials');
1034 $andisol_instance =
new CO_Andisol(
'',
'',
'', $api_key);
1036 if (isset($andisol_instance) && ($andisol_instance instanceof
CO_Andisol) && $andisol_instance->logged_in()) {
1037 if (method_exists(
'CO_Config',
'call_log_handler_function')) {
1038 CO_Config::call_log_handler_function($andisol_instance, $_SERVER);
1041 $login_item = $andisol_instance->get_login_item();
1045 if ($login_item->clear_api_key()) {
1046 header(
'HTTP/1.1 205 Logout Successful');
1048 header(
'HTTP/1.1 200 Logout Unneccessary');
1051 header(
'HTTP/1.1 500 Internal Server Error');
1054 header(
'HTTP/1.1 403 Unauthorized Login');
1058 header(
'HTTP/1.1 401 SSL Connection Required');
1065 $server_secret = isset($_SERVER[
'PHP_AUTH_USER']) ? $_SERVER[
'PHP_AUTH_USER'] : NULL;
1066 $api_key = isset($_SERVER[
'PHP_AUTH_PW']) ? $_SERVER[
'PHP_AUTH_PW'] : NULL;
1068 if (!$server_secret || !$api_key) {
1069 $auth = explode(
'&', $_SERVER[
'QUERY_STRING']);
1070 foreach ($auth as $query) {
1071 $exp = explode(
'=', $query);
1072 if (
'login_server_secret' == $exp[0]) {
1073 $server_secret = trim($exp[1]);
1074 } elseif (
'login_api_key' == $exp[0]) {
1075 $api_key = trim($exp[1]);
1081 if(!(isset($api_key) && $api_key && ($server_secret == Co_Config::server_secret()))) {
1085 $https_requirement =
true;
1088 switch (CO_Config::$ssl_requirement_level) {
1089 case CO_CONFIG_HTTPS_ALL:
1093 case CO_CONFIG_HTTPS_LOGGED_IN_ONLY:
1095 $https_requirement = (NULL != $api_key);
1100 $https_requirement =
false;
1104 if ($https || !$https_requirement) {
1105 $andisol_instance =
new CO_Andisol(
'',
'',
'', $api_key);
1106 if (isset($andisol_instance) && ($andisol_instance instanceof
CO_Andisol)) {
1107 if (method_exists(
'CO_Config',
'call_log_handler_function')) {
1108 CO_Config::call_log_handler_function($andisol_instance, $_SERVER);
1110 $this->_andisol_instance = $andisol_instance;
1112 header(
'HTTP/1.1 500 Internal Server Error');
1116 header(
'HTTP/1.1 401 SSL Connection Required');
1121 header(
'HTTP/1.1 401 SSL Connection Required');
1126 }
catch (Exception $e) {
1127 header(
'HTTP/1.1 500 Internal Server Error');
1137 $ret = CO_Config::plugin_names();
1147 return isset($this->_andisol_instance) ? $this->_andisol_instance->valid() :
false;
1155 return isset($this->_andisol_instance) ? $this->_andisol_instance->logged_in() :
false;
1190 if (is_array($in_path) && (3 >= count($in_path))) {
1191 $command = isset($in_path[0]) ? strtolower(trim(array_shift($in_path))) : [];
1193 if (((
'csv' == $in_response_type) && (
'backup' != $command)) || ((
'backup' == $command) && (!$in_andisol_instance->god() || (
'GET' != $in_http_method) || (
'csv' != $in_response_type)))) {
1194 header(
'HTTP/1.1 400 Improper Baseline Command');
1199 header(
'HTTP/1.1 400 Improper Baseline Command');
if(!defined('LGV_ACCESS_CATCHER')) if(!defined( 'LGV_ANDISOL_CATCHER'))
const __ANDISOL_VERSION__
const __CHAMELEON_VERSION__
_condition_response( $in_response_type, $in_response_as_associative_array=NULL)
static _get_handler( $in_classname)
_process_xsd( $in_schema_file_path)
$version
The version indicator.
$_path
This array will contain any path components that are received via GET, PUT, POST or DELETE.
_process_bulk_row( $in_row_data)
$_response_type
This is the reponse type. It is 'json', 'xml' or 'xsd'.
_process_ping_command( $in_andisol_instance, $in_path=[])
_process_basalt_parameters()
static _output_one_line( $in_line, $in_header_row)
process_command( $in_andisol_instance, $in_http_method, $in_response_type, $in_path=[], $in_query=[])
_process_baseline_command( $in_andisol_instance, $in_http_method, $in_command, $in_path=[], $in_query=[])
$error
Any errors that occured are kept here.
$_andisol_instance
This contains the instance of ANDISOL used by this instance.
$_vars
This associative array will contain any query variables that are received via GET,...
_process_serverinfo_command( $in_andisol_instance, $in_http_method, $in_path=[], $in_query=[])
static _extract_csv_data( $in_text_data)
_baseline_fetch_backup( $in_andisol_instance)
_process_token_command( $in_andisol_instance, $in_http_method, $in_path=[], $in_query=[])
$_plugin_selector
This will be a lowercase string, denoting the plugin selected for the operation.
static $pdo_error_code_invalid_login
static $login_error_code_api_key_mismatch
static $login_error_code_api_key_invalid