root/modules/branches/2.4/music/page.music.php

Revision 10462, 11.0 kB (checked in by p_lindheimer, 2 years ago)

Merged revisions 10461 via svnmerge from
http://www.freepbx.org/v2/svn/modules/branches/2.5

................

r10461 | p_lindheimer | 2010-11-01 13:13:34 -0700 (Mon, 01 Nov 2010) | 46 lines


Merged revisions 10460 via svnmerge from
http://www.freepbx.org/v2/svn/modules/branches/2.6


................

r10460 | p_lindheimer | 2010-11-01 13:02:25 -0700 (Mon, 01 Nov 2010) | 39 lines


Merged revisions 10399-10418,10420-10422,10424-10426,10428-10429,10432,10436-10458 via svnmerge from
http://www.freepbx.org/v2/svn/modules/branches/2.7


................

r10399 | GameGamer?43 | 2010-10-14 10:05:48 -0700 (Thu, 14 Oct 2010) | 1 line


closes #4590 - fixes issues with phonebook import

................

r10457 | p_lindheimer | 2010-11-01 12:46:35 -0700 (Mon, 01 Nov 2010) | 24 lines


Merged revisions 10456 via svnmerge from
http://svn.freepbx.org/modules/branches/2.8


................

r10456 | p_lindheimer | 2010-11-01 12:39:25 -0700 (Mon, 01 Nov 2010) | 17 lines


Merged revisions 10444,10447,10449-10451,10453-10455 via svnmerge from
http://svn.freepbx.org/modules/branches/2.9


........

r10444 | mbrevda | 2010-10-25 05:43:18 -0700 (Mon, 25 Oct 2010) | 1 line


re #4604 - potential injection when uploading files. Can be closed by when published/backported

........

r10454 | p_lindheimer | 2010-11-01 10:51:02 -0700 (Mon, 01 Nov 2010) | 1 line


block xss re #4615

........

r10455 | p_lindheimer | 2010-11-01 12:12:39 -0700 (Mon, 01 Nov 2010) | 1 line


changes to some of the fixes re #4604

........

................

................

r10458 | p_lindheimer | 2010-11-01 12:49:10 -0700 (Mon, 01 Nov 2010) | 1 line


update xml re #4590

................

................

................

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php /* $Id$ */
2 //Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)
3 //
4 //This program is free software; you can redistribute it and/or
5 //modify it under the terms of the GNU General Public License
6 //as published by the Free Software Foundation; either version 2
7 //of the License, or (at your option) any later version.
8 //
9 //This program is distributed in the hope that it will be useful,
10 //but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //GNU General Public License for more details.
13 ?>
14
15 <?php
16 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
17 $randon = isset($_REQUEST['randon'])?$_REQUEST['randon']:'';
18 $randoff = isset($_REQUEST['randoff'])?$_REQUEST['randoff']:'';
19 $category = strtr(isset($_REQUEST['category'])?$_REQUEST['category']:''," ./\"\'\`", "------");
20 if ($category == null) $category = 'default';
21 $display='music';
22
23 global $asterisk_conf;
24
25 if ($category == "default")
26   $path_to_dir = $asterisk_conf['astvarlibdir']."/mohmp3"; //path to directory u want to read.
27 else
28   $path_to_dir = $asterisk_conf['astvarlibdir']."/mohmp3/$category"; //path to directory u want to read.
29
30
31 if (strlen($randon)) {
32   touch($path_to_dir."/.random");
33   createmusicconf();
34 }
35 if (strlen($randoff)) {
36   unlink($path_to_dir."/.random");
37   createmusicconf();
38 }
39 switch ($action) {
40   case "addednew":
41     makemusiccategory($path_to_dir,$category);
42     createmusicconf();
43     needreload();
44     redirect_standard();
45   break;
46   case "addedfile":
47     createmusicconf();
48     needreload();
49 //    redirect_standard();
50   break;
51   case "delete":
52     music_rmdirr("$path_to_dir");
53     $path_to_dir = $asterisk_conf['astvarlibdir']."/mohmp3"; //path to directory u want to read.
54     $category='default';
55     createmusicconf();
56     needreload();
57     redirect_standard();
58   break;
59 }
60
61
62 ?>
63 </div>
64 <div class="rnav"><ul>
65     <li><a href="config.php?display=<?php echo urlencode($display)?>&action=add"><?php echo _("Add Music Category")?></a></li>
66
67 <?php
68 //get existing trunk info
69 $tresults = music_list($asterisk_conf['astvarlibdir']."/mohmp3");
70 if (isset($tresults)) {
71   foreach ($tresults as $tresult) {
72     if ($tresult != "none") {
73       echo "<li><a id=\"".($category==$tresult ? 'current':'')."\" href=\"config.php?display=".urlencode($display)."&category=".urlencode($tresult)."&action=edit\">{$tresult}</a></li>";
74     }
75   }
76 }
77 ?>
78 </ul></div>
79
80
81 <?php
82 function createmusicconf()
83 {
84   global $asterisk_conf;
85
86   $File_Write="";
87   $tresults = music_list($asterisk_conf['astvarlibdir']."/mohmp3");
88   if (isset($tresults)) {
89     foreach ($tresults as $tresult)  {
90       // hack - but his is all a hack until redone, in functions, etc.
91       // this puts a none category to allow no music to be chosen
92       //
93       if ($tresult == "none") {
94         $dir = "/dev/null";
95         $File_Write.="[{$tresult}]\nmode=files\ndirectory={$dir}\n";
96         continue;
97       }
98       if ($tresult != "default" ) {
99         $dir = $asterisk_conf['astvarlibdir']."/mohmp3/{$tresult}/";
100       } else {
101         $dir = $asterisk_conf['astvarlibdir']."/mohmp3/";
102       }
103       if (file_exists("{$dir}.random")) {
104         $File_Write.="[{$tresult}]\nmode=files\ndirectory={$dir}\nrandom=yes\n";
105       } else {
106         $File_Write.="[{$tresult}]\nmode=files\ndirectory={$dir}\n";
107       }
108     }
109   }
110
111
112   $handle = fopen("/etc/asterisk/musiconhold_additional.conf", "w");
113
114   if (fwrite($handle, $File_Write) === FALSE) {
115     echo _("Cannot write to file")." ($tmpfname)";
116     exit;
117   }
118
119   fclose($handle);
120
121   needreload();
122 }
123
124 function makemusiccategory($category)
125 {
126   mkdir("$path_to_dir/$category", 0755);
127 }
128  
129 function build_list()
130 {
131   global $path_to_dir;
132   $pattern = '';
133   $handle=opendir($path_to_dir) ;
134   $extensions = array('mp3','wav'); // list of extensions to match
135  
136   //generate the pattern to look for.
137   $pattern = '/(\.'.implode('|\.',$extensions).')$/i';
138  
139   //store file names that match pattern in an array
140   $i = 0;
141   while (($file = readdir($handle))!==false)
142   {
143     if ($file != "." && $file != "..")
144     {
145    
146       if(preg_match($pattern,$file))
147       {
148         $file_array[$i] = $file; //pattern is matched store it in file_array.
149         $i++;   
150       }
151     }
152  
153   }
154   closedir($handle);
155  
156   return (isset($file_array))?$file_array:null;  //return the size of the array
157  
158 }
159
160 function draw_list($file_array, $path_to_dir, $category)
161 {
162   global $display;
163   //list existing mp3s and provide delete buttons
164   if ($file_array) {
165     foreach ($file_array as $thisfile) {
166       print "<div style=\"text-align:right;width:350px;border: 1px solid;padding:2px;\">";
167       //print "<a style=\"float:left;margin-left:5px;\" href=\"file:". $path_to_dir ."". $thisfile ."\">".$thisfile."</a>";
168       print "<b style=\"float:left;margin-left:5px;\" >".$thisfile."</b>";
169       print "<a style=\"margin-right:5px;\" href=\"".$_SERVER['SCRIPT_NAME']."?display=";
170       print (isset($display)?$display:'')."&del=".urlencode($thisfile)."&category=".$category."\">"._("Delete")."</a>";
171       print "</div><br>";
172     }
173   }
174 }
175
176 function process_mohfile($mohfile,$onlywav=false)
177 {
178   global $path_to_dir;
179   $output = 0;
180   $returncode = 0;
181   $mohfile = escapeshellcmd($mohfile);
182
183   $origmohfile=$path_to_dir."/orig_".$mohfile;
184   $newname = strtr($mohfile,"&", "_");
185   if(strstr($newname,".mp3")) {
186     $onlywav = false;
187   }
188   if(!$onlywav) {
189     $newmohfile=$path_to_dir."/". ((strpos($newname,'.mp3') === false) ? $newname.".mp3" : $newname);
190     $lamecmd="lame --cbr -m m -t -F \"".$origmohfile."\" \"".$newmohfile."\" 2>&1 ";
191     if (strpos($newmohfile,'.mp3') !== false)
192       exec($lamecmd, $output, $returncode);
193     } else {
194       $newmohfile = $path_to_dir."/wav_".$newname;
195       $soxcmd = "sox \"".$origmohfile."\" -r 8000 -c 1 \"".$newmohfile."\" ";
196       $soxresample = "resample -ql ";
197       exec($soxcmd.$soxresample."2>&1", $output, $returncode);
198       if ($returncode != 0) {
199         // try it again without the resample in case the input sample rate was the same
200         //
201         exec("rm -rf \"".$newmohfile."\"");
202         exec($soxcmd."2>&1", $output, $returncode);
203       }
204     }
205   if ($returncode != 0) {
206     return join("<br>\n", $output);
207   }
208   $rmcmd="rm -f \"". $origmohfile."\"";
209   exec($rmcmd);
210   return null;
211 }
212
213 /*function kill_mpg123()
214 {
215   $killcmd="killall -9 mpg123";
216   exec($killcmd);
217 }*/
218 ?>
219
220 <div class="content">
221 <h2><?php echo _("On Hold Music")?></h2>
222
223 <?php
224 if ($action == 'add')
225 {
226   ?>
227   <form name="addcategory" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return addcategory_onsubmit();">
228   <input type="hidden" name="display" value="<?php echo $display?>">
229   <input type="hidden" name="action" value="addednew">
230   <table>
231   <tr><td colspan="2"><h5><?php echo _("Add Music Category")?><hr></h5></td></tr>
232   <tr>
233     <td><a href="#" class="info"><?php echo _("Category Name:")?><span><?php echo _("Allows you to Set up Different Categories for music on hold.  This is useful if you would like to specify different Hold Music or Commercials for various ACD Queues.")?> </span></a></td>
234     <td><input type="text" name="category" value=""></td>
235   </tr>
236   <tr>
237     <td colspan="2"><br><h6><input name="Submit" type="submit" value='<?php echo _("Submit Changes")?>' ></h6></td>   
238   </tr>
239   </table>
240 <script language="javascript">
241 <!--
242
243 var theForm = document.addcategory;
244 theForm.category.focus();
245
246 function addcategory_onsubmit() {
247   var msgInvalidCategoryName = "<?php echo _('Please enter a valid Category Name'); ?>";
248   var msgReservedCategoryName = "<?php echo _('Categories: \"none\" and \"default\" are reserved names. Please enter a different name'); ?>";
249
250   defaultEmptyOK = false;
251   if (!isAlphanumeric(theForm.category.value))
252     return warnInvalid(theForm.category, msgInvalidCategoryName);
253   if (theForm.category.value == "default" || theForm.category.value == "none")
254     return warnInvalid(theForm.category, msgReservedCategoryName);
255  
256   return true;
257 }
258
259 //-->
260 </script>
261
262   </form>
263   <br><br><br><br><br>
264
265 <?php
266 }
267 else
268 {
269 ?>
270
271   <h5><?php echo _("Category:")?> <?php echo $category=="default"?_("default"):$category;?></h5>
272   <?php  if ($category!="default"){?>
273   <p><a href="config.php?display=<?php echo urlencode($display) ?>&action=delete&category=<?php echo urlencode($category) ?>"><?php echo _("Delete Music Category")?> <?php echo $category; ?></a></p><?php }?>
274
275   <form enctype="multipart/form-data" name="upload" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST"/>
276     <?php echo _("Upload a .wav or .mp3 file:")?><br>
277     <input type="hidden" name="display" value="<?php echo $display?>">
278     <input type="hidden" name="category" value="<?php echo "$category" ?>">
279     <input type="hidden" name="action" value="addedfile">
280     <input type="file" name="mohfile"/>
281     <input type="button" value="<?php echo _("Upload")?>" onclick="document.upload.submit(upload);alert('<?php echo addslashes(_("Please wait until the page loads. Your file is being processed."))?>');"/>
282     <br />
283     <input type="checkbox" name="onlywav" checked="checked"><small><?php echo _("Do not encode wav to mp3"); ?></small>
284   </form>
285   <br />
286   <form name="randomon" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
287   <?php
288     if (file_exists("{$path_to_dir}/.random")) {
289       ?> <input type="submit" name="randoff" value="<?php echo _("Disable Random Play");?>"> <?php
290     } else {
291       ?> <input type="submit" name="randon" value="<?php echo _("Enable Random Play");?>"> <?php
292     }
293   ?>
294   </form>
295   <br />
296   <?php
297
298   // Check to see if the upload failed for some reason
299   if (isset($_FILES['mohfile']['name']) && !is_uploaded_file($_FILES['mohfile']['tmp_name'])) {
300     if (strlen($_FILES['mohfile']['name']) == 0) {
301       echo "<h5> PHP "._("Error Processing")."! "._("No file provided")." "._("Please select a file to upload")."</h5>";
302     } else {
303       echo "<h5> PHP "._("Error Processing")." ".htmlentities($_FILES['mohfile']['name'])."! "._("Check")." upload_max_filesize "._("in")." /etc/php.ini</h5>";
304     }
305   }
306   if (isset($_FILES['mohfile']['tmp_name']) && is_uploaded_file($_FILES['mohfile']['tmp_name'])) {
307     //echo $_FILES['mohfile']['name']." uploaded OK";
308     move_uploaded_file($_FILES['mohfile']['tmp_name'], $path_to_dir."/orig_".$_FILES['mohfile']['name']);
309
310     $process_err = process_mohfile($_FILES['mohfile']['name'],($_REQUEST['onlywav'] != ''));
311
312     if (isset($process_err)) {
313       echo "<h5>"._("Error Processing").": \"$process_err\" for ".htmlentities($_FILES['mohfile']['name'])."!</h5>\n";
314       echo "<h5>"._("This is not a fatal error, your Music on Hold may still work.")."</h5>\n";
315     } else {
316       echo "<h5>"._("Completed processing")." ".htmlentities($_FILES['mohfile']['name'])."!</h5>";
317     }
318     needreload();
319     //kill_mpg123();
320   }
321
322   //build the array of files
323   $file_array = build_list();
324   $numf = count($file_array);
325
326
327   if (isset($_REQUEST['del'])) {
328     $del = $_REQUEST['del'];
329     if (strpos($del, "\"") || strpos($del, "\'") || strpos($del, "\;")) {
330       print "You're trying to use an invalid character. Please don't.\n";
331       exit;
332     }
333     if (($numf == 1) && ($category == "default") ){
334       echo "<h5>"._("You must have at least one file for On Hold Music.  Please upload one before deleting this one.")."</h5>";
335     } else {
336       if (@unlink($path_to_dir."/".$del)) {
337         echo "<h5>"._("Deleted")." ".$del."!</h5>";
338       } else {
339         echo "<h5>".sprintf(_("Error Deleting %s"),$del)."!</h5>";
340       }
341       //kill_mpg123();
342       needreload();
343     }
344   }
345   $file_array = build_list();
346   draw_list($file_array, $path_to_dir, $category);
347   ?>
348   <br><br><br><br><br><br>
349 <?php
350 }
351 ?>
Note: See TracBrowser for help on using the browser.