]> Joshua Wise's Git repositories - patchfork.git/blob - player/config.php
Make config page refuse to allow you to select the mini theme (it should only be...
[patchfork.git] / player / config.php
1 <?php
2 /* 
3     Pitchfork Music Player Daemon Client
4     Copyright (C) 2007  Roger Bystrøm
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; version 2 of the License.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19         require_once("../inc/function_test.php");
20         function get_checkbox_from_config($name) {
21                 $var = get_config($name);
22                 if(!is_null($var)&&strlen($var)) {
23                         return "checked='checked'";
24                 }
25                 return "";
26         }
27
28         function return_bytes($val) {
29             $val = trim($val);
30             $last = strtolower($val{strlen($val)-1});
31             switch($last) {
32                 // The 'G' modifier is available since PHP 5.1.0
33                 case 'g':
34                     $val *= 1024;
35                 case 'm':
36                     $val *= 1024;
37                 case 'k':
38                     $val *= 1024;
39             }
40
41             return $val;
42         }
43
44
45         $title = "";
46         @ob_start();
47         require_once("../inc/base.php");
48         require_once("../lang/master.php");
49         header("Content-Type: text/html; charset=UTF-8");
50 ?>
51 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
52 <html>
53 <head>
54 <meta name="robots" content="noindex,nofollow" />
55 <style type="text/css"> 
56         body {
57                 font: 12.4px/160% sans-serif;
58         }
59         .main_container {
60                 border: 1px solid #e2e2e2;
61                 background-color: #f7f7f7; 
62                 padding-left: 8px;
63                 padding-bottom: 10px; 
64         }
65         .red-box {
66                 border:         1px solid #a20000;
67                 background-color: #ffcccc;
68                 padding-left: 5px;
69         }
70         #pinfo {
71                 border: 1px solid #877E6E; 
72                 background-color: #DEE7F7; 
73                 background: #f1f1f1;
74                 padding: 0px 5px 0px 5px;
75                 position: absolute;
76                 top: 30px;
77                 right: 20px;
78         }
79         select, input {
80                 font-size: 0.90em;
81                 line-height: 1em;
82         }
83 </style>
84 <script type='text/javascript'>
85         var showing = false;
86         function toggle_showing_plentries() {
87                 var e = null;
88                 var i =3; 
89                 showing = !showing;
90                 while(e = document.getElementById('ple_' + i)) {
91                         e.style.display = showing?"":"none";
92                         i++;
93                 }
94                 var t = document.getElementById('plentry_show');
95                 t.innerHTML = showing?"&nbsp;&nbsp;Hide nonstandard [~]":"&nbsp;&nbsp;Show nonstandard [+]";
96         }
97 </script>
98 <title><?php echo m("Pitchfork MPD Client Configuration"); ?></title>
99 </head>
100 <body>
101 <?php
102         $new_config = $config?false:true;
103         if(!$config) {
104                 $config = simplexml_load_string("<?xml version='1.0' ?>\n<root>\n</root>\n");
105         }
106         if(isset($_POST['submit'])) {
107                 $vars = array( 'mpd_host', 'mpd_port', 'mpd_pass', 'login_pass', 'update_delay', 
108                                 'metadata_disable', 'theme', 'stop_button', 'shout_url', 'pagination', 'lang',
109                                 'aws_keyid', 'aws_secret');
110                 foreach ($vars as $var) {
111                         $add = "";
112                         if(isset($_POST[$var])&&trim($_POST[$var])!="") 
113                                 $add = trim($_POST[$var]);
114                         
115                         if($var=="pagination") {
116                                 if(!is_numeric($add))
117                                         $add = 0;
118                                 else $add = intval($add);
119                         }
120                         else if($var=="login_pass"&&strlen($add)>0) {
121                                 if($add== HASH_PASS)
122                                         continue;
123                                 $add = generate_hash($add);
124                         }
125                         else if ($var=='aws_secret') {
126                                 if ($add == HASH_PASS)
127                                         continue;
128                         }
129
130                         
131                         if(isset($config->$var)) {
132                                 $config->$var = $add;
133                         }
134                         else {
135                                 $config->addChild($var, $add);
136                         }
137                 }
138
139                 $plentry = null;
140                 if(isset($config->plentry))
141                         $plentry = $config->plentry;
142                 else 
143                         $plentry = $config->addChild("plentry");
144
145                 foreach($pl_fields as $field) {
146                         $val = isset($_POST['plentry_' . $field])?"yes":"";
147                         $plentry->$field = $val;
148                 }
149
150                 // need to save config!
151                 if($config->asXML("../config/config.xml")) {
152                         header("Location: index.php");
153                         echo "<p>If you're not redirected, go here: <a href='index.php'>player</a></p>";
154                         exit();
155                 }
156                 else {
157                         echo "<p class='error'>Could not save your configuration, check that config/config.xml is writeable</p>\n";
158                 }
159         }
160
161         if(!is_writeable("../config")) {
162                 echo "<p class='red-box'>";
163                 echo m("Warning: Your config/ directory is not writeable! Please change owner of directory to apache user.");
164                 echo "</p>\n";
165         }
166         @ob_end_flush();
167
168 ?>
169
170
171
172 <div class='main_container' id='main_container'>
173
174 <h1>Pitchfork configuration</h1>
175
176 <?php if(isset($_GET['new_config'])) 
177         echo "<p>" . m("Let us take a minute to configure this player") . "</p>\n";
178    else echo "<p>" . m("Configure settings") . "</p>";
179 ?>
180 <form action="config.php<?php echo $new_config?'?new_config':''; ?>" method="post">
181 <h2><?php echo m("Connection-settings"); ?> </h2>
182 <p><?php echo m("Where can I find your MPD-server?"); ?></p>
183 <table>
184 <tr><td><?php echo m("Hostname:"); ?> </td>
185 <td><input type='text' value='<?php echo  htmlspecialchars(get_config('mpd_host', 'localhost')) ?>' name='mpd_host' /></td></tr>
186 <tr><td><?php echo m("Port:");?>
187 </td><td><input type='text' value='<?php echo htmlspecialchars(get_config('mpd_port', '6600')) ?>' name='mpd_port' /></td></tr>
188 <tr><td><?php echo m("Password:");?>
189 </td><td><input type='password' value='<?php echo htmlspecialchars(get_config('mpd_pass', '')) ?>' name='mpd_pass' /></td></tr>
190
191 </table>
192 <h2><?php echo m("User interface");?></h2>
193 <p><?php echo m("Some other settings!");?><br/></p>
194 <table>
195 <tr><td><?php echo m("Update time:"); ?> 
196 </td><td><input type='text' title='<?php echo m("How often we should request updates from the server");?>' value='<?php echo htmlspecialchars(get_config('update_delay', '1')) ?>' name='update_delay' /></td></tr>
197         <tr><td><?php echo m("Login password (optional):");?>
198         </td><td><input type='password' title='<?php echo m("If you want to require a password to see these pages you may specify it here");?>' value='<?php 
199         
200         $pass = get_config('login_pass', '');
201         if(substr($pass,0, 4)=="sha:") {
202                 echo HASH_PASS;
203         }
204         else {
205                 echo htmlspecialchars($pass);
206         }
207
208 ?>' name='login_pass' /></td></tr>
209 <tr><td><?php echo m("Theme:");?> </td>
210 <td>
211 <select name='theme'>
212 <?php
213 $themes = get_available_themes();
214 $ctheme = get_config("theme", "default");
215 foreach($themes as $theme) {
216         if ($theme == "mini")
217                 continue;
218         echo "\n<option value='$theme' ";
219         if($theme==$ctheme)
220                 echo "selected='selected' ";
221         echo ">$theme</option>";
222 }
223
224 ?>
225 </select>
226 </td>
227 </tr>
228 <tr><td><?php echo m("Language:");?> </td><td>
229 <select name="lang">
230 <?php 
231         // TODO: move
232         $languages = array("eu" => "Basque", "en" => "English", "fr" => "French", "de" => "German");
233         $clang = get_config("lang", "en");
234         foreach($languages as $l => $n) {
235                 echo "\n<option value='$l'";
236                 if($l==$clang)
237                         echo " selected='selected' ";
238                 echo ">$n</option>";
239         }
240 ?>
241 </select>
242 </td></tr>
243
244 <tr><td><?php echo m("Include stop button:");?></td><td>
245 <input type='checkbox' <?php if(!is_null(get_config("stop_button"))) echo "checked='checked'"; ?> name='stop_button' value='yesplease' />
246 </td></tr>
247 <tr><td><?php echo m("Pagination:");?></td><td><input name='pagination' type='text' value="<?php echo get_config("pagination", 0); ?>" 
248 title="<?php echo m("Maximum number of entries pr. page. Set to 0 to disable.");?>" size="5" /></td></tr>
249 <tr><td>&nbsp; </td><td> </td></tr>
250 <tr><td colspan="2"><?php echo m("Show these fields in the playlist:");?> </td></tr>
251 <tr><td>&nbsp;</td><td><input type='checkbox' disabled='disabled' checked='checked' id='tnode_1' /> <label for='tnode_1'>
252 <?php echo m("Position"); ?></label></td></tr>
253 <?php
254
255 $selected_fields = get_selected_plfields();
256 $length = count($pl_fields);
257 for($i=0; $i<$length;$i++) {
258         if($i==3) {
259                 echo "<tr><td colspan='2' style='cursor: pointer;' id='plentry_show' onclick='toggle_showing_plentries();'>&nbsp;&nbsp;";
260                 echo m("Show nonstandard") . " [+]</td></tr>";
261         }
262         echo "<tr id='ple_$i' ";
263         if($i>=3)
264                 echo "style='display: none; ' ";
265         echo "><td>&nbsp;</td><td>";
266         echo "<input type='checkbox' ";
267         if($selected_fields[$i])
268                 echo "checked='checked' ";
269         echo "name='plentry_".$pl_fields[$i]."' id='pl_i_$i' /> <label for='pl_i_$i'>".$pl_fields[$i]."</label></td></tr>\n";
270 }
271
272 ?>
273 <tr><td>&nbsp;</td><td><input type='checkbox' disabled='disabled' checked='checked' id='tnode_2' /> <label for='tnode_2'> Time</label></td></tr>
274 </table>
275 <h2>Metadata</h2>
276 <p><?php echo m("Configuration for retrieving metadata. This requires that the machine Patchfork is running on can access the internet. ".
277                 "In order to use this feature, you must now have an Amazon AWS account; to get one, <a href=\"http://aws.amazon.com\">visit aws.amazon.com</a>. ".
278                 "Then, get an <a href=\"https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key\">access key</a>, and fill in the details below."); ?></p>
279 <table>
280 <tr><td><?php echo m("Disable metadata:"); ?> </td><td><input type='checkbox' <?php echo get_checkbox_from_config('metadata_disable') ?> name='metadata_disable' /></td></tr>
281 <tr><td><?php echo m("Amazon Access Key ID:"); ?></td><td><input type='text' width='20' value='<?php echo htmlspecialchars(get_config('aws_keyid', '')) ?>' name='aws_keyid' /></td></tr>
282 <tr><td><?php echo m("Amazon Secret Access Key:"); ?></td><td><input type='password' width='40' value='<?
283         $pass = get_config('aws_secret', '');
284         if(strlen($pass) != 0) {
285                 echo HASH_PASS;
286         }
287         ?>' name='aws_secret' /></td></tr>
288 </table>
289 <h2><?php echo m("Shoutcast integration"); ?></h2>
290 <p>
291 <?php echo m("Optionally specify the URL to the shout stream provided by mpd to enable integration with pitchfork.");?> <br/>
292 <input size="35" type='text' name='shout_url' value='<?php if(!is_null(get_config("shout_url"))) echo htmlspecialchars(get_config("shout_url")); ?>' />
293 </p>
294 <p style='padding: 12px 0px 12px 00px;'>
295 <input name='cancel' type='button' value='Cancel' onclick='window.location = "index.php" ' />
296 <input name='submit' type="submit" value="Save" />
297 </p>
298 </form>
299 <?php if(!isset($_GET['new_config'])) { ?>
300 <hr/>
301 <p>
302 For lyrics search to work in the directory browser file-names has to be saved with the lyrics, however when you move/delete files from your library this file reference become wrong. This button removes any references to such files.
303 <br/>
304 <span id='housecleaning_info'></span>
305 <input type='button' value='Housecleaning' onclick='location.href="metadata.php?housecleaning"'/>
306 </p>
307 <?php } 
308
309 function print_yesno($test, $fatal) {
310         if($test) return "<span style='color: green;'>" . m("Yes") . "</span>";
311         else return "<span style='color: " . ($fatal?"red":"orange") . ";'>" . m("No") . "</span>";
312 }
313
314 // function_name:fatal (0/1)
315 function test_function($stuff) {
316         $stuff = explode(":", $stuff);
317         $name = $stuff[0];
318         echo $name . ": ";
319         echo print_yesno(function_exists($name), $stuff[1]);
320         echo "<br/>\n";
321 }
322
323 ?>
324
325 <div id='pinfo'>
326 <h2><?php echo m("Pitchfork info"); ?></h2>
327 <p style='padding: 0px 0px 4px 0px;'>
328 <?php 
329         echo m("Release version:") . " $release_version<br/>\n";
330         echo m("Release date:") . " $release_date<br/><br/>\n";
331         $pl = get_playback();
332         $has_commands = true;
333         try {
334                 if($pl) {
335                         $commands = $pl->getCommands();
336                         /* these are just some of the needed commands */
337                         $needed = array("outputs", "disableoutput", "enableoutput", "plchangesposid");
338                         $res = array_intersect($needed, $commands);
339                         if(count($res)!=count($needed))
340                                 $has_commands = false;
341                         $pl->disconnect();
342                 }
343         }
344         catch(PEAR_Exception $e) {
345                 $has_commands = false;
346         }
347
348         echo m("Connect to mpd:"). " ". print_yesno($pl, true) . "<br/>\n";
349         if($pl) {
350                 echo m("MPD commands:")." " . print_yesno($has_commands, true) . "<br />\n";
351         }
352         echo m("Metadata directory:"). " " . print_yesno((file_exists($metadata_dir)&&is_writeable($metadata_dir))
353                                 ||(!file_exists($metadata_dir)&&is_writeable($config_dir)), true);
354 ?>
355 </p>
356
357 <h3><?php echo m("Functions:"); ?></h3>
358 <p style='padding: 0px 0px 4px 0px; '>
359 <?php 
360         // name:fatal
361         foreach(array("json_encode:0", "simplexml_load_string:1", "mb_internal_encoding:0") as $f)
362                 test_function($f);
363         echo "SimpleXMLaddChild: ";
364         $sxe = array_to_xml(array("test"));
365         if($sxe)
366                 echo print_yesno(is_callable(array($sxe, "addChild"), true), true) . "<br/>";
367         else echo "<span class='color: red'>error</span>\n";
368         $mem = ceil(return_bytes(ini_get("memory_limit"))/(1024*1024));
369         echo m("PHP memory limit:") . " <span style='color: " . ($mem<32?"orange":"green") . "'>" . $mem . "MB</span>";
370
371 ?>
372 </p>
373 <?php
374         if(get_magic_quotes_runtime()) {
375                 echo "<p style='color: orange'>";
376                 echo m("Warning: Magic quotes runtime is on, <br/>please use pitchfork.conf or turn<br/> of manually.");
377                 echo "</p>\n";
378         }
379         if(get_magic_quotes_gpc()) {
380                 echo "<p style='color: orange'>";
381                 echo m("Warning: Magic quotes gpc is on, <br/>please use pitchfork.conf or turn<br/> of manually.");
382                 echo "</p>\n";
383         }
384
385 ?>
386 </div>
387
388 </div>
389
390 </body>
391 </html>
This page took 0.046377 seconds and 4 git commands to generate.