diff --git a/CHANGELOG.md b/CHANGELOG.md index 37dac16..9a217fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,12 @@ All notable changes to this project will be documented in this file. -## [0.0.1] - rev 82 +## [0.0.2] - rev 85 - installer: FreeBSD 13.2 setup works again. - installer: FreeBSD 13.3 setup tested and works - installer: Linux Debian 12.5 bookworm installer +- settings: networks descriptions implemented ## [0.0.1] - rev 77 diff --git a/RELEASE b/RELEASE index 2e0fa05..1e82bf7 100644 --- a/RELEASE +++ b/RELEASE @@ -1 +1 @@ -0.0.1 rev 83 +0.0.2 rev 85 diff --git a/api/libs/api.ophanimmgr.php b/api/libs/api.ophanimmgr.php index 4018282..49deb07 100644 --- a/api/libs/api.ophanimmgr.php +++ b/api/libs/api.ophanimmgr.php @@ -54,7 +54,16 @@ class OphanimMgr { */ protected $port = 42112; + /** + * Contains networks table structure as field=>index + * + * @var array + */ + protected $networksStruct = array(); + //some predefined stuff here + const DB_PATCHES_PATH = 'dist/dumps/patches/'; + const DB_PATCHES_EXT = '.sql'; const CONF_PATH = '/etc/of.conf'; const PRETAG_PATH = '/etc/pretag.map'; const TEMPLATE_PATH = 'dist/collector/of.template'; @@ -66,6 +75,7 @@ class OphanimMgr { //and some routes const URL_ME = '?module=settings'; const PROUTE_NETW_CREATE = 'newnetwork'; + const PROUTE_NETW_DESC = 'newnetworkdescr'; const ROUTE_NETW_DEL = 'deletenetwork'; const ROUTE_START = 'startcollector'; const ROUTE_STOP = 'stopcollector'; @@ -75,6 +85,7 @@ public function __construct() { $this->initMessages(); $this->loadConfigs(); $this->initNetsDb(); + $this->loadNetStruct(); $this->loadNetworks(); } @@ -118,6 +129,58 @@ protected function loadNetworks() { $this->netsCount = sizeof($this->allNetworks); } + /** + * Loads networks database struct and applies some patches if required + * + * @return void + */ + protected function loadNetStruct() { + $patchesApplied = false; + $structTmp = $this->networksDb->getTableStructure(true); + $structTmp = array_flip($structTmp); + $this->networksStruct = $structTmp; + + //0.0.2 patch + if (!isset($this->networksStruct['descr'])) { + debarr($this->networksStruct); + $this->applyDbPatch('0.0.2'); + $patchesApplied = true; + } + + //viewport refresh + if ($patchesApplied) { + ubRouting::nav(self::URL_ME); + } + } + + /** + * Apllies database patch by its name + * + * @param type $patchName + * + * @return void + */ + protected function applyDbPatch($patchName) { + if (!empty($patchName)) { + $patchPath = self::DB_PATCHES_PATH . $patchName . self::DB_PATCHES_EXT; + if (file_exists($patchPath)) { + $patchContent = file_get_contents($patchPath); + if (!empty($patchContent)) { + $patchContent = explode(';', $patchContent); + if (!empty($patchContent)) { + foreach ($patchContent as $io => $eachQuery) { + $eachQuery = trim($eachQuery); + if (!empty($eachQuery)) { + nr_query($eachQuery); + show_success(__('DB patch') . $patchName . ': ' . $eachQuery); + } + } + } + } + } + } + } + /** * Renders available networks list * @@ -125,12 +188,19 @@ protected function loadNetworks() { */ public function renderNetworksList() { $result = ''; + if (!empty($this->allNetworks)) { $cells = wf_TableCell(__('Network')); + if (isset($this->networksStruct['descr'])) { + $cells .= wf_TableCell(__('Description')); + } $cells .= wf_TableCell(__('Actions')); $rows = wf_TableRow($cells, 'table-light'); foreach ($this->allNetworks as $io => $each) { $cells = wf_TableCell($each['network']); + if (isset($this->networksStruct['descr'])) { + $cells .= wf_TableCell($each['descr']); + } $delUrl = self::URL_ME . '&' . self::ROUTE_NETW_DEL . '=' . $each['id']; $actLinks = wf_JSAlertStyled($delUrl, __('Delete'), __('Are you serious') . '?', 'btn cur-p btn-danger btn-color'); $cells .= wf_TableCell($actLinks); @@ -151,6 +221,7 @@ public function renderNetworksList() { public function renderNetworkCreateForm() { $result = ''; $inputs = wf_TextInput(self::PROUTE_NETW_CREATE, __('Network') . '/CIDR', '', false, '20', 'net-cidr') . ' '; + $inputs .= wf_TextInput(self::PROUTE_NETW_DESC, __('Description'), '', false, '20', '') . ' '; $inputs .= wf_Submit(__('Create new'), '', 'class="btn btn-primary btn-color"'); $result .= wf_delimiter(); $result .= wf_Form('', 'POST', $inputs, 'glamour'); @@ -196,13 +267,16 @@ public function isNetworkExists($network) { * Creates new network database record * * @param string $network + * @param string $descr * * @return void */ - public function createNetwork($network) { + public function createNetwork($network, $descr = '') { $netF = ubRouting::filters($network, 'mres'); + $descrF = ubRouting::filters($descr, 'mres'); if (!$this->isNetworkExists($network)) { $this->networksDb->data('network', $netF); + $this->networksDb->data('descr', $descrF); $this->networksDb->create(); } } diff --git a/dist/dumps/ophanimflow.sql b/dist/dumps/ophanimflow.sql index 4a6425f..345ea73 100644 --- a/dist/dumps/ophanimflow.sql +++ b/dist/dumps/ophanimflow.sql @@ -68,4 +68,7 @@ CREATE TABLE `networks` ( `id` int NOT NULL AUTO_INCREMENT, `network` varchar(20) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; \ No newline at end of file +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; + +-- 0.0.2 patch +ALTER TABLE `networks` ADD `descr` VARCHAR(255) NULL AFTER `network`; \ No newline at end of file diff --git a/dist/dumps/patches/0.0.2.sql b/dist/dumps/patches/0.0.2.sql new file mode 100644 index 0000000..a13b1b7 --- /dev/null +++ b/dist/dumps/patches/0.0.2.sql @@ -0,0 +1 @@ +ALTER TABLE `networks` ADD `descr` VARCHAR(255) NULL AFTER `network`; diff --git a/modules/general/settings/index.php b/modules/general/settings/index.php index f49aa7f..923781d 100644 --- a/modules/general/settings/index.php +++ b/modules/general/settings/index.php @@ -6,8 +6,9 @@ if (ubRouting::checkPost($settings::PROUTE_NETW_CREATE)) { $netToCreate = ubRouting::post($settings::PROUTE_NETW_CREATE); + $descrToCreate = ubRouting::post($settings::PROUTE_NETW_DESC); if (!$settings->isNetworkExists($netToCreate)) { - $settings->createNetwork($netToCreate); + $settings->createNetwork($netToCreate, $descrToCreate); ubRouting::nav($settings::URL_ME); } else { show_error(__('Network') . ' `' . $netToCreate . '` ' . __('already exists')); @@ -29,12 +30,12 @@ if (empty($reconfResult)) { ubRouting::nav($settings::URL_ME); } else { - show_error(__('Fatal').': '.$reconfResult); + show_error(__('Fatal') . ': ' . $reconfResult); } } if (ubRouting::checkGet($settings::ROUTE_START)) { - $startResult=$settings->startCollector(); + $startResult = $settings->startCollector(); if (empty($startResult)) { ubRouting::nav($settings::URL_ME); } else {