From 1ee08892e3262f4a9240f975ece09629a78d6fad Mon Sep 17 00:00:00 2001 From: Amol Thite Date: Thu, 14 Jun 2018 15:31:37 +0530 Subject: [PATCH] Task #29 chore: Deprecated site keys view --- code/site/controllers/keys.php | 118 ------------------ code/site/models/key.php | 164 -------------------------- code/site/models/keys.php | 141 ---------------------- code/site/views/keys/index.html | 1 - code/site/views/keys/tmpl/default.php | 47 -------- code/site/views/keys/tmpl/default.xml | 6 - code/site/views/keys/tmpl/edit.php | 54 --------- code/site/views/keys/tmpl/index.html | 1 - code/site/views/keys/view.html.php | 89 -------------- 9 files changed, 621 deletions(-) delete mode 100644 code/site/controllers/keys.php delete mode 100644 code/site/models/key.php delete mode 100644 code/site/models/keys.php delete mode 100644 code/site/views/keys/index.html delete mode 100644 code/site/views/keys/tmpl/default.php delete mode 100644 code/site/views/keys/tmpl/default.xml delete mode 100644 code/site/views/keys/tmpl/edit.php delete mode 100644 code/site/views/keys/tmpl/index.html delete mode 100644 code/site/views/keys/view.html.php diff --git a/code/site/controllers/keys.php b/code/site/controllers/keys.php deleted file mode 100644 index 53c9c0b..0000000 --- a/code/site/controllers/keys.php +++ /dev/null @@ -1,118 +0,0 @@ - - * @link http://techjoomla.com - * Work derived from the original RESTful API by Techjoomla (https://github.com/techjoomla/Joomla-REST-API) - * and the com_api extension by Brian Edgerton (http://www.edgewebworks.com) -*/ - -defined('_JEXEC') or die( 'Restricted access' ); - -jimport('joomla.application.component.controller'); - -class ApiControllerKeys extends ApiController { - - - public function display($cachable = false, $urlparams = array()) { - parent::display(); - } - - private function checkAccess() { - $user = JFactory::getUser(); - - if ($user->get('gid') == 25) : - return true; - endif; - - $params = JComponentHelper::getParams('com_api'); - - if (!$params->get('key_registration')) : - return false; - endif; - - $access_level = $params->get('key_registration_access'); - - if ($user->get('gid') < $access_level) : - return false; - endif; - - return true; - } - - public function cancel() { - - //JRequest::checkToken() or jexit(JText::_("COM_API_INVALID_TOKEN")); - JSession::checkToken() or jexit(JText::_("COM_API_INVALID_TOKEN")); - - $this->setRedirect(JRoute::_('index.php?option=com_api&view=keys', FALSE)); - } - - public function save() { - - JSession::checkToken('default') or jexit(JText::_("COM_API_INVALID_TOKEN")); - - //vishal - for j3.2 - $app = JFactory::getApplication(); - $id = $app->input->post->get('id',0,'INT'); - - if (!$id && !$this->checkAccess()) : - JFactory::getApplication()->redirect('index.php', JText::_('COM_API_NOT_AUTH_MSG')); - exit(); - endif; - - //$domain = JRequest::getVar('domain', '', 'post', 'string'); - $domain = $app->input->post->get('domain','','STRING'); - - $data = array( - 'id' => $id, - 'domain' => $domain, - 'user_id' => JFactory::getUser()->get('id'), - 'enabled' => 1 - ); - - $model = JModel::getInstance('Key', 'ApiModel'); - - if ($model->save($data) === false) : - $this->setRedirect($_SERVER['HTTP_REFERER'], $model->getError(), 'error'); - return false; - endif; - - $this->setRedirect(JRoute::_('index.php?option=com_api&view=keys'), JText::_('COM_API_KEY_SAVED')); - - } - - public function delete() { - - //vishal - for j3.2 - $app = JFactory::getApplication(); - - //$key = $app->input->get('key'); - //JRequest::checkToken('request') or jexit(JText::_("COM_API_INVALID_TOKEN")); - JSession::checkToken('default') or jexit(JText::_("COM_API_INVALID_TOKEN")); - - if (!$this->checkAccess()) : - JFactory::getApplication()->redirect('index.php', JText::_('COM_API_NOT_AUTH_MSG')); - exit(); - endif; - - $user_id = JFactory::getUser()->get('id'); - //$id = JRequest::getInt('id', 0); - $id = $app->input->get('id','','INT'); - - $table = JTable::getInstance('Key', 'ApiTable'); - $table->load($id); - - if ($user_id != $table->user_id) : - $this->setRedirect($_SERVER['HTTP_REFERER'], JText::_("COM_API_UNAUTHORIZED_DELETE_KEY"), 'error'); - return false; - endif; - - $table->delete($id); - - $this->setRedirect($_SERVER['HTTP_REFERER'], JText::_("COM_API_SUCCESSFUL_DELETE_KEY")); - - } - -} diff --git a/code/site/models/key.php b/code/site/models/key.php deleted file mode 100644 index d4be0a2..0000000 --- a/code/site/models/key.php +++ /dev/null @@ -1,164 +0,0 @@ - - * @link http://techjoomla.com - * Work derived from the original RESTful API by Techjoomla (https://github.com/techjoomla/Joomla-REST-API) - * and the com_api extension by Brian Edgerton (http://www.edgewebworks.com) -*/ - -defined('_JEXEC') or die; -jimport('joomla.application.component.model'); - -class ApiModelKey extends ApiModel -{ - public function __construct( $config = array() ) - { - parent::__construct( $config ); - - $app = JFactory::getApplication(); - - $id = $app->input->get( 'id', false,'INT' ); - - if ( !$id ) { - $cid = $app->input->post->get( 'cid', array(),'ARRAY' ); - - $id = @$cid[0]; - } - - if ( $id ) { - $this->setState('id', $id); - } - - } - - public function getList() - { - $where = null; - if($user_id = $this->getState('user_id')) : - $where = 'WHERE userid = '.$this->_db->Quote($user_id); - endif; - - $query = "SELECT id, hash, domain, state, created " - ."FROM #__api_keys " - .$where - ; - $this->_db->setQuery($query); - $tokens = $this->_db->loadObjectList(); - return $tokens; - } - - public function save($data) { - - $creator = JFactory::getUser()->get('id'); - $table = JTable::getInstance('Key', 'ApiTable'); - - $old = JTable::getInstance('Key', 'ApiTable'); - if ($data['id']) : - $old->load($data['id']); - endif; - - if (!$table->bind($data)) : - $this->setError($this->_db->getErrorMsg()); - return false; - endif; - - $table->domain = ($old->domain != $table->domain) ? $this->validateDomain($table->domain) : $table->domain; - if ($table->domain === false) : - return false; - endif; - - $table->created = gmdate("Y-m-d H:i:s"); - $table->created_by = $creator; - - if (!$table->id && !$table->hash) : - $table->hash = $this->generateUniqueHash(); - endif; - - if (!$table->check()) : - $this->setError($table->getError()); - return false; - endif; - - if (!$table->store()) : - $this->setError($table->getError()); - return false; - endif; - - return $table; - } - - public function getData() { - - $table = JTable::getInstance('Key', 'ApiTable'); - if ($this->getState('id', 0)) - $table->load($this->getState('id')); - - return $table; - } - /** - * Delete api key - * - */ - public function delete($cid) { - if (is_array($cid)) : - $where = "id IN (".implode(", ", $cid).")"; - else : - $where = "id = ".(int)$cid; - endif; - - $this->_db->setQuery("DELETE FROM #__api_keys WHERE ".$where); - if (!$this->_db->query()) : - $this->setError($this->_db->getErrorMsg()); - return false; - endif; - return true; - } - - private function generateUniqueHash() { - $seed = $this->makeRandomSeed(); - $hash = sha1(uniqid($seed.microtime())); - - $this->_db->setQuery('SELECT COUNT(*) FROM #__api_keys WHERE hash = "'.$hash.'"'); - $exists = $this->_db->loadResult(); - - if ($exists) : - return $this->generateUniqueHash(); - else : - return $hash; - endif; - } - - private function makeRandomSeed() { - $string = 'abcdefghijklmnopqrstuvwxyz'; - $alpha = str_split($string.strtoupper($string)); - $last = count($alpha)-1; - - $seed = null; - for ($i=0; $i<16; $i++) : - $seed .= $alpha[mt_rand(0, $last)]; - endfor; - return $seed; - } - - public function validateDomain($domain) { - - $sanitized = preg_replace('/(http|https|ftp):\/\//', '', $domain); - - if(!preg_match('/^([0-9a-z-_\.]+\.+[0-9a-z\.]+)|localhost$/i',$sanitized)) : - $this->setError(JText::_('COM_API_INVALID_DOMAIN_MSG')); - return false; - elseif ($sanitized != 'localhost') : - $this->_db->setQuery("SELECT COUNT(*) FROM #__api_keys WHERE domain = ".$this->_db->Quote($sanitized)); - $exists = $this->_db->loadResult(); - if ($exists > 0) : - $this->setError(JText::_('COM_API_DUPLICATE_DOMAIN_MSG')); - return false; - endif; - endif; - - return $sanitized; - } - -} diff --git a/code/site/models/keys.php b/code/site/models/keys.php deleted file mode 100644 index 616718d..0000000 --- a/code/site/models/keys.php +++ /dev/null @@ -1,141 +0,0 @@ - - * @link http://techjoomla.com - * Work derived from the original RESTful API by Techjoomla (https://github.com/techjoomla/Joomla-REST-API) - * and the com_api extension by Brian Edgerton (http://www.edgewebworks.com) -*/ - -defined('_JEXEC') or die; -jimport('joomla.application.component.model'); - -class ApiModelKeys extends ApiModel -{ - - protected $option = null; - protected $view = null; - protected $context = null; - protected $pagination = null; - - protected $list = null; - protected $total = null; - - public function __construct() - { - parent::__construct(); - - //vishal - for j3 changes - $app = JFactory::getApplication(); - - $this->option = $app->input->get('option','','CMD'); - $this->view = $app->input->get('view','','CMD'); - - //$this->option = JRequest::getCmd('option'); - //$this->view = JRequest::getCmd('view'); - - $this->context = $this->option . '.categories'; - - $this->populateState(); - } - - protected function populateState() - { - $app = JFactory::getApplication(); - - $search = $app->getUserStateFromRequest($this->context.'.filter.search', 'filter_search', '', 'string'); - $this->setState('filter.search', $search); - - $limit = $app->getUserStateFromRequest($this->context.'.limit', 'limit', '', 'string'); - $this->setState('limit', $limit); - - $limitstart = $app->getUserStateFromRequest($this->context.'.limitstart', 'limitstart', '', 'string'); - $this->setState('limitstart', $limitstart); - - $filter_order = $app->getUserStateFromRequest($this->context.'.filter.order', 'filter_order', 'k.created', 'string'); - $this->setState('filter.order', $filter_order); - - $filter_order_Dir = $app->getUserStateFromRequest($this->context.'.filter.order_dir', 'filter_order_Dir', 'DESC', 'string'); - $this->setState('filter.order_dir', $filter_order_Dir); - } - - public function getList($override=false, $filter=true) { - if (!$override && $this->get('list') !== null) : - return $this->get('list'); - endif; - - $where = $this->buildWhere(); - $order = $this->buildOrder(); - - $query = "SELECT k.*, u.name, u.username " - ."FROM #__api_keys AS k " - ."LEFT JOIN #__users AS u ON u.id = k.userid " - .$where - .$order - ; - - $this->_db->setQuery($query, $this->getState('limitstart'), $this->getState('limit')); - $this->list = $this->_db->loadObjectList(); - - if ($filter) : - $this->filterList($this->list); - endif; - - return $this->list; - } - - private function filterList( &$list ) - { - for ( $i = 0; $i < count( $list ); $i++ ) { - $row = $list[$i]; - $row->checked_out = false; - $row->checked = JHTML::_('grid.checkedout', $row, $i ); - //$row->published_html = JHTML::_('grid.state', $row, $i); - $row->admin_link = 'index.php?option='.$this->get('option').'&view=key&cid[]='.$row->id; - } - } - - public function getTotal( $override = false ) - { - if ( !$override && $this->get( 'total' ) !== null ) { - return $this->get( 'list' ); - } - - $where = $this->buildWhere(); - $order = $this->buildOrder(); - - $query = "SELECT COUNT(*) " - . "FROM #__api_keys AS k" - . $where - . $order - ; - - $this->_db->setQuery( $query ); - $this->total = $this->_db->loadResult(); - - return $this->total; - } - - private function buildWhere() - { - $where = null; - $wheres = array(); - - if ( !empty( $wheres ) ) { - $where = " WHERE " . implode( ' AND ', $wheres ); - } - - return $where; - } - - private function buildOrder() - { - $ordering = null; - - $ordering = " ORDER BY " . $this->getState( 'filter.order' ) - . ' ' . $this->getState( 'filter.order_dir' ); - - return $ordering; - } -} diff --git a/code/site/views/keys/index.html b/code/site/views/keys/index.html deleted file mode 100644 index fa6d84e..0000000 --- a/code/site/views/keys/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/code/site/views/keys/tmpl/default.php b/code/site/views/keys/tmpl/default.php deleted file mode 100644 index aaddd58..0000000 --- a/code/site/views/keys/tmpl/default.php +++ /dev/null @@ -1,47 +0,0 @@ - - * @link http://techjoomla.com - * Work derived from the original RESTful API by Techjoomla (https://github.com/techjoomla/Joomla-REST-API) - * and the com_api extension by Brian Edgerton (http://www.edgewebworks.com) -*/ -defined('_JEXEC') or die('Restricted access'); -?> - -

