Project

General

Profile

Download (19.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
    pkg.php
5
    Copyright (C) 2004-2012 Scott Ullrich <sullrich@gmail.com>
6
    All rights reserved.
7

    
8
    Redistribution and use in source and binary forms, with or without
9
    modification, are permitted provided that the following conditions are met:
10

    
11
    1. Redistributions of source code must retain the above copyright notice,
12
       this list of conditions and the following disclaimer.
13

    
14
    2. Redistributions in binary form must reproduce the above copyright
15
       notice, this list of conditions and the following disclaimer in the
16
       documentation and/or other materials provided with the distribution.
17

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

    
33
##|+PRIV
34
##|*IDENT=page-package-settings
35
##|*NAME=Package: Settings page
36
##|*DESCR=Allow access to the 'Package: Settings' page.
37
##|*MATCH=pkg.php*
38
##|-PRIV
39

    
40
require_once("guiconfig.inc");
41
require_once("pkg-utils.inc");
42

    
43
function gentitle_pkg($pgname) {
44
	global $config;
45
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
46
}
47

    
48
function domTT_title($title_msg){
49
	print "onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\" onmouseover=\"domTT_activate(this, event, 'content', '{$title_msg}', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle');\"";
50
}
51

    
52
$xml = $_REQUEST['xml'];
53

    
54
if($xml == "") {
55
	print_info_box_np(gettext("ERROR: No package defined."));
56
	exit;
57
} else {
58
	if(file_exists("/usr/local/pkg/" . $xml))
59
		$pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
60
	else {
61
		echo "File not found " . htmlspecialchars($xml);
62
		exit;
63
	}
64
}
65

    
66
if($pkg['donotsave'] <> "") {
67
	Header("Location: pkg_edit.php?xml=" . $xml);
68
	exit;
69
}
70

    
71
if ($pkg['include_file'] != "") {
72
	require_once($pkg['include_file']);
73
}
74

    
75
$package_name = $pkg['menu'][0]['name'];
76
$section      = $pkg['menu'][0]['section'];
77
$config_path  = $pkg['configpath'];
78
$title	      = $pkg['title'];
79

    
80
if($_REQUEST['startdisplayingat']) 
81
	$startdisplayingat = $_REQUEST['startdisplayingat'];
82

    
83
if($_REQUEST['display_maximum_rows']) 
84
	if($_REQUEST['display_maximum_rows'])
85
		$display_maximum_rows = $_REQUEST['display_maximum_rows'];
86

    
87
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
88

    
89
if ($_GET['act'] == "update") {
90
		if(is_array($config['installedpackages'][$pkg['name']]) && $pkg['name'] != ""){
91
			#get current values
92
			$current_values=$config['installedpackages'][$pkg['name']]['config'];
93
			#get updated ids
94
			$update_list=explode(",",$_GET['ids']);
95
			#sort ids to know what to change
96
			$sort_list=$update_list;
97
			sort($sort_list);
98
			#apply updates
99
			foreach(explode(",",$_GET['ids']) as $key=> $value){
100
				$config['installedpackages'][$pkg['name']]['config'][$sort_list[$key]]=$current_values[$update_list[$key]];
101
				}
102
			#save current config
103
			write_config();
104
			#sync package
105
			eval ("{$pkg['custom_php_resync_config_command']}");
106
			}
107
}
108

    
109
if ($_GET['act'] == "del") {
110
		// loop through our fieldnames and automatically setup the fieldnames
111
		// in the environment.  ie: a fieldname of username with a value of
112
		// testuser would automatically eval $username = "testuser";
113
		foreach ($evaledvar as $ip) {
114
			if($pkg['adddeleteeditpagefields']['columnitem'])
115
			  foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
116
				  ${xml_safe_fieldname($column['fielddescr'])} = $ip[xml_safe_fieldname($column['fieldname'])];
117
			  }
118
		}
119

    
120
		$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
121

    
122
		if ($a_pkg[$_GET['id']]) {
123
			unset($a_pkg[$_GET['id']]);
124
			write_config();
125
			if($pkg['custom_delete_php_command'] <> "") {
126
			    if($pkg['custom_php_command_before_form'] <> "")
127
					eval($pkg['custom_php_command_before_form']);
128
		    		eval($pkg['custom_delete_php_command']);
129
			}
130
			header("Location:  pkg.php?xml=" . $xml);
131
			exit;
132
	    }
133
}
134

    
135
ob_start();
136

    
137
$iflist = get_configured_interface_with_descr(false, true);
138
$evaledvar = $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
139

    
140
if($pkg['custom_php_global_functions'] <> "")
141
	eval($pkg['custom_php_global_functions']);
