/**
  * Refresh the APC cache by deleting APC entries.
  *
  * @return void
  */
 public function refreshAPCCache()
 {
     $configModel = new Default_Model_Configuration();
     $server = $configModel->getKey('api_url');
     $hash = isset($server) ? hash('sha1', $server) : '';
     apc_delete($hash . '-Output.default-format');
 }
Esempio n. 2
0
    protected function _initLanguages()
    {
        $languageDir = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'languages';
        Zend_Registry::set('languageDir', $languageDir);

        $translate = new Zend_Translate(
            'gettext', $languageDir
        );

        $translate->addTranslation($languageDir . DIRECTORY_SEPARATOR . 'en_GB.mo', 'en');
        $translate->addTranslation($languageDir . DIRECTORY_SEPARATOR . 'fr_FR.mo', 'fr');
        $translate->addTranslation($languageDir . DIRECTORY_SEPARATOR . 'it_IT.mo', 'it');
        $translate->addTranslation($languageDir . DIRECTORY_SEPARATOR . 'ru_RU.mo', 'ru');

        $locale = new Zend_Session_Namespace('locale');
        if ($locale->value === null) {

            $config_model  = new Default_Model_Configuration();
            $locale_config = $config_model->getKey('locale');

            isset($locale_config) ? $locale->value = $locale_config : $locale->value = 'en';
        }

        $translate->setLocale($locale->value);

        Zend_Registry::set('tr', $translate);
        Zend_Registry::set('Zend_Translate', $translate);
        Zend_Registry::set('Zend_Locale', $locale);
    }
Esempio n. 3
0
 /**
  * Refresh the APC cache by deleting APC entries.
  *
  * @return void
  */
 public function refreshAPCCache()
 {
     $configModel = new Default_Model_Configuration();
     $server = $configModel->getKey('api_url');
     $hash = isset($server) ? hash('sha1', $server) : '';
     $cache = Frapi_Cache::getInstance(FRAPI_CACHE_ADAPTER);
     $cache->delete($hash . '-Output.default-format');
 }
Esempio n. 4
0
 /**
  * Refresh the APC cache by deleting APC entry.
  *
  * @return void
  */
 public function refreshAPCCache()
 {
     $configModel = new Default_Model_Configuration();
     $server = $configModel->getKey('api_url');
     $hash = isset($server) ? hash('sha1', $server) : '';
     $cache = Frapi_Cache::getInstance(FRAPI_CACHE_ADAPTER);
     $cache->delete($hash . '-Errors.user-defined');
     $cache->delete($hash . '-configFile-errors');
 }
Esempio n. 5
0
 public function indexAction()
 {
     $request = $this->getRequest();
     $form = new Default_Form_Tester();
     $confModel = new Default_Model_Configuration();
     if (!$confModel->getKey("api_url")) {
         $this->addInfoMessage($this->tr->_('TESTER_API_INFO_MESSAGE'));
     }
     $this->view->form = $form;
 }
Esempio n. 6
0
 public function init()
 {
     $actions = array('index', 'detail', 'unset', 'unsetall');
     $this->_helper->_acl->allow('admin', $actions);
     $configModel = new Default_Model_Configuration();
     $server = $configModel->getKey('api_url');
     $cache = $configModel->getKey('cache');
     $this->hash = isset($server) ? hash('sha1', $server) : '';
     $this->cache_keys = array("Output.default-format", "Errors.user-defined", "Router.routes-prepared", "Internal.database-dsn", "Output.formats-enabled", "Actions.enabled-private", "Actions.enabled-public", "Partners.emails-keys", "Cache.adapter");
     parent::init();
 }
 public function indexAction()
 {
     $request = $this->getRequest();
     $form = new Default_Form_Tester();
     $confModel = new Default_Model_Configuration();
     if (!$confModel->getKey("api_url")) {
         $this->addInfoMessage("Remember, you can set the default API domain name in " . "<a href=\"/configuration\">configuration</a>!");
     }
     if (!class_exists("HttpRequest")) {
         $this->addErrorMessage("HttpRequest class was not found &#8212; the " . "<a href=\"http://pecl.php.net/package/pecl_http\" title=\"PECL HTTP\">" . "pecl_http</a> package is required to use the tester.");
     }
     $this->view->form = $form;
 }
