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
private function flush_network_wan() { $target = Config::getInstance()->object(); /* configure wan */ $gateways = new Gateways(); foreach ($gateways->gateway_item->iterateItems() as $uuid => $node) { if ($node->interface == 'wan' && $node->ipprotocol == 'inet') { $gateways->gateway_item->del($uuid); } } $wanif = $this->getConfigItem('interfaces.wan.if'); if ($this->interfaces->wan->ipv4_type == 'pppoe') { /* PPPoE configuration will nest interfaces, make sure we can still update the interface once configured */ if (!isset($target->ppps)) { $target->addChild('ppps'); } $pppoe_idx = -1; $max_ptpid = 0; for ($idx = 0; $idx < count($target->ppps->ppp); ++$idx) { if ($target->ppps->ppp[$idx]->if == $wanif) { $pppoe_idx = $idx; } $max_ptpid = max($max_ptpid, $target->ppps->ppp[$idx]->ptpid); } if ($pppoe_idx == -1) { /* add pppoe on top of current configured wan */ $node = $target->ppps->addChild('ppp'); $node->addChild('ports', $wanif); $node->addChild('ptpid', (string)($max_ptpid + 1)); $node->addChild('if', 'pppoe' . $node->ptpid); $target->interfaces->wan->if = (string)$node->if; } else { $node = $target->ppps->ppp[$pppoe_idx]; } $node->type = 'pppoe'; $node->username = (string)$this->interfaces->wan->pppoe_username; $node->password = base64_encode((string)$this->interfaces->wan->pppoe_password); } unset($target->interfaces->wan->dhcphostname); if (in_array($this->interfaces->wan->ipv4_type, ['pppoe', 'dhcp'])) { $target->interfaces->wan->ipaddr = (string)$this->interfaces->wan->ipv4_type; $target->interfaces->wan->subnet = ''; if ($this->interfaces->wan->ipv4_type == 'dhcp') { $target->interfaces->wan->dhcphostname = (string)$this->interfaces->wan->dhcphostname; } } else { $parts = explode('/', $this->interfaces->wan->ipaddr); $target->interfaces->wan->ipaddr = $parts[0]; $target->interfaces->wan->subnet = $parts[1]; if (!$this->interfaces->wan->gateway->isEmpty()) { $gateways->createOrUpdateGateway([ 'interface' => 'wan', 'gateway' => (string)$this->interfaces->wan->gateway, 'name' => 'WAN_GW', 'weight' => 1, 'monitor_disable' => 1, 'descr' => "WAN Gateway", 'defaultgw' => true, ]); } } $target->interfaces->wan->enable = '1'; $target->interfaces->wan->spoofmac = (string)$this->interfaces->wan->spoofmac; $target->interfaces->wan->mtu = (string)$this->interfaces->wan->mtu; $target->interfaces->wan->mss = (string)$this->interfaces->wan->mss; $target->interfaces->wan->blockpriv = (string)$this->interfaces->wan->blockpriv; $target->interfaces->wan->blockbogons = (string)$this->interfaces->wan->blockbogons; $gateways->serializeToConfig(false, true); }
flush wan interface configuration from in-memory model back to config
flush_network_wan
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.php
BSD-2-Clause
private function flush_initial_pass() { /* update root password */ if (!$this->password->isEmpty()) { $usermdl = new User(); $rootuser = $usermdl->getUserByName('root'); if ($rootuser) { $hash = $usermdl->generatePasswordHash((string)$this->password); if ($hash !== false && strpos($hash, '$') === 0) { $rootuser->password = $hash; $usermdl->serializeToConfig(false, true); } } } }
reset root password when offered
flush_initial_pass
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Core/InitialSetup.php
BSD-2-Clause
public function run($model) { if (!($model instanceof Hasync)) { return; } $src = Config::getInstance()->object()->hasync; /* duplicated effort from 1.0.0 since that was functional on early 24.7.x */ if (empty($src->pfsyncenabled)) { /* disabe via pfsyncinterface if not set */ $model->pfsyncinterface = null; } else { /* may need to disable if previous value is no longer available */ $model->pfsyncinterface->normalizeValue(); } }
Remove pfsyncenabled by folding it into the pfsyncinterface setting @param $model
run
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Core/Migrations/MHA1_0_1.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Core/Migrations/MHA1_0_1.php
BSD-2-Clause
public function run($model) { if (!($model instanceof Firmware)) { return; } if (in_array((string)$model->flavour, ['latest', 'libressl'])) { $model->flavour = null; } if (!empty((string)$model->mirror)) { $is_business = strpos((string)$model->mirror, 'opnsense-update.deciso.com') !== false; if ($is_business) { $url = explode('/', (string)$model->mirror); $model->subscription = array_pop($url); $model->mirror = implode('/', $url); } } }
Migrate subscription and remove old flavour types @param $model
run
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Core/Migrations/M1_0_1.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Core/Migrations/M1_0_1.php
BSD-2-Clause
public function __construct($module_root) { $acl_cfg_xml = $module_root . '/ACL/ACL.xml'; if (file_exists($acl_cfg_xml)) { // load ACL xml file and perform some basic validation $this->aclXML = simplexml_load_file($acl_cfg_xml); if ($this->aclXML === false) { throw new \Exception('ACL xml ' . $acl_cfg_xml . ' not valid'); } if ($this->aclXML->getName() != "acl") { throw new \Exception('ACL xml ' . $acl_cfg_xml . ' seems to be of wrong type'); } } }
Construct new ACL for an application @param string $module_root location on disk for this ACL @throws \Exception
__construct
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Core/ACL/ACL.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Core/ACL/ACL.php
BSD-2-Clause
public function update(&$acltags) { foreach ($this->get() as $aclID => $ACLnode) { $acltags[$aclID] = $ACLnode; } }
update provided acl array with content from this list @param array &$acltags
update
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Core/ACL/ACL.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Core/ACL/ACL.php
BSD-2-Clause
public function getTemplateByName($name) { foreach ($this->templates->template->iterateItems() as $template) { if ((string)$template->name === $name) { return $template; } } $newItem = $this->templates->template->Add(); $newItem->name = $name; $newItem->fileid = uniqid(); return $newItem; }
find template by name or return a new object @param $name template name @return mixed
getTemplateByName
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/CaptivePortal/CaptivePortal.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/CaptivePortal/CaptivePortal.php
BSD-2-Clause
public function post($model) { return; }
post migration action, run after config sync @param $model
post
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModelMigration.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModelMigration.php
BSD-2-Clause
protected function init() { return; }
If the model needs a custom initializer, override this init() method Default behaviour is to do nothing in this init.
init
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
private function getNewField($classname) { if (self::$internalCacheReflectionClasses === null) { self::$internalCacheReflectionClasses = array(); } $classname_idx = str_replace("\\", "_", $classname); if (!isset(self::$internalCacheReflectionClasses[$classname_idx])) { $is_derived_from_basefield = false; if (class_exists($classname)) { $field_rfcls = new ReflectionClass($classname); $check_derived = $field_rfcls->getParentClass(); while ($check_derived != false) { if ($check_derived->name == 'OPNsense\Base\FieldTypes\BaseField') { $is_derived_from_basefield = true; break; } $check_derived = $check_derived->getParentClass(); } } else { throw new ModelException("class " . $classname . " missing"); } if (!$is_derived_from_basefield) { // class found, but of wrong type. raise an exception. throw new ModelException("class " . $field_rfcls->name . " of wrong type in model definition"); } self::$internalCacheReflectionClasses[$classname_idx] = $field_rfcls; } return self::$internalCacheReflectionClasses[$classname_idx]; }
fetch reflection class (cached by field type) @param string $classname classname to construct @return BaseField type class @throws ModelException when unable to parse field type @throws ReflectionException when unable to create class
getNewField
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
private function getModelXML() { // determine our caller's filename and try to find the model definition xml // throw error on failure $class_info = new ReflectionClass($this); $model_filename = substr($class_info->getFileName(), 0, strlen($class_info->getFileName()) - 3) . "xml"; if (!file_exists($model_filename)) { throw new ModelException('model xml ' . $model_filename . ' missing'); } $model_xml = simplexml_load_file($model_filename); if ($model_xml === false) { throw new ModelException('model xml ' . $model_filename . ' not valid'); } if ($model_xml->getName() != "model") { throw new ModelException('model xml ' . $model_filename . ' seems to be of wrong type'); } if (!$model_xml->mount) { throw new ModelException('model xml ' . $model_filename . ' missing mount definition'); } return $model_xml; }
fetch model definition after basic validations @return SimpleXMLElement @throws ModelException if the model xml is not found or invalid @throws ReflectionException
getModelXML
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function __get($name) { return $this->internalData->$name; }
reflect getter to internalData (ContainerField) @param string $name property name @return mixed
__get
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function __set($name, $value) { $this->internalData->$name = $value; }
reflect setter to internalData (ContainerField) @param string $name property name @param string $value property value
__set
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function getFlatNodes() { return $this->internalData->getFlatNodes(); }
forward to root node's getFlatNodes @return array all children
getFlatNodes
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function iterateItems() { return $this->internalData->iterateItems(); }
iterate (non virtual) child nodes @return mixed
iterateItems
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function iterateRecursiveItems() { return $this->internalData->iterateRecursiveItems(); }
iterate (non virtual) child nodes recursively @return mixed
iterateRecursiveItems
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function isVolatile() { return $this->internal_mountpoint == ':memory:'; }
check if the model is not persistent in the config @return bool true if memory model, false if config is stored
isVolatile
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function isLegacyMapper() { return str_ends_with($this->internal_mountpoint, '+') && strpos($this->internal_mountpoint, "//") !== 0; }
check if the model maps a legacy model without a container. these should operate similar as regular models, but without a migration or version number (due to the lack of a container) @return bool
isLegacyMapper
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function getValidationSequence() { return $this->internalValidationSequence; }
Return the number of times performValidation() has been called. This can be practical if validations need to cache outcomes which are consistent for the full validation sequence. @return int
getValidationSequence
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function performValidation($validateFullModel = false) { // create a wrapped validator and collect all model validations. $validation = new \OPNsense\Base\Validation(); $validation_data = array(); $all_nodes = $this->internalData->getFlatNodes(); $this->internalValidationSequence++; foreach ($all_nodes as $key => $node) { if ($validateFullModel || $node->isFieldChanged()) { $node_validators = $node->getValidators(); foreach ($node_validators as $item_validator) { if (is_a($item_validator, "OPNsense\\Base\\Constraints\\BaseConstraint")) { $target_key = $item_validator->getOption("node")->__reference; $validation->add($target_key, $item_validator); } else { $validation->add($key, $item_validator); } } if (count($node_validators) > 0) { $validation_data[$key] = (string)$node; } } } return $validation->validate($validation_data); }
validate full model using all fields and data in a single (1 deep) array @param bool $validateFullModel validate full model or only changed fields @return Group
performValidation
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function validate($sourceref = null, $targetref = '', $validateFullModel = false) { $result = []; $valMsgs = $this->performValidation($validateFullModel); foreach ($valMsgs as $msg) { // replace absolute path to attribute for relative one at uuid. if ($sourceref != null) { $fieldnm = str_replace($sourceref, $targetref, $msg->getField()); $result[$fieldnm] = $msg->getMessage(); } else { $fieldnm = $targetref . $msg->getField(); $result[$fieldnm] = $msg->getMessage(); } } return $result; }
perform a validation on changed model fields, using the (renamed) internal reference as a source pointer for the requestor to identify its origin @param null|string $sourceref source reference, for example model.section @param string $targetref target reference, for example section. used as prefix if no source given @return array list of validation errors, indexed by field reference
validate
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function toXML() { // calculate root node from mountpoint if ($this->isVolatile() || $this->isLegacyMapper()) { $xml = new SimpleXMLElement('<root/>'); $this->internalData->addToXMLNode($xml); } else { $xml_root_node = ""; $parts = explode("/", ltrim($this->internal_mountpoint, "/")); foreach ($parts as $part) { $xml_root_node .= "<" . $part . ">"; } foreach (array_reverse($parts) as $part) { $xml_root_node .= "</" . $part . ">"; } $xml = new SimpleXMLElement($xml_root_node); $this->internalData->addToXMLNode($xml->xpath($this->internal_mountpoint)[0]); // add this model's version to the newly created xml structure if (!empty($this->internal_current_model_version)) { $xml->xpath($this->internal_mountpoint)[0]->addAttribute('version', $this->internal_current_model_version); } } return $xml; }
render xml document from model including all parent nodes. (parent nodes are included to ease testing) @return SimpleXMLElement xml representation of the model
toXML
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function getNodeByReference($reference) { $parts = explode(".", $reference); $node = $this->internalData; while (count($parts) > 0) { $childName = array_shift($parts); if ($node->hasChild($childName)) { $node = $node->getChild($childName); } else { return null; } } return $node; }
find node by reference starting at the root node @param string $reference node reference (point separated "node.subnode.subsubnode") @return BaseField|null field node by reference (or null if not found)
getNodeByReference
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function setNodeByReference($reference, $value) { $node = $this->getNodeByReference($reference); if ($node != null) { $node->setValue($value); return true; } else { return false; } }
set node value by name (if reference exists) @param string $reference node reference (point separated "node.subnode.subsubnode") @param string $value @return bool value saved yes/no
setNodeByReference
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function Default() { $this->internalData = new ContainerField(); $config_array = new SimpleXMLElement('<opnsense/>'); $model_xml = $this->getModelXML(); if (!empty($model_xml->version) && $this->internal_model_version != (string)$model_xml->version) { throw new ModelException('Unable to reset to defaults as model on disk is not the same as in memory'); } $this->parseXml($model_xml->items, $config_array, $this->internalData); // trigger post loading event $this->internalData->eventPostLoading(); return $this; }
reset model to its defaults (flush all content) @throws ModelException if the model xml is not found or invalid @throws ReflectionException @return this
Default
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
BSD-2-Clause
public function appendMessage($message) { $this[] = $message; }
Appends a message to the messages list @$message MessageInterface $message
appendMessage
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/Validation.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/Validation.php
BSD-2-Clause
public function validate($data) { $this->data = $data; $phalcon_validation = new \Phalcon\Filter\Validation(); foreach ($this->validators as $field => $validators) { foreach ($validators as $validator) { if (is_a($validator, 'Phalcon\Filter\Validation\ValidatorInterface')) { $phalcon_validation->add($field, $validator); } else { $validator->validate($this, $field); } } } // XXX: temporary dual validation $phalconMsgs = $phalcon_validation->validate($data); if (!empty($phalconMsgs)) { foreach ($phalconMsgs as $phalconMsg) { $this[] = $phalconMsg; } } return $this; }
Validate a set of data according to a set of rules @param array $data
validate
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/Validation.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/Validation.php
BSD-2-Clause
public function setFilters($filters) { if (is_array($filters)) { $this->internalFilters = $filters; $this->updateInternalCacheKey(); } }
set filters to use (in regex) per field, all tags are combined and cached for the next object using the same filters @param $filters filters to use
setFilters
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/InterfaceField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/InterfaceField.php
BSD-2-Clause
public function setAddParentDevices($value) { if (trim(strtoupper($value)) == "Y") { $this->internalAddParentDevices = true; } else { $this->internalAddParentDevices = false; } $this->updateInternalCacheKey(); }
add parent devices to the selection in case the parent has no configuration @param $value boolean value 0/1
setAddParentDevices
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/InterfaceField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/InterfaceField.php
BSD-2-Clause
public function setAllowDynamic($value) { if (trim(strtoupper($value)) == "Y") { $this->internalAllowDynamic = 1; } elseif (trim(strtoupper($value)) == "S") { $this->internalAllowDynamic = 2; } else { $this->internalAllowDynamic = 0; } $this->updateInternalCacheKey(); }
select if dynamic (hotplug) interfaces maybe selectable @param $value Y/N/S (Yes, No, Static)
setAllowDynamic
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/InterfaceField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/InterfaceField.php
BSD-2-Clause
public function getValidators() { $validators = parent::getValidators(); if ($this->internalValue != null) { $validators[] = new Email(['message' => $this->getValidationMessage()]); } return $validators; }
retrieve field validators for this field type @return array returns Email validator
getValidators
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/EmailField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/EmailField.php
BSD-2-Clause
public function setType($value) { if (trim(strtolower($value)) == "ca") { $this->certificateType = "ca"; } elseif (trim(strtolower($value)) == "crl") { $this->certificateType = "crl"; } else { $this->certificateType = "cert"; } }
set certificate type (cert/ca) @param $value certificate type
setType
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CertificateField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CertificateField.php
BSD-2-Clause
public function __construct($ref = null, $tagname = null) { parent:: __construct($ref, $tagname); $this->minimum_value = -99999999999999.0; $this->maximum_value = 99999999999999.0; }
constructor, set absolute min and max values @param null|string $ref direct reference to this object @param null|string $tagname xml tagname to use
__construct
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/NumericField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/NumericField.php
BSD-2-Clause
public function getValidators() { $validators = parent::getValidators(); if ($this->internalValue != null) { $validators[] = new MinMaxValidator([ 'message' => $this->getValidationMessage(), 'min' => $this->minimum_value, 'max' => $this->maximum_value, ]); $validators[] = new Numericality(['message' => $this->getValidationMessage()]); } return $validators; }
retrieve field validators for this field type @return array returns Text/regex validator
getValidators
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/NumericField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/NumericField.php
BSD-2-Clause
public function setModel($mdlStructure) { // only handle array type input if (!is_array($mdlStructure)) { return; } else { $this->mdlStructure = $mdlStructure; // set internal key for this node based on sources and filter criteria $this->internalCacheKey = md5(serialize($mdlStructure)); } }
Set model as reference list, use uuid's as key @param $mdlStructure nested array structure defining the usable datasources.
setModel
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php
BSD-2-Clause
protected function actionPostLoadingEvent() { $this->loadModelOptions(); }
load model options when initialized
actionPostLoadingEvent
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php
BSD-2-Clause
public function setSorted($value) { $this->internalIsSorted = trim(strtoupper($value)) == "Y"; }
select if sort order should be maintained @param $value boolean value Y/N
setSorted
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php
BSD-2-Clause
public function getNodeData() { if ($this->internalIsSorted) { $optKeys = array_merge(explode(',', $this->internalValue), array_keys($this->internalOptionList)); $ordered_option_list = []; foreach (array_unique($optKeys) as $key) { if (in_array($key, array_keys($this->internalOptionList))) { $ordered_option_list[$key] = $this->internalOptionList[$key]; } } $this->internalOptionList = $ordered_option_list; } return parent::getNodeData(); }
get valid options, descriptions and selected value keeps saved item sorting when internalIsSorted is set. @return array
getNodeData
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ModelRelationField.php
BSD-2-Clause
public function setMultiple($value) { if (trim(strtoupper($value)) == "Y") { $this->internalMultiSelect = true; } else { $this->internalMultiSelect = false; } }
select if multiple interfaces may be selected at once @param $value boolean value 0/1
setMultiple
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseListField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseListField.php
BSD-2-Clause
public function setBlankDesc($value) { $this->internalEmptyDescription = gettext($value); }
set descriptive text for empty value @param $value string description
setBlankDesc
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseListField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseListField.php
BSD-2-Clause
public function setHostnameAllowed($value) { $this->internalHostnameAllowed = trim(strtoupper($value)) == "Y"; }
select if a hostname may be provided instead of an address (without addressfamily validation) @param $value string value Y/N
setHostnameAllowed
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/IPPortField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/IPPortField.php
BSD-2-Clause
public function setAsList($value) { $this->internalAsList = trim(strtoupper($value)) == "Y"; }
select if multiple IP-Port combinations may be selected at once @param $value string value Y/N
setAsList
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/IPPortField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/IPPortField.php
BSD-2-Clause
public function getValidators() { $validators = parent::getValidators(); if ($this->internalValue != null) { $validators[] = new UrlValidator(['message' => $this->getValidationMessage()]); } return $validators; }
retrieve field validators for this field type @return array returns Url validator
getValidators
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/UrlField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/UrlField.php
BSD-2-Clause
protected function actionPostLoadingEvent() { return; }
Template action for post loading actions, triggered by eventPostLoadingEvent. Overwrite this method for custom loading hooks.
actionPostLoadingEvent
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function getParentModel() { return $this->internalParentModel; }
Retrieve the model to which this field is attached @return BaseModel parent model
getParentModel
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function isContainer() { return $this->internalIsContainer; }
check if this is a container type without data @return bool returns if this a container type object (no data)
isContainer
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function setInternalReference($ref) { if ($this->internalReference == null) { $this->internalReference = $ref; } else { throw new Exception("cannot change internal reference"); } }
change internal reference, if set it can't be changed for safety purposes. @param $ref internal reference @throws Exception change exception
setInternalReference
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
private function setParentNode($node) { $this->internalParentNode = $node; }
set pointer to parent node, used by addChildNode to backref this node @param BaseField $node pointer to parent
setParentNode
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function getParentNode() { return $this->internalParentNode; }
return this nodes parent (or null if not found) @return null|BaseField
getParentNode
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function __isset($name) { return isset($this->internalChildnodes[$name]); }
Triggered by calling isset() or empty() on an internal child node. Prevents the need for statically casting to a type on __get(). @param $name property name @return bool
__isset
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function iterateItems() { foreach ($this->internalChildnodes as $key => $value) { if ($value->internalIsVirtual == false) { yield $key => $value; } } }
iterate (non virtual) child nodes @return Generator
iterateItems
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function __set($name, $value) { if (isset($this->internalChildnodes[$name])) { $this->internalChildnodes[$name]->setValue($value); } else { throw new InvalidArgumentException($name . " not an attribute of " . $this->internalReference); } }
reflect default setter to internal child nodes @param string $name property name @param string $value property value
__set
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function __toString() { return $this->getCurrentValue(); }
return string interpretation of this field @return string string interpretation of this field
__toString
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function setChanged() { $this->internalInitialValue = true; }
force field to act as changed, used after cloning.
setChanged
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function markUnchanged() { $this->internalInitialValue = $this->internalValue; }
force field to act as unchanged (skip validations)
markUnchanged
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function isFieldChanged() { return $this->internalInitialValue !== $this->internalValue; }
check if field content has changed @return bool change indicator
isFieldChanged
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function hasChild($name) { return isset($this->internalChildnodes[$name]); }
check for existence of child attribute @return bool if child exists
hasChild
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function getConstraintByName($name) { if (isset($this->internalConstraints[$name])) { $constraint = $this->internalConstraints[$name]; if (!empty($constraint['type'])) { try { $constr_class = new ReflectionClass('OPNsense\\Base\\Constraints\\' . $constraint['type']); if ($constr_class->getParentClass()->name == 'OPNsense\Base\Constraints\BaseConstraint') { $constraint['name'] = $name; $constraint['node'] = $this; return $constr_class->newInstance($constraint); } } catch (ReflectionException $e) { /* ignore configuration errors, if the constraint can't be found, skip. */ } } } return null; }
retrieve constraint objects by defined constraints name (/key) @param $name @return null|object
getConstraintByName
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function getValidators() { $validators = $this->getConstraintValidators(); if ($this->isEmptyAndRequired()) { $validators[] = new PresenceOf(['message' => gettext('A value is required.')]); } return $validators; }
return field validators for this field @return array returns validators for this field type (empty if none)
getValidators
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function setInternalIsVirtual() { $this->internalIsVirtual = true; }
Mark this node as virtual, only used as template for structure behind it. Used for array structures.
setInternalIsVirtual
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function getInternalIsVirtual() { return $this->internalIsVirtual; }
returns if this node is virtual, the framework uses this to determine if this node should only be used to clone children. (using ArrayFields) @return bool is virtual node
getInternalIsVirtual
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function getInternalIsVolatile() { return $this->internalIsVolatile; }
returns if this node is volatile, the framework uses this to determine if this node should be stored. @return bool is volatile node
getInternalIsVolatile
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function getNodeData() { return (string)$this; }
companion for getNodes, displays node content. may be overwritten for alternative presentation. @return null|string
getNodeData
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function getDescription() { return (string)$this; }
Return descriptive value of the item. For simple types this is usually the internal value, complex types may return what this value represents. (descriptions of selected items) @return null|string
getDescription
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function setNodes($data) { // update structure with new content foreach ($this->iterateItems() as $key => $node) { if ($data != null && isset($data[$key])) { if ($node->isContainer()) { if (is_array($data[$key])) { $node->setNodes($data[$key]); } else { throw new Exception("Invalid input type for {$key} (configuration error?)"); } } else { $node->setValue($data[$key]); } } } // add new items to array type objects if ($this->isArrayType()) { foreach ($data as $dataKey => $dataValue) { if (!isset($this->$dataKey)) { $node = $this->add(); $node->setNodes($dataValue); } } } }
update model with data returning missing repeating tag types. @param $data array structure containing new model content @throws Exception
setNodes
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function setDefault($value) { $this->internalValue = $value; $this->internalDefaultValue = $value; }
set Default field value ( for usage in model xml ) @param string $value default value
setDefault
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function applyDefault() { $this->internalValue = $this->internalDefaultValue; }
(re)Apply default value without changing the initial value of the field
applyDefault
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function setValidationMessage($msg) { $this->internalValidationMessage = $msg; }
set Validation message ( for usage in model xml ) @param string $msg validation message (on failure)
setValidationMessage
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function setRequired($value) { if (strtoupper(trim($value)) == "Y") { $this->internalIsRequired = true; } else { $this->internalIsRequired = false; } }
Implements required property, the base class only implements the setter. The implemented fieldtype should include the correct validation. @param string $value set if this node/field is required (Y/N)
setRequired
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function normalizeValue() { /* implemented where needed */ }
normalize the internal value to allow passing validation
normalizeValue
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
BSD-2-Clause
public function setAddInverted($value) { if (trim(strtoupper($value)) == "Y") { $this->internalAddInverse = true; } else { $this->internalAddInverse = false; } }
Add inverted countries to selection (prefix !, meaning not) @param string $value boolean value Y/N
setAddInverted
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CountryField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CountryField.php
BSD-2-Clause
public function setIsDNSName($value) { $this->internalIsDNSName = trim(strtoupper($value)) == "Y"; }
is dns name as defined by RFC2181 @param string $value Y/N
setIsDNSName
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/HostnameField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/HostnameField.php
BSD-2-Clause
public function setFqdnWildcardAllowed($value) { $this->internalFqdnWildcardAllowed = trim(strtoupper($value)) == "Y"; }
fqdn (prefix) wildcard (*.my.top.level.domain) allowed @param string $value Y/N
setFqdnWildcardAllowed
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/HostnameField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/HostnameField.php
BSD-2-Clause
public function setFieldSeparator($value) { $this->internalFieldSeparator = $value; }
if multiple hostnames maybe provided at once, set separator. @param string $value separator
setFieldSeparator
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/HostnameField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/HostnameField.php
BSD-2-Clause
public function setValue($value) { $tmp = trim(strtolower($value)); if ($this->enableWellKnown && in_array($tmp, ["any"] + self::$wellknownservices)) { return parent::setValue($tmp); } else { return parent::setValue($value); } }
always lowercase known portnames @param string $value
setValue
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/PortField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/PortField.php
BSD-2-Clause
protected function actionPostLoadingEvent() { if (!isset(self::$internalStaticOptionList[$this->internalCacheKey])) { self::$internalStaticOptionList[$this->internalCacheKey] = array(); $authFactory = new \OPNsense\Auth\AuthenticationFactory(); $allAuthServers = $authFactory->listServers(); foreach ($allAuthServers as $key => $value) { // use filters to determine relevance $isMatched = true; foreach ($this->internalFilters as $filterKey => $filterData) { if (isset($value[$filterKey])) { $fieldData = $value[$filterKey]; } else { // not found, might be a boolean. $fieldData = "0"; } if (!preg_match($filterData, $fieldData)) { $isMatched = false; } } if ($isMatched) { self::$internalStaticOptionList[$this->internalCacheKey][$key] = $key; } } natcasesort(self::$internalStaticOptionList[$this->internalCacheKey]); } $this->internalOptionList = self::$internalStaticOptionList[$this->internalCacheKey]; }
generate validation data (list of AuthServers)
actionPostLoadingEvent
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/AuthenticationServerField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/AuthenticationServerField.php
BSD-2-Clause
public function setSource($source) { $this->internalSourceLink = $source; }
set source location for this node @param string $source reference like root.node.item
setSource
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/LegacyLinkField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/LegacyLinkField.php
BSD-2-Clause
public function newContainerField($ref, $tagname) { $container_node = new ContainerField($ref, $tagname); $parentmodel = $this->getParentModel(); $container_node->setParentModel($parentmodel); return $container_node; }
Construct new content container and attach to this items model @param $ref @param $tagname @return ContainerField
newContainerField
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ArrayField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ArrayField.php
BSD-2-Clause
public function getTemplateNode() { $result = clone $this->internalTemplateNode; return $result; }
retrieve read only template with defaults (copy of internal structure) @return null|BaseField template node
getTemplateNode
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ArrayField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ArrayField.php
BSD-2-Clause
public function setType($value) { $this->vipType = $value; }
set virtual ip type (carp, proxyarp, ..) @param $value string vip type
setType
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/VirtualIPField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/VirtualIPField.php
BSD-2-Clause
public function setKey($value) { if (strtolower($value) == 'mvc') { $this->isLegacyKey = false; } }
as this field type is used to hook legacy fields and MVC ones, specify a key here. default it uses a legacy (subnet) key. @param $value string vip type
setKey
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/VirtualIPField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/VirtualIPField.php
BSD-2-Clause
protected function actionPostLoadingEvent() { if (!isset(self::$internalStaticOptionList[$this->vipType])) { self::$internalStaticOptionList[$this->vipType] = array(); $configObj = Config::getInstance()->object(); if (!empty($configObj->virtualip) && !empty($configObj->virtualip->vip)) { $filter_types = explode(',', $this->vipType); foreach ($configObj->virtualip->vip as $vip) { if ($this->vipType == '*' || in_array($vip->mode, $filter_types)) { if (isset($configObj->{$vip->interface}->descr)) { $intf_name = $configObj->{$vip->interface}->descr; } else { $intf_name = $vip->interface; } if (!empty($vip->vhid)) { $caption = sprintf( gettext("[%s] %s on %s (vhid %s)"), $vip->subnet, $vip->descr, $intf_name, $vip->vhid ); } else { $caption = sprintf(gettext("[%s] %s on %s"), $vip->subnet, $vip->descr, $intf_name); } if ($this->isLegacyKey) { $key = (string)$vip->subnet; } else { $key = (string)$vip->attributes()['uuid']; } self::$internalStaticOptionList[$this->vipType][$key] = $caption; } } natcasesort(self::$internalStaticOptionList[$this->vipType]); } } $this->internalOptionList = self::$internalStaticOptionList[$this->vipType]; }
generate validation data (list of virtual ips)
actionPostLoadingEvent
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/VirtualIPField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/VirtualIPField.php
BSD-2-Clause
public function setSortByValue($value) { if (trim(strtoupper($value)) == "Y") { $this->internalSortByValue = true; } else { $this->internalSortByValue = false; } }
change default sorting order (value vs key) @param $value boolean value Y/N
setSortByValue
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/JsonKeyValueStoreField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/JsonKeyValueStoreField.php
BSD-2-Clause
public function getNodeData() { // set sorting by key (default) or value if ($this->internalSortByValue) { natcasesort($this->internalOptionList); } else { ksort($this->internalOptionList); } return parent::getNodeData(); }
get valid options, descriptions and selected value @return array
getNodeData
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/JsonKeyValueStoreField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/JsonKeyValueStoreField.php
BSD-2-Clause
protected function actionPostLoadingEvent() { if (!isset(self::$internalStaticOptionList[$this->internalCacheKey])) { self::$internalStaticOptionList[$this->internalCacheKey] = array(); $backend = new Backend(); $service_tempfile = "/tmp/configdmodelfield.data"; // check configd daemon for list of available actions, cache results as long as configd is not restarted if (!file_exists($service_tempfile) || filemtime($service_tempfile) < $backend->getLastRestart()) { $response = $backend->configdRun("configd actions json", false, 20); $actions = json_decode($response, true); if (is_array($actions)) { file_put_contents($service_tempfile, $response); } else { $actions = array(); } } else { $actions = json_decode(file_get_contents($service_tempfile), true); if (!is_array($actions)) { $actions = array(); } } foreach ($actions as $key => $value) { // use filters to determine relevance $isMatched = true; foreach ($this->internalFilters as $filterKey => $filterData) { if (isset($value[$filterKey])) { $fieldData = $value[$filterKey]; if (!preg_match($filterData, $fieldData)) { $isMatched = false; } } } if ($isMatched) { if (!isset($value['description']) || $value['description'] == '') { self::$internalStaticOptionList[$this->internalCacheKey][$key] = $key; } else { self::$internalStaticOptionList[$this->internalCacheKey][$key] = $value['description']; } } } natcasesort(self::$internalStaticOptionList[$this->internalCacheKey]); } $this->internalOptionList = self::$internalStaticOptionList[$this->internalCacheKey]; }
generate validation data (list of known configd actions)
actionPostLoadingEvent
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ConfigdActionsField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ConfigdActionsField.php
BSD-2-Clause
public function setSelectOptions($list) { if (is_array($list)) { foreach ($list as $optKey => $optValue) { $this->selectOptions[$optKey] = $optValue; } } else { // string list foreach (explode($this->separatorchar, $list) as $option) { if (strpos($option, "|") !== false) { $tmp = explode("|", $option); $this->selectOptions[$tmp[0]] = $tmp[1]; } else { $this->selectOptions[$option] = $option; } } } }
set all options for this select item. push a key/value array type to set all options or deliver a comma-separated list with keys and optional values divided by a pipe | sign. example : optionA|text for option A, optionB|test for option B @param array|string $list key/value option list
setSelectOptions
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/CSVListField.php
BSD-2-Clause
public function getValidators() { $validators = parent::getValidators(); if ($this->internalValue != null) { $validators[] = new Regex([ 'message' => $this->getValidationMessage(), 'pattern' => '/^[01]$/', ]); } return $validators; }
retrieve field validators for this field type @return array returns validators
getValidators
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BooleanField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BooleanField.php
BSD-2-Clause
public function setValue($value) { parent::setValue(trim(strtolower($value))); }
always lowercase / trim networks @param string $value
setValue
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/NetworkField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/NetworkField.php
BSD-2-Clause
public function setAsList($value) { if (trim(strtoupper($value)) == "Y") { $this->internalAsList = true; } else { $this->internalAsList = false; } }
select if multiple networks may be selected at once @param $value boolean value 0/1
setAsList
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/NetworkField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/NetworkField.php
BSD-2-Clause
public function setStrict($value) { if (trim(strtoupper($value)) == "Y") { $this->internalStrict = true; } else { $this->internalStrict = false; } }
select if host bits are allowed in the notation @param $value
setStrict
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/NetworkField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/NetworkField.php
BSD-2-Clause
public function getValidators() { if (Util::isIpAddress((string)$this) || Util::isSubnet((string)$this)) { // add to option list if input is a valid network or host $this->internalOptionList[(string)$this] = (string)$this; } return parent::getValidators(); }
retrieve field validators for this field type @return array
getValidators
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/NetworkAliasField.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/NetworkAliasField.php
BSD-2-Clause
public function __construct($message, $field = "", $type = "") { $this->message = $message; $this->field = $field; $this->type = $type; }
OPNsense\Base\Messages\Message constructor
__construct
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/Messages/Message.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/Messages/Message.php
BSD-2-Clause
public function __toString() { return $this->message; }
Magic __toString method returns verbose message
__toString
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/Messages/Message.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/Messages/Message.php
BSD-2-Clause
public function setField($field) { $this->field = $field; return $this; }
Sets field name related to message
setField
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/Messages/Message.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/Messages/Message.php
BSD-2-Clause
private function getXmlPropertySetterName($name) { if (!isset(self::$internalClassMethodAliases[$name])) { self::$internalClassMethodAliases[$name] = null; $propKey = strtolower($name); foreach (self::$internalClassSetterNames as $methodName => $propValue) { if ($propKey == strtolower($propValue)) { self::$internalClassMethodAliases[$name] = $methodName; } } } return self::$internalClassMethodAliases[$name]; }
Find setter for property, ignore case @param string $name property name @return null|string method name
getXmlPropertySetterName
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
BSD-2-Clause
public function getSelected() { return $this->selected; }
check if this item is selected @return bool is this item selected
getSelected
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
BSD-2-Clause
public function select() { $this->selected = true; if ($this->parent != null) { $this->parent->select(); } }
set node and all subnodes selected
select
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
BSD-2-Clause
public function toggleSelected($url) { $this->selected = false; foreach ($this->children as $nodeId => &$node) { if ($node->isVisible()) { $node->toggleSelected($url); if ($node->getUrl() != "") { // hash part isn't available on server end $menuItemUrl = explode("#", $node->getUrl())[0]; $match = str_replace(array(".", "*","?", "@"), array("\.", ".*","\?", "\@"), $menuItemUrl); if (preg_match("@^{$match}$@", "{$url}")) { $node->select(); } } } } }
set url and all its parents selected @param string $url target url
toggleSelected
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
BSD-2-Clause
public function findNodeById($id) { foreach ($this->children as $key => &$node) { if ($node->isVisible() && strtolower($node->getId()) == strtolower($id)) { return $node; } } return null; }
find node by id/tag name, ignore case. @param $id id / tagname @return null|MenuItem
findNodeById
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuItem.php
BSD-2-Clause
public function isExpired() { if (file_exists($this->menuCacheFilename)) { $fstat = stat($this->menuCacheFilename); return $this->menuCacheTTL < (time() - $fstat['mtime']); } return true; }
check if stored menu's are expired @return bool is expired
isExpired
php
opnsense/core
src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuSystem.php
https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuSystem.php
BSD-2-Clause