142

    
143
if($pkg['custom_php_command_before_form'] <> "")
144
	eval($pkg['custom_php_command_before_form']);
145

    
146
$pgtitle = array($title);
147
include("head.inc");
148

    
149
?>
150

    
151
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
152
<?php
153
include("fbegin.inc");
154
?>
155
<form action="pkg.php" name="pkgform" method="get">
156
<input type='hidden' name='xml' value='<?=$_REQUEST['xml']?>'>
157
<? if($_GET['savemsg'] <> "") $savemsg = htmlspecialchars($_GET['savemsg']); ?>
158
<?php if ($savemsg) print_info_box($savemsg); ?>
159
<table width="100%" border="0" cellpadding="0" cellspacing="0">
160
<?php
161
if ($pkg['tabs'] <> "") {
162
    $tab_array = array();
163
    foreach($pkg['tabs']['tab'] as $tab) {
164
        if($tab['tab_level'])
165
            $tab_level = $tab['tab_level'];
166
        else
167
            $tab_level = 1;
168
        if(isset($tab['active'])) {
169
            $active = true;
170
        } else {
171
            $active = false;
172
        }
173
		if(isset($tab['no_drop_down']))
174
			$no_drop_down = true;
175
        $urltmp = "";
176
        if($tab['url'] <> "") $urltmp = $tab['url'];
177
        if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml'];
178

    
179
        $addresswithport = getenv("HTTP_HOST");
180
        $colonpos = strpos($addresswithport, ":");
181
        if ($colonpos !== False) {
182
            //my url is actually just the IP address of the pfsense box
183
            $myurl = substr($addresswithport, 0, $colonpos);
184
        } else {
185
            $myurl = $addresswithport;
186
        }
187
        // eval url so that above $myurl item can be processed if need be.
188
        $url = str_replace('$myurl', $myurl, $urltmp);
189

    
190
        $tab_array[$tab_level][] = array(
191
                        $tab['text'],
192
                        $active,
193
                        $url
194
                    );
195
    }
196

    
197
    ksort($tab_array);
198
    foreach($tab_array as $tab) {
199
		echo '<tr><td>';
200
		display_top_tabs($tab, $no_drop_down);
201
        echo '</td></tr>';
202
    }
203
}
204
?>
205
<script>
206
	function setFilter(filtertext) {
207
		$('pkg_filter').value = filtertext;
208
		document.pkgform.submit();
209
	}
210
</script>
211

    
212
<?
213
if($pkg['adddeleteeditpagefields']['movable']){
214
?>
215
        <style type="text/css">
216
            td {
217
                border:0px solid black;
218
            }
219
            
220
            td.up {
221
                cursor:pointer;
222
            }
223

    
224
            td.down {
225
                cursor:pointer;
226
            }
227
            
228
        </style>
229

    
230

    
231
 <script type="text/javascript">
232
                Event.observe(window, "load", function() {
233
                    $$(".up").each(function(element) {
234
                        element.observe("click", up);
235
                    });
236

    
237
                    $$(".down").each(function(element) {
238
                        element.observe("click", down);
239
                    });
240
                });
241

    
242
                
243
                function up(event) {
244
                    var element = event.element().ancestors()[1];
245
                    var previous = element.previous('.movable');
246
                    if (previous) {
247
                        previous.remove();
248
                        element.insert({after:previous});
249
                    }
250
                }
251

    
252
                function down(event) {
253
                    var element = event.element().ancestors()[1];
254
                    var next = element.next('.movable');
255
                    if (next) {
256
                        next.remove();
257
                        element.insert({before:next});
258
                    }
259
                }
260

    
261
                function alertItems() {
262
                         ids = $$('tr[class="movable"]').collect(function(el) { return el.id; });
263
                         return(ids.join(','));
264
                }
265

    
266
                function save_changes_to_xml(xml) {
267
                	if(confirm("<?=gettext("Do you really want to save changes?");?>")){
268
                		var axel = Math.random() + "";
269
    					var num = axel * 1000000000000000000;
270
                		location.href="/pkg.php?xml=" + xml + "&act=update&ids=" + alertItems() + "&nocache=" + num;
271
                		}
272
                    
273
                }
274
                
275
        </script>
276

    
277
<?php }
278
echo "\t<script type=\"text/javascript\" src=\"javascript/domTT/domLib.js\"></script>\n";
279
echo "\t<script type=\"text/javascript\" src=\"javascript/domTT/domTT.js\"></script>\n";
280
echo "\t<script type=\"text/javascript\" src=\"javascript/domTT/behaviour.js\"></script>\n";
281
echo "\t<script type=\"text/javascript\" src=\"javascript/domTT/fadomatic.js\"></script>\n";
282
?>
283
<tr><td><div id="mainarea"><table width="100%" border="0" cellpadding="0" cellspacing="0">
284
	<tr>
