/** * @param array $actionlist */ function dispatch($actionlist) { require_once CLASSES . 'VoodooSetup.php'; if (!count($actionlist)) { // Dont do anything return $this->login(); } $args = array('prepath' => PATH_TO_DOCROOT); $showCredentials = (bool) $this->conf['setup']['insecure_sql_execution']; switch ($actionlist[0]) { // The first admin to be created is the God Admin case 'CreateAdmin': return $this->createAdmin(); break; case 'Login': return $this->login(); break; case 'conf': if (!$this->hasRights($_SESSION['access'], 'conf', 'view')) { return VoodooPrivileges::displayError('Permission Denied'); } $use_conf = ''; if (isset($_REQUEST['conf'])) { $use_conf = $_REQUEST['conf']; } $template =& VoodooTemplate::getInstance(); $template->setDir(ADMIN_TEMPLATES); $conf = VoodooIni::load('voodoo'); $vars = array('prepath' => PATH_TO_DOCROOT, 'controllers' => array()); foreach ($conf['controllers'] as $controller => $enabled) { $enabled && ($vars['controllers'][] = array('name' => $controller, 'selected' => $use_conf == $controller ? ' selected="selected" ' : '')); } if ($conf['controllers'][$use_conf]) { $vars['conf'] = $use_conf; $vars['configuration'] = VoodooIni::getContent($use_conf); if ($this->hasRights($_SESSION['access'], 'conf', 'modify')) { $vars['buttons'] = '<input type="submit" name="save" value="Save Configuration" />'; } } return array('Configuration files', $template->parse('conf.modify', $vars)); break; case 'Init': $complete = false; $cnames = array(); $controllers = $this->controller->voodooConf['controllers']; foreach ($controllers as $controller => $enabled) { $enabled && ($cnames[] = ucfirst($controller)); } if (!$showCredentials || !isset($_POST['dbcredentials'])) { $args['action'] = 'Init'; $template =& VoodooTemplate::getInstance(); $template->setDir(ADMIN_TEMPLATES); $output = ($showCredentials ? $template->parse('credentials', $args) : '') . '<strong>SQL Output</strong><pre class="MonospaceFormat">'; if (!$this->controller->voodooConf['engine']['site.setup']) { $obj = new VoodooSetup(false, $this->controller->conf); $obj->setup(); $output .= $obj->displaySQL(); } foreach ($cnames as $cname) { $output .= $this->controllerSetup($cname); } return array('SQL Output For VOODOO', $output . '</pre>'); } if (!$this->controller->voodooConf['engine']['site.setup']) { $obj = new VoodooSetup($_POST['dbcredentials'], $this->controller->conf); $complete || ($complete = $obj->setup()); } foreach ($cnames as $cname) { $this->controllerSetup($cname, $_POST['dbcredentials']); } header('Location: ' . PATH_TO_DOCROOT . ($complete ? '/' : '/setup/CreateAdmin')); exit; break; case 'Controller': if (count($actionlist) != 2) { exit('Incorrect Setup Of Controller'); } $cname = ucfirst(strtolower($actionlist[1])); if (!$showCredentials || !isset($_POST['dbcredentials'])) { $args['action'] = 'Init'; $template =& VoodooTemplate::getInstance(); $template->setDir(ADMIN_TEMPLATES); $output = ($showCredentials ? $template->parse('credentials', $args) : '') . '<strong>SQL Output</strong><pre class="MonospaceFormat">'; return array('SQL Output For ' . $cname, $output . $this->controllerSetup($cname) . '</pre>'); } $this->controllerSetup($cname, $_POST['dbcredentials']); header('Location: ' . PATH_TO_DOCROOT . '/'); exit; break; } }
/** * @param array $actionlist * @return array(title,content) */ function dispatch($actionlist) { // Less than two params is NOT a valid attachment handler // Example of valids: // * /attachment/Wiki/WikiAttachmentExample // * /attachment/Wiki/WikiAttachmentExample/test.jpg if (count($actionlist) < 2) { return array('Attachment Error', VoodooError::displayError('Incorrect SubController Actionlist')); } // We default to not having an attachment set $attachment = false; if (count($actionlist) == 3) { // The third action from the actionlist is the attachment list($controller, $action, $attachment) = $actionlist; } else { list($controller, $action) = $actionlist; } $this->cont = $controller; $this->action = $action; $lookup = $controller . ($attachment ? '.' . $attachment : ''); // We need at least view rights to continue if (!$this->privs->hasRights($_SESSION['access'], 'view', 'attachment', $this->conf['privileges'], $lookup)) { return array('Attachment Error', VoodooError::displayError('Permission Denied')); } require_once ATTACHMENT_CLASSES . 'Attachment.php'; $class = 'AttachmentLink'; // The controller is enabled. $uc = strtoupper($controller); // Lets see if the linked object has its own linked attachment object if (defined($uc . '_CLASSES')) { $conf = VoodooIni::load($controller); if (!isset($conf['attachment']) || !$conf['attachment']['attachment']) { return array('Attachment Error', VoodooError::displayError('This Controller Doesnt Support Attachments')); } if (isset($conf['attachment']['class'])) { if (!is_file(constant($uc . '_CLASSES') . $conf['attachment']['class'])) { return array('Attachment Error', VoodooError::displayError('This Controller Attachment Class doesnt exist.')); } require_once constant($uc . '_CLASSES') . $conf['attachment']['class']; $class = ucfirst($controller) . 'Attachment'; } } // Lets init a new link object $al = new $class($this->controller->DBConnect(), $uc); if (isset($_REQUEST['action'])) { switch ($_REQUEST['action']) { case 'download': $ad = new AttachmentDownload($this, $attachment, $al); return $ad->execute(); break; case 'create': $ac = new AttachmentCreate($this, $attachment, $al); return $ac->execute(); break; case 'delete': $ad = new AttachmentDelete($this, $attachment, $al); return $ad->execute(); break; case 'modify': break; } } // Display the attachment information, dont auto download $av = new AttachmentView($this, $attachment, $al); return $av->execute(); }
/** * Gets the menu listed in the conf file * TODO: create nested menu's and mkpretty */ function getMenu($conf, $privs) { $p = new VoodooPrivileges($this); $rv = array(); foreach ($conf as $menu => $title) { if (!isset($privs['menu.' . $menu]) || !empty($_SESSION) && $p->hasRights($_SESSION['access'], $menu, 'menu', $privs)) { $rv[] = array('link' => $menu, 'title' => $title, 'class' => ''); } } return $rv; }
/** * @see VoodooPrivileges::hasRights() * @param int $access * @param string $type * @param string $page */ function hasRights($access, $type, $page = '') { return $this->privs->hasRights($access, $type, 'wiki', $this->dispatcher->conf['privileges'], $page); }