ac16917c74a1fdbf9997e610acd64ea19c22a263
4 * This file used to hold a collection of constants, variables and arrays,
5 * which drived the way misc RackTables functions performed. Now most of
6 * them have gone into the database, and there is a user interface
7 * for changing them. This file now provides a couple of functions to
8 * access the new config storage.
13 // Current code version is subject to change with each new release.
14 define ('CODE_VERSION', '0.17.0');
15 define ('MAX_DICT_KEY', 988);
17 define ('TAGNAME_REGEXP', '^[[:alnum:]]([\. _~-]?[[:alnum:]])*$');
18 define ('AUTOTAGNAME_REGEXP', '^\$[[:alnum:]]([\. _~-]?[[:alnum:]])*$');
19 // The latter matches both SunOS and Linux-styled formats.
20 define ('RE_L2_IFCFG', '/^[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?$/i');
21 define ('RE_L2_CISCO', '/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i');
22 define ('RE_L2_SOLID', '/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i');
23 define ('RE_L2_FDRYSTP', '/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i');
24 define ('RE_L2_IPCFG', '/^[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]$/i');
25 define ('RE_IP4_ADDR', '/^[0-9][0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$/i');
26 define ('RE_IP4_NET', '/^[0-9][0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\/[0-9][0-9]?$/i');
28 function getConfigVar ($varname = '')
31 // We assume the only point of cache init, and it is init.php. If it
32 // has failed, we don't retry loading.
33 if (!isset ($configCache))
35 showError ("Configuration cache is unavailable", __FUNCTION__
);
40 showError ("Missing argument", __FUNCTION__
);
43 if (isset ($configCache[$varname]))
45 // Try casting to int, if possible.
46 if ($configCache[$varname]['vartype'] == 'uint')
47 return 0 +
$configCache[$varname]['varvalue'];
49 return $configCache[$varname]['varvalue'];
54 // In softfail mode die only on fatal errors, letting the user check
55 // and resubmit his input.
56 function setConfigVar ($varname = '', $varvalue = '', $softfail = FALSE)
59 if (!isset ($configCache))
61 showError ('Configuration cache is unavailable', __FUNCTION__
);
66 showError ("Empty argument", __FUNCTION__
);
69 // We don't operate on unknown data.
70 if (!isset ($configCache[$varname]))
72 showError ("don't know how to handle '${varname}'", __FUNCTION__
);
75 if ($configCache[$varname]['is_hidden'] != 'no')
77 $errormsg = "'${varname}' is a system variable and cannot be changed by user.";
80 showError ($errormsg, __FUNCTION__
);
83 if (empty ($varvalue) && $configCache[$varname]['emptyok'] != 'yes')
85 $errormsg = "'${varname}' is configured to take non-empty value. Perhaps there was a reason to do so.";
88 showError ($errormsg, __FUNCTION__
);
91 if (!empty ($varvalue) && $configCache[$varname]['vartype'] == 'uint' && (!is_numeric ($varvalue) or $varvalue < 0 ))
93 $errormsg = "'${varname}' can accept UINT values only";
96 showError ($errormsg, __FUNCTION__
);
99 // Update cache only if the changes went into DB.
100 if (storeConfigVar ($varname, $varvalue))
102 $configCache[$varname]['varvalue'] = $varvalue;
107 return "storeConfigVar ('${varname}', '${varvalue}') failed in setConfigVar()";