code
stringlengths 17
247k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public function setItemAction($uuid)
{
$node = $this->getModel()->getNodeByReference('lagg.' . $uuid);
$overlay = null;
if (!empty($node)) {
// not allowed to change lagg interface name
$overlay['laggif'] = (string)$node->laggif;
}
$result = $this->setBase("lagg", "lagg", $uuid, $overlay);
if ($result['result'] != 'failed') {
$this->stashUpdate($overlay !== null ? $overlay['laggif'] : $this->request->get('lagg')['laggif']);
}
return $result;
} | Update lagg with given properties
@param string $uuid internal id
@return array save result + validation output | setItemAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Interfaces/Api/LaggSettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Interfaces/Api/LaggSettingsController.php | BSD-2-Clause |
public function getItemAction($uuid = null)
{
return $this->getBase("lagg", "lagg", $uuid);
} | Retrieve lagg settings or return defaults for new one
@param $uuid item unique id
@return array lagg content | getItemAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Interfaces/Api/LaggSettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Interfaces/Api/LaggSettingsController.php | BSD-2-Clause |
private function handleFormValidations($response)
{
if (!empty($response['validations'])) {
foreach (array_keys($response['validations']) as $fieldname) {
if (in_array($fieldname, ['vip.subnet', 'vip.subnet_bits'])) {
if (empty($response['validations']['vip.network'])) {
$response['validations']['vip.network'] = [];
}
if (is_array($response['validations'][$fieldname])) {
$response['validations']['vip.network'] = array_merge(
$response['validations']['vip.network'],
$response['validations'][$fieldname]
);
} else {
$response['validations']['vip.network'][] = $response['validations'][$fieldname];
}
unset($response['validations'][$fieldname]);
}
}
}
return $response;
} | remap subnet and subnet_bits to network (which represents combined field) | handleFormValidations | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Interfaces/Api/VipSettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Interfaces/Api/VipSettingsController.php | BSD-2-Clause |
private function stashUpdate($greif)
{
file_put_contents("/tmp/.gre.todo", "{$greif}\n", FILE_APPEND | LOCK_EX);
chmod("/tmp/.gre.todo", 0750);
} | write updated or removed gre to temp | stashUpdate | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Interfaces/Api/GreSettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Interfaces/Api/GreSettingsController.php | BSD-2-Clause |
public function setItemAction($uuid)
{
$node = $this->getModel()->getNodeByReference('gre.' . $uuid);
$overlay = null;
if (!empty($node)) {
// not allowed to change gre interface name
$overlay['greif'] = (string)$node->greif;
}
$result = $this->setBase("gre", "gre", $uuid, $overlay);
if ($result['result'] != 'failed') {
$this->stashUpdate($overlay !== null ? $overlay['greif'] : $this->request->get('gre')['greif']);
}
return $result;
} | Update gre with given properties
@param string $uuid internal id
@return array save result + validation output | setItemAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Interfaces/Api/GreSettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Interfaces/Api/GreSettingsController.php | BSD-2-Clause |
public function getItemAction($uuid = null)
{
return $this->getBase("gre", "gre", $uuid);
} | Retrieve gre settings or return defaults for new one
@param $uuid item unique id
@return array gre content | getItemAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Interfaces/Api/GreSettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Interfaces/Api/GreSettingsController.php | BSD-2-Clause |
public function statusAction()
{
return [
'enabled' => isset(Config::getInstance()->object()->ipsec->enable),
'isDirty' => file_exists('/tmp/ipsec.dirty') // is_subsystem_dirty('ipsec')
];
} | Returns the status of the legacy subsystem, which currently only includes a boolean specifying if the subsystem
is marked as dirty, which means that there are pending changes.
@return array | statusAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/LegacySubsystemController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/LegacySubsystemController.php | BSD-2-Clause |
public function setItemAction($uuid = null)
{
return $this->setBase('preSharedKey', 'preSharedKeys.preSharedKey', $uuid);
} | Update preSharedKey with given properties
@param $uuid
@return array
@throws \OPNsense\Base\UserException
@throws \ReflectionException | setItemAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/PreSharedKeysController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/PreSharedKeysController.php | BSD-2-Clause |
public function addItemAction()
{
return $this->addBase('preSharedKey', 'preSharedKeys.preSharedKey');
} | Add new preSharedKey with given properties
@return array
@throws \OPNsense\Base\UserException
@throws \ReflectionException | addItemAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/PreSharedKeysController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/PreSharedKeysController.php | BSD-2-Clause |
public function getItemAction($uuid = null)
{
return $this->getBase('preSharedKey', 'preSharedKeys.preSharedKey', $uuid);
} | Retrieve key pair or return defaults for new one
@param $uuid
@return array
@throws \ReflectionException | getItemAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/PreSharedKeysController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/PreSharedKeysController.php | BSD-2-Clause |
public function setItemAction($uuid = null)
{
$response = $this->setBase('keyPair', 'keyPairs.keyPair', $uuid);
if (!empty($response['result']) && $response['result'] === 'saved') {
touch('/tmp/ipsec.dirty'); // mark_subsystem_dirty('ipsec')
}
return $response;
} | Update key pair with given properties
@param $uuid
@return array
@throws \OPNsense\Base\UserException
@throws \ReflectionException | setItemAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/KeyPairsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/KeyPairsController.php | BSD-2-Clause |
public function addItemAction()
{
$response = $this->addBase('keyPair', 'keyPairs.keyPair');
if (!empty($response['result']) && $response['result'] === 'saved') {
touch('/tmp/ipsec.dirty'); // mark_subsystem_dirty('ipsec')
}
return $response;
} | Add new key pair with given properties
@return array
@throws \OPNsense\Base\UserException
@throws \ReflectionException | addItemAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/KeyPairsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/IPsec/Api/KeyPairsController.php | BSD-2-Clause |
function getOcspInfoDataAction($caref)
{
$config = Config::getInstance()->object();
$revoked = [];
foreach ($config->crl as $crl) {
if ((string)$crl->caref == $caref) {
foreach ($crl->cert as $cert) {
if (!empty((string)$cert->revoke_time)) {
$dt = new \DateTime("@" . $cert->revoke_time);
$revoked[(string)$cert->refid] = $dt->format("ymdHis") . "Z";
}
}
}
}
$result = '';
foreach ($config->cert as $cert) {
if ((string)$cert->caref == $caref) {
$refid = (string)$cert->refid;
$x509 = openssl_x509_parse(base64_decode($cert->crt));
$valid_to = date('Y-m-d H:i:s', $x509['validTo_time_t']);
$rev_date = '';
if (!empty($revoked[$refid])) {
$status = 'R';
$rev_date = $revoked[$refid];
} elseif ($x509['validTo_time_t'] < time()) {
$status = 'E';
} else {
$status = 'V';
}
$result .= sprintf(
"%s\t%s\t%s\t%s\tunknown\t%s\n",
$status, // Certificate status flag (V=valid, R=revoked, E=expired).
$x509['validTo'], // Certificate expiration date in YYMMDDHHMMSSZ format.
$rev_date, // Certificate revocation date in YYMMDDHHMMSSZ[,reason] format.
$x509['serialNumberHex'], // Certificate serial number in hex.
$x509['name'] // Certificate distinguished name.
);
}
}
return ['payload' => $result];
} | for demonstration purposes, we need a CA index file as specified
at https://pki-tutorial.readthedocs.io/en/latest/cadb.html | getOcspInfoDataAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Trust/Api/CrlController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Trust/Api/CrlController.php | BSD-2-Clause |
public function reconfigureAction()
{
if ($this->request->isPost()) {
$backend = new Backend();
$backend->configdRun('template reload OPNsense/Shaper');
$backend->configdRun('template reload OPNsense/IPFW');
$result = trim($backend->configdRun("shaper reload"));
if ($result != "OK") {
return ["status" => "error reloading shaper (" . $result . ")"];
}
$result = trim($backend->configdRun("ipfw reload"));
if ($result != "OK") {
return ["status" => "error reloading ipfw (" . $result . ")"];
}
return ["status" => "ok"];
}
return ["status" => "failed"];
} | reconfigure shaper/ipfw, generate config and reload | reconfigureAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/ServiceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/ServiceController.php | BSD-2-Clause |
public function getPipeAction($uuid = null)
{
return $this->getBase("pipe", "pipes.pipe", $uuid);
} | Retrieve pipe settings or return defaults
@param $uuid item unique id
@return array traffic shaper pipe content
@throws \ReflectionException when not bound to model | getPipeAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | BSD-2-Clause |
public function setPipeAction($uuid)
{
return $this->setBase("pipe", "pipes.pipe", $uuid);
} | Update pipe with given properties
@param string $uuid internal id
@return array save result + validation output
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | setPipeAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | BSD-2-Clause |
public function addPipeAction()
{
return $this->addBase("pipe", "pipes.pipe", [
"origin" => "TrafficShaper",
"number" => (new TrafficShaper())->newPipeNumber()
]);
} | Add new pipe and set with attributes from post
@return array save result + validation output
@throws \OPNsense\Base\ModelException when not bound to model
@throws \OPNsense\Base\ValidationException when field validations fail | addPipeAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | BSD-2-Clause |
public function togglePipeAction($uuid, $enabled = null)
{
return $this->toggleBase("pipes.pipe", $uuid, $enabled);
} | Toggle pipe defined by uuid (enable/disable)
@param $uuid user defined rule internal id
@param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
@return array save result
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | togglePipeAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | BSD-2-Clause |
public function getQueueAction($uuid = null)
{
return $this->getBase("queue", "queues.queue", $uuid);
} | Retrieve queue settings or return defaults
@param $uuid item unique id
@return array traffic shaper queue content
@throws \ReflectionException when not bound to model | getQueueAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | BSD-2-Clause |
public function setQueueAction($uuid)
{
return $this->setBase("queue", "queues.queue", $uuid);
} | Update queue with given properties
@param string $uuid internal id
@return array save result + validation output
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | setQueueAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | BSD-2-Clause |
public function addQueueAction()
{
return $this->addBase("queue", "queues.queue", [
"origin" => "TrafficShaper",
"number" => (new TrafficShaper())->newQueueNumber()
]);
} | Add new queue and set with attributes from post
@return array save result + validation output
@throws \OPNsense\Base\ModelException when not bound to model | addQueueAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | BSD-2-Clause |
public function toggleQueueAction($uuid, $enabled = null)
{
return $this->toggleBase("queues.queue", $uuid, $enabled);
} | Toggle queue defined by uuid (enable/disable)
@param $uuid user defined rule internal id
@param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
@return array save result
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | toggleQueueAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | BSD-2-Clause |
public function getRuleAction($uuid = null)
{
$fetchmode = $this->request->has("fetchmode") ? $this->request->get("fetchmode") : null;
$result = $this->getBase("rule", "rules.rule", $uuid);
if ($uuid === null || $fetchmode == 'copy') {
$result["rule"]["sequence"] = (string)((new TrafficShaper())->getMaxRuleSequence() + 1);
}
return $result;
} | Retrieve rule settings or return defaults for new rule
@param $uuid item unique id
@return array traffic shaper rule content
@throws \ReflectionException when not bound to model | getRuleAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | BSD-2-Clause |
public function setRuleAction($uuid)
{
return $this->setBase("rule", "rules.rule", $uuid);
} | Update rule with given properties
@param string $uuid internal id
@return array save result + validation output
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | setRuleAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | BSD-2-Clause |
public function addRuleAction()
{
return $this->addBase('rule', 'rules.rule', [ "origin" => "TrafficShaper"]);
} | Add new rule and set with attributes from post
@return array save result + validation output
@throws \OPNsense\Base\ModelException when not bound to model
@throws \OPNsense\Base\ValidationException when field validations fail | addRuleAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | BSD-2-Clause |
public function toggleRuleAction($uuid, $enabled = null)
{
return $this->toggleBase("rules.rule", $uuid, $enabled);
} | Toggle rule defined by uuid (enable/disable)
@param $uuid user defined rule internal id
@param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
@return array save result
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | toggleRuleAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api/SettingsController.php | BSD-2-Clause |
public function InterfaceAction()
{
$response = (new Backend())->configdRun('interface show traffic');
return json_decode($response, true);
} | retrieve interface traffic stats
@return array | InterfaceAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/TrafficController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/TrafficController.php | BSD-2-Clause |
public function TopAction($interfaces)
{
$response = [];
$config = Config::getInstance()->object();
$iflist = [];
$ifmap = [];
foreach (explode(',', $interfaces) as $intf) {
if (isset($config->interfaces->$intf) && !empty($config->interfaces->$intf->if)) {
$iflist[] = (string)$config->interfaces->$intf->if;
$ifmap[(string)$config->interfaces->$intf->if] = $intf;
}
}
if (count($iflist) > 0) {
$data = (new Backend())->configdpRun('interface show top', [implode(",", $iflist)]);
$data = json_decode($data, true);
if (is_array($data)) {
foreach ($data as $if => $content) {
if (isset($ifmap[$if])) {
$response[$ifmap[$if]] = $content;
}
}
}
}
return $response;
} | retrieve interface top traffic hosts
@param $interfaces string comma separated list of interfaces
@return array | TopAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/TrafficController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/TrafficController.php | BSD-2-Clause |
public function topAction(
$provider = null,
$from_date = null,
$to_date = null,
$field = null,
$measure = null,
$max_hits = null
) {
// cleanse input
$filter = new SanitizeFilter();
$provider = $filter->sanitize($provider, "alnum");
$from_date = $filter->sanitize($from_date, "int");
$to_date = $filter->sanitize($to_date, "int");
$field = $filter->sanitize($field, "string");
$measure = $filter->sanitize($measure, "string");
$max_hits = $filter->sanitize($max_hits, "int");
if ($this->request->isGet()) {
$protocols = $this->getProtocolsAction();
$services = $this->getServicesAction();
if ($this->request->get("filter_field") != null && $this->request->get("filter_value") != null) {
$filter_fields = explode(',', $this->request->get("filter_field"));
$filter_values = explode(',', $this->request->get("filter_value"));
$data_filter = "";
foreach ($filter_fields as $field_indx => $filter_field) {
if ($data_filter != '') {
$data_filter .= ',';
}
if (isset($filter_values[$field_indx])) {
$data_filter .= $filter_field . '=' . $filter_values[$field_indx];
}
}
$data_filter = "'{$data_filter}'";
} else {
// no filter, empty parameter
$data_filter = "''";
}
$backend = new Backend();
$configd_cmd = "netflow aggregate top {$provider} {$from_date} {$to_date} {$field}";
$configd_cmd .= " {$measure} {$data_filter} {$max_hits}";
$response = $backend->configdRun($configd_cmd);
$graph_data = json_decode($response, true);
if (is_array($graph_data)) {
foreach ($graph_data as &$record) {
if (isset($record['dst_port']) || isset($record['service_port'])) {
$portnum = $record['dst_port'] ?? $record['service_port'];
$label = $portnum;
$protocol = '';
if (isset($record['protocol']) && isset($protocols[$record['protocol']])) {
$protocol = sprintf(" (%s)", $protocols[$record['protocol']]);
}
if (isset($services[$portnum])) {
$label = $services[$portnum];
}
$record['last_seen_str'] = '';
if (!empty($record['last_seen'])) {
$record['last_seen_str'] = date('Y-m-d H:i:s', $record['last_seen']);
}
$record['label'] = $label . $protocol;
}
}
return $graph_data;
}
}
return array();
} | request top usage data (for reporting), values can optionally be filtered using filter_field and filter_value
@param string $provider provider class name
@param string $from_date from timestamp
@param string $to_date to timestamp
@param string $field field name(s) to aggregate
@param string $measure measure [octets, packets]
@param string $max_hits maximum number of results
@return array timeseries | topAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetworkinsightController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetworkinsightController.php | BSD-2-Clause |
public function getMetadataAction()
{
if ($this->request->isGet()) {
$backend = new Backend();
$configd_cmd = "netflow aggregate metadata json";
$response = $backend->configdRun($configd_cmd);
$metadata = json_decode($response, true);
if ($metadata != null) {
return $metadata;
}
}
return array();
} | get metadata from backend aggregation process
@return array timeseries | getMetadataAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetworkinsightController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetworkinsightController.php | BSD-2-Clause |
public function exportAction(
$provider = null,
$from_date = null,
$to_date = null,
$resolution = null
) {
$this->response->setRawHeader("Content-Type: application/octet-stream");
$this->response->setRawHeader("Content-Disposition: attachment; filename=" . $provider . ".csv");
if ($this->request->isGet() && $provider != null && $resolution != null) {
$backend = new Backend();
$configd_cmd = "netflow aggregate export {$provider} {$from_date} {$to_date} {$resolution}";
$response = $backend->configdRun($configd_cmd);
return $response;
} else {
return "";
}
} | request timeserie data to use for reporting
@param string $provider provider class name
@param string $from_date from timestamp
@param string $to_date to timestamp
@param string $resolution resolution in seconds
@return string csv output | exportAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetworkinsightController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetworkinsightController.php | BSD-2-Clause |
public function getInterfaceNamesAction()
{
return $this->getInterfaceNames();
} | retrieve interface name mapping
@return array interface mapping (raw interface to description) | getInterfaceNamesAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | BSD-2-Clause |
public function getArpAction()
{
$backend = new Backend();
if ($this->request->get('resolve') == 'yes') {
$response = $backend->configdRun('interface list arp -r json');
} else {
$response = $backend->configdRun('interface list arp json');
}
$arptable = json_decode($response, true);
$intfmap = $this->getInterfaceNames();
// merge arp output with interface names
if (is_array($arptable)) {
foreach ($arptable as &$arpentry) {
if (array_key_exists($arpentry['intf'], $intfmap)) {
$arpentry['intf_description'] = $intfmap[$arpentry['intf']];
} else {
$arpentry['intf_description'] = "";
}
}
}
return $arptable;
} | retrieve system arp table contents
@return array | getArpAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | BSD-2-Clause |
public function searchArpAction()
{
return $this->searchRecordsetBase($this->getArpAction());
} | search wrapper around getArpAction
@return array | searchArpAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | BSD-2-Clause |
public function getNdpAction()
{
$backend = new Backend();
$response = $backend->configdRun('interface list ndp json');
$ndptable = json_decode($response, true);
$intfmap = $this->getInterfaceNames();
// merge ndp output with interface names
if (is_array($ndptable)) {
foreach ($ndptable as &$ndpentry) {
if (array_key_exists($ndpentry['intf'], $intfmap)) {
$ndpentry['intf_description'] = $intfmap[$ndpentry['intf']];
} else {
$ndpentry['intf_description'] = "";
}
}
}
return $ndptable;
} | retrieve system ndp table contents
@return array | getNdpAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | BSD-2-Clause |
public function searchNdpAction()
{
return $this->searchRecordsetBase($this->getNdpAction());
} | search wrapper around getNdpAction
@return array | searchNdpAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | BSD-2-Clause |
public function getProtocolStatisticsAction()
{
return json_decode((new Backend())->configdRun('interface show protocol'), true);
} | retrieve system-wide statistics for each network protocol
@return mixed | getProtocolStatisticsAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | BSD-2-Clause |
public function getInterfaceStatisticsAction()
{
$stats = [];
$tmp = json_decode((new Backend())->configdRun('interface show interfaces'), true);
if (is_array($tmp) && !empty($tmp['statistics']) && !empty($tmp['statistics']['interface'])) {
$intfmap = $this->getInterfaceNames();
foreach ($tmp['statistics']['interface'] as $node) {
if (!empty($intfmap[$node['name']])) {
$key = sprintf("[%s] (%s) / %s", $intfmap[$node['name']], $node['name'], $node['address']);
} else {
$key = sprintf("[%s] / %s", $node['name'], $node['address']);
}
$stats[$key] = $node;
}
}
return ['statistics' => $stats];
} | retrieve system-wide statistics for each network adapter
@return mixed | getInterfaceStatisticsAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | BSD-2-Clause |
public function getInterfaceConfigAction()
{
return json_decode((new Backend())->configdRun('interface list ifconfig'), true);
} | retrieve status/config for each network adapter
@return mixed | getInterfaceConfigAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | BSD-2-Clause |
public function CarpStatusAction($status)
{
if ($this->request->isPost()) {
$response = json_decode((new Backend())->configdpRun('interface carp_set_status', [$status]), true);
if (!empty($response)) {
return $response;
}
}
return array("message" => "error");
} | set new carp node status (enable, disable, maintenance)
@return array | CarpStatusAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | BSD-2-Clause |
public function getMemoryStatisticsAction()
{
return json_decode((new Backend())->configdRun('interface show memory'), true);
} | retrieve statistics recorded by the memory management routines
@return mixed | getMemoryStatisticsAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | BSD-2-Clause |
public function getBpfStatisticsAction()
{
return json_decode((new Backend())->configdRun('interface show bpf'), true);
} | retrieve bpf(4) peers statistics
@return mixed | getBpfStatisticsAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/InterfaceController.php | BSD-2-Clause |
public function getActivityAction()
{
$backend = new Backend();
$response = $backend->configdRun('system diag activity json');
$activity = json_decode($response, true);
return $activity;
} | retrieve system activity (top)
@return array | getActivityAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/ActivityController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/ActivityController.php | BSD-2-Clause |
public function setconfigAction()
{
$result = array("result" => "failed");
if ($this->request->hasPost("netflow")) {
// load model and update with provided data
$mdlNetflow = new Netflow();
$mdlNetflow->setNodes($this->request->getPost("netflow"));
if ((string)$mdlNetflow->collect->enable == 1) {
// add localhost (127.0.0.1:2056) as target if local capture is configured
if (strpos((string)$mdlNetflow->capture->targets, "127.0.0.1:2056") === false) {
if ((string)$mdlNetflow->capture->targets != "") {
$targets = explode(",", (string)$mdlNetflow->capture->targets);
} else {
$targets = array();
}
$targets[] = "127.0.0.1:2056";
$mdlNetflow->capture->targets = implode(',', $targets);
}
}
// perform validation
$validations = $mdlNetflow->validate();
if (count($validations)) {
$result['validations'] = array();
foreach ($validations as $valkey => $validation) {
$result['validations']['netflow.' . $valkey] = $validation;
}
} else {
// serialize model to config and save
$mdlNetflow->serializeToConfig();
Config::getInstance()->save();
$result["result"] = "saved";
}
}
return $result;
} | update netflow configuration fields
@return array
@throws \OPNsense\Base\ValidationException | setconfigAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetflowController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetflowController.php | BSD-2-Clause |
public function cacheStatsAction()
{
$backend = new Backend();
$response = $backend->configdRun("netflow cache stats json");
$stats = json_decode($response, true);
if ($stats != null) {
return $stats;
} else {
return array();
}
} | Retrieve netflow cache statistics
@return array cache statistics per netgraph node | cacheStatsAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetflowController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetflowController.php | BSD-2-Clause |
public function delStateAction($stateid, $creatorid)
{
if ($this->request->isPost()) {
$filter = new SanitizeFilter();
$response = (new Backend())->configdpRun("filter kill state", [
$filter->sanitize($stateid, "hexval"),
$filter->sanitize($creatorid, "hexval")
]);
return [
'result' => $response
];
}
return ['result' => ""];
} | delete / drop a specific state by state+creator id | delStateAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/FirewallController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/FirewallController.php | BSD-2-Clause |
public function listRuleIdsAction()
{
if ($this->request->isGet()) {
$response = json_decode((new Backend())->configdpRun("filter list rule_ids"), true);
if ($response != null) {
return ["items" => $response];
}
}
return ["items" => []];
} | return rule'ids and descriptions from running config | listRuleIdsAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/FirewallController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/FirewallController.php | BSD-2-Clause |
public function pfStatisticsAction($section = null)
{
return json_decode((new Backend())->configdpRun('filter diag info', [$section]), true);
} | retrieve various pf statistics
@return mixed | pfStatisticsAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/FirewallController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/FirewallController.php | BSD-2-Clause |
public function pfStatesAction()
{
$response = trim((new Backend())->configdRun("filter diag state_size"));
if (!empty($response)) {
$response = explode(PHP_EOL, $response);
return [
'current' => explode(' ', $response[0])[1],
'limit' => explode(' ', $response[1])[1]
];
}
return ["result" => "failed"];
} | retrieve pf state amount and states limit | pfStatesAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/FirewallController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/FirewallController.php | BSD-2-Clause |
protected function reconfigureForceRestart()
{
return 0;
} | avoid restarting Monit on reconfigure | reconfigureForceRestart | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/ServiceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/ServiceController.php | BSD-2-Clause |
private function bashColorToCSS($string)
{
$colors = [
'/\x1b\[0;30m(.*?)\x1b\[0m/s' => '<strong>$1</strong>',
'/\x1b\[0;30m(.*?)\x1b\[0m/s' => '<span class="text-info">$1</span>',
'/\x1b\[0;31m(.*?)\x1b\[0m/s' => '<span class="text-danger">$1</span>',
'/\x1b\[0;32m(.*?)\x1b\[0m/s' => '<span class="text-success">$1</span>',
'/\x1b\[0;33m(.*?)\x1b\[0m/s' => '<span class="text-warning">$1</span>',
'/\x1b\[0;34m(.*?)\x1b\[0m/s' => '<span class="text-info">$1</span>',
'/\x1b\[0;35m(.*?)\x1b\[0m/s' => '<span class="text-danger">$1</span>',
'/\x1b\[0;36m(.*?)\x1b\[0m/s' => '<span class="text-primary">$1</span>',
'/\x1b\[0;37m(.*?)\x1b\[0m/s' => '<span class="text-info">$1</span>',
'/\x1b\[0;39m(.*?)\x1b\[0m/s' => '<span>$1</span>',
'/\x1b\[1;30m(.*?)\x1b\[0m/s' => '<strong class="text-info">$1</strong>',
'/\x1b\[1;31m(.*?)\x1b\[0m/s' => '<strong class="text-danger">$1</strong>',
'/\x1b\[1;32m(.*?)\x1b\[0m/s' => '<strong class="text-success">$1</strong>',
'/\x1b\[1;33m(.*?)\x1b\[0m/s' => '<strong class="text-warning">$1</strong>',
'/\x1b\[1;34m(.*?)\x1b\[0m/s' => '<strong class="text-info">$1</strong>',
'/\x1b\[1;35m(.*?)\x1b\[0m/s' => '<strong class="text-danger">$1</strong>',
'/\x1b\[1;36m(.*?)\x1b\[0m/s' => '<strong class="text-primary">$1</strong>',
'/\x1b\[1;37m(.*?)\x1b\[0m/s' => '<strong class="text-info">$1</strong>',
'/\x1b\[0;90m(.*?)\x1b\[0m/s' => '<span class="text-info">$1</span>',
'/\x1b\[0;91m(.*?)\x1b\[0m/s' => '<span class="text-danger">$1</span>',
'/\x1b\[0;92m(.*?)\x1b\[0m/s' => '<span class="text-success">$1</span>',
'/\x1b\[0;93m(.*?)\x1b\[0m/s' => '<span class="text-warning">$1</span>',
'/\x1b\[0;94m(.*?)\x1b\[0m/s' => '<span class="text-info">$1</span>',
'/\x1b\[0;95m(.*?)\x1b\[0m/s' => '<span class="text-danger">$1</span>',
'/\x1b\[0;96m(.*?)\x1b\[0m/s' => '<span class="text-primary">$1</span>',
'/\x1b\[0;97m(.*?)\x1b\[0m/s' => '<span class="text-info">$1</span>'
];
return preg_replace(array_keys($colors), $colors, $string);
} | convert bash color escape codes to CSS
@param $string
@return string | bashColorToCSS | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/StatusController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/StatusController.php | BSD-2-Clause |
public function dirtyAction()
{
$result = array('status' => 'ok');
$result['monit']['dirty'] = $this->getModel()->configChanged();
return $result;
} | check if changes to the monit settings were made
@return array result | dirtyAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | BSD-2-Clause |
public function getAlertAction($uuid = null)
{
return $this->getBase("alert", "alert", $uuid);
} | Retrieve alert settings or return defaults
@param $uuid item unique id
@return array monit alert content
@throws \ReflectionException when not bound to model | getAlertAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | BSD-2-Clause |
public function setAlertAction($uuid)
{
return $this->setBase("alert", "alert", $uuid);
} | Update alert with given properties
@param string $uuid internal id
@return array save result + validation output
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | setAlertAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | BSD-2-Clause |
public function addAlertAction()
{
return $this->addBase("alert", "alert");
} | Add alert with given properties
@return array save result + validation output
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | addAlertAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | BSD-2-Clause |
public function toggleAlertAction($uuid, $enabled = null)
{
return $this->toggleBase("alert", $uuid, $enabled);
} | Toggle alert defined by uuid (enable/disable)
@param $uuid alert internal id
@param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
@return array save result
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | toggleAlertAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | BSD-2-Clause |
public function getServiceAction($uuid = null)
{
return $this->getBase("service", "service", $uuid);
} | Retrieve service settings or return defaults
@param $uuid item unique id
@return array monit service content
@throws \ReflectionException when not bound to model | getServiceAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | BSD-2-Clause |
public function setServiceAction($uuid)
{
return $this->setBase("service", "service", $uuid);
} | Update service with given properties
@param string $uuid internal id
@return array save result + validation output
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | setServiceAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | BSD-2-Clause |
public function addServiceAction()
{
return $this->addBase("service", "service");
} | Add service with given properties
@return array save result + validation output
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | addServiceAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | BSD-2-Clause |
public function toggleServiceAction($uuid, $enabled = null)
{
return $this->toggleBase("service", $uuid, $enabled);
} | Toggle service defined by uuid (enable/disable)
@param $uuid service internal id
@param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
@return array save result
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | toggleServiceAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | BSD-2-Clause |
public function getTestAction($uuid = null)
{
return $this->getBase("test", "test", $uuid);
} | Retrieve test settings or return defaults
@param $uuid item unique id
@return array monit test content
@throws \ReflectionException when not bound to model | getTestAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | BSD-2-Clause |
public function setTestAction($uuid)
{
return $this->setBase("test", "test", $uuid);
} | Update test with given properties
@param string $uuid internal id
@return array save result + validation output
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | setTestAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | BSD-2-Clause |
public function addTestAction()
{
return $this->addBase("test", "test");
} | Add test with given properties
@return array save result + validation output
@throws \OPNsense\Base\ValidationException when field validations fail
@throws \ReflectionException when not bound to model | addTestAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/Monit/Api/SettingsController.php | BSD-2-Clause |
public function killSessionAction()
{
if (!$this->request->isPost()) {
return ['result' => 'failed'];
}
$server_id = $this->request->get('server_id', null);
$session_id = $this->request->get('session_id', null);
if ($server_id != null && $session_id != null) {
$data = json_decode((new Backend())->configdpRun('openvpn kill', [$server_id, $session_id]) ?? '', true);
if (!empty($data)) {
return $data;
}
return ['result' => 'failed'];
} else {
return ['status' => 'invalid'];
}
} | kill session by source ip:port or common name
@return array | killSessionAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/OpenVPN/Api/ServiceController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/OpenVPN/Api/ServiceController.php | BSD-2-Clause |
public function storePresetsAction($vpnid)
{
$result = array("result" => "failed");
if ($this->request->isPost()) {
$result = $this->validatePresetsAction($vpnid);
if ($result['result'] == 'ok' && $result['changed']) {
$this->getModel()->serializeToConfig();
Config::getInstance()->save();
}
}
return $result;
} | store presets when valid and changed
@param $vpnid server handle
@return array status and validation output
@throws \OPNsense\Base\ModelException | storePresetsAction | php | opnsense/core | src/opnsense/mvc/app/controllers/OPNsense/OpenVPN/Api/ExportController.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/controllers/OPNsense/OpenVPN/Api/ExportController.php | BSD-2-Clause |
public function isUsed($name)
{
foreach ($this->ruleIterator() as $node) {
if (in_array($name, explode(",", (string)$node->category))) {
return true;
}
}
return false;
} | refactor category usage (replace category in rules) | isUsed | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Firewall/Category.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Firewall/Category.php | BSD-2-Clause |
public function rollback($revision)
{
$filename = Config::getInstance()->getBackupFilename($revision);
if ($filename) {
// fiddle with the dom, copy OPNsense->Firewall->Filter from backup to current config
$sourcexml = simplexml_load_file($filename);
if ($sourcexml->OPNsense->Firewall->Filter) {
$sourcedom = dom_import_simplexml($sourcexml->OPNsense->Firewall->Filter);
$targetxml = Config::getInstance()->object();
$targetdom = dom_import_simplexml($targetxml->OPNsense->Firewall->Filter);
$node = $targetdom->ownerDocument->importNode($sourcedom, true);
$targetdom->parentNode->replaceChild($node, $targetdom);
Config::getInstance()->save();
return true;
}
}
return false;
} | Rollback this model to a previous version.
Make sure to remove this object afterwards, since its contents won't be updated.
@param $revision float|string revision number
@return bool action performed (backup revision existed) | rollback | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Firewall/Filter.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Firewall/Filter.php | BSD-2-Clause |
private function getAliasSource()
{
$sources = [];
$sources[] = [['filter', 'rule'], ['source', 'address']];
$sources[] = [['filter', 'rule'], ['destination', 'address']];
$sources[] = [['filter', 'rule'], ['source', 'port']];
$sources[] = [['filter', 'rule'], ['destination', 'port']];
$sources[] = [['filter', 'scrub', 'rule'], ['dst']];
$sources[] = [['filter', 'scrub', 'rule'], ['src']];
$sources[] = [['filter', 'scrub', 'rule'], ['dstport']];
$sources[] = [['filter', 'scrub', 'rule'], ['srcport']];
$sources[] = [['nat', 'rule'], ['source', 'address']];
$sources[] = [['nat', 'rule'], ['source', 'port']];
$sources[] = [['nat', 'rule'], ['destination', 'address']];
$sources[] = [['nat', 'rule'], ['destination', 'port']];
$sources[] = [['nat', 'rule'], ['target']];
$sources[] = [['nat', 'rule'], ['local-port']];
$sources[] = [['nat', 'onetoone'], ['destination', 'address']];
$sources[] = [['nat', 'outbound', 'rule'], ['source', 'network']];
$sources[] = [['nat', 'outbound', 'rule'], ['sourceport']];
$sources[] = [['nat', 'outbound', 'rule'], ['destination', 'network']];
$sources[] = [['nat', 'outbound', 'rule'], ['dstport']];
$sources[] = [['nat', 'outbound', 'rule'], ['target']];
$sources[] = [['staticroutes', 'route'], ['network']];
// os-firewall plugin paths
$sources[] = [['OPNsense', 'Firewall', 'Filter', 'rules', 'rule'], ['source_net']];
$sources[] = [['OPNsense', 'Firewall', 'Filter', 'rules', 'rule'], ['source_port']];
$sources[] = [['OPNsense', 'Firewall', 'Filter', 'rules', 'rule'], ['destination_net']];
$sources[] = [['OPNsense', 'Firewall', 'Filter', 'rules', 'rule'], ['destination_port']];
$sources[] = [['OPNsense', 'Firewall', 'Filter', 'snatrules', 'rule'], ['source_net']];
$sources[] = [['OPNsense', 'Firewall', 'Filter', 'snatrules', 'rule'], ['source_port']];
$sources[] = [['OPNsense', 'Firewall', 'Filter', 'snatrules', 'rule'], ['destination_net']];
$sources[] = [['OPNsense', 'Firewall', 'Filter', 'snatrules', 'rule'], ['destination_port']];
return $sources;
} | return locations where aliases can be used inside the configuration
@return array alias source map | getAliasSource | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Firewall/Alias.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Firewall/Alias.php | BSD-2-Clause |
private function searchConfig($name)
{
$cfgObj = Config::getInstance()->object();
foreach ($this->getAliasSource() as $aliasref) {
$cfgsection = $cfgObj;
foreach ($aliasref[0] as $cfgName) {
if ($cfgsection != null) {
$cfgsection = $cfgsection->$cfgName;
}
}
if ($cfgsection != null) {
$nodeidx = 0;
foreach ($cfgsection as $inode) {
$node = $inode;
foreach ($aliasref[1] as $cfgName) {
$node = $node->$cfgName;
}
if ((string)$node == $name) {
$ref = implode('.', $aliasref[0]) . "." . $nodeidx . "/" . implode('.', $aliasref[1]);
yield array($ref, &$inode, &$node);
}
$nodeidx++;
}
}
}
} | search configuration items where the requested alias is used
@param $name alias name
@return \Generator [reference, confignode, matched item] | searchConfig | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Firewall/Alias.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Firewall/Alias.php | BSD-2-Clause |
public function flushCache()
{
$this->aliasIteratorCache = [];
$this->aliasReferenceCache = [];
} | flush cached objects and references | flushCache | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Firewall/Alias.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Firewall/Alias.php | BSD-2-Clause |
public function post($model)
{
if ($model instanceof Alias) {
$cfgObj = Config::getInstance()->object();
unset($cfgObj->aliases);
}
} | cleanup old config after config save, we need the old data to avoid race conditions in validations
@param $model | post | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Firewall/Migrations/M1_0_0.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Firewall/Migrations/M1_0_0.php | BSD-2-Clause |
public function getPriority()
{
$configObj = Config::getInstance()->object();
$interface = (string)$this->interface;
if (strpos($interface, ",") !== false || empty($interface)) {
// floating (multiple interfaces involved)
return 200000;
} elseif (
!empty($configObj->interfaces) &&
!empty($configObj->interfaces->$interface) &&
!empty($configObj->interfaces->$interface->type) &&
$configObj->interfaces->$interface->type == 'group'
) {
if (static::$ifgroups === null) {
static::$ifgroups = [];
foreach ((new Group())->ifgroupentry->iterateItems() as $node) {
if (!empty((string)$node->sequence)) {
static::$ifgroups[(string)$node->ifname] = (int)((string)$node->sequence);
}
}
}
if (!isset(static::$ifgroups[$interface])) {
static::$ifgroups[$interface] = 0;
}
// group type
return 300000 + static::$ifgroups[$interface];
} else {
// default
return 400000;
}
} | rule priority is treated equally to the legacy rules, first "floating" then groups and single interface
rules are handled last
@return int priority in the ruleset, sequence should determine sort order. | getPriority | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/FilterRuleField.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/FilterRuleField.php | BSD-2-Clause |
public function getSeparatorChar()
{
return $this->separatorchar;
} | return separator character used
@return string | getSeparatorChar | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasContentField.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasContentField.php | BSD-2-Clause |
private function validatePartialIPv6Network($data)
{
$messages = array();
foreach ($this->getItems($data) as $pnetwork) {
if (!Util::isIpAddress("0000" . $pnetwork)) {
$messages[] = sprintf(
gettext('Entry "%s" is not a valid partial ipv6 address definition (e.g. ::1000).'),
$pnetwork
);
}
}
return $messages;
} | Validate partial ipv6 network definition
@param array $data to validate
@return bool|Callback
@throws \OPNsense\Base\ModelException | validatePartialIPv6Network | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasContentField.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasContentField.php | BSD-2-Clause |
private function validatePartialMacAddr($data)
{
$messages = array();
foreach ($this->getItems($data) as $macaddr) {
if (!preg_match('/^[0-9A-Fa-f]{2}(?:[:][0-9A-Fa-f]{2}){1,5}$/i', $macaddr)) {
$messages[] = sprintf(
gettext('Entry "%s" is not a valid (partial) MAC address.'),
$macaddr
);
}
}
return $messages;
} | Validate (partial) mac address options
@param array $data to validate
@return bool|Callback
@throws \OPNsense\Base\ModelException | validatePartialMacAddr | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasContentField.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasContentField.php | BSD-2-Clause |
private function validateGroups($data)
{
$messages = [];
$all_groups = $this->getUserGroups();
foreach ($this->getItems($data) as $group) {
if (!isset($all_groups[$group])) {
$messages[] = sprintf(gettext('Entry "%s" is not a valid group id.'), $group);
}
}
return $messages;
} | Validate (partial) mac address options
@param array $data to validate
@return array
@throws \OPNsense\Base\ModelException | validateGroups | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasContentField.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Firewall/FieldTypes/AliasContentField.php | BSD-2-Clause |
public function run($model)
{
$config = Config::getInstance()->object();
if (isset($config->syslog) && count($config->syslog->children()) > 0) {
$model->general->loglocal = empty((string)$config->syslog->disablelocallogging) ? "1" : "0"; /* inverted */
$model->general->maxfilesize = (string)$config->syslog->maxfilesize;
$model->general->maxpreserve = (string)$config->syslog->preservelogs;
}
parent::run($model);
} | Migrate older models into shared model
@param $model | run | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Syslog/Migrations/M1_0_2.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Syslog/Migrations/M1_0_2.php | BSD-2-Clause |
public function createOrUpdateGateway($fields, $uuid = null)
{
if ($uuid != null) {
$node = $this->getNodeByReference('gateway_item.' . $uuid);
} else {
/* Create gateway */
$node = $this->getNodeByReference('gateway_item');
if ($node != null && $node->isArrayType()) {
$uuid = $this->gateway_item->generateUUID();
$node = $node->Add();
$node->setAttributeValue("uuid", $uuid);
}
}
if ($node != null && !empty($fields) && is_array($fields)) {
$node->setNodes($fields);
/* disable exception on validation failure */
$this->serializeToConfig(false, true);
}
} | Backwards compatibility for wizard, setaddr | createOrUpdateGateway | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php | BSD-2-Clause |
private function getRealInterface($definedIntf, $ifname, $ipproto = 'inet')
{
if (empty($definedIntf[$ifname])) {
/* name already resolved or invalid */
return $ifname;
}
$ifcfg = $definedIntf[$ifname];
$realif = $ifcfg['if'];
if ($ipproto == 'inet6') {
switch ($ifcfg['ipaddrv6'] ?? 'none') {
case '6rd':
case '6to4':
$realif = "{$ifname}_stf";
break;
default:
break;
}
}
return $realif;
} | return the device name present in the system for the specific configuration
@param string $ifname name of the interface
@param array $definedIntf configuration of interface
@param string $ipproto inet/inet6 type
@return string $realif target device name | getRealInterface | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php | BSD-2-Clause |
private function newKey($prio, $is_default = false)
{
if (empty($this->cached_gateways)) {
$this->gatewaySeq = 1;
}
if ($prio > 255) {
$prio = 255;
}
return sprintf("%01d%04d%010d", $is_default, 256 - $prio, $this->gatewaySeq++);
} | generate new sort key for a gateway
@param string|int $prio priority
@param bool $is_default is default wan gateway
@return string key | newKey | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php | BSD-2-Clause |
public function getDefaultGW($skip = null, $ipproto = 'inet')
{
foreach ($this->getGateways() as $gateway) {
if ($gateway['ipprotocol'] == $ipproto) {
if (is_array($skip) && in_array($gateway['name'], $skip)) {
continue;
} elseif (
!empty($gateway['disabled']) ||
!empty($gateway['defunct']) ||
!empty($gateway['is_loopback']) ||
!empty($gateway['force_down'])
) {
continue;
} else {
return $gateway;
}
}
}
// not found
return null;
} | determine default gateway, exclude gateways in skip list
since getGateways() is correctly ordered, we just need to find the first active, not down gateway
@param array|null $skip list of gateways to ignore
@param string $ipproto inet/inet6 type
@return string type name | getDefaultGW | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php | BSD-2-Clause |
public function gatewaysIndexedByName($disabled = false, $localhost = false, $inactive = false)
{
$result = array();
foreach ($this->getGateways() as $gateway) {
if (!empty($gateway['disabled']) && !$disabled) {
continue;
}
if (!empty($gateway['is_loopback']) && !$localhost) {
continue;
}
if (empty($gateway['is_loopback']) && empty($gateway['if']) && !$inactive) {
continue;
}
$result[$gateway['name']] = $gateway;
}
return $result;
} | determine default gateway, exclude gateways in skip list
@param bool $disabled return disabled gateways
@param bool $localhost inet/inet6 type
@param bool $inactive is inactive
@return array name => gateway | gatewaysIndexedByName | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php | BSD-2-Clause |
public function getGroupNames()
{
$result = array();
if (isset($this->configHandle->gateways)) {
foreach ($this->configHandle->gateways->children() as $tag => $gw_group) {
if ($tag == "gateway_group") {
$result[] = (string)$gw_group->name;
}
}
}
return $result;
} | return gateway groups (only names)
@return array list of names | getGroupNames | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php | BSD-2-Clause |
public function post($model)
{
if ($model instanceof Gateways) {
foreach ($model->gateway_item->iterateRecursiveItems() as $node) {
if (!$node->getInternalIsVirtual() && !empty((string)$node)) {
/* There is at least one entry stored. */
unset(Config::getInstance()->object()->gateways->gateway_item);
return;
}
}
}
} | cleanup old config after config save
@param $model | post | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Routing/Migrations/M1_0_0.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Routing/Migrations/M1_0_0.php | BSD-2-Clause |
public function hasRule($sid)
{
$this->updateSIDlist();
return array_key_exists($sid, $this->sid_list);
} | check if rule overwrite exists
@param string $sid unique id
@return bool | hasRule | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/IDS/IDS.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/IDS/IDS.php | BSD-2-Clause |
public function setAction($sid, $action)
{
$rule = $this->getRule($sid);
$rule->action = $action;
} | set new action for selected rule
@param string $sid unique id
@param $action | setAction | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/IDS/IDS.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/IDS/IDS.php | BSD-2-Clause |
public function getRuleStatus($sid, $default)
{
$this->updateSIDlist();
if (!empty($sid) && array_key_exists($sid, $this->sid_list)) {
return (string)$this->sid_list[$sid]->enabled;
} else {
return $default;
}
} | retrieve current altered rule status
@param string $sid unique id
@param string $default default value
@return string|bool default, 0, 1 ( default, true, false) | getRuleStatus | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/IDS/IDS.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/IDS/IDS.php | BSD-2-Clause |
public function getRuleAction($sid, $default, $response_plain = false)
{
$this->updateSIDlist();
if (!empty($sid) && array_key_exists($sid, $this->sid_list)) {
if (!$response_plain) {
return $this->sid_list[$sid]->action->getNodeData();
} else {
$act = (string)$this->sid_list[$sid]->action;
if (array_key_exists($act, $this->action_list)) {
return $this->action_list[$act]['value'];
} else {
return $act;
}
}
} elseif (!$response_plain) {
// generate selection for new field
$default_types = $this->action_list;
if (array_key_exists($default, $default_types)) {
foreach ($default_types as $key => $value) {
if ($key == $default) {
$default_types[$key]['selected'] = 1;
} else {
$default_types[$key]['selected'] = 0;
}
}
}
// select default
return $default_types;
} else {
// return plaintext default
if (array_key_exists($default, $this->action_list)) {
return $this->action_list[$default]['value'];
} else {
return $default;
}
}
} | retrieve current (altered) rule action
@param string $sid unique id
@param string $default default value
@param bool $response_plain response as text ot model (select list)
@return string|bool default, <action value> ( default, true, false) | getRuleAction | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/IDS/IDS.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/IDS/IDS.php | BSD-2-Clause |
public function getFileNode($filename)
{
foreach ($this->files->file->iterateItems() as $NodeKey => $NodeValue) {
if ($filename == $NodeValue->filename) {
return $NodeValue;
}
}
// add a new node
$node = $this->files->file->Add();
$node->filename = $filename;
return $node;
} | retrieve (rule) file entry from config or add a new one
@param string $filename list of filename to merge into config
@return BaseField number of appended items | getFileNode | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/IDS/IDS.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/IDS/IDS.php | BSD-2-Clause |
public function run($model)
{
$cfgObj = Config::getInstance()->object();
if (!isset($cfgObj->OPNsense->IDS->files->file)) {
return;
}
$csets = array();
$nsets = array();
$changed_sets = ['emerging-current_events.rules', 'emerging-trojan.rules',
'emerging-malware.rules', 'emerging-info.rules', 'emerging-policy.rules'];
$new_sets = ['emerging-ja3.rules', 'emerging-hunting.rules', 'emerging-adware_pup.rules',
'emerging-phishing.rules', 'emerging-exploit_kit.rules', 'emerging-coinminer.rules',
'emerging-malware.rules'];
foreach ($model->files->file->iterateItems() as $file) {
if (in_array((string)$file->filename, $changed_sets)) {
$csets[(string)$file->filename] = $file;
}
if (in_array((string)$file->filename, $new_sets)) {
$nsets[(string)$file->filename] = $file;
}
}
// add all new to config in deselected state
foreach ($new_sets as $filename) {
if (empty($nsets[$filename])) {
$node = $model->files->file->Add();
$node->filename = $filename;
$nsets[$filename] = $node;
}
}
// map rulesets
if (!empty($csets['emerging-malware.rules']) && $csets['emerging-malware.rules']->enabled == "1") {
$nsets['emerging-adware_pup.rules']->enabled = "1";
}
if (!empty($csets['emerging-current_events.rules']) && $csets['emerging-current_events.rules']->enabled == "1") {
$nsets['emerging-phishing.rules']->enabled = "1";
$nsets['emerging-exploit_kit.rules']->enabled = "1";
}
if (!empty($csets['emerging-trojan.rules']) && $csets['emerging-trojan.rules']->enabled == "1") {
$nsets['emerging-coinminer.rules']->enabled = "1";
$nsets['emerging-malware.rules']->enabled = "1";
}
if (!empty($csets['emerging-info.rules']) && $csets['emerging-info.rules']->enabled == "1") {
$nsets['emerging-hunting.rules']->enabled = "1";
}
if (!empty($csets['emerging-policy.rules']) && $csets['emerging-policy.rules']->enabled == "1") {
$nsets['emerging-hunting.rules']->enabled = "1";
}
if (!empty($csets['emerging-trojan.rules'])) {
// deprecated ruleset
$model->files->file->del($csets['emerging-trojan.rules']->getAttribute('uuid'));
}
} | Emerging threats suricata 5 ruleset movements
@param IDS $model | run | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/IDS/Migrations/M1_0_7.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/IDS/Migrations/M1_0_7.php | BSD-2-Clause |
public function run($model)
{
$cfgObj = Config::getInstance()->object();
$affectedUuids = [];
if (!isset($cfgObj->OPNsense->IDS->userDefinedRules->rule)) {
return;
}
foreach ($cfgObj->OPNsense->IDS->userDefinedRules->rule as $rule) {
if (!empty($rule->geoip) || !empty($rule->geoip_direction)) {
$affectedUuids[] = (string)$rule['uuid'];
}
}
// Update the affected rule in the model
/** @var BaseField $node */
foreach ($model->userDefinedRules->rule->iterateItems() as $node) {
if (in_array($node->getAttribute('uuid'), $affectedUuids)) {
$node->enabled = '0';
// Description can be up to 255 characters, truncate as necessary.
$node->description = substr(
$node->description . ' - Old GeoIP rule, disabled by migration',
0,
255
);
}
}
} | Disable rules that have GeoIP config set
@param IDS $model | run | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/IDS/Migrations/M1_0_2.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/IDS/Migrations/M1_0_2.php | BSD-2-Clause |
public function queryRuleInfo()
{
static::$queryRules = true;
} | by default the PolicyRulesField acts as a standard ArrayField, unless queryRuleInfo() in which case
the next created object will query for local rule data. (to limit load) | queryRuleInfo | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/IDS/FieldTypes/PolicyRulesField.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/IDS/FieldTypes/PolicyRulesField.php | BSD-2-Clause |
protected function actionPostLoadingEvent()
{
if (empty(self::$internalStaticOptionList)) {
self::$internalStaticOptionList = array();
// XXX: we could add caching here if configd overhead is an issue
$response = (new Backend())->configdRun("ids list rulemetadata") ?? '';
$data = json_decode($response, true);
if (!empty($data)) {
foreach ($data as $prop => $values) {
foreach ($values as $value) {
$item_key = "{$prop}.{$value}";
self::$internalStaticOptionList[$item_key] = $value;
}
}
}
}
$this->internalOptionList = self::$internalStaticOptionList;
} | generate validation data (list of metadata options) | actionPostLoadingEvent | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/IDS/FieldTypes/PolicyContentField.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/IDS/FieldTypes/PolicyContentField.php | BSD-2-Clause |
private function urlMasks($username)
{
if (array_key_exists($username, $this->userDatabase)) {
// fetch masks from user privs
foreach ($this->userDatabase[$username]["priv"] as $privset) {
foreach ($privset as $urlmask) {
yield $urlmask;
}
}
// fetch masks from assigned groups
foreach ($this->userDatabase[$username]["groups"] as $itemkey => $group) {
if (array_key_exists($group, $this->allGroupPrivs)) {
foreach ($this->allGroupPrivs[$group] as $privset) {
foreach ($privset as $urlmask) {
yield $urlmask;
}
}
}
}
}
/*
* Always allow logout and menu, should be yielded as final items
* to prevent redirect to the logout page in case unauthorised
* pages are tried.
*/
yield 'index.php?logout';
yield 'api/core/menu/*';
} | iterator to collect all assigned access patterns for this user
@param string $username user name | urlMasks | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | BSD-2-Clause |
public function isPageAccessible($username, $url)
{
if (!empty($_SESSION['user_shouldChangePassword'])) {
// when a password change is enforced, lock all other endpoints
foreach (['system_usermanager_passwordmg.php*', 'ui/user_portal', 'api/user_portal/user/*'] as $pattern) {
if ($this->urlMatch($url, $pattern)) {
return true;
}
}
return false;
}
foreach ($this->urlMasks($username) as $urlmask) {
if ($this->urlMatch($url, $urlmask)) {
return true;
}
}
return false;
} | check if an endpoint url is accessible by the specified user.
@param string $username user name
@param string $url full url, for example /firewall_rules.php
@return bool | isPageAccessible | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | BSD-2-Clause |
public function inGroup($username, $groupname, $byname = true)
{
if (!empty($this->userDatabase[$username])) {
if ($byname) {
return in_array($groupname, $this->userDatabase[$username]['groups']);
} else {
return in_array($groupname, $this->userDatabase[$username]['gids']);
}
}
return false;
} | check if user has group membership
@param string $username user name
@param string $groupname group name
@param boolean $byname query by name (or gid)
@return bool|null|string|string[] | inGroup | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | BSD-2-Clause |
public function getPrivList()
{
// convert json priv map to array
$priv_list = [];
foreach ($this->ACLtags as $aclKey => $aclItem) {
$priv_list[$aclKey] = [];
foreach ($aclItem as $propName => $propValue) {
if ($propName == 'name') {
// translate name tag
$priv_list[$aclKey][$propName] = gettext($propValue);
} else {
$priv_list[$aclKey][$propName] = $propValue;
}
}
}
// sort by name ( case insensitive )
uasort($priv_list, function ($a, $b) {
return strcasecmp($a["name"], $b["name"]);
});
return $priv_list;
} | return privilege list as array (sorted), only for backward compatibility
@return array | getPrivList | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | BSD-2-Clause |
public function persist($nowait = true)
{
$this->mergePluggableACLs();
$fp = fopen($this->aclCacheFilename, file_exists($this->aclCacheFilename) ? "r+" : "w+");
$lockMode = $nowait ? LOCK_EX | LOCK_NB : LOCK_EX;
if (flock($fp, $lockMode)) {
ftruncate($fp, 0);
fwrite($fp, json_encode($this->ACLtags));
fflush($fp);
flock($fp, LOCK_UN);
fclose($fp);
chmod($this->aclCacheFilename, 0660);
return true;
}
return false;
} | Load and persist ACL configuration to disk.
When locked we just load all the module ACL's and continue by default (return false),
this has a slight performance impact but is usually better then waiting for likely the same content being
written by another session.
@param bool $nowait when the cache is locked, skip waiting for it to become available.
@return bool has persisted | persist | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | BSD-2-Clause |
public function invalidateCache()
{
@unlink($this->aclCacheFilename);
} | invalidate cache, removes cache file from disk if available, which forces the next request to persist() again | invalidateCache | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | BSD-2-Clause |
public function isExpired()
{
if (file_exists($this->aclCacheFilename)) {
$fstat = stat($this->aclCacheFilename);
return $this->aclCacheTTL < (time() - $fstat['mtime']);
}
return true;
} | check if pluggable ACL's are expired
@return bool is expired | isExpired | php | opnsense/core | src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Core/ACL.php | BSD-2-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.