obj = TTnew( $class_name ); return true; } public function __call( $method, $params ) { Debug::text( 'TTSoapServerHandler Call: Class: ' . get_class( $this->obj ) . ' Method: ' . $method, __FILE__, __LINE__, __METHOD__, 10 ); if ( isWhiteListedAPICall( $this->obj, $method ) == true ) { if ( method_exists( $this->obj, $method ) ) { return call_user_func_array( [ $this->obj, $method ], $params ); } else { $api_auth = new APIAuthentication(); $validator = TTnew( 'Validator' ); /** @var Validator $validator */ Debug::text( 'Class: ' . get_class( $this->obj ) . ' Method: ' . $method . ' does not exist!', __FILE__, __LINE__, __METHOD__, 10 ); return $api_auth->returnHandler( false, 'EXCEPTION', TTi18n::getText( 'Method: "%1" does not exist.', [ $validator->escapeHTML( $method ) ] ) ); } } else { $api_auth = new APIAuthentication(); $validator = TTnew( 'Validator' ); /** @var Validator $validator */ Debug::text( 'Class: ' . get_class( $this->obj ) . ' Method: ' . $method . ' is private!', __FILE__, __LINE__, __METHOD__, 10 ); return $api_auth->returnHandler( false, 'EXCEPTION', TTi18n::getText( 'Method: "%1" is private, unable to call.', [ $validator->escapeHTML( $method ) ] ) ); } } } $class_prefix = 'API'; $class_name = false; //Class name is case sensitive! //Get proper class name early, as we need to allow if ( isset( $_GET['Class'] ) && $_GET['Class'] != '' ) { $class_name = $_GET['Class']; //If API wasn't already put on the class, add it manually. if ( strtolower( substr( $class_name, 0, 3 ) ) != 'api' ) { $class_name = $class_prefix . $class_name; } $class_name = TTgetPluginClassName( $class_name ); } else { $class_name = TTgetPluginClassName( $class_prefix . 'Authentication' ); } //$class_factory = ( isset($_GET['Class']) AND $_GET['Class'] != '' ) ? $_GET['Class'] : 'Authentication'; //Default to APIAuthentication class if none is specified. //$class_name = TTgetPluginClassName( $class_prefix.$class_factory ); $soap_server = new SoapServer( null, [ 'uri' => 'urn:api', 'encoding' => 'UTF-8' ] ); if ( ( isset( $config_vars['other']['installer_enabled'] ) && $config_vars['other']['installer_enabled'] == false ) && ( !isset( $config_vars['other']['down_for_maintenance'] ) || isset( $config_vars['other']['down_for_maintenance'] ) && $config_vars['other']['down_for_maintenance'] == '' ) ) { $authentication = new Authentication(); $session_id = getSessionID(); if ( isset( $session_id ) && $session_id != '' ) { Debug::text( 'SOAP Session ID: ' . $session_id . ' Source IP: ' . Misc::getRemoteIPAddress(), __FILE__, __LINE__, __METHOD__, 10 ); if ( $authentication->isSessionIDAPIKey( $session_id ) == true ) { $authentication_type_id = 700; //API Key } else { $authentication_type_id = 800; //USER_NAME } if ( $authentication->Check( $session_id, $authentication_type_id ) === true ) { Debug::text( 'SOAP Class Factory: ' . $class_name, __FILE__, __LINE__, __METHOD__, 10 ); if ( $class_name != '' && class_exists( $class_name ) ) { $current_user = $authentication->getObject(); if ( is_object( $current_user ) ) { $current_user_prefs = handleOverridePreferences( $current_user ); $clf = new CompanyListFactory(); $current_company = $clf->getByID( $current_user->getCompany() )->getCurrent(); if ( is_object( $current_company ) ) { Debug::text( 'Handling SOAP Call To API Factory: ' . $class_name . ' UserName: ' . $current_user->getUserName(), __FILE__, __LINE__, __METHOD__, 10 ); $soap_server->setObject( new TTSoapServerHandler( $class_name ) ); $soap_server->handle(); } else { Debug::text( 'Failed to get Company Object!', __FILE__, __LINE__, __METHOD__, 10 ); } } else { Debug::text( 'Failed to get User Object!', __FILE__, __LINE__, __METHOD__, 10 ); } } else { Debug::text( 'Class Factory does not exist!', __FILE__, __LINE__, __METHOD__, 10 ); $soap_server->fault( 9800, 'Class Factory (' . $class_name . ') does not exist!' ); } } else { TTi18n::chooseBestLocale(); //Make sure we set the locale as best we can when not logged in Debug::text( 'User not authenticated! Session likely timed out.', __FILE__, __LINE__, __METHOD__, 10 ); $soap_server->setObject( new TTSoapServerHandler( 'APIAuthentication' ) ); $soap_server->handle(); //PHP appears to exit in this function if there is an error. } } else { TTi18n::chooseBestLocale(); //Make sure we set the locale as best we can when not logged in Debug::text( 'SOAP UnAuthenticated!', __FILE__, __LINE__, __METHOD__, 10 ); $valid_unauthenticated_classes = getUnauthenticatedAPIClasses(); if ( $class_name != '' && in_array( $class_name, $valid_unauthenticated_classes ) && class_exists( $class_name ) ) { $soap_server->setObject( new TTSoapServerHandler( $class_name ) ); $soap_server->handle(); //PHP appears to exit in this function if there is an error. } else { Debug::text( 'Class: ' . $class_name . ' does not exist! (unauth)', __FILE__, __LINE__, __METHOD__, 10 ); } } } else { Debug::text( 'WARNING: Installer/Down For Maintenance is enabled... Service is disabled!', __FILE__, __LINE__, __METHOD__, 10 ); $soap_server->fault( 9500, APPLICATION_NAME . ' is currently undergoing maintenance. We apologize for any inconvenience this may cause, please try again later.' ); } ?>