- - - - - - - - - tokens); $i++) : - $t = $this->tokens[$i]; - $class = $i%2 ? 'sectiontableentry2' : 'sectiontableentry1'; - $img = $t->state ? 'tick.png' : 'publish_x.png'; - $edit_link = JRoute::_('index.php?option=com_api&view=keys&layout=edit&id='.$t->id); - $delete_link = JRoute::_('index.php?option=com_api&c=keys&task=delete&id='.$t->id.'&'.$this->session_token.'=1'); - $canChange = $this->user->authorise('core.edit.state', 'com_api'); - ?> - - - - - - - -
 
domain;?>hash;?> - state, $i, 'keys.', $canChange, 'cb'); ?> - - can_register) : ?> - Delete - -
- -can_register) : ?> - - diff --git a/code/site/views/keys/tmpl/default.xml b/code/site/views/keys/tmpl/default.xml deleted file mode 100644 index 5d3f545..0000000 --- a/code/site/views/keys/tmpl/default.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - View and generate API Keys - - diff --git a/code/site/views/keys/tmpl/edit.php b/code/site/views/keys/tmpl/edit.php deleted file mode 100644 index 74b77a8..0000000 --- a/code/site/views/keys/tmpl/edit.php +++ /dev/null @@ -1,54 +0,0 @@ - - * @link http://techjoomla.com - * Work derived from the original RESTful API by Techjoomla (https://github.com/techjoomla/Joomla-REST-API) - * and the com_api extension by Brian Edgerton (http://www.edgewebworks.com) -*/ -defined('_JEXEC') or die('Restricted access'); - -JFactory::getDocument()->addScriptDeclaration(" - function submitbutton(pressbutton) { - if (pressbutton == 'save') { - var domain = document.adminForm.domain.value; - var regex_sanitize = /(http|https|ftp):\/\//i - var sanitized = domain.replace(regex_sanitize, ''); - var regex_validate = /^([0-9a-z-_\.]+\.+[0-9a-z\.])+|localhost$/i; - if (regex_validate.test(sanitized) == false) { - alert('".JText::_("COM_API_INVALID_DOMAIN_MSG")."'); - return false; - } - } - submitform(pressbutton); - } -"); - -?> - -

