/**
  * (non-PHPdoc)
  * @see Tinebase_Server_Interface::handle()
  */
 public function handle(\Zend\Http\Request $request = null, $body = null)
 {
     Tinebase_Session::setSessionOptions(array('use_cookies' => 0, 'use_only_cookies' => 0));
     Tinebase_Core::initFramework();
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' is snom xml request. method: ' . $this->getRequestMethod());
     }
     $server = new Tinebase_Http_Server();
     $server->setClass('Voipmanager_Frontend_Snom', 'Voipmanager');
     $server->setClass('Phone_Frontend_Snom', 'Phone');
     $server->handle($_REQUEST);
 }
Example #2
0
 /**
  * handler for HTTP api requests
  * @todo session expire handling
  * 
  * @return HTTP
  */
 public function handle()
 {
     Setup_Core::initFramework();
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' is http request. method: ' . (isset($_REQUEST['method']) ? $_REQUEST['method'] : 'EMPTY'));
     }
     $server = new Tinebase_Http_Server();
     $server->setClass('Setup_Frontend_Http', 'Setup');
     if (empty($_REQUEST['method'])) {
         $_REQUEST['method'] = 'Setup.mainScreen';
     }
     $server->handle($_REQUEST);
 }
Example #3
0
 /**
  * handler for command line scripts
  * 
  * @return boolean
  */
 public function handle()
 {
     if (isset($_REQUEST['TINE20SESSID'])) {
         Zend_Session::setId($_REQUEST['TINE20SESSID']);
     }
     Tinebase_Core::initFramework();
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' is snom xml request. method: ' . (isset($_REQUEST['method']) ? $_REQUEST['method'] : 'EMPTY'));
     }
     $server = new Tinebase_Http_Server();
     $server->setClass('Voipmanager_Frontend_Snom', 'Voipmanager');
     $server->setClass('Phone_Frontend_Snom', 'Phone');
     $server->handle($_REQUEST);
 }
 /**
  * (non-PHPdoc)
  * @see Tinebase_Server_Interface::handle()
  */
 public function handle(\Zend\Http\Request $request = null, $body = null)
 {
     Tinebase_Session_Abstract::setSessionEnabled('TINE20SETUPSESSID');
     if (Tinebase_Session::sessionExists()) {
         Setup_Core::startSetupSession();
     }
     Setup_Core::initFramework();
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' is http request. method: ' . $this->getRequestMethod());
     }
     $server = new Tinebase_Http_Server();
     $server->setClass('Setup_Frontend_Http', 'Setup');
     $server->setClass('Tinebase_Frontend_Http', 'Tinebase');
     // needed for fetching translation in DEVELOPMENT mode
     if (empty($_REQUEST['method'])) {
         $_REQUEST['method'] = 'Setup.mainScreen';
     }
     $server->handle($_REQUEST);
 }
