public function testExecuteController() { $logger = $this->getMock('Conpago\\Logging\\Contract\\ILogger'); $response = $this->getMock('Conpago\\Helpers\\Contract\\IResponse'); $requestDataReader = $this->getMock('Conpago\\Helpers\\Contract\\IRequestDataReader'); $requestData = $this->getMock('Conpago\\Helpers\\Contract\\IRequestData'); $requestDataReader->expects($this->any())->method('getRequestData')->willReturn($requestData); $controller = $this->getMock('Conpago\\Presentation\\Contract\\IController'); $controller->expects($this->once())->method('execute')->with($requestData); $appConfig = $this->getMock('Conpago\\Config\\Contract\\IAppConfig'); $webApp = new WebApp($requestDataReader, $controller, $response, $logger, $appConfig); $webApp->run(); }
function build() { $page = $this->parent; $breadcrumb = ' <ul class="breadcrumb">' . PHP_EOL; if ($page->parent->config->config['core']['maintenance']) { $breadcrumb .= ' <li class="active">Maintenance</li>' . PHP_EOL; } elseif (!$page->parent->config->config['core']['database']) { $breadcrumb .= ' <li class="active">Site Error</li>' . PHP_EOL; } else { if ($page->getStatus() != 200) { $breadcrumb .= ' <li><a href="/">Home</a></li>' . PHP_EOL; $breadcrumb .= ' <li class="active">' . $page->getTitle() . '</li>' . PHP_EOL; } elseif (WebApp::get('cat3') !== NULL) { $breadcrumb .= ' <li><a href="/">Home</a></li>' . PHP_EOL; $breadcrumb .= ' <li><a href="/' . WebApp::get('cat1') . '">' . ucfirst(WebApp::get('cat1')) . '</a></li>' . PHP_EOL; $breadcrumb .= ' <li><a href="/' . WebApp::get('cat1') . '/' . WebApp::get('cat2') . '">' . ucfirst(WebApp::get('cat2')) . '</a></li>' . PHP_EOL; $breadcrumb .= ' <li class="active">' . $page->getTitle() . '</li>' . PHP_EOL; } elseif (WebApp::get('cat2') !== NULL) { $breadcrumb .= ' <li><a href="/">Home</a></li>' . PHP_EOL; $breadcrumb .= ' <li><a href="/' . WebApp::get('cat1') . '">' . ucfirst(WebApp::get('cat1')) . '</a></li>' . PHP_EOL; $breadcrumb .= ' <li class="active">' . $page->getTitle() . '</li>' . PHP_EOL; } elseif (WebApp::get('cat1') !== 'core') { $breadcrumb .= ' <li><a href="/">Home</a></li>' . PHP_EOL; $breadcrumb .= ' <li class="active">' . $page->getTitle() . '</li>' . PHP_EOL; } else { $breadcrumb .= ' <li class="active">Home</li>' . PHP_EOL; } } $breadcrumb .= ' </ul>' . PHP_EOL; $this->breadcrumb = $breadcrumb; }
public function setAjax() { //$this->parent->addHeader('content-type', 'application/json'); // Check to see if we are in maintenance mode if (!$this->parent->config->config['core']['database']) { $this->setStatus(500); return; } for ($i = 1; $i != 3; $i++) { ${'cat' . $i} = WebApp::get('cat' . $i); } if (!file_exists(__MODULE__ . '/' . $cat2 . '/ajax.php')) { $this->parent->debug($this::name_space . ': Could not find "ajax.php"!'); $this->result = new ActionResult($this, $_SERVER['REQUEST_URI'], 0, 'Whoops, something went wrong with that action and we\'re trying to fix it. <br />Error: <code>Ajax Ctrl not found</code>'); return; } if (!@(include_once __MODULE__ . '/' . $cat2 . '/ajax.php')) { $this->parent->debug($this::name_space . ': Could not access "ajax.php"! Check r/w permissions'); $this->result = new ActionResult($this, $_SERVER['REQUEST_URI'], 0, 'Whoops, something went wrong with that action and we\'re trying to fix it. <br />Error: <code>Failed to open Ajax</code>'); return; } if (class_exists('AjaxController')) { $this->ctrl = new AjaxController($this); $this->parent->debug($this::name_space . ': AjaxController loaded'); } else { $this->parent->debug($this::name_space . ': Could not find AjaxController class in "ajax.php"!'); $this->result = new ActionResult($this, $_SERVER['REQUEST_URI'], 0, 'Whoops, something went wrong with that action and we\'re trying to fix it. <br />Error: <code>Ajax Ctrl Ob not found</code>'); } }
public function menu_pages() { $q = WebApp::get('q'); $m = WebApp::get('m'); if ($q === NULL) { return new ActionResult($this, Server::get('HTTP_Referer'), 0, 'No search term sent', B_T_FAIL, array('pages' => array())); } if ($m === NULL || $m === '') { return new ActionResult($this, Server::get('HTTP_Referer'), 0, 'No module selected', B_T_FAIL, array('pages' => array())); } $pages = array(); $q = '%' . $q . '%'; $page_query = $this->mySQL_r->prepare("SELECT `ID`,`title` FROM `core_pages` WHERE `title` LIKE ? AND `module_id`=?"); if (!$page_query) { return new ActionResult($this, Server::get('HTTP_Referer'), 0, 'Query failed', B_T_FAIL, array('pages' => array())); } $page_query->bind_param('si', $q, $m); $page_query->execute(); $page_query->store_result(); $page_query->bind_result($id, $value); while ($page_query->fetch()) { $page['id'] = $id; $page['text'] = $value; if ($id >= pow(10, 6)) { $page['text'] = '* ' . $page['text']; } $pages[] = $page; } return new ActionResult($this, '/admin/core/menu_add', 0, 'Success', B_T_SUCCESS, array('pages' => $pages)); }
public function delete() { $options = WebApp::post('options') === NULL ? array() : strgetcsv(WebApp::post('options')); if (count($options) == 0) { return new ActionResult($this, '/admin/core/option_view', 0, 'No option(s) were selected!', B_T_FAIL); } foreach ($options as $option) { $validated = GUMP::is_valid(array('opt' => $option), array('opt' => 'integer')); if ($validated !== true) { return new ActionResult($this, '/admin/core/option_view', 0, 'No option(s) were selected!', B_T_FAIL); } } $delete = $this->mySQL_w->prepare("DELETE FROM `core_options` WHERE `id`=?"); $affected_rows = 0; foreach ($options as $id) { $delete->bind_param('i', $id); $delete->execute(); $delete->store_result(); $affected_rows += $delete->affected_rows; } if ($affected_rows == count($options)) { $this->parent->parent->logEvent($this::name_space, 'Deleted options: ' . csvgetstr($options)); return new ActionResult($this, '/admin/core/option_view', 1, 'Successfully deleted selected option(s)!', B_T_SUCCESS); } else { $this->parent->parent->logEvent($this::name_space, 'Deleted some options: ' . csvgetstr($options)); return new ActionResult($this, '/admin/core/option_view', 1, 'Successfully deleted ' . $affected_rows . '/' . count($options) . ' selected option(s)!<br /><small>Possible cause: <code>Unknown</code></small>', B_T_WARNING); } }
function getFooter($parent) { if (WebApp::get('cat1') == 'admin' && $this->parent->parent->user->is_loggedIn()) { return $this->_processPage(__LIBDIR__ . '/modules/admin/pages/footer.php'); } else { return $this->_processPage(__LIBDIR__ . '/modules/core/pages/footer.php'); } }
function uninstall($ctrl) { $uninstall = file_get_contents(dirname(__FILE__) . '/sql/uninstall.sql'); if ($ctrl->mySQL_w->multi_query($uninstall) !== false) { WebApp::clearQuery($ctrl->mySQL_w); return true; } else { return false; } }
function _getFilename() { $pagefile = __MODULE__ . '/location/admin/'; if (WebApp::get('cat3') !== NULL) { $pagefile .= WebApp::get('cat3'); } else { $pagefile .= 'dash'; } return $pagefile; }
/** * Configure Backend Controllers */ public function before() { parent::before(); // Configure Backend require_once APPPATH . 'config' . DIRECTORY_SEPARATOR . 'backend.php'; // Navigation init Navigation::init(Kohana::$config->load('sitemap')->as_array()); // Configure WebApp init data WebApp::set_init_data(array('is_backend' => true, 'backend_url' => URL::backend(), 'base_url' => URL::site())); }
function processAction() { $action = WebApp::get('cat3'); if (is_callable(array($this, $action))) { $this->result = $this->{$action}(); return true; } else { $this->result = new ActionResult($this, Server::get('Request_URI'), 0, 'Whoops, something went wrong with that action and we\'re trying to fix it. <br />Error: <code>Action not found: "' . Server::get('Request_URI') . '"</code>'); return false; } }
public function __construct($file, $php_self, $request_uri) { // parent::__construct($file, $php_self, $request_uri); // if (!isset($this->_config->module['userrole'])) { $this->_config->module['userrole'] = 0; } // $this->addHook('navbar', array($this, 'render_navbar_logged_user')); }
/** * * * @param type $args */ public function __construct($args) { // parent::__construct($args); // if (!isset($this->_config->module['userrole'])) { $this->_config->module['userrole'] = 0; } // $this->addHook('navbar', array($this, 'renderNavbarSessionUser')); }
/** * Example: overrride render method to add content * @return * @param object $view */ protected function render(array $view) { $user = $this->user->getApp_user_name(); // hack: user is logged in if ($user) { $xtra = sprintf('<ul><li><a href="%s">Layer action "test"</a></li>', $this->getActionUrl('test')); $xtra .= sprintf('<li><a href="%s">Test Two legged OAuth call</a></li>', $this->getActionUrl('two_legged')); $xtra .= sprintf('<li><a href="%s">Test Three legged OAuth call</a></li></ul>', $this->getActionUrl('three_legged')); $view['content'] = $xtra . $view['content']; } parent::render($view); }
function _getFilename() { $pagefile = __MODULE__ . '/modules/admin/'; if (WebApp::get('cat3') !== NULL) { $pagefile .= WebApp::get('cat3'); if (WebApp::get('cat4') !== NULL && WebApp::get('cat3') == 'install' || WebApp::get('cat5') !== NULL && WebApp::get('cat4') !== NULL && WebApp::get('cat3') == 'update' || WebApp::get('cat4') !== NULL && WebApp::get('cat3') == 'uninstall') { $pagefile .= '_fromdir'; } } else { $pagefile .= 'dash'; } return $pagefile; }
function _getFilename() { $pagefile = __LIBDIR__ . '/modules/' . WebApp::get('cat2') . '/admin/'; if (WebApp::get('cat3') !== NULL) { $pagefile .= WebApp::get('cat3'); if (WebApp::get('cat4') !== NULL) { $pagefile .= '_' . WebApp::get('cat4'); } } else { $pagefile .= 'dash'; } return $pagefile; }
function processAjax() { $ajax = WebApp::get('cat3'); if (WebApp::get('cat4') !== NULL) { $ajax .= '_' . WebApp::get('cat4'); } if (is_callable(array($this, $ajax))) { $this->result = $this->{$ajax}(); return true; } else { $this->result = new ActionResult($this, $_SERVER['REQUEST_URI'], 0, 'Whoops, something went wrong with that action and we\'re trying to fix it. <br />Error: <code>Ajax not found</code>'); return false; } }
/** * Gets the list of the available valid webapps. * * @return array */ public function &getWebAppsList() { $list = array(); if ($dh = opendir($this->home)) { while (($file = readdir($dh)) !== false) { if ($file != '.' and $file != '..' and is_dir($this->home . $file)) { if (WebApp::isValid($this->home . $file)) { $list[] = $file; } } } closedir($dh); } return $list; }
public function clear_status_msg() { $msg_id = WebApp::get('msg_id'); if ($msg_id === NULL) { $msg_id = WebApp::post('msg_id'); } if ($msg_id === NULL) { $this->parent->parent->debug($this::name_space . ': MSG ID was not provided!'); return new ActionResult($this, '/', 0, 'Failed to clear status message. No ID found.', B_T_FAIL); } $msg_id = trim(str_replace('alert_', '', $msg_id)); $msg_id = base64_decode($msg_id); Session::del('status_msg', $msg_id); $this->parent->parent->debug($this::name_space . ': MSG ID "' . $msg_id . '" was ' . (Session::get('status_msg', $msg_id) === NULL ? '' : 'not ') . 'cleared'); return new ActionResult($this, '/', 0, 'Cleared status message.', B_T_SUCCESS); }
function _getFilename($cat1 = '', $cat2 = '', $cat3 = '', $cat4 = '') { if ($cat1 == '') { for ($i = 1; $i <= 4; $i++) { ${'cat' . $i} = WebApp::get('cat' . $i); } } $pagefile = __LIBDIR__ . '/modules/' . $cat1 . '/pages/'; if ($cat2 !== NULL && $cat2 !== '') { $pagefile .= $cat2; if ($cat3 !== NULL && $cat3 !== '') { $pagefile .= '_' . $cat3; } } else { $pagefile .= 'home'; } return $pagefile; }
public function processPage() { if (WebApp::get('cat2') !== NULL) { $pagefile = $this->ctrl->_getFilename(); } else { $pagefile = $this->_getFilename(); } if (!file_exists($pagefile . '.php')) { $this->parent->parent->debug($this::name_space . ': Failed to load page file "' . str_replace(__LIBDIR__, '', $pagefile) . '.php!'); return false; } $this->parent->parent->debug($this::name_space . ': Loading file "' . str_replace(__LIBDIR__, '', $pagefile . '.php') . '"...'); if (WebApp::get('cat2') !== NULL) { $this->parent->setContent($this->ctrl->_processPage($pagefile . '.php')); } else { $this->parent->setContent($this->_processPage($pagefile . '.php')); } return true; }
public function secondary_groups() { $q = WebApp::get('q'); if ($q === NULL) { return new ActionResult($this, Server::get('HTTP_Referer'), 0, 'No search term sent', B_T_FAIL, array('groups' => array())); } $groups = array(); $q = '%' . $q . '%'; $group_query = $this->mySQL_r->prepare("SELECT `GID`,`name` FROM `core_groups` WHERE `name` LIKE ? AND `type`='s'"); $group_query->bind_param('s', $q); $group_query->execute(); $group_query->store_result(); $group_query->bind_result($id, $value); while ($group_query->fetch()) { $group['id'] = $id; $group['text'] = $value; $groups[] = $group; } return new ActionResult($this, '/admin/email', 0, 'Success', B_T_SUCCESS, array('groups' => $groups)); }
public function setFile() { include __LIBDIR__ . '/fileMIMEs.php'; $this->MIMEs = $MIME_type; if (WebApp::get('cat1') == 'css' || WebApp::get('cat1') == 'js' || WebApp::get('cat1') == 'images') { $filename = strtolower(WebApp::get('cat2')) . '/' . WebApp::get('cat1') . '/' . WebApp::get('cat3'); $i = 4; while (WebApp::get('cat' . $i) !== NULL) { $filename .= '/' . WebApp::get('cat' . $i); $i++; } $this->parent->addHeader('file', $filename); $file = __MODULE__ . '/' . $filename; } elseif (WebApp::get('cat1') == 'fonts') { $file = __EXECDIR__ . '/' . Server::get('REQUEST_URI'); } if (file_exists($file)) { $this->file = $file; } else { $this->file = false; } }
public function check() { $this->parent->parent->debug($this::name_space . ': Checking for login token...'); if (!$this->parent->parent->config->config['core']['database']) { return false; } // Check for token cookie if (Cookie::get('ltkn') === NULL) { $this->parent->parent->debug($this::name_space . ': Login token not found!'); return false; } $this->parent->parent->debug($this::name_space . ': Found token'); $token = Cookie::get('ltkn'); $sessID = Session::getID(); $userID = Session::get('WebApp.User', 'userID'); // It does exist so... // Find token in database where userID = the userID in the token $this->parent->parent->debug($this::name_space . ': Checking sessions table for:'); $this->parent->parent->debug('T: ' . $token . '/ S: ' . $sessID . '/ U: ' . $userID); $token_query = $this->mySQL_r->prepare("SELECT INET_NTOA(`IP`), `auth` FROM `core_sessions` WHERE `token`=? AND `session`=? AND `user`=?"); $token_query->bind_param('ssi', $token, $sessID, $userID); $token_query->execute(); $token_query->store_result(); if ($token_query->num_rows != 1) { $this->parent->parent->debug($this::name_space . ': Failed to find session.'); return false; } $token_query->bind_result($ip, $auth); $token_query->fetch(); if (Server::get('remote_addr') != $ip || $auth) { $update_query = $this->mySQL_w->prepare("UPDATE `core_sessions` SET `auth`=1 WHERE `token`=?"); $update_query->bind_param('s', $token); $update_query->execute(); WebApp::forceRedirect('/user/auth?r=' . urlencode(Server::get('request_uri'))); } $this->parent->parent->debug($this::name_space . ': Found session. Token Check successful!'); return true; }
public function contacts() { $q = WebApp::get('q'); if ($q === NULL) { return new ActionResult($this, '/admin/email', 0, 'No search term sent', B_T_FAIL, array('contacts' => array())); } $contacts = array(); if (filter_var($q, FILTER_VALIDATE_EMAIL)) { $contact['id'] = $q; $contact['text'] = $q; $contacts[] = $contact; } $q = '%' . $q . '%'; $user_query = $this->mySQL_r->prepare("SELECT `username`, CONCAT(`f_name`, ' ', `s_name`) FROM `core_users` WHERE CONCAT(`username`, ' ', `email`) LIKE ?"); $group_query = $this->mySQL_r->prepare("SELECT `name` FROM `core_groups` WHERE `name` LIKE ?"); $user_query->bind_param('s', $q); $user_query->execute(); $user_query->store_result(); $user_query->bind_result($id, $value); while ($user_query->fetch()) { $contact['id'] = $id; $contact['text'] = $value; $contacts[] = $contact; } $user_query->free_result(); $group_query->bind_param('s', $q); $group_query->execute(); $group_query->store_result(); $group_query->bind_result($value); while ($group_query->fetch()) { $contact['id'] = $value; $contact['text'] = '* ' . $value; $contacts[] = $contact; } return new ActionResult($this, '/admin/email', 0, 'Success', B_T_SUCCESS, array('contacts' => $contacts)); }
public function save() { if (WebApp::post('mysql_r_pass') === '') { WebApp::post('mysql_r_pass', $this->parent->parent->config->config['mysql']['r']['pass']); } if (WebApp::post('mysql_w_pass') === '') { WebApp::post('mysql_r_pass', $this->parent->parent->config->config['mysql']['w']['pass']); } $gump = new GUMP(); $gump->validation_rules(array('core_errors' => 'required|boolean', 'core_maintenance' => 'required|boolean', 'core_debug' => 'required|boolean', 'core_https_a' => 'required|boolean', 'core_https_f' => 'required|boolean', 'core_cdn' => 'required', 'mysql_db' => 'required', 'mysql_r_user' => 'required', 'mysql_r_host' => 'required', 'mysql_r_port' => 'required|integer', 'mysql_w_user' => 'required', 'mysql_w_host' => 'required', 'mysql_w_port' => 'required|integer', 'reCAPTCHA_pub' => 'required|alpha_dash', 'reCAPTCHA_priv' => 'required|alpha_dash')); $gump->filter_rules(array('core_cdn' => 'trim|urlencode')); $valid_data = $gump->run($_POST); if ($valid_data === false) { return new ActionResult($this, '/admin/core/config_edit', 0, 'Failed to save config!<br />Error: <code>Please check you have completed all fields as instructed.</code>', B_T_FAIL); } $configFile = fopen(__LIBDIR__ . '/config.inc.php', 'w'); if (fwrite($configFile, $this->getFile($valid_data))) { fclose($configFile); return new ActionResult($this, '/admin/core/config_view', 1, 'Succeesfully saved config!', B_T_SUCCESS); } else { fclose($configFile); return new ActionResult($this, '/admin/core/config_edit', 0, 'Failed to save config!', B_T_SFAIL); } }
function add() { $title = WebApp::post('title') === NULL ? '' : WebApp::post('title'); $p_from = WebApp::post('p_from') === '' ? NULL : getSQLDate(WebApp::post('p_from')); $p_to = WebApp::post('p_to') === '' ? NULL : getSQLDate(WebApp::post('p_to')); $article = WebApp::post('article') === NULL ? '' : WebApp::post('article'); $user = $this->parent->parent->user->getUserID(); $group = $this->parent->parent->user->getGroup(); $aid = removeSpecialChars($title); $article_add = $this->mySQL_w->prepare("INSERT INTO `news_articles` (`title`,`aid`,`user`,`group`,`article`,`date_p`,`publish_f`,`publish_u`) VALUES(?,?,?,?,?,NOW(),?,?)"); if ($article_add == false) { return new ActionResult($this, '/admin/news/article_add', 0, 'Failed to save article.<br />Error: <code>Query failed</code>', B_T_FAIL); } $article_add->bind_param('ssiisss', $title, $aid, $user, $group, $article, $p_from, $p_to); $article_add->execute(); $article_add->store_result(); if ($article_add->affected_rows == 1) { $this->parent->parent->logEvent($this::name_space, 'Added article ' . $title); return new ActionResult($this, '/admin/news/article_view', 1, 'Successfully saved article!', B_T_SUCCESS); } else { $this->parent->parent->logEvent($this::name_space, 'Failed to add article ' . $title); return new ActionResult($this, '/admin/news/article_add', 0, 'Failed to add article.<br />Error: <code>' . $this->mySQL_w->error . '</code>', B_T_FAIL); } }
/** * Initialize WebApp with Layerdefinition object * * @param Laerdefinition $definition * * Initializes HTTP (optionally configured for oAuth requests) */ public function initDefinition($definition) { parent::__construct($definition); }
<?php require_once 'core/webapp.php'; $topmodul = 'gnopaste'; $app = new WebApp(array('topmodul' => $topmodul, 'skip' => array('auth', 'bench', 'test'), 'loglevel' => 3)); $app->run($topmodul);
<?php if (1) { $auditacts = array('list-addform', 'list-dodelete', 'updatefield'); if (in_array($act, $auditacts)) { if (!$gtbl) { $gtbl = new WebApp(); } $gtbl->setTbl($_CONFIG['operatelogtbl']); $gtbl->set('userid', $userid); $gtbl->set('useremail', $user->getEmail()); $gtbl->set('parentid', $_REQUEST['id'] == '' ? 0 : $_REQUEST['id']); $gtbl->set('parenttype', $tbl); $gtbl->set('actionstr', "act:[" . $act . "] id:[" . ($_REQUEST['id'] == '' ? $_REQUEST['id.old'] : $_REQUEST['id']) . "]"); # see act/dodelete.php $hm = $gtbl->setBy("userid,useremail,parentid,parenttype,actionstr,inserttime", null); error_log(__FILE__ . ": log succ. act:[{$act}]"); } else { #error_log(__FILE__.": log fail. act:[$act]"); } }
} $(".location_need_check").removeClass("disabled"); }else{ $("#edit_btn").addClass("disabled"); $(".location_need_check").addClass("disabled"); } }); $("#edit_btn").click(function(e){ var locations = $('.locations_check').filter(":checked") if(locations.length==1){ var id = locations.first().val(); document.location.href = "edit/"+id; }else if(locations.length>1){ alert("Please select one location only to edit"); } return false; }); }) </script> <div> </div> </div> </div> <?php if ($this->inGroup(2, true)) { $delete_modal = $page->getPlugin('modalconf', array('delete', 'location', WebApp::action('location', 'delete', true), 'post')); $delete_modal->addDefaultConfig(); $delete_modal->setDefaultContent()->SetDefaultModal()->setRightBtn('danger', 'Delete', 'trash')->build(); print $delete_modal->getModal(); }