-

key->id ? JText::_('COM_API_EDIT_KEY_PAGE_TITLE') : JText::_('COM_API_NEW_KEY_PAGE_TITLE');?>

-
-

- - - -

- key->hash) : ?> -

- - key->hash;?> -

- -

- - -

- - - - - - -
diff --git a/code/site/views/keys/tmpl/index.html b/code/site/views/keys/tmpl/index.html deleted file mode 100644 index fa6d84e..0000000 --- a/code/site/views/keys/tmpl/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/code/site/views/keys/view.html.php b/code/site/views/keys/view.html.php deleted file mode 100644 index e03383b..0000000 --- a/code/site/views/keys/view.html.php +++ /dev/null @@ -1,89 +0,0 @@ - - * @link http://techjoomla.com - * Work derived from the original RESTful API by Techjoomla (https://github.com/techjoomla/Joomla-REST-API) - * and the com_api extension by Brian Edgerton (http://www.edgewebworks.com) -*/ - -// no direct access -defined('_JEXEC') or die('Restricted access'); - -class ApiViewKeys extends ApiView { - - public $can_register = null; - - public function __construct() { - parent::__construct(); - - $user = JFactory::getUser(); - - if (!$user->get('id')) - { - JFactory::getApplication()->redirect('index.php', JText::_('COM_API_NOT_AUTH_MSG')); - exit(); - } - - $params = JComponentHelper::getParams('com_api'); - - $this->set('can_register', $params->get('key_registration', false) && $user->get('gid') >= $params->get('key_registration_access', 18)); - - } - - public function display($tpl = null) { - - JHTML::stylesheet('com_api.css', 'components/com_api/assets/css/'); - - if ($this->routeLayout($tpl)) : - return; - endif; - - $user = JFactory::getUser(); - - $model = JModelLegacy::getInstance('Key', 'ApiModel'); - $model->setState('user_id', $user->get('id')); - $tokens = $model->getList(); - - $new_token_link = JRoute::_('index.php?option=com_api&view=keys&layout=new'); - - $this->session_token = JHtml::_('form.token'); - $this->new_token_link = $new_token_link; - $this->user = $user; - $this->tokens = $tokens; - - parent::display($tpl); - } - - protected function displayNew($tpl=null) { - $this->setLayout('edit'); - $this->displayEdit($tpl); - } - - protected function displayEdit($tpl=null) { - - $app = JFactory::getApplication(); - - JHTML::script('joomla.javascript.js', 'includes/js/'); - - $this->assignRef('return', $_SERVER['HTTP_REFERER']); - - $key = JTable::getInstance('Key', 'ApiTable'); - if ($id = $app->input->get('id', 0 ,'INT')) : - $key->load($id); - if ($key->user_id != JFactory::getUser()->get('id')) : - JFactory::getApplication()->redirect($_SERVER['HTTP_REFERER'], JText::_('COM_API_UNAUTHORIZED_EDIT_KEY')); - return false; - endif; - elseif (!$this->can_register) : - JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_api&view=keys'), JText::_('COM_API_UNAUTHORIZED_REGISTER')); - return false; - endif; - - $this->assignRef('key', $key); - - parent::display($tpl); - } - -}