Mercurial > hg > mlmmj
annotate contrib/web/php-admin/htdocs/save.php @ 769:fc5892d87716
Update php code to use superglobals
author | Ben Schmidt |
---|---|
date | Fri, 29 Oct 2010 22:13:47 +1100 |
parents | 75fb7729c6e8 |
children | b9b60f3dd694 |
rev | line source |
---|---|
309 | 1 <?php |
2 | |
3 /* mlmmj/php-admin: | |
4 * Copyright (C) 2004 Christoph Thiel <ct at kki dot org> | |
5 * | |
6 * mlmmj/php-perl: | |
7 * Copyright (C) 2004 Morten K. Poulsen <morten at afdelingp.dk> | |
8 * Copyright (C) 2004 Christian Laursen <christian@pil.dk> | |
9 * | |
10 * Permission is hereby granted, free of charge, to any person obtaining a copy | |
11 * of this software and associated documentation files (the "Software"), to | |
12 * deal in the Software without restriction, including without limitation the | |
13 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
14 * sell copies of the Software, and to permit persons to whom the Software is | |
15 * furnished to do so, subject to the following conditions: | |
16 * | |
17 * The above copyright notice and this permission notice shall be included in | |
18 * all copies or substantial portions of the Software. | |
19 * | |
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
26 * IN THE SOFTWARE. | |
27 */ | |
28 | |
759
73c8715367fb
Better techniques for locating support files in php-admin
Ben Schmidt
parents:
732
diff
changeset
|
29 require(dirname(dirname(__FILE__))."/conf/config.php"); |
73c8715367fb
Better techniques for locating support files in php-admin
Ben Schmidt
parents:
732
diff
changeset
|
30 require(dirname(__FILE__)."/class.rFastTemplate.php"); |
309 | 31 |
32 function mlmmj_boolean($name, $nicename, $text) | |
33 { | |
769 | 34 global $tpl, $topdir, $list; |
309 | 35 |
36 $file = $topdir."/".$list."/control/".$name; | |
37 | |
769 | 38 if(isset($_POST[$name]) && !empty($_POST[$name])) |
309 | 39 { |
40 if(!touch($file)) | |
41 die("Couldn't open ".$file." for writing"); | |
732
b37f66e0852b
Ensure files written by php-admin have Unix EOL and sane permissions
Ben Schmidt
parents:
725
diff
changeset
|
42 if (!chmod($file, 0644)) |
b37f66e0852b
Ensure files written by php-admin have Unix EOL and sane permissions
Ben Schmidt
parents:
725
diff
changeset
|
43 die("Couldn't chmod ".$file); |
309 | 44 } |
45 else | |
46 @unlink($file); | |
47 } | |
48 | |
49 function mlmmj_string ($name, $nicename, $text) | |
50 { | |
51 mlmmj_list($name, $nicename, $text); | |
52 } | |
53 | |
54 function mlmmj_list($name, $nicename, $text) | |
55 { | |
769 | 56 global $tpl, $topdir, $list; |
309 | 57 |
58 $file = $topdir."/".$list."/control/".$name; | |
59 | |
769 | 60 if(isset($_POST[$name]) && !empty($_POST[$name])) |
309 | 61 { |
62 if (!$fp = fopen($file, "w")) | |
63 die("Couldn't open ".$file." for writing"); | |
64 | |
769 | 65 fwrite($fp, preg_replace('/\\r/',"",$_POST[$name])); |
309 | 66 fclose($fp); |
732
b37f66e0852b
Ensure files written by php-admin have Unix EOL and sane permissions
Ben Schmidt
parents:
725
diff
changeset
|
67 |
b37f66e0852b
Ensure files written by php-admin have Unix EOL and sane permissions
Ben Schmidt
parents:
725
diff
changeset
|
68 if (!chmod($file, 0644)) |
b37f66e0852b
Ensure files written by php-admin have Unix EOL and sane permissions
Ben Schmidt
parents:
725
diff
changeset
|
69 die("Couldn't chmod ".$file); |
309 | 70 } |
71 else | |
72 @unlink($file); | |
73 | |
74 } | |
75 | |
503 | 76 // Perl's encode_entities (to be able to use tunables.pl) |
77 function encode_entities($str) { return htmlentities($str); } | |
78 | |
79 | |
710
6d354f3a8d90
Replaced class.FastTemplate.php with class.rFastTemplate.php in contrib/web/php-admin (Christoph Thiel)
mortenp
parents:
687
diff
changeset
|
80 $tpl = new rFastTemplate($templatedir); |
309 | 81 |
769 | 82 $list = $_POST["list"]; |
309 | 83 |
384 | 84 if(!isset($list)) |
85 die("no list specified"); | |
86 | |
762
dbb144f085a5
Fix php-admin to work when topdir contains a symlink (e.g. on Mac)
Ben Schmidt
parents:
759
diff
changeset
|
87 if (dirname(realpath($topdir."/".$list)) != realpath($topdir)) |
725
d92234debf5c
Better validation of input in php-admin (Thomas Goirand)
Ben Schmidt
parents:
722
diff
changeset
|
88 die("list outside topdir"); |
722
773c6ef6fb10
Validate input in php-admin to avoid altering arbitrary files
Ben Schmidt
parents:
710
diff
changeset
|
89 |
309 | 90 if(!is_dir($topdir."/".$list)) |
91 die("non-existent list"); | |
92 | |
93 $tpl->define(array("main" => "save.html")); | |
94 $tpl->assign(array("LIST" => htmlentities($list))); | |
95 | |
759
73c8715367fb
Better techniques for locating support files in php-admin
Ben Schmidt
parents:
732
diff
changeset
|
96 $tunables = file_get_contents($confdir.'/tunables.pl'); |
503 | 97 eval($tunables); |
309 | 98 |
99 $tpl->parse("MAIN","main"); | |
100 $tpl->FastPrint("MAIN"); | |
101 | |
102 ?> |