make the configuration defaults data shareable
authorDenis Ovsienko <denis@ovsienko.info>
Fri, 30 Nov 2018 22:42:21 +0000 (22:42 +0000)
committerDenis Ovsienko <denis@ovsienko.info>
Fri, 30 Nov 2018 23:47:45 +0000 (23:47 +0000)
Move the array from resetUIConfig() to a new function,
getConfigDefaults(). Place the new function in dictionary.php as that is
the best way to make it available in the installer (which still does not
use it though). Update renderUIResetForm() to use a new opcode that
works better with the hardcoded require_once in index.php.

wwwroot/inc/dictionary.php
wwwroot/inc/interface-config.php
wwwroot/inc/navigation.php
wwwroot/inc/ophandlers.php
wwwroot/index.php

index 0dcd4b7..2b63a19 100644 (file)
@@ -103,6 +103,95 @@ function platform_is_ok ($test_innodb = FALSE)
        return !$nerrs;
 }
 
+// FIXME: Use this in the installer instead of the hardcoded SQL.
+function getConfigDefaults()
+{
+       return array
+       (
+               'MASSCOUNT' => '8',
+               'MAXSELSIZE' => '30',
+               'ROW_SCALE' => '2',
+               'IPV4_ADDRS_PER_PAGE' => '256',
+               'DEFAULT_RACK_HEIGHT' => '42',
+               'DEFAULT_SLB_VS_PORT' => '',
+               'DEFAULT_SLB_RS_PORT' => '',
+               'DETECT_URLS' => 'no',
+               'RACK_PRESELECT_THRESHOLD' => '1',
+               'DEFAULT_IPV4_RS_INSERVICE' => 'no',
+               'AUTOPORTS_CONFIG' => '4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm',
+               'SHOW_EXPLICIT_TAGS' => 'yes',
+               'SHOW_IMPLICIT_TAGS' => 'yes',
+               'SHOW_AUTOMATIC_TAGS' => 'no',
+               'DEFAULT_OBJECT_TYPE' => '4',
+               'IPV4_AUTO_RELEASE' => '1',
+               'SHOW_LAST_TAB' => 'yes',
+               'EXT_IPV4_VIEW' => 'yes',
+               'TREE_THRESHOLD' => '25',
+               'IPV4_JAYWALK' => 'no',
+               'ADDNEW_AT_TOP' => 'yes',
+               'IPV4_TREE_SHOW_USAGE' => 'no',
+               'PREVIEW_TEXT_MAXCHARS' => '10240',
+               'PREVIEW_TEXT_ROWS' => '25',
+               'PREVIEW_TEXT_COLS' => '80',
+               'PREVIEW_IMAGE_MAXPXS' => '320',
+               'VENDOR_SIEVE' => '',
+               'IPV4LB_LISTSRC' => 'false',
+               'IPV4OBJ_LISTSRC' => 'not ({$typeid_3} or {$typeid_9} or {$typeid_10} or {$typeid_11})',
+               'IPV4NAT_LISTSRC' => '{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_798}',
+               'ASSETWARN_LISTSRC' => '{$typeid_4} or {$typeid_7} or {$typeid_8}',
+               'NAMEWARN_LISTSRC' => '{$typeid_4} or {$typeid_7} or {$typeid_8}',
+               'RACKS_PER_ROW' => '12',
+               'FILTER_PREDICATE_SIEVE' => '',
+               'FILTER_DEFAULT_ANDOR' => 'and',
+               'FILTER_SUGGEST_ANDOR' => 'yes',
+               'FILTER_SUGGEST_TAGS' => 'yes',
+               'FILTER_SUGGEST_PREDICATES' => 'yes',
+               'FILTER_SUGGEST_EXTRA' => 'no',
+               'DEFAULT_SNMP_COMMUNITY' => 'public',
+               'IPV4_ENABLE_KNIGHT' => 'yes',
+               'TAGS_TOPLIST_SIZE' => '50',
+               'TAGS_QUICKLIST_SIZE' => '20',
+               'TAGS_QUICKLIST_THRESHOLD' => '50',
+               'ENABLE_MULTIPORT_FORM' => 'no',
+               'DEFAULT_PORT_IIF_ID' => '1',
+               'DEFAULT_PORT_OIF_IDS' => '1=24; 3=1078; 4=1077; 5=1079; 6=1080; 8=1082; 9=1084; 10=1588; 11=1668; 12=1589; 13=1590; 14=1591',
+               'IPV4_TREE_RTR_AS_CELL' => 'no',
+               'PROXIMITY_RANGE' => '0',
+               'IPV4_TREE_SHOW_VLAN' => 'yes',
+               'VLANSWITCH_LISTSRC' => '',
+               'VLANNET_LISTSRC' => '',
+               'DEFAULT_VDOM_ID' => '',
+               'DEFAULT_VST_ID' => '',
+               'STATIC_FILTER' => 'yes',
+               '8021Q_DEPLOY_MINAGE' => '300',
+               '8021Q_DEPLOY_MAXAGE' => '3600',
+               '8021Q_DEPLOY_RETRY' => '10800',
+               '8021Q_WRI_AFTER_CONFT_LISTSRC' => 'false',
+               '8021Q_INSTANT_DEPLOY' => 'no',
+               'CDP_RUNNERS_LISTSRC' => '',
+               'LLDP_RUNNERS_LISTSRC' => '',
+               'SHRINK_TAG_TREE_ON_CLICK' => 'yes',
+               'MAX_UNFILTERED_ENTITIES' => '0',
+               'SYNCDOMAIN_MAX_PROCESSES' => '0',
+               'PORT_EXCLUSION_LISTSRC' => '{$typeid_3} or {$typeid_10} or {$typeid_11} or {$typeid_1505} or {$typeid_1506}',
+               'FILTER_RACKLIST_BY_TAGS' => 'yes',
+               'MGMT_PROTOS' => 'ssh: {$typeid_4}; telnet: {$typeid_8}',
+               'SYNC_8021Q_LISTSRC' => '',
+               'QUICK_LINK_PAGES' => 'depot,ipv4space,rackspace',
+               'VIRTUAL_OBJ_CSV' => '1504,1505,1506,1507',
+               'DATETIME_ZONE' => 'UTC',
+               'DATETIME_FORMAT' => '%Y-%m-%d',
+               'DATEONLY_FORMAT' => '%Y-%m-%d',
+               'SEARCH_DOMAINS' => '',
+               '8021Q_EXTSYNC_LISTSRC' => 'false',
+               '8021Q_MULTILINK_LISTSRC' => 'false',
+               'REVERSED_RACKS_LISTSRC' => 'false',
+               'NEAREST_RACKS_CHECKBOX' => 'yes',
+               'SHOW_OBJECTTYPE' => 'yes',
+               'IPV4_TREE_SHOW_UNALLOCATED' => 'yes',
+       );
+}
+
 $dictionary = array
 (
        1 => array ('chapter_id' => 1, 'dict_value' => 'BlackBox'),
index 656395a..7f39551 100644 (file)
@@ -853,7 +853,7 @@ function renderConfigEditor ()
 
 function renderUIResetForm()
 {
-       printOpFormIntro ('go');
+       printOpFormIntro ('resetUIConfig');
        echo "This button will reset user interface configuration to its defaults (except organization name): ";
        echo "<input type=submit value='proceed'>";
        echo "</form>";
index 180537a..33aef7b 100644 (file)
@@ -638,7 +638,7 @@ $tabhandler['ui']['default'] = 'renderUIConfig';
 $tabhandler['ui']['edit'] = 'renderConfigEditor';
 $tabhandler['ui']['reset'] = 'renderUIResetForm';
 $ophandler['ui']['edit']['upd'] = 'updateUI';
-$ophandler['ui']['reset']['go'] = 'resetUIConfig';
+$ophandler['ui']['reset']['resetUIConfig'] = 'resetUIConfig';
 $interface_requires['ui-*'] = 'interface-config.php';
 
 $page['tagtree']['title'] = 'Tag tree';
index 782230a..84c2c7a 100644 (file)
@@ -1550,96 +1550,10 @@ function resetMyPreference ()
        showFuncMessage (__FUNCTION__, 'OK');
 }
 
-// FIXME: Move the default values to dictionary.php and feed from there into
-// this function and the installer to avoid duplication.
 function resetUIConfig()
 {
        setFuncMessages (__FUNCTION__, array ('OK' => 57));
-       $defaults = array
-       (
-               'MASSCOUNT' => '8',
-               'MAXSELSIZE' => '30',
-               'ROW_SCALE' => '2',
-               'IPV4_ADDRS_PER_PAGE' => '256',
-               'DEFAULT_RACK_HEIGHT' => '42',
-               'DEFAULT_SLB_VS_PORT' => '',
-               'DEFAULT_SLB_RS_PORT' => '',
-               'DETECT_URLS' => 'no',
-               'RACK_PRESELECT_THRESHOLD' => '1',
-               'DEFAULT_IPV4_RS_INSERVICE' => 'no',
-               'AUTOPORTS_CONFIG' => '4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm',
-               'SHOW_EXPLICIT_TAGS' => 'yes',
-               'SHOW_IMPLICIT_TAGS' => 'yes',
-               'SHOW_AUTOMATIC_TAGS' => 'no',
-               'DEFAULT_OBJECT_TYPE' => '4',
-               'IPV4_AUTO_RELEASE' => '1',
-               'SHOW_LAST_TAB' => 'yes',
-               'EXT_IPV4_VIEW' => 'yes',
-               'TREE_THRESHOLD' => '25',
-               'IPV4_JAYWALK' => 'no',
-               'ADDNEW_AT_TOP' => 'yes',
-               'IPV4_TREE_SHOW_USAGE' => 'no',
-               'PREVIEW_TEXT_MAXCHARS' => '10240',
-               'PREVIEW_TEXT_ROWS' => '25',
-               'PREVIEW_TEXT_COLS' => '80',
-               'PREVIEW_IMAGE_MAXPXS' => '320',
-               'VENDOR_SIEVE' => '',
-               'IPV4LB_LISTSRC' => 'false',
-               'IPV4OBJ_LISTSRC' => 'not ({$typeid_3} or {$typeid_9} or {$typeid_10} or {$typeid_11})',
-               'IPV4NAT_LISTSRC' => '{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_798}',
-               'ASSETWARN_LISTSRC' => '{$typeid_4} or {$typeid_7} or {$typeid_8}',
-               'NAMEWARN_LISTSRC' => '{$typeid_4} or {$typeid_7} or {$typeid_8}',
-               'RACKS_PER_ROW' => '12',
-               'FILTER_PREDICATE_SIEVE' => '',
-               'FILTER_DEFAULT_ANDOR' => 'and',
-               'FILTER_SUGGEST_ANDOR' => 'yes',
-               'FILTER_SUGGEST_TAGS' => 'yes',
-               'FILTER_SUGGEST_PREDICATES' => 'yes',
-               'FILTER_SUGGEST_EXTRA' => 'no',
-               'DEFAULT_SNMP_COMMUNITY' => 'public',
-               'IPV4_ENABLE_KNIGHT' => 'yes',
-               'TAGS_TOPLIST_SIZE' => '50',
-               'TAGS_QUICKLIST_SIZE' => '20',
-               'TAGS_QUICKLIST_THRESHOLD' => '50',
-               'ENABLE_MULTIPORT_FORM' => 'no',
-               'DEFAULT_PORT_IIF_ID' => '1',
-               'DEFAULT_PORT_OIF_IDS' => '1=24; 3=1078; 4=1077; 5=1079; 6=1080; 8=1082; 9=1084; 10=1588; 11=1668; 12=1589; 13=1590; 14=1591',
-               'IPV4_TREE_RTR_AS_CELL' => 'no',
-               'PROXIMITY_RANGE' => '0',
-               'IPV4_TREE_SHOW_VLAN' => 'yes',
-               'VLANSWITCH_LISTSRC' => '',
-               'VLANNET_LISTSRC' => '',
-               'DEFAULT_VDOM_ID' => '',
-               'DEFAULT_VST_ID' => '',
-               'STATIC_FILTER' => 'yes',
-               '8021Q_DEPLOY_MINAGE' => '300',
-               '8021Q_DEPLOY_MAXAGE' => '3600',
-               '8021Q_DEPLOY_RETRY' => '10800',
-               '8021Q_WRI_AFTER_CONFT_LISTSRC' => 'false',
-               '8021Q_INSTANT_DEPLOY' => 'no',
-               'CDP_RUNNERS_LISTSRC' => '',
-               'LLDP_RUNNERS_LISTSRC' => '',
-               'SHRINK_TAG_TREE_ON_CLICK' => 'yes',
-               'MAX_UNFILTERED_ENTITIES' => '0',
-               'SYNCDOMAIN_MAX_PROCESSES' => '0',
-               'PORT_EXCLUSION_LISTSRC' => '{$typeid_3} or {$typeid_10} or {$typeid_11} or {$typeid_1505} or {$typeid_1506}',
-               'FILTER_RACKLIST_BY_TAGS' => 'yes',
-               'MGMT_PROTOS' => 'ssh: {$typeid_4}; telnet: {$typeid_8}',
-               'SYNC_8021Q_LISTSRC' => '',
-               'QUICK_LINK_PAGES' => 'depot,ipv4space,rackspace',
-               'VIRTUAL_OBJ_CSV' => '1504,1505,1506,1507',
-               'DATETIME_ZONE' => 'UTC',
-               'DATETIME_FORMAT' => '%Y-%m-%d',
-               'DATEONLY_FORMAT' => '%Y-%m-%d',
-               'SEARCH_DOMAINS' => '',
-               '8021Q_EXTSYNC_LISTSRC' => 'false',
-               '8021Q_MULTILINK_LISTSRC' => 'false',
-               'REVERSED_RACKS_LISTSRC' => 'false',
-               'NEAREST_RACKS_CHECKBOX' => 'yes',
-               'SHOW_OBJECTTYPE' => 'yes',
-               'IPV4_TREE_SHOW_UNALLOCATED' => 'yes',
-       );
-       foreach ($defaults as $name => $value)
+       foreach (getConfigDefaults() as $name => $value)
                setConfigVar ($name, $value);
        callHook ('resetUIConfig_hook');
        showFuncMessage (__FUNCTION__, 'OK');
index 69a39a3..95ec625 100644 (file)
@@ -205,6 +205,10 @@ try {
                // snmp.php is an exception, it is treated by a special hack
                if (isset ($_REQUEST['op']) && $_REQUEST['op'] == 'querySNMPData')
                        require_once 'inc/snmp.php';
+               // FIXME: One more time doing this and the hack should rather be replaced
+               // with a better structured solution.
+               if (isset ($_REQUEST['op']) && $_REQUEST['op'] == 'resetUIConfig')
+                       require_once 'inc/dictionary.php';
                require_once 'inc/init.php';
                try
                {