Example #5
0
 /**
  * handler for command line scripts
  * 
  * @return boolean
  */
 public function handle()
 {
     Tinebase_Core::initFramework();
     #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ .' is Asterisk curl request: ' . print_r($_REQUEST, true));
     if (Tinebase_Controller::getInstance()->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR'], 'TineAsterisk') === true) {
         $server = new Tinebase_Http_Server();
         $server->setClass('Voipmanager_Frontend_Asterisk_SipPeers', 'Voipmanager_SipPeers');
         $server->setClass('Voipmanager_Frontend_Asterisk_SipRegs', 'Voipmanager_SipRegs');
         $server->setClass('Voipmanager_Frontend_Asterisk_CallForward', 'Voipmanager_CallForward');
         $server->setClass('Voipmanager_Frontend_Asterisk_MeetMe', 'Voipmanager_MeetMe');
         list($class, $method) = explode('.', $_REQUEST['method']);
         // ugly hack to parse requests from res_config_curl
         if ($method == 'handleResConfig') {
             // set method to a usefull value
             $pos = strpos($_REQUEST['action'], '?');
             if ($pos !== false) {
                 $action = substr($_REQUEST['action'], 0, $pos);
                 list($key, $value) = explode('=', substr($_REQUEST['action'], $pos + 1));
                 $_REQUEST[$key] = $value;
             } else {
                 $action = $_REQUEST['action'];
             }
             #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ .' action: ' . $action);
             $method = ucfirst(substr($action, 1));
             $_REQUEST['method'] = $class . '.handle' . $method;
         }
         #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ .' action: ' . print_r($_REQUEST, true));
         $server->handle($_REQUEST);
         Tinebase_Controller::getInstance()->logout($_SERVER['REMOTE_ADDR']);
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' auth failed ');
         }
     }
 }
 /**
  * (non-PHPdoc)
  * @see Tinebase_Server_Interface::handle()
  */
 public function handle(\Zend\Http\Request $request = null, $body = null)
 {
     $this->_request = $request instanceof \Zend\Http\Request ? $request : Tinebase_Core::get(Tinebase_Core::REQUEST);
     $this->_body = $body !== null ? $body : fopen('php://input', 'r');
     Tinebase_Core::initFramework();
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' is Asterisk curl request: ' . print_r($_REQUEST, true));
     }
     if (Tinebase_Controller::getInstance()->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $this->_request, self::REQUEST_TYPE) === true) {
         $server = new Tinebase_Http_Server();
         $server->setClass('Voipmanager_Frontend_Asterisk_SipPeers', 'Voipmanager_SipPeers');
         $server->setClass('Voipmanager_Frontend_Asterisk_SipRegs', 'Voipmanager_SipRegs');
         $server->setClass('Voipmanager_Frontend_Asterisk_CallForward', 'Voipmanager_CallForward');
         $server->setClass('Voipmanager_Frontend_Asterisk_MeetMe', 'Voipmanager_MeetMe');
         $_REQUEST['method'] = $this->getRequestMethod();
         $server->handle($_REQUEST);
         Tinebase_Controller::getInstance()->logout($_SERVER['REMOTE_ADDR']);
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' auth failed ');
         }
     }
 }
