forked from lirantal/daloradius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-db.php
247 lines (200 loc) · 10.5 KB
/
config-db.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/*
*********************************************************************************************************
* daloRADIUS - RADIUS Web Platform
* Copyright (C) 2007 - Liran Tal <[email protected]> All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*********************************************************************************************************
*
* Authors: Liran Tal <[email protected]>
* Filippo Lauria <[email protected]>
*
*********************************************************************************************************
*/
include ("library/checklogin.php");
$operator = $_SESSION['operator_user'];
include('library/check_operator_perm.php');
include_once('library/config_read.php');
include_once("lang/main.php");
include("library/validation.php");
include("library/layout.php");
// init logging variables
$log = "visited page: ";
$logAction = "";
$logDebugSQL = "";
$db_tbl_param_label = array(
'CONFIG_DB_TBL_RADCHECK' => t('all','radcheck'),
'CONFIG_DB_TBL_RADREPLY' => t('all','radreply'),
'CONFIG_DB_TBL_RADGROUPREPLY' => t('all','radgroupreply'),
'CONFIG_DB_TBL_RADGROUPCHECK' => t('all','radgroupcheck'),
'CONFIG_DB_TBL_RADUSERGROUP' => t('all','usergroup'),
'CONFIG_DB_TBL_RADACCT' => t('all','radacct'),
'CONFIG_DB_TBL_RADNAS' => t('all','nas'),
'CONFIG_DB_TBL_RADHG' => t('all','hunt'),
'CONFIG_DB_TBL_RADPOSTAUTH' => t('all','radpostauth'),
'CONFIG_DB_TBL_RADIPPOOL' => t('all','radippool'),
'CONFIG_DB_TBL_DALOUSERINFO' => t('all','userinfo'),
'CONFIG_DB_TBL_DALODICTIONARY' => t('all','dictionary'),
'CONFIG_DB_TBL_DALOREALMS' => t('all','realms'),
'CONFIG_DB_TBL_DALOPROXYS' => t('all','proxys'),
'CONFIG_DB_TBL_DALOBILLINGMERCHANT' => t('all','billingmerchant'),
'CONFIG_DB_TBL_DALOBILLINGPAYPAL' => t('all','billingpaypal'),
'CONFIG_DB_TBL_DALOBILLINGPLANS' => t('all','billingplans'),
'CONFIG_DB_TBL_DALOBILLINGRATES' => t('all','billingrates'),
'CONFIG_DB_TBL_DALOBILLINGHISTORY' => t('all','billinghistory'),
'CONFIG_DB_TBL_DALOBATCHHISTORY' => t('button', 'BatchHistory'),
'CONFIG_DB_TBL_DALOBILLINGPLANSPROFILES' => 'Billing Plans Profiles',
'CONFIG_DB_TBL_DALOUSERBILLINFO' => t('all','billinginfo'),
'CONFIG_DB_TBL_DALOBILLINGINVOICE' => t('all','Invoice'),
'CONFIG_DB_TBL_DALOBILLINGINVOICEITEMS' => t('all','InvoiceItems'),
'CONFIG_DB_TBL_DALOBILLINGINVOICESTATUS' => t('all','InvoiceStatus'),
'CONFIG_DB_TBL_DALOBILLINGINVOICETYPE' => t('all','InvoiceType'),
'CONFIG_DB_TBL_DALOPAYMENTTYPES' => t('all','payment_type'),
'CONFIG_DB_TBL_DALOPAYMENTS' => t('all','payments'),
'CONFIG_DB_TBL_DALOOPERATORS' => t('all','operators'),
'CONFIG_DB_TBL_DALOOPERATORS_ACL' => t('all','operators_acl'),
'CONFIG_DB_TBL_DALOOPERATORS_ACL_FILES' => t('all','operators_acl_files'),
'CONFIG_DB_TBL_DALOHOTSPOTS' => t('all','hotspots'),
'CONFIG_DB_TBL_DALONODE' => t('all','node'),
);
$generic_db_conf_params = array(
'CONFIG_DB_HOST' => t('all','DatabaseHostname'),
'CONFIG_DB_USER' => t('all','DatabaseUser'),
'CONFIG_DB_PASS' => t('all','DatabasePass'),
'CONFIG_DB_NAME' => t('all','DatabaseName'),
);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (array_key_exists('csrf_token', $_POST) && isset($_POST['csrf_token']) && dalo_check_csrf_token($_POST['csrf_token'])) {
// if the form has been submitted we validate and store the configuration
if (array_key_exists('CONFIG_DB_ENGINE', $_POST) && isset($_POST['CONFIG_DB_ENGINE']) &&
in_array(strtolower($_POST['CONFIG_DB_ENGINE']), array_keys($valid_db_engines))) {
$configValues['CONFIG_DB_ENGINE'] = $_POST['CONFIG_DB_ENGINE'];
}
if (array_key_exists('CONFIG_DB_PORT', $_POST) && isset($_POST['CONFIG_DB_PORT']) &&
intval($_POST['CONFIG_DB_PORT']) >= 0 && intval($_POST['CONFIG_DB_PORT']) <= 65535) {
$configValues['CONFIG_DB_PORT'] = intval($_POST['CONFIG_DB_PORT']);
}
foreach ($generic_db_conf_params as $param => $caption) {
if (array_key_exists($param, $_POST) && isset($_POST[$param])) {
$configValues[$param] = $_POST[$param];
}
}
// validate table name
foreach ($db_tbl_param_label as $param => $label) {
if (array_key_exists($param, $_POST) && isset($_POST[$param]) && preg_match(DB_TABLE_NAME_REGEX, $_POST[$param]) !== false) {
$configValues[$param] = $_POST[$param];
}
}
include("library/config_write.php");
} else {
// csrf
$failureMsg = "CSRF token error";
$logAction .= "$failureMsg on page: ";
}
}
// print HTML prologue
$extra_css = array(
// css tabs stuff
"css/tabs.css"
);
$extra_js = array(
// js tabs stuff
"library/javascript/tabs.js"
);
$title = t('Intro','configmain.php');
$help = t('helpPage','configmain');
print_html_prologue($title, $langCode, $extra_css, $extra_js);
include("menu-config.php");
echo '<div id="contentnorightbar">';
print_title_and_help($title, $help);
include_once('include/management/actionMessages.php');
// set navbar stuff
$navkeys = array( 'Settings', 'DatabaseTables' );
// print navbar controls
print_tab_header($navkeys);
// open form
open_form();
// tab 0
open_tab($navkeys, 0, true);
$input_descriptors0 = array();
$input_descriptors0[] = array(
"name" => "CONFIG_DB_ENGINE",
"caption" => t('all','DBEngine'),
"selected_value" => $configValues['CONFIG_DB_ENGINE'],
"type" => "select",
"options" => $valid_db_engines,
);
$input_descriptors0[] = array(
"name" => "CONFIG_DB_PORT",
"caption" => t('all','DatabasePort'),
"value" => $configValues['CONFIG_DB_PORT'],
"type" => "number",
"min" => "0",
"max" => "65535",
);
foreach ($generic_db_conf_params as $name => $caption) {
$input_descriptors0[] = array(
"name" => $name,
"caption" => $caption,
"value" => $configValues[$name],
"type" => "text"
);
}
$fieldset0_descriptor = array(
"title" => t('title','Settings'),
);
open_fieldset($fieldset0_descriptor);
foreach ($input_descriptors0 as $input_descriptor) {
print_form_component($input_descriptor);
}
close_fieldset();
close_tab();
// tab 1
open_tab($navkeys, 1);
$input_descriptors1 = array();
foreach ($db_tbl_param_label as $name => $caption) {
$input_descriptors1[] = array(
"name" => $name,
"caption" => $caption,
"value" => $configValues[$name],
"pattern" => trim(DB_TABLE_NAME_REGEX, "/"),
"type" => "text"
);
}
$fieldset1_descriptor = array(
"title" => t('title','DatabaseTables'),
);
open_fieldset($fieldset1_descriptor);
foreach ($input_descriptors1 as $input_descriptor) {
print_form_component($input_descriptor);
}
close_fieldset();
close_tab();
// other fields
$input_descriptors2 = array();
$input_descriptors2[] = array(
"type" => "submit",
"name" => "submit",
"value" => t('buttons','apply')
);
$input_descriptors2[] = array(
"name" => "csrf_token",
"type" => "hidden",
"value" => dalo_csrf_token(),
);
foreach ($input_descriptors2 as $input_descriptor) {
print_form_component($input_descriptor);
}
close_form();
include('include/config/logging.php');
print_footer_and_html_epilogue();
?>