Project

General

Profile

Feature #14625 » lcdproc_screens.php

Elvis Impersonator, 08/01/2023 07:25 PM

 
1
<?php
2
/*
3
 * lcdproc_screens.php
4
 *
5
 * part of pfSense (https://www.pfsense.org/)
6
 * Copyright (c) 2016-2023 Rubicon Communications, LLC (Netgate)
7
 * Copyright (c) 2016 Treer
8
 * Copyright (c) 2008 Mark J Crane
9
 * All rights reserved.
10
 *
11
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14
 *
15
 * http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22
 */
23
require_once("guiconfig.inc");
24
require_once("/usr/local/pkg/lcdproc.inc");
25

    
26
$lcdproc_screens_config = config_get_path('installedpackages/lcdprocscreens/config/0', []);
27

    
28
// Set default values for anything not in the $config
29
$pconfig = $lcdproc_screens_config;
30
if (!isset($pconfig['scr_version']))                         $pconfig['scr_version']                         = false;
31
if (!isset($pconfig['scr_time']))                            $pconfig['scr_time']                            = false;
32
if (!isset($pconfig['scr_uptime']))                          $pconfig['scr_uptime']                          = false;
33
if (!isset($pconfig['scr_hostname']))                        $pconfig['scr_hostname']                        = false;
34
if (!isset($pconfig['scr_system']))                          $pconfig['scr_system']                          = false;
35
if (!isset($pconfig['scr_disk']))                            $pconfig['scr_disk']                            = false;
36
if (!isset($pconfig['scr_load']))                            $pconfig['scr_load']                            = false;
37
if (!isset($pconfig['scr_states']))                          $pconfig['scr_states']                          = false;
38
if (!isset($pconfig['scr_carp']))                            $pconfig['scr_carp']                            = false;
39
if (!isset($pconfig['scr_ipsec']))                           $pconfig['scr_ipsec']                           = false;
40
if (!isset($pconfig['scr_interfaces']))                      $pconfig['scr_interfaces']                      = false;
41
if (!isset($pconfig['scr_gwsum']))                           $pconfig['scr_gwsum']                           = false;
42
if (!isset($pconfig['scr_gwstatus']))                        $pconfig['scr_gwstatus']                        = false;
43
if (!isset($pconfig['scr_mbuf']))                            $pconfig['scr_mbuf']                            = false;
44
if (!isset($pconfig['scr_packages']))                        $pconfig['scr_packages']                        = false;
45
if (!isset($pconfig['scr_cpufrequency']))                    $pconfig['scr_cpufrequency']                    = false;
46
if (!isset($pconfig['scr_cputemperature']))                  $pconfig['scr_cputemperature']                  = false;
47
if (!isset($pconfig['scr_cputemperature_unit']))             $pconfig['scr_cputemperature_unit']             = 'c';
48
if (!isset($pconfig['scr_ntp']))                             $pconfig['scr_ntp']                         = false;
49
if (!isset($pconfig['scr_traffic']))                         $pconfig['scr_traffic']                         = false;
50
if (!isset($pconfig['scr_traffic_interface']))               $pconfig['scr_traffic_interface']               = '';
51
if (!isset($pconfig['scr_top_interfaces_by_bps']))           $pconfig['scr_top_interfaces_by_bps']           = false;
52
if (!isset($pconfig['scr_top_interfaces_by_total_bytes']))   $pconfig['scr_top_interfaces_by_total_bytes']   = false;
53
if (!isset($pconfig['scr_top_interfaces_by_bytes_today']))   $pconfig['scr_top_interfaces_by_bytes_today']   = false;
54
if (!isset($pconfig['scr_interfaces_link']))                 $pconfig['scr_interfaces_link']                 = false;
55
if (!isset($pconfig['scr_traffic_by_address']))              $pconfig['scr_traffic_by_address']              = false;
56
if (!isset($pconfig['scr_traffic_by_address_if']))           $pconfig['scr_traffic_by_address_if']           = '';
57
if (!isset($pconfig['scr_traffic_by_address_sort']))         $pconfig['scr_traffic_by_address_sort']         = 'in';
58
if (!isset($pconfig['scr_traffic_by_address_filter']))       $pconfig['scr_traffic_by_address_filter']       = 'local';
59
if (!isset($pconfig['scr_traffic_by_address_hostipformat'])) $pconfig['scr_traffic_by_address_hostipformat'] = 'descr';
60
if (!isset($pconfig['scr_apcupsd']))                         $pconfig['scr_apcupsd']                         = false;
61
if (!isset($pconfig['scr_nutups']))                          $pconfig['scr_nutups']                          = false;
62

    
63
if ($_POST) {
64
	unset($input_errors);
65
	$pconfig = $_POST;
66

    
67
	// Input validation would go here, with any invalid values found
68
	// in $_POST being added to $input_errors, e.g:
69
	//   $input_errors[] = "Descriptive error message for the user.";
70

    
71
	if (!$input_errors) {
72
		$lcdproc_screens_config['scr_version']                         = $pconfig['scr_version'];
73
		$lcdproc_screens_config['scr_time']                            = $pconfig['scr_time'];
74
		$lcdproc_screens_config['scr_uptime']                          = $pconfig['scr_uptime'];
75
		$lcdproc_screens_config['scr_hostname']                        = $pconfig['scr_hostname'];
76
		$lcdproc_screens_config['scr_system']                          = $pconfig['scr_system'];
77
		$lcdproc_screens_config['scr_disk']                            = $pconfig['scr_disk'];
78
		$lcdproc_screens_config['scr_load']                            = $pconfig['scr_load'];
79
		$lcdproc_screens_config['scr_states']                          = $pconfig['scr_states'];
80
		$lcdproc_screens_config['scr_carp']                            = $pconfig['scr_carp'];
81
		$lcdproc_screens_config['scr_ipsec']                           = $pconfig['scr_ipsec'];
82
		$lcdproc_screens_config['scr_interfaces']                      = $pconfig['scr_interfaces'];
83
		$lcdproc_screens_config['scr_gwsum']                           = $pconfig['scr_gwsum'];
84
		$lcdproc_screens_config['scr_gwstatus']                        = $pconfig['scr_gwstatus'];
85
		$lcdproc_screens_config['scr_mbuf']                            = $pconfig['scr_mbuf'];
86
		$lcdproc_screens_config['scr_packages']                        = $pconfig['scr_packages'];
87
		$lcdproc_screens_config['scr_cpufrequency']                    = $pconfig['scr_cpufrequency'];
88
		$lcdproc_screens_config['scr_cputemperature']                  = $pconfig['scr_cputemperature'];
89
		$lcdproc_screens_config['scr_cputemperature_unit']             = $pconfig['scr_cputemperature_unit'];
90
		$lcdproc_screens_config['scr_ntp']          	               = $pconfig['scr_ntp'];
91
		$lcdproc_screens_config['scr_traffic']                         = $pconfig['scr_traffic'];
92
		$lcdproc_screens_config['scr_traffic_interface']               = $pconfig['scr_traffic_interface'];
93
		$lcdproc_screens_config['scr_top_interfaces_by_bps']           = $pconfig['scr_top_interfaces_by_bps'];
94
		$lcdproc_screens_config['scr_top_interfaces_by_total_bytes']   = $pconfig['scr_top_interfaces_by_total_bytes'];
95
		$lcdproc_screens_config['scr_top_interfaces_by_bytes_today']   = $pconfig['scr_top_interfaces_by_bytes_today'];
96
		$lcdproc_screens_config['scr_interfaces_link']                 = $pconfig['scr_interfaces_link'];
97
		$lcdproc_screens_config['scr_traffic_by_address']              = $pconfig['scr_traffic_by_address'];
98
		$lcdproc_screens_config['scr_traffic_by_address_if']           = $pconfig['scr_traffic_by_address_if'];
99
		$lcdproc_screens_config['scr_traffic_by_address_sort']         = $pconfig['scr_traffic_by_address_sort'];
100
		$lcdproc_screens_config['scr_traffic_by_address_filter']       = $pconfig['scr_traffic_by_address_filter'];
101
		$lcdproc_screens_config['scr_traffic_by_address_hostipformat'] = $pconfig['scr_traffic_by_address_hostipformat'];
102
		$lcdproc_screens_config['scr_apcupsd']                         = $pconfig['scr_apcupsd'];
103
		$lcdproc_screens_config['scr_nutups']                          = $pconfig['scr_nutups'];
104

    
105
		config_set_path('installedpackages/lcdprocscreens/config/0', $lcdproc_screens_config);
106
		write_config("lcdproc: Screen settings saved");
107
		sync_package_lcdproc();
108
	}
109
}
110

    
111
$shortcut_section = 'lcdproc';
112

    
113
$pgtitle = array(gettext("Services"), gettext("LCDproc"), gettext("Screens"));
114
include("head.inc");
115

    
116
if ($input_errors) {
117
	print_input_errors($input_errors);
118
}
119

    
120
$tab_array = array();
121
$tab_array[] = array(gettext("Server"),  false, "/packages/lcdproc/lcdproc.php");
122
$tab_array[] = array(gettext("Screens"), true,  "/packages/lcdproc/lcdproc_screens.php");
123
display_top_tabs($tab_array);
124

    
125
$form = new Form();
126
$section = new Form_Section('LCD info screens');
127

    
128
// Add the Version checkbox
129
$section->addInput(
130
	new Form_Checkbox(
131
		'scr_version', // checkbox name (id)
132
		'Version', // checkbox label
133
		'Display the version', // checkbox text
134
		$pconfig['scr_version'] // checkbox initial value
135
	)
136
);
137
$section->addInput(
138
	new Form_Checkbox(
139
		'scr_time', // checkbox name (id)
140
		'Time', // checkbox label
141
		'Display the time', // checkbox text
142
		$pconfig['scr_time'] // checkbox initial value
143
	)
144
);
145
$section->addInput(
146
	new Form_Checkbox(
147
		'scr_uptime', // checkbox name (id)
148
		'Up-time', // checkbox label
149
		'Display the up-time', // checkbox text
150
		$pconfig['scr_uptime'] // checkbox initial value
151
	)
152
);
153
$section->addInput(
154
	new Form_Checkbox(
155
		'scr_hostname', // checkbox name (id)
156
		'Hostname', // checkbox label
157
		'Display the Hostname', // checkbox text
158
		$pconfig['scr_hostname'] // checkbox initial value
159
	)
160
);
161
$section->addInput(
162
	new Form_Checkbox(
163
		'scr_system', // checkbox name (id)
164
		'System', // checkbox label
165
		'Display system info', // checkbox text
166
		$pconfig['scr_system'] // checkbox initial value
167
	)
168
);
169
$section->addInput(
170
	new Form_Checkbox(
171
		'scr_disk', // checkbox name (id)
172
		'Disk', // checkbox label
173
		'Display the percentage of disk-space used', // checkbox text
174
		$pconfig['scr_disk'] // checkbox initial value
175
	)
176
);
177
$section->addInput(
178
	new Form_Checkbox(
179
		'scr_load', // checkbox name (id)
180
		'Load', // checkbox label
181
		'Display the load average of the system over the last 1, 5, and 15 minutes', // checkbox text
182
		$pconfig['scr_load'] // checkbox initial value
183
	)
184
);
185
$section->addInput(
186
	new Form_Checkbox(
187
		'scr_states', // checkbox name (id)
188
		'States', // checkbox label
189
		'Display the states', // checkbox text
190
		$pconfig['scr_states'] // checkbox initial value
191
	)
192
);
193
$section->addInput(
194
	new Form_Checkbox(
195
		'scr_carp', // checkbox name (id)
196
		'Carp', // checkbox label
197
		'Display CARP state', // checkbox text
198
		$pconfig['scr_carp'] // checkbox initial value
199
	)
200
);
201
$section->addInput(
202
	new Form_Checkbox(
203
		'scr_ipsec', // checkbox name (id)
204
		'IPsec', // checkbox label
205
		'Display IPsec tunnels', // checkbox text
206
		$pconfig['scr_ipsec'] // checkbox initial value
207
	)
208
);
209
$section->addInput(
210
	new Form_Checkbox(
211
		'scr_interfaces', // checkbox name (id)
212
		'Interfaces', // checkbox label
213
		'Display status of interfaces', // checkbox text
214
		$pconfig['scr_interfaces'] // checkbox initial value
215
	)
216
);
217
$section->addInput(
218
	new Form_Checkbox(
219
		'scr_gwsum', // checkbox name (id)
220
		'Gateway Summary', // checkbox label
221
		'Display a Gateway status (up/down) summary', // checkbox text
222
		$pconfig['scr_gwsum'] // checkbox initial value
223
	)
224
);
225
$section->addInput(
226
	new Form_Checkbox(
227
		'scr_gwstatus', // checkbox name (id)
228
		'Gateway Status', // checkbox label
229
		'Display Gateway Status', // checkbox text
230
		$pconfig['scr_gwstatus'] // checkbox initial value
231
	)
232
)->setHelp('A 4-row 20-column display size, or higher, is required for this screen.');
233
$section->addInput(
234
	new Form_Checkbox(
235
		'scr_mbuf', // checkbox name (id)
236
		'Mbuf', // checkbox label
237
		'Display the MBuf usage', // checkbox text
238
		$pconfig['scr_mbuf'] // checkbox initial value
239
	)
240
);
241
$section->addInput(
242
	new Form_Checkbox(
243
		'scr_packages', // checkbox name (id)
244
		'Package Info', // checkbox label
245
		'Display package count/updates', // checkbox text
246
		$pconfig['scr_packages'] // checkbox initial value
247
	)
248
);
249
$section->addInput(
250
	new Form_Checkbox(
251
		'scr_cpufrequency', // checkbox name (id)
252
		'CPU Frequency', // checkbox label
253
		'Display CPU power saving rate', // checkbox text
254
		$pconfig['scr_cpufrequency'] // checkbox initial value
255
	)
256
);
257

    
258
$section->addInput(
259
	new Form_Checkbox(
260
		'scr_ntp', // checkbox name (id)
261
		'NTP Status', // checkbox label
262
		'Display NTP status', // checkbox text
263
		$pconfig['scr_ntp'] // checkbox initial value
264
	)
265
);
266
 
