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