Commit | Line | Data |
---|---|---|
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. |
9d686348 | 14 | define ('CODE_VERSION', '0.14.12'); |
e673ee24 | 15 | |
9c0b0016 DO |
16 | // The name of hash used to store account password hashes |
17 | // in the database. I think, we are happy with this one forever. | |
18 | define ('PASSWORD_HASH', 'sha1'); | |
75d3818d | 19 | |
9c0b0016 DO |
20 | function getConfigVar ($varname = '') |
21 | { | |
22 | global $configCache; | |
23 | // We assume the only point of cache init, and it is init.php. If it | |
24 | // has failed, we don't retry loading. | |
25 | if (!isset ($configCache)) | |
26 | { | |
61e269b5 | 27 | showError ("Configuration cache is unavailable", __FUNCTION__); |
9c0b0016 DO |
28 | die; |
29 | } | |
30 | if ($varname == '') | |
31 | { | |
61e269b5 | 32 | showError ("Missing argument", __FUNCTION__); |
9c0b0016 DO |
33 | die; |
34 | } | |
35 | if (isset ($configCache[$varname])) | |
36 | { | |
37 | // Try casting to int, if possible. | |
c461c579 | 38 | if ($configCache[$varname]['vartype'] == 'uint') |
9c0b0016 DO |
39 | return 0 + $configCache[$varname]['varvalue']; |
40 | else | |
41 | return $configCache[$varname]['varvalue']; | |
42 | } | |
43 | return NULL; | |
44 | } | |
45 | ||
c461c579 DO |
46 | // In softfail mode die only on fatal errors, letting the user check |
47 | // and resubmit his input. | |
48 | function setConfigVar ($varname = '', $varvalue = '', $softfail = FALSE) | |
9c0b0016 DO |
49 | { |
50 | global $configCache; | |
51 | if (!isset ($configCache)) | |
52 | { | |
61e269b5 | 53 | showError ('Configuration cache is unavailable', __FUNCTION__); |
9c0b0016 DO |
54 | die; |
55 | } | |
56 | if (empty ($varname)) | |
57 | { | |
61e269b5 | 58 | showError ("Empty argument", __FUNCTION__); |
9c0b0016 DO |
59 | die; |
60 | } | |
61 | // We don't operate on unknown data. | |
62 | if (!isset ($configCache[$varname])) | |
63 | { | |
61e269b5 | 64 | showError ("don't know how to handle '${varname}'", __FUNCTION__); |
9c0b0016 DO |
65 | die; |
66 | } | |
67 | if (empty ($varvalue) && $configCache[$varname]['emptyok'] != 'yes') | |
68 | { | |
c461c579 DO |
69 | $errormsg = "'${varname}' is configured to take non-empty value. Perhaps there was a reason to do so."; |
70 | if ($softfail) | |
71 | return $errormsg; | |
61e269b5 | 72 | showError ($errormsg, __FUNCTION__); |
c461c579 DO |
73 | die; |
74 | } | |
f1e7f725 | 75 | if (!empty ($varvalue) && $configCache[$varname]['vartype'] == 'uint' && (!is_numeric ($varvalue) or $varvalue < 0 )) |
c461c579 DO |
76 | { |
77 | $errormsg = "'${varname}' can accept UINT values only"; | |
78 | if ($softfail) | |
79 | return $errormsg; | |
61e269b5 | 80 | showError ($errormsg, __FUNCTION__); |
9c0b0016 DO |
81 | die; |
82 | } | |
83 | // Update cache only if the changes went into DB. | |
84 | if (storeConfigVar ($varname, $varvalue)) | |
c461c579 | 85 | { |
9c0b0016 | 86 | $configCache[$varname]['varvalue'] = $varvalue; |
c461c579 DO |
87 | if ($softfail) |
88 | return ''; | |
89 | } | |
90 | elseif ($softfail) | |
f1e7f725 | 91 | return "storeConfigVar ('${varname}', '${varvalue}') failed in setConfigVar()"; |
9c0b0016 | 92 | } |
8d07e3e0 | 93 | |
e673ee24 | 94 | ?> |