r3178 - justify bits for 0.17.6
[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.
f008ff99 14define ('CODE_VERSION', '0.17.6');
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,
2803fbe6 25 '0.17.5' => 1322,
63811a09 26 '0.17.6' => 1326,
ca3d68bd
DO
27);
28
23818dde
DO
29define ('TAGNAME_REGEXP', '^[[:alnum:]]([\. _~-]?[[:alnum:]])*$');
30define ('AUTOTAGNAME_REGEXP', '^\$[[:alnum:]]([\. _~-]?[[:alnum:]])*$');
05771508
DO
31// The latter matches both SunOS and Linux-styled formats.
32define ('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');
33define ('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');
34define ('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 35define ('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
36define ('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');
37define ('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');
38define ('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
39define ('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');
40define ('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 41
9c0b0016
DO
42function getConfigVar ($varname = '')
43{
44 global $configCache;
45 // We assume the only point of cache init, and it is init.php. If it
46 // has failed, we don't retry loading.
47 if (!isset ($configCache))
48 {
61e269b5 49 showError ("Configuration cache is unavailable", __FUNCTION__);
9c0b0016
DO
50 die;
51 }
52 if ($varname == '')
53 {
61e269b5 54 showError ("Missing argument", __FUNCTION__);
9c0b0016
DO
55 die;
56 }
57 if (isset ($configCache[$varname]))
58 {
59 // Try casting to int, if possible.
c461c579 60 if ($configCache[$varname]['vartype'] == 'uint')
9c0b0016
DO
61 return 0 + $configCache[$varname]['varvalue'];
62 else
63 return $configCache[$varname]['varvalue'];
64 }
65 return NULL;
66}
67
c461c579
DO
68// In softfail mode die only on fatal errors, letting the user check
69// and resubmit his input.
70function setConfigVar ($varname = '', $varvalue = '', $softfail = FALSE)
9c0b0016
DO
71{
72 global $configCache;
73 if (!isset ($configCache))
74 {
61e269b5 75 showError ('Configuration cache is unavailable', __FUNCTION__);
9c0b0016
DO
76 die;
77 }
59a83bd8 78 if (!strlen ($varname))
9c0b0016 79 {
61e269b5 80 showError ("Empty argument", __FUNCTION__);
9c0b0016
DO
81 die;
82 }
83 // We don't operate on unknown data.
84 if (!isset ($configCache[$varname]))
85 {
61e269b5 86 showError ("don't know how to handle '${varname}'", __FUNCTION__);
9c0b0016
DO
87 die;
88 }
dc2f1801
DO
89 if ($configCache[$varname]['is_hidden'] != 'no')
90 {
91 $errormsg = "'${varname}' is a system variable and cannot be changed by user.";
92 if ($softfail)
93 return $errormsg;
94 showError ($errormsg, __FUNCTION__);
95 die;
96 }
59a83bd8 97 if (!strlen ($varvalue) && $configCache[$varname]['emptyok'] != 'yes')
9c0b0016 98 {
c461c579
DO
99 $errormsg = "'${varname}' is configured to take non-empty value. Perhaps there was a reason to do so.";
100 if ($softfail)
101 return $errormsg;
61e269b5 102 showError ($errormsg, __FUNCTION__);
c461c579
DO
103 die;
104 }
59a83bd8 105 if (strlen ($varvalue) && $configCache[$varname]['vartype'] == 'uint' && (!is_numeric ($varvalue) or $varvalue < 0 ))
c461c579
DO
106 {
107 $errormsg = "'${varname}' can accept UINT values only";
108 if ($softfail)
109 return $errormsg;
61e269b5 110 showError ($errormsg, __FUNCTION__);
9c0b0016
DO
111 die;
112 }
113 // Update cache only if the changes went into DB.
114 if (storeConfigVar ($varname, $varvalue))
c461c579 115 {
9c0b0016 116 $configCache[$varname]['varvalue'] = $varvalue;
c461c579
DO
117 if ($softfail)
118 return '';
119 }
120 elseif ($softfail)
f1e7f725 121 return "storeConfigVar ('${varname}', '${varvalue}') failed in setConfigVar()";
9c0b0016 122}
8d07e3e0 123
e673ee24 124?>