Esempio n. 8
0
 /**
  * Generate documentation, in available formats.
  *
  * @return void
  **/
 public function generateAction()
 {
     $doc_data = array();
     $emod = new Default_Model_Error();
     $amod = new Default_Model_Action();
     $omod = new Default_Model_Output();
     $cmod = new Default_Model_Configuration();
     $doc_data['actions'] = $amod->getAll();
     $doc_data['output-types'] = $omod->getAll();
     $doc_data['errors'] = $emod->getAll();
     $doc_data['base_url'] = $cmod->getKey('api_url');
     $this->view->doc_data = $doc_data;
 }
    public function indexAction()
    {
        $config_model = new Default_Model_Configuration();
        $form         = new Default_Form_Configuration();
        $lang_form    = new Default_Form_Language();

        $config_dir = Zend_Registry::get('localConfigPath');
        $config_file = $config_dir . 'configurations.xml';

        // Lets make sure our permissions are ok before the user modifies config
        if (!is_writable($config_dir)) {
            $configPathMessage = sprintf($this->tr->_('ACTION_DIR_PROBLEM'), $config_dir);
            $setupHelpMessage  = $this->tr->_('SETUP_HELP_MESSAGE');
            $this->addErrorMessage(
                $configPathMessage .' <br /><br />' . $setupHelpMessage
            );
        } elseif (!is_writable($config_file)) {
            $configFileMessage = sprintf($this->tr->_('FILE_NOT_WRITABLE'), $config_file);
            $setupHelpMessage  = $this->tr->_('SETUP_HELP_MESSAGE');
            $this->addErrorMessage(
                 $configFileMessage .' <br /><br />' . $setupHelpMessage
            );
        }    
   
        $request = $this->getRequest();
        if ($request->isPost()) {
            if ($form->isValid($request->getPost())) {
                try {
                    $res = $config_model->updateApiUrl($request->getParam('api_url'));
                    if ($res !== false) {
                        $this->addMessage($this->tr->_('CONFIG_UPDATE_SUCCESS'));
                        $this->_redirect('/configuration');
                    } else  {
                        $this->addErrorMessage($this->tr->_('CONFIG_UPDATE_FAIL'));
                    }
                } catch (RuntimeException $e) {
                    $this->addErrorMessage($this->tr->_('CONFIG_UPDATE_FAIL') . ": " . $e->getMessage());
                } 
            }
        } else {
            $form->populate(array(
                'api_url' => $config_model->getKey('api_url')
            ));
        }
        $this->view->form = $form;
        $this->view->lang_form = $lang_form;
    }
Esempio n. 10
0
 public function indexAction()
 {
     $config_model = new Default_Model_Configuration();
     $data = $this->_request->getParams();
     if ($this->_request->isPost()) {
         if (isset($data['system_wide']) && $data['system_wide'] == 1) {
             $config_model->updateLocale($data['languages']);
         }
         $localeSession = new Zend_Session_Namespace('locale');
         $translate = Zend_Registry::get('tr');
         $translate->setLocale($data['languages']);
         $locale = new Zend_Locale($data['languages']);
         Zend_Registry::set('locale', $locale);
         Zend_Registry::set('tr', $translate);
         $localeSession->value = $data['languages'];
     }
     $this->_redirect('/');
 }
 public function indexAction()
 {
     $config_model = new Default_Model_Configuration();
     $form = new Default_Form_Configuration();
     $data = $this->_request->getParams();
     if ($this->_request->isPost()) {
         if ($form->isValid($data)) {
             $res = $config_model->updateApiUrl($data['api_url']);
             if ($res !== false) {
                 $this->addMessage('Configuration updated!');
                 $this->_redirect('/configuration');
             }
         }
     } else {
         $form->populate(array('api_url' => $config_model->getKey('api_url')));
         $this->view->form = $form;
     }
 }
Esempio n. 12
0
 public function editAction()
 {
     $form = new Default_Form_Database();
     $model = new Default_Model_Configuration();
     $this->view->form = $form;
     $data = $this->_request->getParams();
     if ($this->_request->isPost()) {
         if ($form->isValid($data)) {
             $res = $model->editDb($data);
             if ($res !== false) {
                 $this->addMessage('Database updated with great success!');
                 $this->_redirect('/database');
             }
         }
     } else {
         $res = $model->getDbConfig();
         $keys = array();
         foreach ($res as $key => $value) {
             $keys[$value['key']] = $value['value'];
         }
         $form->populate($keys);
         $this->view->form = $form;
     }
 }
Esempio n. 13
0
 /**
  * Refresh the APC cache by deleting APC entries.
  *
  * @return void
  */
 public function refreshAPCCache()
 {
     $configModel = new Default_Model_Configuration();
     $server = $configModel->getKey('api_url');
     $hash = isset($server) ? hash('sha1', $server) : '';
     $cache = Frapi_Cache::getInstance(FRAPI_CACHE_ADAPTER);
     $cache->delete($hash . '-Actions.enabled-public');
     $cache->delete($hash . '-Actions.enabled-private');
     $cache->delete($hash . '-Router.routes-prepared');
     $cache->delete($hash . '-configFile-actions');
 }