285
		<td class="tabcont">
286
			<table width="100%" border="0" cellpadding="6" cellspacing="0">
287
			<tbody>
288
<?php
289
				/* Handle filtering bar A-Z */				
290
				$include_filtering_inputbox = false;
291
				$colspan = 0;
292
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") 
293
					foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column)
294
						$colspan++;
295
				if($pkg['fields']['field']) {
296
					// First find the sorting type field if it exists
297
					foreach($pkg['fields']['field'] as $field) {
298
						if($field['type'] == "sorting") {
299
							$sortable="on";
300
							if(isset($field['include_filtering_inputbox'])) 
301
								$include_filtering_inputbox = true;
302
							if($display_maximum_rows < 1) 
303
								if($field['display_maximum_rows']) 
304
									$display_maximum_rows = $field['display_maximum_rows'];
305
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
306
							echo "Filter by: ";
307
							$isfirst = true;
308
							for($char = 65; $char < 91; $char++) {
309
								if(!$isfirst) 
310
									echo " | ";
311
								echo "<a href=\"#\" onClick=\"setFilter('" . chr($char) . "');\">" . chr($char) . "</a>";
312
								$isfirst = false;
313
							}
314
							echo "</td></tr>";
315
							echo "<tr><td class='listhdrr' colspan='$colspan'><center>";
316
							if($field['sortablefields']) {
317
								echo "Filter field: <select name='pkg_filter_type'>";
318
								foreach($field['sortablefields']['item'] as $si) {
319
									if($si['name'] == $_REQUEST['pkg_filter_type']) 
320
										$SELECTED = "SELECTED";
321
									else 
322
										$SELECTED = "";
323
									echo "<option value='{$si['name']}' {$SELECTED}>{$si['name']}</option>";
324
								}
325
								echo "</select>";
326
							}
327
							if($include_filtering_inputbox) 
328
								echo "&nbsp;&nbsp;Filter text: <input id='pkg_filter' name='pkg_filter' value='" . $_REQUEST['pkg_filter'] . "'> <input type='submit' value='Filter'>";
329
							echo "</td></tr><tr><td><font siez='-3'>&nbsp;</td></tr>";
330
						}
331
					}
332
				}
333
?>
334
				<tr>
335
<?php
336
				if($display_maximum_rows) {
337
					$totalpages = ceil(round((count($evaledvar) / $display_maximum_rows),9));
338
					$page = 1;
339
					$tmpcount = 0;
340
					$tmppp = 0;
341
					if(is_array($evaledvar)) {
342
						foreach ($evaledvar as $ipa) {
343
							if($tmpcount == $display_maximum_rows) {
344
								$page++;
345
								$tmpcount = 0;
346
							}
347
							if($tmppp == $startdisplayingat)
348
						 		break;
349
							$tmpcount++;
350
							$tmppp++;
351
						}
352
					}
353
					echo "<tr><td colspan='" . count($pkg['adddeleteeditpagefields']['columnitem']) . "'>";
354
					echo "<table width='100%'>";
355
					echo "<tr>";
356
					echo "<td align='left'>Displaying page $page of $totalpages</b></td>";
357
					echo "<td align='right'>Rows per page: <select onChange='document.pkgform.submit();' name='display_maximum_rows'>";
358
					for($x=5; $x<250; $x++) {
359
						if($x == $display_maximum_rows)
360
							$SELECTED = "SELECTED";
361
						else 
362
							$SELECTED = "";
363
						echo "<option value='$x' $SELECTED>$x</option>\n";
364
						$x=$x+4;
365
					}
366
					echo "</select></td></tr>";
367
					echo "</table>";
368
					echo "</td></tr>";
369
				}
