-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup.php
601 lines (489 loc) · 23.6 KB
/
setup.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2024 The Cacti Group |
| |
| 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. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
include_once(__DIR__ . '/include/arrays.php');
function plugin_routerconfigs_version () {
global $config;
$info = parse_ini_file($config['base_path'] . '/plugins/routerconfigs/INFO', true);
return $info['info'];
}
function plugin_routerconfigs_install () {
api_plugin_register_hook('routerconfigs', 'top_header_tabs', 'routerconfigs_show_tab', 'setup.php');
api_plugin_register_hook('routerconfigs', 'top_graph_header_tabs', 'routerconfigs_show_tab', 'setup.php');
api_plugin_register_hook('routerconfigs', 'config_arrays', 'routerconfigs_config_arrays', 'setup.php');
api_plugin_register_hook('routerconfigs', 'draw_navigation_text', 'routerconfigs_draw_navigation_text', 'setup.php');
api_plugin_register_hook('routerconfigs', 'config_settings', 'routerconfigs_config_settings', 'setup.php');
api_plugin_register_hook('routerconfigs', 'poller_bottom', 'routerconfigs_poller_bottom', 'setup.php');
api_plugin_register_hook('routerconfigs', 'page_head', 'routerconfigs_page_head', 'setup.php');
api_plugin_register_realm('routerconfigs', 'router-devices.php,router-accounts.php,router-backups.php,router-compare.php,router-devtypes.php', __('Router Configs', 'routerconfigs'), 1);
routerconfigs_setup_table_new();
}
function plugin_routerconfigs_uninstall () {
/* Do any extra Uninstall stuff here */
}
function plugin_routerconfigs_upgrade() {
/* Here we will upgrade to the newest version */
routerconfigs_check_upgrade();
return false;
}
function routerconfigs_check_upgrade() {
global $config, $database_default;
include_once($config['library_path'] . '/database.php');
include_once($config['library_path'] . '/functions.php');
// Let's only run this check if we are on a page that actually needs the data
$files = array('plugins.php','router-devices.php');
if (!in_array(get_current_page(), $files)) {
return;
}
$current = plugin_routerconfigs_version();
$current = $current['version'];
$old = db_fetch_cell("SELECT version FROM plugin_config WHERE directory='routerconfigs'");
if ($current != $old) {
api_plugin_register_hook('routerconfigs', 'top_header_tabs', 'routerconfigs_show_tab', 'setup.php', 1);
api_plugin_register_hook('routerconfigs', 'top_graph_header_tabs', 'routerconfigs_show_tab', 'setup.php', 1);
/* update realms for old versions */
if (cacti_version_compare($old,'0.2','<')) {
api_plugin_register_realm('routerconfigs', 'router-devices.php,router-accounts.php,router-backups.php,router-compare.php', 'Plugin -> Router Configs', 1);
/* get the realm id's and change from old to new */
$user = db_fetch_cell("SELECT id FROM plugin_realms WHERE file='router-devices.php'");
if ($user > 0) {
$users = db_fetch_assoc('SELECT user_id FROM user_auth_realm WHERE realm_id=86');
if (sizeof($users)) {
foreach($users as $u) {
db_execute("INSERT INTO user_auth_realm
(realm_id, user_id) VALUES ($user, " . $u['user_id'] . ')
ON DUPLICATE KEY UPDATE realm_id=VALUES(realm_id)');
db_execute('DELETE FROM user_auth_realm
WHERE user_id=' . $u['user_id'] . "
AND realm_id=$user");
}
}
}
}
if (cacti_version_compare($old, '1.4.0', '<')) {
plugin_routerconfigs_fix_backups_pre14();
}
if (cacti_version_compare($old, '1.5.1', '<')) {
// Remove old columns of backups
if (db_column_exists('plugin_routerconfigs_backups', 'config')) {
db_execute('ALTER TABLE plugin_routerconfigs_backups
DROP COLUMN `config`');
}
if (db_column_exists('plugin_routerconfigs_backups','username')) {
db_execute('ALTER TABLE plugin_routerconfigs_backups
CHANGE COLUMN `username` `lastuser` varchar(64)');
}
if (db_column_exists('plugin_routerconfigs_devices','password')) {
db_execute('ALTER TABLE plugin_routerconfigs_devices
DROP COLUMN `password`');
}
if (db_column_exists('plugin_routerconfigs_devices', 'anykey')) {
db_execute('ALTER TABLE plugin_routerconfigs_devices
DROP COLUMN `anykey`');
}
// Rename existing columns of devices
if (db_column_exists('plugin_routerconfigs_devices','connect_type')) {
db_execute('ALTER TABLE plugin_routerconfigs_devices
CHANGE COLUMN `connect_type` `connecttype` varchar(10) DEFAULT \'\'');
}
if (db_column_exists('plugin_routerconfigs_devices','username')) {
db_execute('ALTER TABLE plugin_routerconfigs_devices
CHANGE COLUMN `username` `lastuser` varchar(64)');
}
// Add new/missing columns of devices
if (!db_column_exists('plugin_routerconfigs_devices','connecttype')) {
db_execute('ALTER TABLE plugin_routerconfigs_devices
ADD COLUMN `connecttype` varchar(10) DEFAULT \'\'');
}
if (!db_column_exists('plugin_routerconfigs_devices','nextbackup')) {
db_execute('ALTER TABLE plugin_routerconfigs_devices
ADD COLUMN `nextbackup` int(18)');
}
if (!db_column_exists('plugin_routerconfigs_devices','nextattempt')) {
db_execute('ALTER TABLE plugin_routerconfigs_devices
ADD COLUMN `nextattempt` int(18)');
}
if (!db_column_exists('plugin_routerconfigs_devices', 'timeout')) {
db_execute('ALTER TABLE plugin_routerconfigs_devices
ADD COLUMN `timeout` int(18)');
}
if (!db_column_exists('plugin_routerconfigs_devices', 'sleep')) {
db_execute('ALTER TABLE plugin_routerconfigs_devices
ADD COLUMN `sleep` int(18)');
}
if (!db_column_exists('plugin_routerconfigs_devices', 'elevated')) {
db_execute('ALTER TABLE plugin_routerconfigs_devices
ADD COLUMN `elevated` char(3)');
}
// Perform tidy up of devices
db_execute('UPDATE plugin_routerconfigs_devices SET
nextbackup = IFNULL(nextbackup,0),
nextattempt = IFNULL(nextattempt,0)');
// Rename existing columns of device types
if (db_column_exists('plugin_routerconfigs_devicetypes','connect_type')) {
db_execute('ALTER TABLE plugin_routerconfigs_devicetypes
CHANGE COLUMN `connect_type` `connecttype` varchar(10) DEFAULT \'\'');
}
if (db_column_exists('plugin_routerconfigs_devicetypes','username')) {
db_execute('ALTER TABLE plugin_routerconfigs_devicetypes
CHANGE COLUMN `username` `promptuser` varchar(64)');
}
if (db_column_exists('plugin_routerconfigs_devicetypes','password')) {
db_execute('ALTER TABLE plugin_routerconfigs_devicetypes
CHANGE COLUMN `password` `promptpass` varchar(256)');
}
// Add new/missing columns of device types
if (!db_column_exists('plugin_routerconfigs_devicetypes', 'anykey')) {
db_execute('ALTER TABLE plugin_routerconfigs_devicetypes
ADD COLUMN `anykey` varchar(50) DEFAULT \'\'');
}
if (!db_column_exists('plugin_routerconfigs_devicetypes', 'configfile')) {
db_execute('ALTER TABLE plugin_routerconfigs_devicetypes
ADD COLUMN `configfile` varchar(256) DEFAULT \'\'');
}
if (!db_column_exists('plugin_routerconfigs_devicetypes','connecttype')) {
db_execute('ALTER TABLE plugin_routerconfigs_devicetypes
ADD COLUMN `connecttype` varchar(10) DEFAULT \'both\'');
}
if (!db_column_exists('plugin_routerconfigs_devicetypes', 'sleep')) {
db_execute('ALTER TABLE plugin_routerconfigs_devicetypes
ADD COLUMN `sleep` int(18)');
}
if (!db_column_exists('plugin_routerconfigs_devicetypes', 'timeout')) {
db_execute('ALTER TABLE plugin_routerconfigs_devicetypes
ADD COLUMN `timeout` int(18)');
}
if (!db_column_exists('plugin_routerconfigs_devicetypes', 'elevated')) {
db_execute('ALTER TABLE plugin_routerconfigs_devicetypes
ADD COLUMN `elevated` char(3)');
}
}
if (cacti_version_compare($old, '1.5.2', '<')) {
if (!db_column_exists('plugin_routerconfigs_devicetypes','promptconfirm')) {
db_execute('ALTER TABLE plugin_routerconfigs_devicetypes
ADD COLUMN `promptconfirm` varchar(64) DEFAULT \'confirm|to tftp:\'');
}
}
if (cacti_version_compare($old, '1.5.3', '<')) {
if (!db_column_exists('plugin_routerconfigs_devicetypes','promptconfirm')) {
db_execute('ALTER TABLE plugin_routerconfigs_devicetypes
MODIFY COLUMN `promptconfirm` varchar(64) DEFAULT \'confirm|to tftp:\'');
}
}
AddDeviceTypes();
db_execute("UPDATE plugin_config
SET version='$current'
WHERE directory='routerconfigs'");
}
}
function routerconfigs_check_dependencies() {
global $plugins, $config;
return true;
}
function routerconfigs_setup_table_new() {
$data = array();
$data['primary'] = 'id';
$data['type'] = 'InnoDB';
$data['comment'] = 'Router Config Accounts';
$data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true);
$data['columns'][] = array('name' => 'name', 'type' => 'varchar(64)', 'NULL' => true);
$data['columns'][] = array('name' => 'username', 'type' => 'varchar(64)', 'NULL' => true);
$data['columns'][] = array('name' => 'password', 'type' => 'varchar(256)', 'NULL' => true);
$data['columns'][] = array('name' => 'enablepw', 'type' => 'varchar(256)', 'NULL' => true);
$data['columns'][] = array('name' => 'elevated', 'type' => 'varchar(3)', 'NULL' => true);
api_plugin_db_table_create ('routerconfigs', 'plugin_routerconfigs_accounts', $data);
$data = array();
$data['type'] = 'InnoDB';
$data['comment'] = 'Router Config Backups';
$data['primary'] = 'id';
$data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true);
$data['columns'][] = array('name' => 'btime', 'type' => 'int(18)', 'NULL' => true);
$data['columns'][] = array('name' => 'device', 'type' => 'int(11)', 'NULL' => true);
$data['columns'][] = array('name' => 'directory', 'type' => 'varchar(255)', 'NULL' => true);
$data['columns'][] = array('name' => 'filename', 'type' => 'varchar(255)', 'NULL' => true);
$data['columns'][] = array('name' => 'lastchange', 'type' => 'int(24)', 'NULL' => true);
$data['columns'][] = array('name' => 'lastuser', 'type' => 'varchar(64)', 'NULL' => true);
$data['keys'][] = array('name' => 'btime', 'columns' => 'btime');
$data['keys'][] = array('name' => 'device', 'columns' => 'device');
$data['keys'][] = array('name' => 'directory', 'columns' => 'directory');
$data['keys'][] = array('name' => 'lastchange', 'columns' => 'lastchange');
api_plugin_db_table_create ('routerconfigs', 'plugin_routerconfigs_backups', $data);
$data = array();
$data['primary'] = 'id';
$data['type'] = 'InnoDB';
$data['comment'] = 'Router Config Devices';
$data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true);
$data['columns'][] = array('name' => 'enabled', 'type' => 'varchar(2)', 'NULL' => true);
$data['columns'][] = array('name' => 'ipaddress', 'type' => 'varchar(128)', 'NULL' => true);
$data['columns'][] = array('name' => 'hostname', 'type' => 'varchar(255)', 'NULL' => true);
$data['columns'][] = array('name' => 'directory', 'type' => 'varchar(255)', 'NULL' => true);
$data['columns'][] = array('name' => 'account', 'type' => 'int(11)', 'NULL' => true);
$data['columns'][] = array('name' => 'lastchange', 'type' => 'int(24)', 'NULL' => true);
$data['columns'][] = array('name' => 'lastuser', 'type' => 'varchar(64)', 'NULL' => true);
$data['columns'][] = array('name' => 'device', 'type' => 'int(11)', 'NULL' => true);
$data['columns'][] = array('name' => 'schedule', 'type' => 'int(11)', 'NULL' => true);
$data['columns'][] = array('name' => 'lasterror', 'type' => 'varchar(255)', 'NULL' => true);
$data['columns'][] = array('name' => 'lastbackup', 'type' => 'int(18)', 'NULL' => true);
$data['columns'][] = array('name' => 'nextbackup', 'type' => 'int(18)', 'NULL' => true);
$data['columns'][] = array('name' => 'lastattempt', 'type' => 'int(18)', 'NULL' => true);
$data['columns'][] = array('name' => 'nextattempt', 'type' => 'int(18)', 'NULL' => true);
$data['columns'][] = array('name' => 'devicetype', 'type' => 'int(11)', 'NULL' => true);
$data['columns'][] = array('name' => 'connecttype', 'type' => 'varchar(10)', 'NULL' => true);
$data['columns'][] = array('name' => 'elevated', 'type' => 'varchar(3)', 'NULL' => true);
$data['columns'][] = array('name' => 'sleep', 'type' => 'int(11)', 'NULL' => true);
$data['columns'][] = array('name' => 'timeout', 'type' => 'int(11)', 'NULL' => true);
$data['columns'][] = array('name' => 'debug', 'type' => 'longblob', 'NULL' => true);
$data['keys'][] = array('name' => 'enabled', 'columns' => 'enabled');
$data['keys'][] = array('name' => 'schedule', 'columns' => 'schedule');
$data['keys'][] = array('name' => 'ipaddress', 'columns' => 'ipaddress');
$data['keys'][] = array('name' => 'account', 'columns' => 'account');
$data['keys'][] = array('name' => 'lastbackup', 'columns' => 'lastbackup');
$data['keys'][] = array('name' => 'lastattempt', 'columns' => 'lastattempt');
$data['keys'][] = array('name' => 'devicetype', 'columns' => 'devicetype');
api_plugin_db_table_create ('routerconfigs', 'plugin_routerconfigs_devices', $data);
$data = array();
$data['primary'] = 'id';
$data['type'] = 'InnoDB';
$data['comment'] = 'Router Config Device Types';
$data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true);
$data['columns'][] = array('name' => 'name', 'type' => 'varchar(64)', 'NULL' => true);
$data['columns'][] = array('name' => 'promptuser', 'type' => 'varchar(64)', 'NULL' => true);
$data['columns'][] = array('name' => 'promptpass', 'type' => 'varchar(256)', 'NULL' => true);
$data['columns'][] = array('name' => 'connecttype', 'type' => 'varchar(10)', 'NULL' => true);
$data['columns'][] = array('name' => 'configfile', 'type' => 'varchar(256)', 'NULL' => true);
$data['columns'][] = array('name' => 'copytftp', 'type' => 'varchar(64)', 'NULL' => true);
$data['columns'][] = array('name' => 'version', 'type' => 'varchar(64)', 'NULL' => true);
$data['columns'][] = array('name' => 'promptconfirm', 'type' => 'varchar(64)', 'NULL' => true);
$data['columns'][] = array('name' => 'confirm', 'type' => 'varchar(64)', 'NULL' => true);
$data['columns'][] = array('name' => 'sleep', 'type' => 'int(11)', 'NULL' => true);
$data['columns'][] = array('name' => 'timeout', 'type' => 'int(11)', 'NULL' => true);
$data['columns'][] = array('name' => 'forceconfirm', 'type' => 'char(2)', 'NULL' => true, 'default' => 'on');
$data['columns'][] = array('name' => 'checkendinconfig', 'type' => 'char(2)', 'NULL' => true, 'default' => 'on');
$data['columns'][] = array('name' => 'anykey', 'type' => 'varchar(50)', 'NULL' => true);
$data['columns'][] = array('name' => 'elevated', 'type' => 'varchar(3)', 'NULL' => true);
api_plugin_db_table_create ('routerconfigs', 'plugin_routerconfigs_devicetypes', $data);
AddDeviceTypes();
}
function AddDeviceTypes() {
AddDeviceType('Cisco IOS', 'username:', 'password:', 'copy run tftp', 'show version', 'y', '', 'on','');
AddDeviceType('Cisco CatOS', 'username:', 'password:', 'copy config tftp', '', 'y', 'on', '', '');
AddDeviceType('Cisco Nexus', 'Username:', 'Password:', 'copy running-config tftp://%SERVER%/%FILE% vrf management', 'show version', '', '', '', '');
AddDeviceType('HP Comware', 'usernmae:', 'password:', 'copy startup.cfg tftp://%SERVER%/%FILE%', '', '', '', '', 'on');
AddDeviceType('Dell Switch', 'User', 'Password', 'copy running-config tftp://%SERVER%/%FILE% vrf management', 'show version', 'y', '', '', '', 'Are you sure you want to start');
}
function AddDeviceType($name, $promptuser, $promptpass, $copytftp, $version, $confirm, $forceconfirm, $checkendinconfig, $elevated, $promptconfirm = 'confirm|to tftp:') {
$params = array( $name, $promptuser, $promptpass, $copytftp, $version, $confirm, $forceconfirm, $checkendinconfig, $elevated, $promptconfirm, $name );
db_execute_prepared("INSERT INTO plugin_routerconfigs_devicetypes
(name, promptuser, promptpass, copytftp, version,
confirm, forceconfirm, checkendinconfig, elevated,
promptconfirm)
SELECT
? AS name, ? AS promptuser, ? AS promptpass, ? AS copytftp, ? AS version,
? AS confirm, ? AS forceconfirm, ? AS checkendinconfig, ? AS elevated,
? AS promptconfirm FROM DUAL
WHERE NOT EXISTS(SELECT * FROM plugin_routerconfigs_devicetypes
WHERE name = ? LIMIT 1)", $params);
}
function routerconfigs_page_head () {
global $config;
if (strpos(get_current_page(), 'router-compare.php')) {
print '<link rel="stylesheet" type="text/css" href="' . $config['url_path'] . "plugins/routerconfigs/diff.css\">\n";
}
}
function routerconfigs_poller_bottom () {
global $config;
$h = date('G', time());
$s = date('i', time()) * 60;
/* Check for the polling interval, only valid with the Multipoller patch */
$poller_interval = read_config_option('poller_interval');
if (!isset($poller_interval)) {
$poller_interval = 300;
}
if ($s < $poller_interval) {
$command_string = trim(read_config_option('path_php_binary'));
if (trim($command_string) == '') {
$command_string = 'php';
}
$extra_args = ' -q ' . $config['base_path'] . '/plugins/routerconfigs/router-download.php';
$daily = read_config_option('routerconfigs_hour');
if ($daily === false || $daily < 0 || $daily > 23) {
$daily = 0;
}
$daily = (int)$daily;
if ($h != $daily) {
$extra_args .= ' --retry';
}
cacti_log(__("DEBUG: Executing '%s' with arguments '%s'", $command_string, $extra_args, 'routerconfigs'), true, 'RCONFIG', POLLER_VERBOSITY_DEBUG);
exec_background($command_string, $extra_args);
}
}
function routerconfigs_config_settings () {
global $tabs, $settings, $config, $rc_settings;
routerconfigs_check_upgrade();
$tabs['routerconfigs'] = __('Router Configs', 'routerconfigs');
if (isset($settings['routerconfigs'])) {
$settings['routerconfigs'] = array_merge($settings['routerconfigs'], $rc_settings);
} else {
$settings['routerconfigs'] = $rc_settings;
}
}
function routerconfigs_config_arrays () {
global $menu;
plugin_routerconfigs_upgrade();
if (read_config_option('routerconfigs_presentation') == 'console') {
$menu[__('Utilities', 'routerconfigs')]['plugins/routerconfigs/router-devices.php'] = __('Router Configs', 'routerconfigs');
}
}
function routerconfigs_draw_navigation_text ($nav) {
$nav['router-devices.php:'] = array(
'title' => __('Router Devices', 'routerconfigs'),
'mapping' => 'index.php:',
'url' => 'router-devices.php',
'level' => '1'
);
$nav['router-devices.php:edit'] = array(
'title' => __('(edit)', 'routerconfigs'),
'mapping' => 'index.php:,router-devices.php:',
'url' => 'router-devices.php',
'level' => '2'
);
$nav['router-devices.php:actions'] = array(
'title' => __('(actions)', 'routerconfigs'),
'mapping' => 'index.php:,router-devices.php:',
'url' => 'router-devices.php',
'level' => '2'
);
$nav['router-devices.php:viewconfig'] = array(
'title' => __('View Config', 'routerconfigs'),
'mapping' => 'index.php:,router-devices.php:',
'url' => 'router-devices.php',
'level' => '2'
);
$nav['router-devices.php:viewdebug'] = array(
'title' => __('View Debug', 'routerconfigs'),
'mapping' => 'index.php:,router-devices.php:',
'url' => 'router-devices.php',
'level' => '2'
);
$nav['router-backups.php:'] = array(
'title' => __('Router Backups', 'routerconfigs'),
'mapping' => 'index.php:',
'url' => 'router-backups.php',
'level' => '1'
);
$nav['router-backups.php:edit'] = array(
'title' => __('(edit)', 'routerconfigs'),
'mapping' => 'index.php:,router-backups.php:',
'url' => 'router-backups.php',
'level' => '2'
);
$nav['router-backups.php:actions'] = array(
'title' => __('(actions)', 'routerconfigs'),
'mapping' => 'index.php:,router-backups.php:',
'url' => 'router-backups.php',
'level' => '2'
);
$nav['router-backups.php:viewconfig'] = array(
'title' => __('View Config', 'routerconfigs'),
'mapping' => 'index.php:,router-backups.php:',
'url' => 'router-backups.php',
'level' => '2'
);
$nav['router-accounts.php:'] = array(
'title' => __('Router Accounts', 'routerconfigs'),
'mapping' => 'index.php:',
'url' => 'router-accounts.php',
'level' => '1'
);
$nav['router-accounts.php:edit'] = array(
'title' => __('(edit)', 'routerconfigs'),
'mapping' => 'index.php:,router-accounts.php:',
'url' => 'router-accounts.php',
'level' => '2'
);
$nav['router-accounts.php:actions'] = array(
'title' => __('(actions)', 'routerconfigs'),
'mapping' => 'index.php:,router-accounts.php:',
'url' => 'router-accounts.php',
'level' => '2'
);
$nav['router-compare.php:'] = array(
'title' => __('Router Compare', 'routerconfigs'),
'mapping' => 'index.php:',
'url' => 'router-compare.php',
'level' => '1'
);
return $nav;
}
function plugin_routerconfigs_combinepaths($path1, $path2) {
if (strlen($path2) < 1 || $path2[0] != '/') {
if (strlen($path1) && $path1[strlen($path1)- 1] != '/') {
$path1 = $path1 . '/';
}
} else {
$path1 = '';
}
if (strlen($path2) && $path2[strlen($path2)- 1] != '/') {
$path2 = $path2 . '/';
}
return $path1 . $path2;
}
function plugin_routerconfigs_fix_backups_pre14() {
$backups = db_fetch_assoc('SELECT id, directory, filename FROM plugin_routerconfigs_backups');
foreach ($backups as $backup) {
$filename = trim($backup['filename']);
$path = $backup['directory'];
if (strlen($path) && $path[strlen($path) - 1] != '/') {
$path = $path . '/';
}
if (strlen($path) < 1 || $path[0] != '/') {
$path = plugin_routerconfigs_combinepaths(read_config_option('routerconfigs_backup_path'), $path);
}
if (basename($filename) != $filename || $path != $backup['directory']) {
$dir = trim(dirname($filename));
if ($dir == '.') {
$dir = '';
}
$dir = plugin_routerconfigs_combinepaths($path, $dir);
db_execute_prepared('UPDATE plugin_routerconfigs_backups
SET directory = ?, filename = ?
WHERE id = ?',
array($dir, basename($filename), $backup['id']));
}
}
}
function routerconfigs_show_tab() {
global $config;
$tabstyle = read_config_option('routerconfigs_presentation');
$selected_theme = get_selected_theme();
if (api_plugin_user_realm_auth('router-devices.php') && $tabstyle == 'toptab') {
if (preg_match('/router-devices.php/', $_SERVER['REQUEST_URI'], $matches)) {
$down = true;
} else {
$down = false;
}
print '<a id="routerconfigs"
href="' . $config['url_path'] . 'plugins/routerconfigs/router-devices.php">
<img src="' . ($selected_theme == 'classic' ? get_classic_tabimage(__('Routers', 'routerconfig'), $down):'#') . '" alt="' . __esc('RouterConfigs', 'routerconfigs') . '"></a>';
}
}