Project

General

Profile

Download (16.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
    index.php
5
    Copyright (C) 2004, 2005 Scott Ullrich
6
    All rights reserved.
7

    
8
    Originally part of m0n0wall (http://m0n0.ch/wall)
9
    Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
    All rights reserved.
11

    
12
    Redistribution and use in source and binary forms, with or without
13
    modification, are permitted provided that the following conditions are met:
14

    
15
    1. Redistributions of source code must retain the above copyright notice,
16
       this list of conditions and the following disclaimer.
17

    
18
    2. Redistributions in binary form must reproduce the above copyright
19
       notice, this list of conditions and the following disclaimer in the
20
       documentation and/or other materials provided with the distribution.
21

    
22
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
    oR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
    POSSIBILITY OF SUCH DAMAGE.
32
*/
33

    
34
	## Load Essential Includes
35
	require_once('guiconfig.inc');
36
	require_once('notices.inc');
37

    
38
	## Load Functions Files
39
	require_once('includes/functions.inc.php');
40

    
41

    
42
	## Load AJAX, Initiate Class ###############################################
43
	require_once('includes/sajax.class.php');
44

    
45
	## Initiate Class and Set location of ajax file containing 
46
	## the information that we need for this page. Also set functions
47
	## that SAJAX will be using.
48
	$oSajax = new sajax();
49
	$oSajax->sajax_remote_uri = 'sajax/index.sajax.php';
50
	$oSajax->sajax_request_type = 'POST';
51
	$oSajax->sajax_export("get_stats");
52
	$oSajax->sajax_handle_client_request();
53
	############################################################################
54

    
55

    
56
	## Check to see if we have a swap space,
57
	## if true, display, if false, hide it ...
58
	if(file_exists("/usr/sbin/swapinfo")) {
59
		$swapinfo = `/usr/sbin/swapinfo`;
60
		if(stristr($swapinfo,'%') == true) $showswap=true;
61
	}
62

    
63

    
64
	## User recently restored his config.
65
	## If packages are installed lets resync
66
	if(file_exists('/conf/needs_package_sync')) {
67
		if($config['installedpackages'] <> '') {
68
			conf_mount_rw();
69
			unlink('/conf/needs_package_sync');
70
			header('Location: pkg_mgr_install.php?mode=reinstallall');
71
			exit;
72
		}
73
	}
74

    
75

    
76
	## If it is the first time webGUI has been
77
	## accessed since initial install show this stuff.
78
	if(file_exists('/conf/trigger_initial_wizard')) {
79

    
80
		$pgtitle = 'pfSense first time setup';
81
		include('head.inc');
82

    
83
		echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
84
		echo "<form>\n";
85
		echo "<center>\n";
86
		echo "<img src=\"/themes/{$g['theme']}/images/logo.gif\" border=\"0\"><p>\n";
87
		echo "<div \" style=\"width:700px;background-color:#ffffff\" id=\"nifty\">\n";
88
		echo "Welcome to pfSense!<p>\n";
89
		echo "One moment while we start the initial setup wizard.<p>\n";
90
		echo "Embedded platform users: Please be patient, the wizard takes a little longer to run than the normal gui.<p>\n";
91
		echo "To bypass the wizard, click on the pfSense wizard on the initial page.\n";
92
		echo "</div>\n";
93
		echo "<meta http-equiv=\"refresh\" content=\"1;url=wizard.php?xml=setup_wizard.xml\">\n";
94
		echo "<script type=\"text/javascript\">\n";
95
		echo "NiftyCheck();\n";
96
		echo "Rounded(\"div#nifty\",\"all\",\"#000\",\"#FFFFFF\",\"smooth\");\n";
97
		echo "</script>\n";
98
		exit;
99
	}
100

    
101

    
102
	## Find out whether there's hardware encryption or not
103
	unset($hwcrypto);
104
	$fd = @fopen("{$g['varlog_path']}/dmesg.boot", "r");
105
	if ($fd) {
106
		while (!feof($fd)) {
107
			$dmesgl = fgets($fd);
108
			if (preg_match("/^hifn.: (.*?),/", $dmesgl, $matches)) {
109
				$hwcrypto = $matches[1];
110
				break;
111
			}
112
		}
113
		fclose($fd);
114
	}
115
	
116
//build list of widgets
117
$directory = "widgets/widgets/";
118
$dirhandle  = opendir($directory);
119
$filename = "";
120
$widgetnames = array ();
121
$widgetfiles = array();
122

    
123
while (false !== ($filename = readdir($dirhandle))) {
124
	$periodpos = strpos($filename, ".");
125
	$widgetname = substr($filename, 0, $periodpos);
126
	$widgetnames[] = $widgetname;
127
	if ($widgetname != "system_information")
128
		$widgetfiles[] = $filename;   		
129
}
130
sort($widgetfiles);
131
array_unshift($widgetfiles, "system_information.widget.php");
132

    
133

    
134
if (!is_array($config['widgets'])) {
135
	$config['widgets'] = array();
136
}
137

    
138
$pconfig['sequence'] = $config['widgets']['sequence'];
139
	
140
if ($_POST){
141
	$config['widgets']['sequence'] = $_POST['sequence'];
142
	
143
	foreach ($widgetnames as $widget){
144
		if ($_POST[$widget . '-config']){
145
			$config['widgets'][$widget . '-config'] = $_POST[$widget . '-config'];
146
		}
147
	}
148
	
149
	write_config();
150
	header("Location: index.php");
151
	exit;
152
}
153

    
154
	
155
if ($config['widgets'])
156
{
157
	$widgetlist = $pconfig['sequence'];
158
	
159
	$colpos = array();
160
	$savedwidgetfiles = array();
161
	$widgetname = "";
162
	$widgetlist = explode(",",$widgetlist);
163
	foreach ($widgetlist as $widget){
164
		$dashpos = strpos($widget, "-");		
165
		$widgetname = substr($widget, 0, $dashpos);
166
		$colposition = strpos($widget, ":");		
167
		$displayposition = strrpos($widget, ":");
168
		$colpos[] = substr($widget,$colposition+1, $displayposition - $colposition-1);
169
		$displayarray[] = substr($widget,$displayposition+1);
170
		$savedwidgetfiles[] = $widgetname . ".widget.php";
171
	}
172
	foreach ($widgetnames as $widget){
173
		if ($config['widgets'][$widget . '-config']){
174
			$pconfig[$widget . '-config'] = $config['widgets'][$widget . '-config'];
175
		}
176
	}	
177
}
178

    
179

    
180
//build list of php include files
181
$phpincludefiles = Array();
182
$directory = "widgets/include/";
183
$dirhandle  = opendir($directory);
184
$filename = "";
185
while (false !== ($filename = readdir($dirhandle))) {
186
	$phpincludefiles[] = $filename;
187
}
188
foreach($phpincludefiles as $includename) {
189
	if(!stristr($includename, ".inc"))
190
		continue;	
191
	include($directory . $includename);
192
}
193
	
194
	
195

    
196
$jscriptstr = <<<EOD
197
<script language="javascript" type="text/javascript">
198

    
199
function addDiv(selectedDiv){
200
	selectedDiv = selectedDiv + "-div";
201
	Effect.Appear(selectedDiv, {duration:1});
202
	d = document;	
203
	selectIntLink = selectedDiv + "-input";
204
	textlink = d.getElementById(selectIntLink);
205
	textlink.value = "show";	
206
	showSave(); 
207
}
208

    
209
function configureDiv(selectedDiv){
210
	selectIntLink = selectedDiv + "-settings";	
211
	d = document;
212
	textlink = d.getElementById(selectIntLink);
213
	if (textlink.style.display == "none")
214
		Effect.BlindDown(selectIntLink, {duration:1});
215
	else
216
		Effect.BlindUp(selectIntLink, {duration:1});
217
}
218

    
219
function showDiv(selectedDiv,swapButtons){
220
		//appear element
221
    Effect.BlindDown(selectedDiv, {duration:1});      
222
    showSave();    
223
	d = document;	
224
    if (swapButtons){
225
	    selectIntLink = selectedDiv + "-min";
226
		textlink = d.getElementById(selectIntLink);
227
		textlink.style.display = "inline";
228
	    
229
	    
230
	    selectIntLink = selectedDiv + "-open";
231
		textlink = d.getElementById(selectIntLink);
232
		textlink.style.display = "none";
233

    
234
    }
235
	selectIntLink = selectedDiv + "-div-input";
236
	textlink = d.getElementById(selectIntLink);
237
	textlink.value = "show";	
238
    
239
}
240
	
241
function minimizeDiv(selectedDiv,swapButtons){
242
	//fade element
243
    Effect.BlindUp(selectedDiv, {duration:1});      
244
    showSave();
245
	d = document;	
246
    if (swapButtons){
247
	    selectIntLink = selectedDiv + "-open";
248
		textlink = d.getElementById(selectIntLink);
249
		textlink.style.display = "inline";	    
250
	    
251
	    selectIntLink = selectedDiv + "-min";
252
		textlink = d.getElementById(selectIntLink);
253
		textlink.style.display = "none";
254
    }  		
255
	selectIntLink = selectedDiv + "-div-input";
256
	textlink = d.getElementById(selectIntLink);
257
	textlink.value = "hide";	  
258
    
259
}
260

    
261
function closeDiv(selectedDiv){	
262
	showSave();
263
	selectedDiv = selectedDiv + "-div";
264
	Effect.Fade(selectedDiv, {duration:1});
265
	d = document;
266
	selectIntLink = selectedDiv + "-input";
267
	textlink = d.getElementById(selectIntLink);
268
	textlink.value = "close";	
269
}
270

    
271
function showSave(){
272
	d = document;
273
	selectIntLink = "submit";
274
	textlink = d.getElementById(selectIntLink);
275
	textlink.style.display = "inline";	
276
}
277

    
278
function updatePref(){	
279
	var widgets = document.getElementsByClassName('widgetdiv');
280
	var widgetSequence = "";
281
	var firstprint = false;	
282
	d = document;
283
	for (i=0; i<widgets.length; i++){
284
		if (firstprint)
285
			widgetSequence += ",";
286
		var widget = widgets[i].id;
287
		widgetSequence += widget + ":" + widgets[i].parentNode.id + ":";
288
		widget = widget + "-input";
289
		textlink = d.getElementById(widget).value;
290
		widgetSequence += textlink;
291
		firstprint = true;		
292
	}
293
	selectLink = "sequence";
294
	textlink = d.getElementById(selectLink);
295
	textlink.value = widgetSequence;
296
	return true;	
297
}
298

    
299
</script>
300
EOD;
301
$closehead = false;
302

    
303
## Set Page Title and Include Header
304
$pgtitle = "pfSense webGUI";
305
include("head.inc");
306
	
307
	
308
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domLib.js\"></script>";
309
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/domTT.js\"></script>";
310
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/behaviour.js\"></script>";
311
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"/javascript/domTT/fadomatic.js\"></script>";
312
?>
313

    
314
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
315
<form action="index.php" method="post">
316
<script language="javascript" type="text/javascript">
317
// <![CDATA[
318
columns = ['col1','col2'];
319
// ]]>
320

    
321
</script>
322

    
323

    
324
<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
325
<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
326

    
327
<?php
328
include("fbegin.inc");
329
echo $jscriptstr;
330
	if(!file_exists("/usr/local/www/themes/{$g['theme']}/no_big_logo"))
331
		echo "<center><img src=\"./themes/".$g['theme']."/images/logobig.jpg\"></center><br>";
332
?>
333

    
334
<?php 
335
	?>
336
<div id="widgetcontainer" style="display:none">
337
		<div id="content1"><h1>Available Widgets</h1><p><?php
338
			foreach($widgetfiles as $widget) {			
339
				if(!stristr($widget, "widget.php"))
340
					continue;		
341
				
342
				$periodpos = strpos($widget, ".");
343
				$widgetname = substr($widget, 0, $periodpos);
344
				$nicename = $widgetname;
345
				$nicename = str_replace("_", " ", $nicename);
346
				//make the title look nice
347
				$nicename = ucwords($nicename);?>
348
				<span style="cursor: pointer;" onclick='return addDiv("<?php echo $widgetname; ?>")'><u><?php echo $nicename; ?></u></span><br><?php
349
			}
350
		?>
351
		</p>
352
	</div>
353
</div>
354

    
355
<input type="hidden" value="" name="sequence" id="sequence">
356
<p class="pgtitle">System Overview&nbsp;&nbsp;&nbsp;
357
<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="Click here to add widgets" style="cursor: help;" onmouseup="domTT_activate(this, event, 'content', document.getElementById('content1'), 'type', 'velcro', 'delay', 0, 'fade', 'both', 'fadeMax', 100, 'styleClass', 'niceTitle');" />
358
&nbsp;&nbsp;&nbsp;
359
		<input id="submit" name="submit" type="submit" style="display:none" onclick="return updatePref();" class="formbtn" value="Save Settings" />
360
</p>
361

    
362
<div style="clear:both;"></div>
363
<div id="niftyOutter">
364
	<?php
365
	$totalwidgets = count($widgetfiles);
366
	$halftotal = $totalwidgets / 2 -1;
367
	$widgetcounter = 0;
368
	$directory = "widgets/widgets/";
369
	$printed = false;
370
	$firstprint = false;
371
	?> 
372
	<div id="col1" style="float:left;width:49%;padding: 2px;padding-bottom:40px">		
373
	<?php
374
	
375
	if ($config['widgets']){
376
		$widgetlist = $savedwidgetfiles;
377
		
378
		//add widgets that may not be in the saved configuration, in case they want to be added later
379
		foreach ($widgetfiles as $defaultwidgets){
380
			
381
			if (!in_array($defaultwidgets, $savedwidgetfiles)){
382
				$widgetlist[] = $defaultwidgets;
383
			}
384
		}		
385
		
386
	}
387
	else
388
		$widgetlist = $widgetfiles;	
389
	
390
	foreach($widgetlist as $widget) {
391
	
392
		if(!stristr($widget, "widget.php"))
393
			continue;		
394
		
395
		$periodpos = strpos($widget, ".");
396
		$widgetname = substr($widget, 0, $periodpos);	
397
		if ($widgetname != ""){
398
		$nicename = $widgetname;
399
		$nicename = str_replace("_", " ", $nicename);
400
			
401
		//make the title look nice
402
		$nicename = ucwords($nicename);
403
		
404
		if ($config['widgets']){
405
			if ($displayarray[$widgetcounter] == "show"){
406
				$divdisplay = "block";
407
				$display = "block";
408
				$inputdisplay = "show";					
409
				$showdiv = "none";
410
				$mindiv = "inline";
411
			}
412
			else if ($displayarray[$widgetcounter] == "hide") {
413
				$divdisplay = "block";
414
				$display = "none";
415
				$inputdisplay = "hide";		
416
				$showdiv = "inline";
417
				$mindiv = "none";
418
			}
419
			else if ($displayarray[$widgetcounter] == "close"){
420
				$divdisplay = "none";
421
				$display = "block";
422
				$inputdisplay = "close";			
423
				$showdiv = "none";
424
				$mindiv = "inline";
425
			}
426
			else{
427
				$divdisplay = "none";
428
				$display = "block";
429
				$inputdisplay = "none";
430
				$showdiv = "none";
431
				$mindiv = "inline";
432
			}
433
		}
434
		else
435
		{
436
			if ($firstprint == false){
437
				$divdisplay = "block";
438
				$display = "block";
439
				$inputdisplay = "show";					
440
				$showdiv = "none";
441
				$mindiv = "inline";
442
				$firstprint = true;
443
			}
444
			else
445
			{
446
				$divdisplay = "none";
447
				$display = "block";
448
				$inputdisplay = "close";			
449
				$showdiv = "none";
450
				$mindiv = "inline";
451
			}
452
		}
453
			
454
		
455
		if ($config['widgets']){
456
			if ($colpos[$widgetcounter] == "col2" && $printed == false)
457
			{
458
				$printed = true;
459
				?>
460
				</div>
461
				<div id="col2" style="float:right;width:49%;padding: 2px;padding-bottom:40px">		
462
				<?php
463
			}
464
		}
465
		else if ($widgetcounter >= $halftotal && $printed == false){
466
			$printed = true;
467
			?>
468
			</div>
469
			<div id="col2" style="float:right;width:49%;padding: 2px;padding-bottom:40px">		
470
			<?php
471
		}
472
					
473
		?>		
474
		<div style="clear:both;"></div>
475
		<div  id="<?php echo $widgetname;?>-div" class="widgetdiv" style="display:<?php echo $divdisplay; ?>;">
476
			<input type="hidden" value="<?php echo $inputdisplay;?>" id="<?php echo $widgetname;?>-div-input" name="<?php echo $widgetname;?>-div-input">
477
			<div id="<?php echo $widgetname;?>topic" class="widgetheader" style="cursor:move">
478
				<div style="float:left;">
479
					<?php echo $nicename;?>
480
				</div>
481
				<div align="right" style="float:right;">	
482
					<div id="<?php echo $widgetname;?>-configure" onclick='return configureDiv("<?php echo $widgetname;?>")' style="display:none; cursor:pointer" ><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_configure.gif" /></div>									
483
					<div id="<?php echo $widgetname;?>-open" onclick='return showDiv("<?php echo $widgetname;?>",true)' style="display:<?php echo $showdiv;?>; cursor:pointer" ><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_open.gif" /></div>	
484
					<div id="<?php echo $widgetname;?>-min" onclick='return minimizeDiv("<?php echo $widgetname;?>",true)' style="display:<?php echo $mindiv;?>; cursor:pointer" ><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_minus.gif"/></div>												
485
					<div id="<?php echo $widgetname;?>-close" onclick='return closeDiv("<?php echo $widgetname;?>",true)' style="display:inline; cursor:pointer" ><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_close.gif" /></div>	
486
				</div>
487
				<div style="clear:both;"></div>
488
			</div>
489
			<div id="<?php echo $widgetname;?>" style="display:<?php echo $display; ?>;">
490
				<?php include($directory . $widget); ?>
491
			</div>
492
			<div style="clear:both;"></div>
493
		</div>
494
		<?php 	
495
	$widgetcounter++;
496
		}
497
	}//end foreach	
498
	?>			
499
	</div><!-- end col -->
500
	<?php  if ($printed == false){
501
			$printed = true;
502
			?>
503
			</div>
504
			<div id="col2" style="float:right;width:49%;padding: 2px;padding-bottom:40px"></div>
505
		
506
			<?php } ?>
507
	<div style="clear:both;"></div>
508
</div>
509

    
510
<?php include("fend.inc"); ?>
511
	    
512
<script type="text/javascript">
513

    
514
	// <![CDATA[
515
	Sortable.create("col1", {tag:'div',dropOnEmpty:true,containment:columns,handle:'widgetheader',constraint:false,only:'widgetdiv',onChange:showSave});	
516
	Sortable.create("col2", {tag:'div',dropOnEmpty:true,containment:columns,handle:'widgetheader',constraint:false,only:'widgetdiv',onChange:showSave});		
517
	// ]]>	
518
	
519
	<?php
520
	//build list of javascript include files
521
	$jsincludefiles = array();
522
	$directory = "widgets/javascript/";
523
	$dirhandle  = opendir($directory);
524
	$filename = "";
525
	while (false !== ($filename = readdir($dirhandle))) {
526
   		$jsincludefiles[] = $filename;
527
	}
528
	foreach($jsincludefiles as $jsincludename) {
529
		if(!stristr($jsincludename, ".js"))
530
			continue;	
531
		include($directory . $jsincludename);
532
	}
533
	?>
534
</script>
535
</form>
536
</body>
537
</html>
(72-72/181)