370
				$cols = 0;
371
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
372
				    foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
373
						echo "<td class=\"listhdrr\">" . $column['fielddescr'] . "</td>";
374
						$cols++;
375
				    }
376
				}
377
				echo "</tr>";
378
				$i=0;
379
				$pagination_startingrow=0;
380
				$pagination_counter=0;
381
			    if($evaledvar)
382
			    foreach ($evaledvar as $ip) {
383
				if($startdisplayingat) {
384
					if($i < $startdisplayingat) {
385
						$i++;
386
						continue;
387
					}
388
				}
389
				if($_REQUEST['pkg_filter']) {
390
					// Handle filterered items
391
					if($pkg['fields']['field'] && !$filter_regex) {
392
						// First find the sorting type field if it exists
393
						foreach($pkg['fields']['field'] as $field) {
394
							if($field['type'] == "sorting") {
395
								if($field['sortablefields']['item']) {
396
									foreach($field['sortablefields']['item'] as $sf) {
397
										if($sf['name'] == $_REQUEST['pkg_filter_type']) {
398
											$filter_fieldname = $sf['fieldname'];
399
											if($sf['regex'])
400
												$filter_regex = str_replace("%FILTERTEXT%", $_REQUEST['pkg_filter'], trim($sf['regex']));
401
											else
402
												$filter_regex = "/{$_REQUEST['pkg_filter']}/i";
403
										}
404
									}
405
								}
406
							}
407
						}
408
					}
409
					// Do we have something to filter on?
410
					unset($filter_matches);
411
					if($pkg['adddeleteeditpagefields']['columnitem'] <> "") {
412
						foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
413
							$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
414
							if($column['fieldname'] == $filter_fieldname) {
415
								if($filter_regex) {
416
									//echo "$filter_regex - $fieldname<p/>";
417
									preg_match($filter_regex, $fieldname, $filter_matches);
418
									break;
419
								}
420
							}
421
						}
422
					}
423
					if(!$filter_matches) {
424
						$i++;
425
						continue;
426
					}
427
				}
428
				if($pkg['adddeleteeditpagefields']['movable'])
429
					echo "<tr valign=\"top\" class=\"movable\" id=\"$i\">\n";
430
				else
431
					echo "<tr valign=\"top\" >\n";
432
				if($pkg['adddeleteeditpagefields']['columnitem'] <> "")
433
					foreach ($pkg['adddeleteeditpagefields']['columnitem'] as $column) {
434
						if ($column['fieldname'] == "description")
435
							$class = "listbg";
436
						else
437
							$class = "listlr";
438
?>
439
						<td class="<?=$class;?>" ondblclick="document.location='pkg_edit.php?xml=<?=$xml?>&act=edit&id=<?=$i;?>';">
440
							<?php
441
								$fieldname = $ip[xml_safe_fieldname($column['fieldname'])];
442
								if ($column['type'] == "interface") {
443
									echo  $column['prefix'] . $iflist[$fieldname] . $column['suffix'];
444
							    } else {
445
							    	if ($column['encoding'] == "base64")
446
										echo  $column['prefix'] . base64_decode($fieldname) . $column['suffix'];
447
									else if($column['listmodeon'] && $fieldname == "on")
448
								   		echo $column['prefix'] . gettext($column['listmodeon']). $column['suffix'];
449
								   	else if($column['listmodeoff'] && $fieldname == "")
450
								    	echo $column['prefix'] .gettext($column['listmodeoff']). $column['suffix'];
451
									else
452
										echo $column['prefix'] . $fieldname ." ". $column['suffix'];
453
							    }
454
							?>
455
						</td>
456

    
457
							<?php
458
					}
459
?>
460

    
461
				<td valign="left" width="80" >
