Esempio n. 1
0
 public static function main()
 {
     $title = $content = NULL;
     $message = Access::getMessage();
     if (!Current_User::allow('access')) {
         Current_User::disallow();
         exit;
     }
     $panel = Access::cpanel();
     if (isset($_REQUEST['command'])) {
         $command = $_REQUEST['command'];
     } else {
         $command = $panel->getCurrentTab();
     }
     // If the command is empty, that means no tabs were set
     // In this case, an admin with full rights needs to log in
     if (empty($command)) {
         $title = dgettext('access', 'Sorry');
         $content = dgettext('access', 'Access needs a higher administrator\'s attention before you may use it.');
     } else {
         switch ($command) {
             case 'post_admin':
                 Access::saveAdmin();
                 Access::sendMessage(dgettext('access', 'Settings saved.'), 'admin');
                 break;
             case 'restore_default':
                 $source = PHPWS_SOURCE_DIR . 'core/inc/htaccess';
                 $dest = PHPWS_HOME_DIR . '.htaccess';
                 if (copy($source, $dest)) {
                     Access::sendMessage(dgettext('access', 'Default .htaccess file restored.'), 'update');
                 } else {
                     Access::sendMessage(dgettext('access', 'Unable to restore default .htaccess file.'), 'update');
                 }
                 break;
             case 'post_deny_allow':
                 $result = Access::postDenyAllow();
                 if ($result == false) {
                     Access::sendMessage(dgettext('access', 'IP address was not formatted correctly or not allowed.'), 'deny_allow');
                 } elseif (PHPWS_Error::isError($result)) {
                     PHPWS_Error::log($result);
                     Access::sendMessage(dgettext('access', 'An error occurred.') . ' ' . dgettext('access', 'Please check your logs.'), 'deny_allow');
                 }
                 Access::sendMessage(NULL, 'deny_allow');
                 break;
             case 'delete_allow_deny':
                 PHPWS_Core::initModClass('access', 'Allow_Deny.php');
                 $allow_deny = new Access_Allow_Deny($_GET['ad_id']);
                 $allow_deny->delete();
                 Access::sendMessage(dgettext('access', 'IP address deleted.'), 'deny_allow');
                 break;
             case 'deny_allow':
                 PHPWS_Core::initModClass('access', 'Forms.php');
                 $title = dgettext('access', 'Denys and Allows');
                 $content = Access_Forms::denyAllowForm();
                 break;
             case 'delete_shortcut':
                 PHPWS_Core::initModClass('access', 'Shortcut.php');
                 $shortcut = new Access_Shortcut($_REQUEST['shortcut_id']);
                 if (empty($shortcut->_error) && $shortcut->id) {
                     $result = $shortcut->delete();
                     if (PHPWS_Error::isError($result)) {
                         Access::sendMessage(dgettext('access', 'An error occurred when deleting your shortcut.'), 'shortcuts');
                     }
                 }
                 Access::sendMessage(dgettext('access', 'Shortcut deleted'), 'shortcuts');
                 break;
             case 'shortcuts':
                 PHPWS_Core::initModClass('access', 'Forms.php');
                 $title = dgettext('access', 'Shortcuts');
                 $content = Access_Forms::shortcuts();
                 break;
             case 'post_shortcut_list':
                 $message = NULL;
                 $result = Access::postShortcutList();
                 if (PHPWS_Error::isError($result)) {
                     $message = dgettext('access', 'An error occurred.') . ' ' . dgettext('access', 'Please check your logs.');
                 }
                 Access::sendMessage($message, 'shortcuts');
                 break;
             case 'edit_shortcut':
                 PHPWS_Core::initModClass('access', 'Forms.php');
                 echo Access_Forms::shortcut_menu();
                 exit;
                 break;
             case 'post_shortcut':
                 PHPWS_Core::initModClass('access', 'Shortcut.php');
                 $sch_id = filter_input(INPUT_POST, 'sch_id', FILTER_SANITIZE_NUMBER_INT);
                 if ($sch_id) {
                     $shortcut = new Access_Shortcut($sch_id);
                 } else {
                     $shortcut = new Access_Shortcut();
                 }
                 try {
                     $shortcut->postShortcut();
                     $shortcut->save();
                     $json['keyword'] = $shortcut->keyword;
                     $json['error'] = 0;
                 } catch (\Exception $e) {
                     $json['message'] = $e->getMessage();
                     $json['error'] = 1;
                 }
                 echo json_encode($json);
                 exit;
                 break;
             case 'htaccess':
                 if (Current_User::isDeity()) {
                     $title = dgettext('access', 'htaccess');
                     $content = Access::htaccess();
                 } else {
                     Current_User::disallow();
                 }
                 break;
             case 'add_rewritebase':
                 if (Current_User::isDeity()) {
                     Access::addRewriteBase();
                     PHPWS_Core::goBack();
                 } else {
                     Current_User::disallow();
                 }
                 break;
             case 'add_forward':
                 if (Current_User::isDeity()) {
                     Access::addForward();
                     PHPWS_Core::goBack();
                 } else {
                     Current_User::disallow();
                 }
                 break;
             case 'remove_forward':
                 if (Current_User::isDeity()) {
                     Access::removeForward();
                     PHPWS_Core::goBack();
                 } else {
                     Current_User::disallow();
                 }
                 break;
             case 'menu_fix':
                 Access::menuFix();
                 PHPWS_Core::goBack();
                 break;
             case 'page_fix':
                 Access::pageFix();
                 PHPWS_Core::goBack();
                 break;
             case 'autoforward_on':
                 PHPWS_Settings::set('access', 'forward_ids', 1);
                 PHPWS_Settings::save('access');
                 PHPWS_Core::goBack();
                 break;
             case 'autoforward_off':
                 PHPWS_Settings::set('access', 'forward_ids', 0);
                 PHPWS_Settings::save('access');
                 PHPWS_Core::goBack();
                 break;
         }
     }
     $tpl['TITLE'] = $title;
     $tpl['MESSAGE'] = $message;
     $tpl['CONTENT'] = $content;
     $main = PHPWS_Template::process($tpl, 'access', 'main.tpl');
     $panel->setContent($main);
     $finalPanel = $panel->display();
     Layout::add(PHPWS_ControlPanel::display($finalPanel));
 }