/* API requests */ $_api_token_login = filter_input(INPUT_POST, 'token', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '^[a-z0-9]{64}$^']]); $_api_passwd_password = filter_input(INPUT_POST, 'secret', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '^[a-z0-9]{64}$^']]); /* Run API request */ if ($_api_token_login && $_api_passwd_password && $_page_request == 'api') { $_ajax_request = true; //Enable JSON output $_global_api = new API($connection); /* Try to login */ if (!$_global_api->initialize($_api_token_login, $_api_passwd_password)) { echo json_encode(array('connected' => false, 'res' => $_global_api->_warning)); die; } /* API Rate limit control */ $_global_rate_limit = new Rate($connection, $_global_api->getID()); if (!$_global_rate_limit->allowed()) { echo json_encode(array('connected' => true, 'res' => 'Maximum API rate limit reached, please wait!')); die; } /* read given cmd */ $_api_cmd = filter_input(INPUT_POST, 'cmd', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '^[a-zA-Z]{5,25}$^']]); if (!$_api_cmd) { echo json_encode(array('connected' => true, 'cmd' => null)); } else { if ($_api_cmd == 'newsession') { echo json_encode(array('connected' => true, 'cmd' => 'newsession', 'res' => $_global_api->new_session(filter_input(INPUT_POST, 'sName', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '^([a-zA-Z\'()-_[:blank:]-]{5,50})$^']]), filter_input(INPUT_POST, 'sMode', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '^([a-zA-Z\'[:blank:]-]{5,25})$^']]), filter_input(INPUT_PORT, 'sMap', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '^([a-zA-Z\'[:blank:]-]{5,25})$^']]), filter_input(INPUT_POST, 'sMaxSlot', FILTER_VALIDATE_INT), filter_input(INPUT_POST, 'sHost', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '^([a-zA-Z0-9\\-_s,]{3,16})$^']]), filter_input(INPUT_POST, 'mKey', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '^[a-zA-Z0-9?@\\.;:!_-]{5,22}$^']]), filter_input(INPUT_POST, 'mKeyRequired', FILTER_VALIDATE_BOOLEAN), filter_input(INPUT_POST, 'sVisible', FILTER_VALIDATE_BOOLEAN)), 'message' => $_global_api->_warning)); } else { if ($_api_cmd == 'endsession') { echo json_encode(array('connected' => true, 'cmd' => $_api_cmd, 'res' => $_global_api->end_session(filter_input(INPUT_POST, 'cSession', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '^[a-z0-9]{64}$^']])), 'message' => $_global_api->_warning)); } else { if ($_api_cmd == 'newclient') {