462
					<a href="pkg_edit.php?xml=<?=$xml?>&act=edit&id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" <?=domTT_title("Edit this item")?>></a>
463
					<a href="pkg.php?xml=<?=$xml?>&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this item?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" <?=domTT_title("Remove this item")?>></a>
464
					<?php if($pkg['adddeleteeditpagefields']['movable']){?>
465
						<!--http://prototypejs.org/api/element/previous-->
466
						<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_up.gif" class="up" width="17" height="17" border="0" <?=domTT_title("Move this item up")?>>
467
						<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_down.gif" class="down" width="17" height="17" border="0" <?=domTT_title("Move this item down")?>>
468
					<?php }?>
469
				</td>
470
</tr>
471
<?php
472

    
473
				// Handle pagination and display_maximum_rows
474
				if($display_maximum_rows) {
475
					if($pagination_counter == ($display_maximum_rows-1) or 
476
					   $i ==  (count($evaledvar)-1)) {
477
						$colcount = count($pkg['adddeleteeditpagefields']['columnitem']);
478
						$final_footer = "";
479
						$final_footer .= "<tr><td colspan='$colcount'>";
480
						$final_footer .=  "<table width='100%'><tr>";
481
						$final_footer .=  "<td align='left'>";
482
						$startingat = $startdisplayingat - $display_maximum_rows;
483
						if($startingat > -1) {
484
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat={$startingat}&display_maximum_rows={$display_maximum_rows}'>";
485
						} else {
486
							if($startingnat > 1) 
487
								$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=0&display_maximum_rows={$display_maximum_rows}'>";
488
						}
489
						$final_footer .=  "<font size='2'><< Previous page</a>";
490
						if($tmppp + $display_maximum_rows > count($evaledvar)) 
491
							$endingrecord = count($evaledvar);
492
						else 
493
							$endingrecord = $tmppp + $display_maximum_rows;
494
						$final_footer .=  "</td><td align='center'>";
495
						$tmppp++;
496
						$final_footer .=  "<font size='2'>Displaying {$tmppp} - {$endingrecord} / " . count($evaledvar) . " records";
497
						$final_footer .=  "</td><td align='right'>&nbsp;";
498
						if(($i+1) < count($evaledvar))
499
							$final_footer .=  "<a href='pkg.php?xml=" . $_REQUEST['xml'] . "&startdisplayingat=" . ($startdisplayingat + $display_maximum_rows) . "&display_maximum_rows={$display_maximum_rows}'>";
500
						$final_footer .=  "<font size='2'>Next page >></a>";	
501
						$final_footer .=  "</td></tr></table></td></tr>";
502
						$i = count($evaledvar);
503
						break;
504
					}
505
				}
506
				$i++;
507
				$pagination_counter++;
508
			    }
509
?>
510
				<tr>
511
					<td colspan="<?=$cols?>"></td>
512
					<td>
513
						<table border="0" cellspacing="0" cellpadding="1">
514
							<tr>
515
								<td valign="middle"><a href="pkg_edit.php?xml=<?=$xml?>&id=<?=$i?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" <?=domTT_title("Add a new item")?>></a></td>
516
								<?php if($pkg['adddeleteeditpagefields']['description']){?>
517
								<td valign="middle"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_info_pkg.gif" width="17" height="17" border="0" <?=domTT_title($pkg['adddeleteeditpagefields']['description'])?>></td>
518
								<?php }?>								
519
							</tr>
520
						</table>
521
					</td>
522
				</tr>
523
				<?=$final_footer?>
524
				<?php if($pkg['adddeleteeditpagefields']['movable']){?>
525
				<td><input class="formbtn" type="button" value="Save" name="Submit" onclick="save_changes_to_xml('<?=$xml?>')"></td>
526
				<?php }?>
527
				
528
				</tbody>
529
		</table>
530
	</td>
531
</tr>
532
</table>
533
</div></tr></td></table>
534

    
535
</form>
536
<?php include("fend.inc"); ?>
537

    
538
<?php
539
	echo "<!-- filter_fieldname: {$filter_fieldname} -->";
540
	echo "<!-- filter_regex: {$filter_regex} -->";
541
?>
542

    
543
</body>
544
</html>
(119-119/226)