Esempio n. 14
0
define('CONSOLE_CONTROLLERS_PATH', APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'console' . DIRECTORY_SEPARATOR . 'controllers');
// Define application environment
define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production');
set_include_path('.' . PATH_SEPARATOR . ROOT_PATH . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR . get_include_path());
// Create application, bootstrap, and run
require_once 'Zend/Application.php';
require_once ROOT_PATH . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'Frapi' . DIRECTORY_SEPARATOR . 'AllFiles.php';
require_once ROOT_PATH . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR . 'AllFiles.php';
/**
 * Set our HTTP_HOST so hashing will work properly
 */
global $_SERVER;
$_SERVER['HTTP_HOST'] = '';
$app = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'application.ini');
$app->bootstrap(array('config', 'db', 'defaultAutoloader', 'languages'));
$configModel = new Default_Model_Configuration();
$_SERVER['HTTP_HOST'] = $configModel->getKey('api_url');
// Valid things we can do
$routes = array('action' => array('add' => 'action/add', 'delete' => 'action/delete', 'test' => 'action/test'), 'actions' => array('list' => 'action/list', 'sync' => 'action/sync'), 'error' => array('add' => 'errors/add', 'delete' => 'errors/delete'), 'errors' => array('list' => 'errors/list'), 'partner' => array('add' => 'partner/add', 'delete' => 'partner/delete'), 'partners' => array('list' => 'partner/list'));
$tr = Zend_Registry::get('tr');
if ($argc < 3) {
    echo $tr->_('USAGE_MSG') . PHP_EOL;
    exit;
}
$action = $argv[1];
$module = $argv[2];
if (!isset($routes[$module][$action])) {
    echo $tr->_('INVALID_MODULE_ACTION') . PHP_EOL;
    echo $tr->_('VALID_OPTIONS') . ':' . PHP_EOL;
    foreach ($routes as $module => $actions) {
        echo $module . PHP_EOL;
Esempio n. 15
0
 public function init()
 {
     $routesAndActions = array('Actions' => array(), 'Routes' => array());
     $model = new Default_Model_Action();
     $allActions = $model->getAll();
     foreach ($allActions as $db_action) {
         $routesAndActions['Actions'][$db_action['hash']] = $db_action['name'];
         if (!empty($db_action['route'])) {
             $routesAndActions['Routes']['route-' . $db_action['hash']] = $db_action['route'];
         }
     }
     $action = new Zend_Form_Element_Select('action');
     $action->setLabel('Action');
     $action->addMultiOptions($routesAndActions);
     $this->addElement($action);
     $params = new Zend_Form_Element_Text('query_uri');
     $params->setLabel('Query URI');
     $params->setRequired(true);
     $params->setAttrib('size', '80');
     $this->addElement($params);
     $t = new Default_Model_Tester();
     $output = $t->buildForm();
     $p = new Lupin_Form_Element_Static('params');
     $p->setValue($output);
     $p->setLabel('Params');
     $this->addElement($p);
     $formats = array();
     $outputModel = new Default_Model_Output();
     $format = new Zend_Form_Element_Select('format');
     $format->setLabel('Format');
     $format->setRequired(true);
     foreach ($outputModel->getAll() as $key => $db_format) {
         $formats[$db_format["name"]] = $db_format["name"] . (!$db_format["enabled"] ? " (disabled)" : '');
         if ($db_format["default"] != '0') {
             $format->setValue(array($db_format["name"], $db_format["name"]));
         }
     }
     $format->addMultiOptions($formats);
     $this->addElement($format);
     $methods = array('get' => 'GET', 'post' => 'POST', 'put' => 'PUT', 'delete' => 'DELETE', 'head' => 'HEAD');
     $method = new Zend_Form_Element_Select('method');
     $method->setLabel('Method');
     $method->setRequired(true);
     $method->addMultiOptions($methods);
     $this->addElement($method);
     $email = new Zend_Form_Element_Text('email');
     $email->setLabel('Email');
     $email->setAttrib('size', '40');
     $this->addElement($email);
     $key = new Zend_Form_Element_Text('key');
     $key->setLabel('Secret Key');
     $key->setAttrib('size', '40');
     $this->addElement($key);
     $email_key = new Zend_Form_Element_Select('email-key');
     $email_key->setLabel('Load Email/Key Combo');
     $params->setAttrib('size', '55');
     $emails_keys = array(0 => 'Select a combination to fill the fields above.');
     $partnerModel = new Default_Model_Partner();
     $partners = $partnerModel->getAll();
     if (!empty($partners)) {
         foreach ($partners as $key => $partner) {
             if (!empty($partner)) {
                 $emails_keys[$partner['hash']] = $partner['email'] . ' / ' . $partner['api_key'];
             }
         }
     }
     $email_key->addMultiOptions($emails_keys);
     $this->addElement($email_key);
     $config_model = new Default_Model_Configuration();
     $url = new Zend_Form_Element_Text('url');
     $url->setLabel('API Domain');
     $url->setRequired(true);
     $url->setValue($config_model->getKey("api_url"));
     $this->addElement($url);
     parent::init();
 }
Esempio n. 16
0
 public function init()
 {
     $this->setAction(URL_BASE . '/tester');
     $tr = Zend_Registry::get('tr');
     $routesAndActions = array('Routes' => array(), 'History' => array());
     $model = new Default_Model_Action();
     $allActions = $model->getAll();
     foreach ($allActions as $db_action) {
         if (!empty($db_action['route'])) {
             $routesAndActions['Routes']['route-' . $db_action['hash']] = $db_action['route'];
         }
     }
     $test_history = new Zend_Session_Namespace('test_history');
     $history = $test_history->value;
     if ($history) {
         foreach ($history as $route => $data) {
             if (!empty($route)) {
                 $routesAndActions['History'][$route] = $route;
             }
         }
     }
     $action = new Zend_Form_Element_Select('action');
     $action->setLabel($tr->_('ACTION'));
     $action->addMultiOptions($routesAndActions);
     $this->addElement($action);
     $params = new Zend_Form_Element_Text('query_uri');
     $params->setLabel($tr->_('QUERY_URI'));
     $params->setRequired(true);
     $params->addValidator('NotEmpty', true, array('messages' => $tr->_('GENERAL_MISSING_TEXT_VALUE')));
     $params->setAttrib('size', '80');
     $this->addElement($params);
     $t = new Default_Model_Tester();
     $output = $t->buildForm();
     $p = new Lupin_Form_Element_Static('params');
     $p->setValue($output);
     $p->setLabel($tr->_('PARAMS'));
     $this->addElement($p);
     $formats = array();
     $outputModel = new Default_Model_Output();
     $format = new Zend_Form_Element_Select('format');
     $format->setLabel($tr->_('FORMAT'));
     $format->setRequired(true);
     foreach ($outputModel->getAll() as $key => $db_format) {
         $formats[$db_format["name"]] = $db_format["name"] . (!$db_format["enabled"] ? " (" . $tr->_('DISABLED') . ")" : '');
         if ($db_format["default"] != '0') {
             $format->setValue(array($db_format["name"], $db_format["name"]));
         }
     }
     $format->addMultiOptions($formats);
     $this->addElement($format);
     $methods = array('get' => 'GET', 'post' => 'POST', 'put' => 'PUT', 'delete' => 'DELETE', 'head' => 'HEAD');
     // Explicitly turn off translations, our DELETE got translated
     $method = new Zend_Form_Element_Select('method', array('disableTranslator' => true));
     $method->setLabel($tr->_('METHOD'));
     $method->setRequired(true);
     $method->addMultiOptions($methods);
     $this->addElement($method);
     $email = new Zend_Form_Element_Text('email');
     $email->setLabel($tr->_('EMAIL'));
     $email->setAttrib('size', '40');
     $this->addElement($email);
     $key = new Zend_Form_Element_Text('key');
     $key->setLabel($tr->_('SECRET_KEY'));
     $key->setAttrib('size', '40');
     $this->addElement($key);
     $email_key = new Zend_Form_Element_Select('email-key');
     $email_key->setLabel($tr->_('LOAD_EMAIL_KEY'));
     $params->setAttrib('size', '55');
     $emails_keys = array(0 => $tr->_('SELECT_COMBO_OF_FIELDS'));
     $partnerModel = new Default_Model_Partner();
     $partners = $partnerModel->getAll();
     if (!empty($partners)) {
         foreach ($partners as $key => $partner) {
             if (!empty($partner)) {
                 $emails_keys[$partner['hash']] = $partner['email'] . ' / ' . $partner['api_key'];
             }
         }
     }
     $email_key->addMultiOptions($emails_keys);
     $this->addElement($email_key);
     $config_model = new Default_Model_Configuration();
     $url = new Zend_Form_Element_Text('url');
     $url->setLabel($tr->_('API_DOMAIN'));
     $url->setRequired(true);
     $url->addValidator('NotEmpty', true, array('messages' => $tr->_('GENERAL_MISSING_TEXT_VALUE')));
     $url->setValue($config_model->getKey("api_url"));
     $this->addElement($url);
     $ssl = new Zend_Form_Element_Checkbox('ssl');
     $ssl->setLabel($tr->_('USE_HTTPS'));
     $this->addElement($ssl);
     parent::init();
 }
Esempio n. 17
0
 /**
  * Test an action
  *
  * This is the test action method. It test a specific action.
  *
  * @return void
  */
 public function testAction()
 {
     $this->_helper->viewRenderer->setViewSuffix('txt');
     // The options we are accepting for adding
     $options = new Zend_Console_Getopt(array('name|n=s' => 'Name of the action to call.', 'parameters|p=s' => 'Paramters to use. For example var1=val1&var2=val2', 'format|f=s' => 'Format to return. Defaults to XML.', 'method|m=s' => 'Method to use. Defaults to GET.', 'email|e=s' => 'Email or username to use.', 'secretkey|sk=s' => 'Secret key associated with email passed.', 'domain|d=s' => 'Domain to use, if not included will use default', 'query-uri|u=s' => 'Query uri to use. For example /testing/1', 'https|h' => 'Use https.'));
     try {
         $options->parse();
     } catch (Zend_Console_Getopt_Exception $e) {
         $this->view->message = $e->getUsageMessage();
         return;
     }
     if ($options->name == '') {
         $this->view->message = $options->getUsageMessage();
         return;
     }
     $confModel = new Default_Model_Configuration();
     if (!$confModel->getKey('api_url')) {
         $this->view->message = 'Remember you can set the default API domain name in your admin configuration.' . PHP_EOL;
     }
     if (!class_exists('HttpRequest')) {
         $this->view->message = 'HttpRequest class was not found the pecl_http (http://pecl.php.net/package/pecl_http) package is required to use the tester.' . PHP_EOL;
         return;
     }
     $action_name = $options->name;
     $params = $options->parameters;
     $format = $options->format;
     $method = $options->method;
     $email = $options->email;
     $password = $options->secretkey;
     $url = $options->domain;
     $ssl = $options->https;
     $query_uri = $options->getOption('query-uri');
     if ($url == '') {
         $url = $confModel->getKey('api_url');
     }
     if ($query_uri == '') {
         $actionModel = new Default_Model_Action();
         $actions = $actionModel->getAll();
         foreach ($actions as $action_details) {
             if ($action_details['name'] == $action_name) {
                 $query_uri = $action_details['route'];
             }
         }
     }
     $newMethod = HTTP_METH_GET;
     switch (strtolower($method)) {
         case 'get':
             $newMethod = HTTP_METH_GET;
             break;
         case 'post':
             $newMethod = HTTP_METH_POST;
             break;
         case 'put':
             $newMethod = HTTP_METH_PUT;
             break;
         case 'delete':
             $newMethod = HTTP_METH_DELETE;
             break;
         case 'head':
             $newMethod = HTTP_METH_HEAD;
             break;
     }
     $request_url = 'http' . ($ssl !== null ? 's' : '') . '://' . $url . '/' . $query_uri . '.' . strtolower($format);
     $httpOptions = array();
     if ($email && $password) {
         $httpOptions = array('headers' => array('Accept' => '*/*'), 'httpauth' => $email . ':' . $password, 'httpauthtype' => HTTP_AUTH_DIGEST);
     }
     $request = new HttpRequest($request_url, $newMethod, $httpOptions);
     if ("POST" == strtoupper($method)) {
         $request->setBody($params);
     } else {
         $request->setQueryData($params);
     }
     $res = $request->send();
     $responseInfo = $request->getResponseInfo();
     $this->view->request_url = $responseInfo['effective_url'];
     $this->view->response_header = $this->collapseHeaders($res->getHeaders());
     $this->view->content = $res->getBody();
     $this->view->status = $res->getResponseCode();
     $this->view->method = isset($method) ? strtoupper($method) : 'GET';
     $this->view->request_post_fields = $newMethod == HTTP_METH_POST ? $params : '';
 }
Esempio n. 18
0
 /**
  * Refresh the APC cache by deleting APC entries.
  *
  * @return void
  */
 public function refreshAPCCache()
 {
     $configModel = new Default_Model_Configuration();
     $server = $configModel->getKey('api_url');
     $hash = isset($server) ? hash('sha1', $server) : '';
     apc_delete($hash . '-Actions.enabled-public');
     apc_delete($hash . '-Actions.enabled-private');
     apc_delete($hash . '-Router.routes-prepared');
 }