diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableServiceControllerBase.php b/src/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableServiceControllerBase.php index 0b19690fb..dea4b5b7a 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableServiceControllerBase.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableServiceControllerBase.php @@ -105,7 +105,6 @@ abstract class ApiMutableServiceControllerBase extends ApiControllerBase public function startAction() { if ($this->request->isPost()) { - // close session for long running action $this->sessionClose(); $backend = new Backend(); $response = $backend->configdRun(escapeshellarg(static::$internalServiceName) . ' start'); @@ -122,7 +121,6 @@ abstract class ApiMutableServiceControllerBase extends ApiControllerBase public function stopAction() { if ($this->request->isPost()) { - // close session for long running action $this->sessionClose(); $backend = new Backend(); $response = $backend->configdRun(escapeshellarg(static::$internalServiceName) . ' stop'); @@ -139,7 +137,6 @@ abstract class ApiMutableServiceControllerBase extends ApiControllerBase public function restartAction() { if ($this->request->isPost()) { - // close session for long running action $this->sessionClose(); $backend = new Backend(); $response = $backend->configdRun(escapeshellarg(static::$internalServiceName) . ' restart'); @@ -149,26 +146,39 @@ abstract class ApiMutableServiceControllerBase extends ApiControllerBase } } + /** + * reconfigure force restart check, return zero for soft-reload + */ + protected function reconfigureForceRestart() + { + return 1; + } + /** * reconfigure, generate config and reload */ public function reconfigureAction() { if ($this->request->isPost()) { - // close session for long running action $this->sessionClose(); $model = $this->getModel(); $backend = new Backend(); - $this->stopAction(); + if ((string)$model->getNodeByReference(static::$internalServiceEnabled) != '1' || + $this->reconfigureForceRestart()) { + $backend->configdRun(escapeshellarg(static::$internalServiceName) . ' stop'); + } - // generate template $backend->configdRun('template reload ' . escapeshellarg(static::$internalServiceTemplate)); - // (re)start daemon if ((string)$model->getNodeByReference(static::$internalServiceEnabled) == '1') { - $this->startAction(); + $runStatus = $this->statusAction(); + if ($runStatus['status'] != 'running') { + $backend->configdRun(escapeshellarg(static::$internalServiceName) . ' start'); + } else { + $backend->configdRun(escapeshellarg(static::$internalServiceName) . ' reconfigure'); + } } return array('status' => 'ok'); diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/ServiceController.php b/src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/ServiceController.php index 915fb5488..34fc8befe 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/ServiceController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api/ServiceController.php @@ -43,51 +43,17 @@ class ServiceController extends ApiMutableServiceControllerBase static $internalServiceTemplate = 'OPNsense/Proxy'; static $internalServiceName = 'proxy'; - /** - * reconfigure squid, generate config and reload - */ - public function reconfigureAction() + protected function reconfigureForceRestart() { - if ($this->request->isPost()) { - // close session for long running action - $this->sessionClose(); + $mdlProxy = new Proxy(); - $force_restart = false; + // some operations can not be performed by a squid -k reconfigure, + // try to determine if we need a stop/start here + $prev_sslbump_cert = trim(@file_get_contents('/var/squid/ssl_crtd.id')); + $prev_cache_active = !empty(trim(@file_get_contents('/var/squid/cache/active'))); - $mdlProxy = new Proxy(); - $backend = new Backend(); - - $runStatus = $this->statusAction(); - - // some operations can not be performed by a squid -k reconfigure, - // try to determine if we need a stop/start here - $prev_sslbump_cert = trim(@file_get_contents('/var/squid/ssl_crtd.id')); - $prev_cache_active = !empty(trim(@file_get_contents('/var/squid/cache/active'))); - $force_restart = (((string)$mdlProxy->forward->sslcertificate) != $prev_sslbump_cert) || - (!empty((string)$mdlProxy->general->cache->local->enabled) != $prev_cache_active); - - // stop squid when disabled - if ($runStatus['status'] == "running" && - ($mdlProxy->general->enabled->__toString() == 0 || $force_restart)) { - $this->stopAction(); - } - - // generate template - $backend->configdRun('template reload OPNsense/Proxy'); - - // (res)start daemon - if ($mdlProxy->general->enabled->__toString() == 1) { - if ($runStatus['status'] == "running" && !$force_restart) { - $backend->configdRun("proxy reconfigure"); - } else { - $this->startAction(); - } - } - - return array("status" => "ok"); - } else { - return array("status" => "failed"); - } + return (((string)$mdlProxy->forward->sslcertificate) != $prev_sslbump_cert) || + (!empty((string)$mdlProxy->general->cache->local->enabled) != $prev_cache_active); } /**