Example #7
0
 /**
  * handler for HTTP api requests
  * @todo session expire handling
  * 
  * @return HTTP
  */
 public function handle()
 {
     try {
         Tinebase_Core::initFramework();
         Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . ' Is HTTP request. method: ' . (isset($_REQUEST['method']) ? $_REQUEST['method'] : 'EMPTY'));
         //Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ .' Rawdata: ' . print_r($_REQUEST, true));
         $server = new Tinebase_Http_Server();
         //NOTE: auth check for Tinebase HTTP api is done via Tinebase_Http::checkAuth
         $server->setClass('Tinebase_Frontend_Http', 'Tinebase');
         // register addidional HTTP apis only available for authorised users
         if (Zend_Auth::getInstance()->hasIdentity()) {
             if (empty($_REQUEST['method'])) {
                 $_REQUEST['method'] = 'Tinebase.mainScreen';
             }
             $applicationParts = explode('.', $_REQUEST['method']);
             $applicationName = ucfirst($applicationParts[0]);
             if (Tinebase_Core::getUser() && Tinebase_Core::getUser()->hasRight($applicationName, Tinebase_Acl_Rights_Abstract::RUN)) {
                 try {
                     $server->setClass($applicationName . '_Frontend_Http', $applicationName);
                 } catch (Exception $e) {
                     Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " Failed to add HTTP API for application '{$applicationName}' Exception: \n" . $e);
                 }
             }
         }
         if (empty($_REQUEST['method'])) {
             $_REQUEST['method'] = 'Tinebase.login';
         }
         $server->handle($_REQUEST);
     } catch (Exception $exception) {
         if (!is_object(Tinebase_Core::getLogger())) {
             // no logger -> exception happened very early, just rethrow it
             error_log($exception);
             header('HTTP/1.0 503 Service Unavailable');
             die('Service Unavailable');
         }
         Tinebase_Core::getLogger()->INFO($exception);
         $server = new Tinebase_Http_Server();
         $server->setClass('Tinebase_Frontend_Http', 'Tinebase');
         if ($exception instanceof Zend_Session_Exception) {
             Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . ' Attempt to request a privileged Http-API method without valid session from "' . $_SERVER['REMOTE_ADDR']);
             // expire session cookie for client
             Zend_Session::expireSessionCookie();
             header('HTTP/1.0 403 Forbidden');
             exit;
         } else {
             try {
                 // check if setup is required
                 $setupController = Setup_Controller::getInstance();
                 if ($setupController->setupRequired()) {
                     $server->handle(array('method' => 'Tinebase.setupRequired'));
                 } else {
                     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                         Tinebase_Core::getLogger()->DEBUG(__CLASS__ . '::' . __METHOD__ . ' (' . __LINE__ . ') Http-Api exception: ' . print_r($exception, true));
                     }
                     $server->handle(array('method' => 'Tinebase.exception'));
                 }
             } catch (Exception $e) {
                 error_log($exception);
                 header('HTTP/1.0 503 Service Unavailable');
                 die('Service Unavailable');
             }
         }
     }
 }
 /**
  * (non-PHPdoc)
  * @see Tinebase_Server_Interface::handle()
  */
 public function handle(\Zend\Http\Request $request = null, $body = null)
 {
     $this->_request = $request instanceof \Zend\Http\Request ? $request : Tinebase_Core::get(Tinebase_Core::REQUEST);
     $this->_body = $body !== null ? $body : fopen('php://input', 'r');
     $server = new Tinebase_Http_Server();
     $server->setClass('Tinebase_Frontend_Http', 'Tinebase');
     $server->setClass('Filemanager_Frontend_Download', 'Download');
     try {
         if (Tinebase_Session::sessionExists()) {
             try {
                 Tinebase_Core::startCoreSession();
             } catch (Zend_Session_Exception $zse) {
                 // expire session cookie for client
                 Tinebase_Session::expireSessionCookie();
             }
         }
         Tinebase_Core::initFramework();
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Is HTTP request. method: ' . $this->getRequestMethod());
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' REQUEST: ' . print_r($_REQUEST, TRUE));
         }
         // register additional HTTP apis only available for authorised users
         if (Tinebase_Session::isStarted() && Zend_Auth::getInstance()->hasIdentity()) {
             if (empty($_REQUEST['method'])) {
                 $_REQUEST['method'] = 'Tinebase.mainScreen';
             }
             $applicationParts = explode('.', $this->getRequestMethod());
             $applicationName = ucfirst($applicationParts[0]);
             if (Tinebase_Core::getUser() && Tinebase_Core::getUser()->hasRight($applicationName, Tinebase_Acl_Rights_Abstract::RUN)) {
                 try {
                     $server->setClass($applicationName . '_Frontend_Http', $applicationName);
                 } catch (Exception $e) {
                     Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " Failed to add HTTP API for application '{$applicationName}' Exception: \n" . $e);
                 }
             }
         } else {
             if (empty($_REQUEST['method'])) {
                 $_REQUEST['method'] = 'Tinebase.login';
             }
             // sessionId got send by client, but we don't use sessions for non authenticated users
             if (Tinebase_Session::sessionExists()) {
                 // expire session cookie on client
                 Tinebase_Session::expireSessionCookie();
             }
         }
         $this->_method = $this->getRequestMethod();
         $server->handle($_REQUEST);
     } catch (Zend_Json_Server_Exception $zjse) {
         // invalid method requested or not authenticated, etc.
         Tinebase_Exception::log($zjse);
         Tinebase_Core::getLogger()->INFO(__METHOD__ . '::' . __LINE__ . ' Attempt to request a privileged Http-API method without valid session from "' . $_SERVER['REMOTE_ADDR']);
         header('HTTP/1.0 403 Forbidden');
         exit;
     } catch (Exception $exception) {
         Tinebase_Exception::log($exception, false);
         try {
             $setupController = Setup_Controller::getInstance();
             if ($setupController->setupRequired()) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setup required');
                 }
                 $this->_method = 'Tinebase.setupRequired';
             } else {
                 if (preg_match('/download|export/', $this->_method)) {
                     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Server error during download/export - exit with 500');
                     }
                     header('HTTP/1.0 500 Internal Server Error');
                     exit;
                 } else {
                     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Show mainscreen with setup exception');
                     }
                     $this->_method = 'Tinebase.exception';
                 }
             }
             $server->handle(array('method' => $this->_method));
         } catch (Exception $e) {
             header('HTTP/1.0 503 Service Unavailable');
             die('Service Unavailable');
         }
     }
 }