예제 #1
0
 public function ajaxHandler()
 {
     switch ($_REQUEST['command']) {
         case "removenetwork":
             if (!isset($_REQUEST['net'])) {
                 throw new \Exception("No net");
             }
             return $this->removeNetwork($_REQUEST['net']);
         case "addnetworktozone":
             if (!isset($_REQUEST['net'])) {
                 throw new \Exception("No net");
             }
             if (!isset($_REQUEST['zone'])) {
                 throw new \Exception("No Zone");
             }
             $zones = $this->getZones();
             if (!isset($zones[$_REQUEST['zone']])) {
                 throw new \Exception("Invalid zone {$zone}");
             }
             return $this->addNetworkToZone(trim($_REQUEST['net']), $_REQUEST['zone']);
         case "updatenetwork":
             if (!isset($_REQUEST['net'])) {
                 throw new \Exception("No net");
             }
             if (!isset($_REQUEST['zone'])) {
                 throw new \Exception("No Zone");
             }
             return $this->changeNetworksZone(trim($_REQUEST['net']), $_REQUEST['zone']);
         case "addrfc":
             return $this->addRfcNetworks();
         case "addthishost":
             $thishost = $this->detectHost();
             $nets = $this->getConfig("networkmaps");
             if (!is_array($nets)) {
                 $nets = array();
             }
             $nets[$thishost] = "trusted";
             $this->setConfig("networkmaps", $nets);
             return $this->runHook('addnetwork', array('trusted' => array($thishost)));
         case "addthisnetwork":
             $thisnet = $this->detectNetwork();
             $nets = $this->getConfig("networkmaps");
             if (!is_array($nets)) {
                 $nets = array();
             }
             $nets[$thisnet] = "trusted";
             $this->setConfig("networkmaps", $nets);
             return $this->runHook('addnetwork', array('trusted' => array($thisnet)));
         case "updateinterface":
             // Remove any notifications about invalid interface configurations
             $this->Notifications()->delete('firewall', 'trustedint');
             $this->Notifications()->delete('firewall', 'newint');
             return $this->runHook('updateinterface', array('iface' => $_REQUEST['iface'], 'newzone' => $_REQUEST['zone']));
         case "updaterfw":
             return $this->setConfig($_REQUEST['proto'], $_REQUEST['value'] == "true", 'rfw');
         case "addtoblacklist":
             return $this->addToBlacklist(htmlentities($_REQUEST['entry'], \ENT_QUOTES, 'UTF-8', false));
         case "removefromblacklist":
             return $this->removeFromBlacklist(htmlentities($_REQUEST['entry'], \ENT_QUOTES, 'UTF-8', false));
         case "setsafemode":
             if ($_REQUEST['value'] == "disabled") {
                 return $this->disableSafemode();
             } elseif ($_REQUEST['value'] == "enabled") {
                 return $this->enableSafemode();
             } else {
                 throw new \Exception("Unknown safemode");
             }
         case "setrejectmode":
             if ($_REQUEST['value'] != "reject") {
                 return $this->setConfig("dropinvalid", true);
             } else {
                 return $this->setConfig("dropinvalid", false);
             }
             // Custom firewall rules.
             // Custom firewall rules.
         // Custom firewall rules.
         // Custom firewall rules.
         case "addcustomrule":
             return $this->addCustomService(htmlentities($_REQUEST['name'], \ENT_QUOTES, 'UTF-8', false), $_REQUEST['proto'], $_REQUEST['port']);
         case "editcustomrule":
             return $this->editCustomService($_REQUEST['id'], htmlentities($_REQUEST['name'], \ENT_QUOTES, 'UTF-8', false), $_REQUEST['proto'], $_REQUEST['port']);
         case "deletecustomrule":
             return $this->deleteCustomService($_REQUEST['id']);
         case "updatecustomzones":
             if (!isset($_REQUEST['zones'])) {
                 $_REQUEST['zones'] = array();
             }
             return $this->setCustomServiceZones($_REQUEST['id'], $_REQUEST['zones']);
             // Attackers page
         // Attackers page
         case "getattackers":
             include __DIR__ . "/Attacks.class.php";
             $a = new Firewall\Attacks($this->getJiffies());
             $smart = $this->getSmartObj();
             return $a->getAllAttacks($smart->getRegistrations());
         case "delattacker":
             return $this->runHook("removeallblocks", array("unblock" => $_REQUEST['target']));
             // OOBE
         // OOBE
         case "getoobequestion":
             include __DIR__ . "/OOBE.class.php";
             $o = new Firewall\OOBE($this);
             return $o->getQuestion();
         case "answeroobequestion":
             include __DIR__ . "/OOBE.class.php";
             $o = new Firewall\OOBE($this);
             return $o->answerQuestion();
         case "abortoobe":
             $this->setConfig("abortoobe", true);
             return true;
         case "restartoobe":
             $o = \FreePBX::OOBE()->getConfig("completed");
             if (!is_array($o)) {
                 throw new \Exception("OOBE isn't an array");
             }
             unset($o['firewall']);
             \FreePBX::OOBE()->setConfig("completed", $o);
             $this->setConfig("oobeanswered", array());
             $this->setConfig("abortoobe", false);
             return;
         default:
             throw new \Exception("Sad Panda - " . $_REQUEST['command']);
     }
 }