Commit ee863f0b authored by Ad Schellevis's avatar Ad Schellevis

(proxy) require post action for service control

parent 3b62a276
...@@ -39,14 +39,18 @@ use \OPNsense\Proxy\Proxy; ...@@ -39,14 +39,18 @@ use \OPNsense\Proxy\Proxy;
class ServiceController extends ApiControllerBase class ServiceController extends ApiControllerBase
{ {
/** /**
* start proxy service * start proxy service (in background)
* @return array * @return array
*/ */
public function startAction() public function startAction()
{ {
$backend = new Backend(); if ($this->request->isPost()) {
$response = $backend->configdRun("proxy start", true); $backend = new Backend();
return array("response" => $response); $response = $backend->configdRun("proxy start", true);
return array("response" => $response);
} else {
return array("response" => array());
}
} }
/** /**
...@@ -55,9 +59,13 @@ class ServiceController extends ApiControllerBase ...@@ -55,9 +59,13 @@ class ServiceController extends ApiControllerBase
*/ */
public function stopAction() public function stopAction()
{ {
$backend = new Backend(); if ($this->request->isPost()) {
$response = $backend->configdRun("proxy stop"); $backend = new Backend();
return array("response" => $response); $response = $backend->configdRun("proxy stop");
return array("response" => $response);
} else {
return array("response" => array());
}
} }
/** /**
...@@ -66,9 +74,13 @@ class ServiceController extends ApiControllerBase ...@@ -66,9 +74,13 @@ class ServiceController extends ApiControllerBase
*/ */
public function restartAction() public function restartAction()
{ {
$backend = new Backend(); if ($this->request->isPost()) {
$response = $backend->configdRun("proxy restart"); $backend = new Backend();
return array("response" => $response); $response = $backend->configdRun("proxy restart");
return array("response" => $response);
} else {
return array("response" => array());
}
} }
/** /**
...@@ -105,31 +117,35 @@ class ServiceController extends ApiControllerBase ...@@ -105,31 +117,35 @@ class ServiceController extends ApiControllerBase
*/ */
public function reconfigureAction() public function reconfigureAction()
{ {
// close session for long running action if ($this->request->isPost()) {
$this->sessionClose(); // close session for long running action
$this->sessionClose();
$mdlProxy = new Proxy(); $mdlProxy = new Proxy();
$backend = new Backend(); $backend = new Backend();
$runStatus = $this->statusAction(); $runStatus = $this->statusAction();
// stop squid when disabled // stop squid when disabled
if ($runStatus['status'] == "running" && $mdlProxy->general->enabled->__toString() == 0) { if ($runStatus['status'] == "running" && $mdlProxy->general->enabled->__toString() == 0) {
$this->stopAction(); $this->stopAction();
} }
// generate template // generate template
$backend->configdRun("template reload OPNsense.Proxy"); $backend->configdRun("template reload OPNsense.Proxy");
// (res)start daemon // (res)start daemon
if ($mdlProxy->general->enabled->__toString() == 1) { if ($mdlProxy->general->enabled->__toString() == 1) {
if ($runStatus['status'] == "running") { if ($runStatus['status'] == "running") {
$backend->configdRun("proxy reconfigure"); $backend->configdRun("proxy reconfigure");
} else { } else {
$this->startAction(); $this->startAction();
}
} }
}
return array("status" => "ok"); return array("status" => "ok");
} else {
return array("status" => "failed");
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment