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

Revision 10463, 10.3 kB (checked in by p_lindheimer, 2 years ago)

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

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

r10462 | p_lindheimer | 2010-11-01 13:25:23 -0700 (Mon, 01 Nov 2010) | 53 lines


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=".$thisfile."&category=".$category."\">"._("Delete")."</a>";
171       print "</div><br>";
172     }
173   }
174 }
175
176 function process_mohfile($mohfile)
177 {
178   global $path_to_dir;
179   $output = 0;
180   $returncode = 0;
181   $mohfile = escapeshellcmd($mohfile);
182   $origmohfile=$path_to_dir."/orig_".$mohfile;
183   $newname = strtr($mohfile,"&", "_");
184   $newmohfile=$path_to_dir."/". ((strpos($newname,'.mp3') === false) ? $newname.".mp3" : $newname);
185   $lamecmd="lame --cbr -m m -t -F \"".$origmohfile."\" \"".$newmohfile."\" 2>&1 ";
186   if (strpos($newmohfile,'.mp3') !== false)
187     exec($lamecmd, $output, $returncode);
188   if ($returncode != 0) {
189     return join("<br>\n", $output);
190   }
191   $rmcmd="rm -f \"". $origmohfile."\"";
192   exec($rmcmd);
193   return null;
194 }
195
196 /*function kill_mpg123()
197 {
198   $killcmd="killall -9 mpg123";
199   exec($killcmd);
200 }*/
201 ?>
202
203 <div class="content">
204 <h2><?php echo _("On Hold Music")?></h2>
205
206 <?php
207 if ($action == 'add')
208 {
209   ?>
210   <form name="addcategory" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return addcategory_onsubmit();">
211   <input type="hidden" name="display" value="<?php echo $display?>">
212   <input type="hidden" name="action" value="addednew">
213   <table>
214   <tr><td colspan="2"><h5><?php echo _("Add Music Category")?><hr></h5></td></tr>
215   <tr>
216     <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>
217     <td><input type="text" name="category" value=""></td>
218   </tr>
219   <tr>
220     <td colspan="2"><br><h6><input name="Submit" type="submit" value='<?php echo _("Submit Changes")?>' ></h6></td>   
221   </tr>
222   </table>
223 <script language="javascript">
224 <!--
225
226 var theForm = document.addcategory;
227 theForm.category.focus();
228
229 function addcategory_onsubmit() {
230   var msgInvalidCategoryName = "<?php echo _('Please enter a valid Category Name'); ?>";
231   var msgReservedCategoryName = "<?php echo _('Categories: \"none\" and \"default\" are reserved names. Please enter a different name'); ?>";
232
233   defaultEmptyOK = false;
234   if (!isAlphanumeric(theForm.category.value))
235     return warnInvalid(theForm.category, msgInvalidCategoryName);
236   if (theForm.category.value == "default" || theForm.category.value == "none")
237     return warnInvalid(theForm.category, msgReservedCategoryName);
238  
239   return true;
240 }
241
242 //-->
243 </script>
244
245   </form>
246   <br><br><br><br><br>
247
248 <?php
249 }
250 else
251 {
252 ?>
253
254   <h5><?php echo _("Category:")?> <?php echo $category=="default"?_("default"):$category;?></h5>
255   <?php  if ($category!="default"){?>
256   <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 }?>
257
258   <form enctype="multipart/form-data" name="upload" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST"/>
259     <?php echo _("Upload a .wav or .mp3 file:")?><br>
260     <input type="hidden" name="display" value="<?php echo $display?>">
261     <input type="hidden" name="category" value="<?php echo "$category" ?>">
262     <input type="hidden" name="action" value="addedfile">
263     <input type="file" name="mohfile"/>
264     <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."))?>');"/>
265   </form>
266   <br />
267   <form name="randomon" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
268   <?php
269     if (file_exists("{$path_to_dir}/.random")) {
270       ?> <input type="submit" name="randoff" value="Disable Random Play"> <?php
271     } else {
272       ?> <input type="submit" name="randon" value="Enable Random Play"> <?php
273     }
274   ?>
275   </form>
276   <br />
277   <?php
278
279   // Check to see if the upload failed for some reason
280   if (isset($_FILES['mohfile']['name']) && !is_uploaded_file($_FILES['mohfile']['tmp_name'])) {
281     if (strlen($_FILES['mohfile']['name']) == 0) {
282       echo "<h5> PHP "._("Error Processing")."! "._("No file provided")." "._("Please select a file to upload")."</h5>";
283     } else {
284       echo "<h5> PHP "._("Error Processing")." ".htmlentities($_FILES['mohfile']['name'])."! "._("Check")." upload_max_filesize "._("in")." /etc/php.ini</h5>";
285     }
286   }
287   if (isset($_FILES['mohfile']['tmp_name']) && is_uploaded_file($_FILES['mohfile']['tmp_name'])) {
288     //echo $_FILES['mohfile']['name']." uploaded OK";
289     move_uploaded_file($_FILES['mohfile']['tmp_name'], $path_to_dir."/orig_".$_FILES['mohfile']['name']);
290     $process_err = process_mohfile($_FILES['mohfile']['name']);
291     if (isset($process_err)) {
292       echo "<h5>"._("Error Processing").": \"$process_err\" for ".htmlentities($_FILES['mohfile']['name'])."!</h5>\n";
293       echo "<h5>"._("This is not a fatal error, your Music on Hold may still work.")."</h5>\n";
294     } else {
295       echo "<h5>"._("Completed processing")." ".htmlentities($_FILES['mohfile']['name'])."!</h5>";
296     }
297     needreload();
298     //kill_mpg123();
299   }
300
301   //build the array of files
302   $file_array = build_list();
303   $numf = count($file_array);
304
305
306   if (isset($_REQUEST['del'])) {
307     $del = $_REQUEST['del'];
308     if (strpos($del, "\"") || strpos($del, "\'") || strpos($del, "\;")) {
309       print "You're trying to use an invalid character. Please don't.\n";
310       exit;
311     }
312     if (($numf == 1) && ($category == "default") ){
313       echo "<h5>"._("You must have at least one file for On Hold Music.  Please upload one before deleting this one.")."</h5>";
314     } else {
315       if (@unlink($path_to_dir."/".$del)) {
316         echo "<h5>"._("Deleted")." ".$del."!</h5>";
317       } else {
318         echo "<h5>".sprintf(_("Error Deleting %s"),$del)."!</h5>";
319       }
320       //kill_mpg123();
321       needreload();
322     }
323   }
324   $file_array = build_list();
325   draw_list($file_array, $path_to_dir, $category);
326   ?>
327   <br><br><br><br><br><br>
328 <?php
329 }
330 ?>
Note: See TracBrowser for help on using the browser.