267
 
268
$group = new Form_Group('CPU Temperature');
269
$group->add(
270
	new Form_Checkbox(
271
		'scr_cputemperature', // checkbox name (id)
272
		'CPU Temperature', // checkbox label
273
		'Display CPU temperature', // checkbox text
274
		$pconfig['scr_cputemperature'] // checkbox initial value
275
	)
276
);
277
$group->add(
278
	new Form_Select(
279
		'scr_cputemperature_unit',
280
		'',
281
		$pconfig['scr_cputemperature_unit'],
282
		array (
283
			'c'	=> gettext('Celsius'),
284
			'f'	=> gettext('Fahrenheit')
285
		)
286
))->setHelp('Unit of temperature');
287
$section->add($group);
288

    
289
$group = new Form_Group('Traffic of interface');
290

    
291
$group->add(
292
	new Form_Checkbox(
293
		'scr_traffic', // checkbox name (id)
294
		'', // checkbox label
295
		'Display total bytes since last boot (in & out), for interface:', // checkbox text
296
		$pconfig['scr_traffic'] // checkbox initial value
297
	)
298
);
299
$group->add(
300
	new Form_Select(
301
		'scr_traffic_interface',
302
		'',
303
		$pconfig['scr_traffic_interface'], // Initial value.
304
		get_configured_interface_with_descr()
305
	)
306
);
307
$section->add($group);
308

    
309
$section->addInput(
310
	new Form_Checkbox(
311
		'scr_top_interfaces_by_bps', // checkbox name (id)
312
		'Interfaces by traffic', // checkbox label
313
		'Interfaces listed with current bits-per-second (in & out)', // checkbox text
314
		$pconfig['scr_top_interfaces_by_bps'] // checkbox initial value
315
	)
316
)->setHelp('A 4-row 20-column display size, or higher, is recommended for this screen.');
317
$section->addInput(
318
	new Form_Checkbox(
319
		'scr_top_interfaces_by_total_bytes', // checkbox name (id)
320
		'Interfaces by volume', // checkbox label
321
		'Interfaces listed with total bytes since last boot (in & out)', // checkbox text
322
		$pconfig['scr_top_interfaces_by_total_bytes'] // checkbox initial value
323
	)
324
)->setHelp('A 4-row 20-column display size, or higher, is recommended for this screen.');
325
$section->addInput(
326
	new Form_Checkbox(
327
		'scr_top_interfaces_by_bytes_today', // checkbox name (id)
328
		'Interfaces by volume today', // checkbox label
329
		'Interfaces listed with total bytes since the start of the day, or since LCDproc reset (in & out)', // checkbox text
330
		$pconfig['scr_top_interfaces_by_bytes_today'] // checkbox initial value
331
	)
332
)->setHelp('A 4-row 20-column display size, or higher, is recommended for this screen.');
333

    
334
$section->addInput(
335
	new Form_Checkbox(
336
		'scr_interfaces_link', // checkbox name (id)
337
		'Interfaces link status', // checkbox label
338
		'Display the interfaces current link status', // checkbox text
339
		$pconfig['scr_interfaces_link'] // checkbox initial value
340
	)
341
)->setHelp(
342
	'This will create a seperate status screen for each inferface with four lines each:%1$s' .
343
	'%2$sIFNAME%3$s: %2$slink status%3$s%1$s' .
344
	'v4: %2$sip v4 address%3$s%1$s' .
345
	'v6: %2$sip v6 address%3$s%1$s' .
346
	'm: %2$smac address%3$s%1$s' .
347
	'A 4-row 20-column display size, or higher, is recommended for this screen.',
348
	'<br/>', '&lt;', '&gt;', '&hyphen;'
349
);
350

    
351
$group = new Form_Group('Addresses by traffic');
352

    
353
$group->add(new Form_Checkbox(
354
		'scr_traffic_by_address',
355
		'',
356
		'Display IP traffic:',
357
		$pconfig['scr_traffic_by_address']
358
));
359
$group->add(new Form_Select(
360
	'scr_traffic_by_address_if',
361
	null,
362
	$pconfig['scr_traffic_by_address_if'],
363
	get_configured_interface_with_descr()
364
))->setHelp('Interface');
365
$group->add(new Form_Select(
366
	'scr_traffic_by_address_sort',
367
	null,
368
	$pconfig['scr_traffic_by_address_sort'],
369
	array (
370
		'in'	=> gettext('Bandwidth In'),
371
		'out'	=> gettext('Bandwidth Out')
372
	)
373
))->setHelp('Sort by');
374
$group->add(new Form_Select(
375
	'scr_traffic_by_address_filter',
376
	null,
377
	$pconfig['scr_traffic_by_address_filter'],
378
	array (
379
		'local'	=> gettext('Local'),
380
		'remote'=> gettext('Remote'),
381
		'all'	=> gettext('All')
382
	)
383
))->setHelp('Filter');
384
$group->add(new Form_Select(
385
	'scr_traffic_by_address_hostipformat',
386
	null,
387
	$pconfig['scr_traffic_by_address_hostipformat'],
388
	array (
389
		''		=> gettext('IP Address'),
390
		'hostname'	=> gettext('Host Name'),
391
		'descr'		=> gettext('Description'),
392
		'fqdn'		=> gettext('FQDN')
393
	)
394
))->setHelp('Display');
395

    
396
$group->setHelp('A 4-row 20-column display size, or higher, is recommended for this screen.');
397
$section->add($group);
398

    
399
if (file_exists("/usr/local/pkg/apcupsd.inc")) {
400
	$section->addInput(
401
		new Form_Checkbox(
402
			'scr_apcupsd', // checkbox name (id)
403
			'APC UPS Info', // checkbox label
404
			'Display current APC UPS status from APCUPSD Package', // checkbox text
405
			$pconfig['scr_apcupsd'] // checkbox initial value
406
		)
407
	);
408
}
409

    
410
if (file_exists("/usr/local/pkg/nut/nut.inc")) {
411
	$section->addInput(
412
		new Form_Checkbox(
413
			'scr_nutups', // checkbox name (id)
414
			'NUT UPS Info', // checkbox label
415
			'Display current UPS status from NUT Package', // checkbox text
416
			$pconfig['scr_nutups'] // checkbox initial value
417
		)
418
	);
419
}
420

    
421
$form->add($section);
422
print($form);
423

    
424
?>
425

    
426
<div class="infoblock">
427
	<?=print_info_box('For more information see: <a href="http://lcdproc.org/docs.php3">LCDproc documentation</a>.', 'info')?>
428
</div>
429

    
430
<?php include("foot.inc"); ?>
(5-5/7)