r3060 - 0.17.4 pre-release justifications
[racktables] / inc / config.php
CommitLineData
b325120a 1<?php
e673ee24 2/*
9c0b0016
DO
3 *
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
201056a2 6 * them have gone into the database, and there is a user interface
9c0b0016
DO
7 * for changing them. This file now provides a couple of functions to
8 * access the new config storage.
9 *
8d07e3e0
DO
10 */
11
8d07e3e0 12
9c0b0016 13// Current code version is subject to change with each new release.
e49d8a77 14define ('CODE_VERSION', '0.17.4');
7fa7047a
DO
15define ('CHAP_OBJTYPE', 1);
16define ('CHAP_PORTTYPE', 2);
e673ee24 17
ca3d68bd
DO
18$max_dict_key = array
19(
20 '0.17.0' => 988,
21 '0.17.1' => 988,
22 '0.17.2' => 1150,
70992855 23 '0.17.3' => 1150,
681f2138 24 '0.17.4' => 1150,
ca3d68bd
DO
25);
26
23818dde
DO
27define ('TAGNAME_REGEXP', '^[[:alnum:]]([\. _~-]?[[:alnum:]])*$');
28define ('AUTOTAGNAME_REGEXP', '^\$[[:alnum:]]([\. _~-]?[[:alnum:]])*$');
05771508
DO
29// The latter matches both SunOS and Linux-styled formats.
30define ('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');
31define ('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');
32define ('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');
1930dc7f 33define ('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');
d516d719
DO
34define ('RE_L2_WWN_COLON', '/^[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');
35define ('RE_L2_WWN_HYPHEN', '/^[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');
36define ('RE_L2_WWN_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][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i');
05771508
DO
37define ('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');
38define ('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');
26131670 39
9c0b0016
DO
40function getConfigVar ($varname = '')
41{
42 global $configCache;
43 // We assume the only point of cache init, and it is init.php. If it
44 // has failed, we don't retry loading.
45 if (!isset ($configCache))
46 {
61e269b5 47 showError ("Configuration cache is unavailable", __FUNCTION__);
9c0b0016
DO
48 die;
49 }
50 if ($varname == '')
51 {
61e269b5 52 showError ("Missing argument", __FUNCTION__);
9c0b0016
DO
53 die;
54 }
55 if (isset ($configCache[$varname]))
56 {
57 // Try casting to int, if possible.
c461c579 58 if ($configCache[$varname]['vartype'] == 'uint')
9c0b0016
DO
59 return 0 + $configCache[$varname]['varvalue'];
60 else
61 return $configCache[$varname]['varvalue'];
62 }
63 return NULL;
64}
65
c461c579
DO
66// In softfail mode die only on fatal errors, letting the user check
67// and resubmit his input.
68function setConfigVar ($varname = '', $varvalue = '', $softfail = FALSE)
9c0b0016
DO
69{
70 global $configCache;
71 if (!isset ($configCache))
72 {
61e269b5 73 showError ('Configuration cache is unavailable', __FUNCTION__);
9c0b0016
DO
74 die;
75 }
59a83bd8 76 if (!strlen ($varname))
9c0b0016 77 {
61e269b5 78 showError ("Empty argument", __FUNCTION__);
9c0b0016
DO
79 die;
80 }
81 // We don't operate on unknown data.
82 if (!isset ($configCache[$varname]))
83 {
61e269b5 84 showError ("don't know how to handle '${varname}'", __FUNCTION__);
9c0b0016
DO
85 die;
86 }
dc2f1801
DO
87 if ($configCache[$varname]['is_hidden'] != 'no')
88 {
89 $errormsg = "'${varname}' is a system variable and cannot be changed by user.";
90 if ($softfail)
91 return $errormsg;
92 showError ($errormsg, __FUNCTION__);
93 die;
94 }
59a83bd8 95 if (!strlen ($varvalue) && $configCache[$varname]['emptyok'] != 'yes')
9c0b0016 96 {
c461c579
DO
97 $errormsg = "'${varname}' is configured to take non-empty value. Perhaps there was a reason to do so.";
98 if ($softfail)
99 return $errormsg;
61e269b5 100 showError ($errormsg, __FUNCTION__);
c461c579
DO
101 die;
102 }
59a83bd8 103 if (strlen ($varvalue) && $configCache[$varname]['vartype'] == 'uint' && (!is_numeric ($varvalue) or $varvalue < 0 ))
c461c579
DO
104 {
105 $errormsg = "'${varname}' can accept UINT values only";
106 if ($softfail)
107 return $errormsg;
61e269b5 108 showError ($errormsg, __FUNCTION__);
9c0b0016
DO
109 die;
110 }
111 // Update cache only if the changes went into DB.
112 if (storeConfigVar ($varname, $varvalue))
c461c579 113 {
9c0b0016 114 $configCache[$varname]['varvalue'] = $varvalue;
c461c579
DO
115 if ($softfail)
116 return '';
117 }
118 elseif ($softfail)
f1e7f725 119 return "storeConfigVar ('${varname}', '${varvalue}') failed in setConfigVar()";
9c0b0016 120}
8d07e3e0 121
e673ee24 122?>