PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/patches/Servicios/sbin/www/delete.php

https://github.com/frisco82/HMR600.com-Firmware
PHP | 378 lines | 293 code | 60 blank | 25 comment | 83 complexity | 432956dbd3aa5c9b171cc1f4f59a934f MD5 | raw file
  1. <?php
  2. //This file will allow to create Play List (mylist.All).
  3. header('Content-Type: text/html; charset=utf-8');
  4. session_start();
  5. error_reporting(0);
  6. $_SESSION['redirect'] = $_SERVER['REQUEST_URI'];
  7. include '/tmp/lang.php';
  8. //if login option is true check login status
  9. $file = "/usr/local/etc/setup.php";
  10. $fp = fopen($file, 'r');
  11. $fileData = fread($fp, filesize($file));
  12. fclose($fp);
  13. $line = explode("\n", $fileData);
  14. $i = 1;
  15. while ($i <= 5) {
  16. $dataPair = explode('=', $line[$i]);
  17. if ($dataPair[0] == "Login" && $dataPair[1] == "true") {
  18. if ($_SESSION['loggedIn'] != 1) {
  19. header("Location:login_form.php");
  20. exit;
  21. }
  22. }
  23. $i++;
  24. }
  25. $id = $_POST['user_id'];
  26. $pass = $_POST['user_pass'];
  27. $Netshare_path = substr($_GET['dir'],0,12);
  28. if ($Netshare_path == "/tmp/myshare"){
  29. $mydir = $_GET['dir'];
  30. $mediapath = stripslashes($_GET['dir']);
  31. if ($mydir != "/tmp/myshare"){
  32. $uplink = substr_replace($_GET['dir'],'',strlen($_GET['dir'])-strlen(strrchr( $_GET['dir'],'/')));
  33. //check whether already mounted?
  34. $mydir1 = $mydir;
  35. $mydir1 = str_replace("(", "\(", $mydir1);
  36. $mydir1 = str_replace(")", "\)", $mydir1);
  37. $mydir1 = str_replace(" ", "\ ", $mydir1);
  38. $cmd = "mount |grep ".$mydir1;
  39. exec($cmd, $output1, $result1);
  40. if((substr($mydir, -4) == ".smb") || (substr($mydir, -4) == ".nfs") and ($output1[0] == "")){
  41. $ShareName = '/tmp/myshare/.cmd'.strrchr( $mydir,'/');
  42. $ShareName = str_replace("(", "\(", $ShareName);
  43. $ShareName = str_replace(")", "\)", $ShareName);
  44. $ShareName = str_replace(" ", "\ ", $ShareName);
  45. //mount
  46. $cmd = $ShareName . ' ' . $id . ' ' . $pass;
  47. exec($cmd, $output, $result);
  48. if ($result != 0){
  49. //$share = strrchr( $mydir,'/');
  50. //echo "<script>alert('Can not mount $share');</script>";
  51. //echo "<script>alert('mydirectory.....$mydir');</script>";
  52. echo "<script>window.open('smblogin.php?dir=$mydir', 'All', 'width=350,height=150');</script>";
  53. echo "<script>location.href='delete.php?dir=$uplink';</script>";
  54. }else if($id != ''){
  55. echo "<script>location.href='delete.php?dir=$mydir';</script>";
  56. }
  57. }
  58. $files = myscan($mydir);
  59. sort($files);
  60. //$mydir = str_replace("(", "\(", $mydir);
  61. //$mydir = str_replace(")", "\)", $mydir);
  62. $command = 'cd ' .$mydir1.';ls -alh > /tmp/aaa' ;
  63. shell_exec($command);
  64. $file1 = "/tmp/aaa";
  65. $fp1 = fopen($file1, 'r');
  66. //$fileData1 = fread($fp1, filesize($file1));
  67. $j=0;
  68. while (!feof($fp1)) {
  69. $line1[$j++] = fgets($fp1, 4096);
  70. }
  71. fclose($fp1);
  72. }else{
  73. $file = "/tmp/myshare/share.list";
  74. $fp = fopen($file, 'r');
  75. //$fileData = fread($fp, filesize($file));
  76. $j=0;
  77. while (!feof($fp)) {
  78. $files[$j++] = fgets($fp, 4096);
  79. }
  80. fclose($fp);
  81. }
  82. }else{
  83. $root = "/tmp/usbmounts";
  84. if ((substr($_GET['dir'],0,2) != '/.') and (substr($_GET['dir'],0,1) != '.') and ($_GET['dir'] != '')) {
  85. $mydir = $root . $_GET['dir'];
  86. $mediapath = stripslashes($_GET['dir']);
  87. }else{
  88. $mydir = $root;
  89. }
  90. //echo "<script>alert('$mydir');</script>";
  91. $uplink = substr_replace($_GET['dir'],'',strlen($_GET['dir'])-strlen(strrchr( $_GET['dir'],'/')));
  92. $files = myscan($mydir);
  93. sort($files);
  94. $mydir1 = $mydir;
  95. $mydir1 = str_replace("(", "\(", $mydir1);
  96. $mydir1 = str_replace(")", "\)", $mydir1);
  97. $command = 'cd ' .str_replace(" ", "\ ", $mydir1).';ls -alh > /tmp/aaa' ;
  98. shell_exec($command);
  99. $file1 = "/tmp/aaa";
  100. $fp1 = fopen($file1, 'r');
  101. //$fileData1 = fread($fp1, filesize($file1));
  102. $j=0;
  103. while (!feof($fp1)) {
  104. $line1[$j++] = fgets($fp1, 4096);
  105. }
  106. fclose($fp1);
  107. }
  108. function myscan($dir) {
  109. $arrfiles = array();
  110. $arrfiles = opendir(stripslashes($dir));
  111. while (false !== ($filename = readdir($arrfiles))) {
  112. $files[] = $filename;
  113. }
  114. return $files;
  115. }
  116. //to deetct internal HDD exists or not
  117. $HDDInfo = shell_exec("df -h|grep /dev/scsi/host0/bus0/target0/lun0/part1");
  118. sscanf($HDDInfo,"%s %s %s %s", $aaa,$HDDTotal, $HDDUsed, $HDDFree);
  119. ?>
  120. <script language=javascript>
  121. checked=false;
  122. function checkedAll(filelist) {
  123. var aa= document.getElementById('filelist');
  124. if (checked == false)
  125. {
  126. checked = true
  127. }else{
  128. checked = false
  129. }
  130. for (var i =0; i < aa.elements.length; i++){
  131. aa.elements[i].checked = checked;
  132. }
  133. }
  134. function change(){
  135. flg = 0;
  136. for(i=0;i<document.filelist.length;i++){
  137. if(document.filelist[i].checked == true){
  138. flg = 1;
  139. break;
  140. }else{
  141. flg = 0;
  142. }
  143. }
  144. if(flg == 0){
  145. alert("<?echo $STR_NoFileToDel;?>");
  146. return false;
  147. }
  148. var ok = confirm('<?echo $STR_ReallyDelete;?>');
  149. if(ok){
  150. document.filelist.target = 'gframe';
  151. document.filelist.action = 'delete_file.php?dir=<? echo $mediapath;?>';
  152. // document.filelist.action = window.open('delete_file.php?dir=<? echo $mediapath;?>','Playlist','height=300,width=987,left=150,top=200');
  153. document.filelist.submit();
  154. }
  155. }
  156. //window.open('m3uMusic.php','Playlist','height=675,width=987,left=150,top=200');\";>";
  157. </script>
  158. <HTML>
  159. <head>
  160. <!--meta http-equiv="Content-Type" content="text/html; charset=utf-8" /-->
  161. <title> <?echo $STR_DeleteTitle;?></title>
  162. <link rel="stylesheet" type="text/css" href="dlf/styles.css" />
  163. </head>
  164. <body marginwidth=0 marginheight=0 leftmargin=0 topmargin=0 oncontextmenu="return false;" onunLoad="window.opener.location.reload();">
  165. <table width="100%" height="50" background="dlf/top_menu.jpg" border="0" cellspacing="0" cellpadding="0">
  166. <tr>
  167. <td width=850 height="50" align=middle><font face="arial" color="#ff0000"><h2><?echo $STR_DeleteTitle;?></h2></font></td>
  168. </tr>
  169. </table>
  170. <center>
  171. <table cellspacing="0" cellpadding="0" border="0" width=450 height=500>
  172. <tr><td height="10"></td><tr>
  173. <tr><td cellspacing="0" cellpadding="0" border="0" height=500 width=500 valign="top">
  174. <div id="listingcontainer1">
  175. <table cellspacing="0" cellpadding="0" border="0">
  176. <tr height=18><td></td></tr>
  177. <tr><td width=10></td>
  178. <td>
  179. <div id="listing1">
  180. <?
  181. //echo "<div style='width: 850; height: 520; overflow: scroll; border: 1px solid #A7C5FF; background: transparent ;'>";
  182. if(!$_GET["dir"]==''){
  183. echo '<table width="500" cellspacing="0" cellpadding="0" border="0" onMouseOver="this.style.backgroundImage= \'url(dlf/rollover_bar.png)\'" onMouseOut="this.style.backgroundImage=\'none\'"><tr><td>';
  184. echo "<table><tr><td><img src='dlf/dirup.png' align='center'>";
  185. echo "<td colspan='200'><a href='" . $_SERVER['PHP_SELF'] . "?dir=" . $uplink ."'>" . $STR_ParentDirectory . "</a></td></tr></table>";
  186. echo "</td></tr></table>";
  187. }
  188. echo "<form id='filelist' name='filelist' method='post' action='javascript:change();'>";
  189. if (($mediapath != '')and ($mydir != "/tmp/myshare")){
  190. // echo "&nbsp";
  191. echo "<input type='checkbox' name='selectall' onclick='checkedAll(filelist);'><font face='Arial' color='white' size='2'>" . $STR_SelectAll;
  192. }
  193. if ($Netshare_path == "/tmp/myshare"){
  194. for ($x=0; $x<($j-1); $x++) {
  195. if ($mydir == "/tmp/myshare"){
  196. echo '<table width="500" height="3" cellspacing="0" cellpadding="0" border="0" onMouseOver="this.style.backgroundImage= \'url(dlf/rollover_bar.png)\'" onMouseOut="this.style.backgroundImage=\'none\'">';
  197. echo '<tr><td>';
  198. echo "<table><tr><td><img src='dlf/folder.png' align='center'>";
  199. echo "<td width=380><a href=\"" . $_SERVER['PHP_SELF'] . "?dir=" . $mediapath . "/" . $files[$x] . "\" class='rollover'>" . $files[$x] . "</td>";
  200. echo "</tr></table>";
  201. echo "</td></tr></table>";
  202. }else if(substr($line1[$x],0,1) == 'd'){
  203. if (($files[$x] != '.') and ($files[$x] != "..") and ($files[$x] != "Recycled") and ($files[$x] != "System Volume Information") and (substr($files[$x],0,1) != ".") and ($files[$x] != "lost+found")){
  204. echo '<table width="500" height="3" cellspacing="0" cellpadding="0" border="0" onMouseOver="this.style.backgroundImage= \'url(dlf/rollover_bar.png)\'" onMouseOut="this.style.backgroundImage=\'none\'">';
  205. echo "<tr> <td>";
  206. echo "<table cellspacing='1' cellpadding='0'><tr><td><input type='checkbox' name='filelist[]' value=\"$files[$x]\">";
  207. echo "<td><img src='dlf/folder.png' align='center'>";
  208. echo "<td width=380><a href=\"" . $_SERVER['PHP_SELF'] . "?dir=" . $mediapath . "/" . $files[$x] . "\" class='rollover'>" . $files[$x] . "</td>";
  209. echo "</tr></table>";
  210. echo "</td>";
  211. echo "<td width='370'></td>";
  212. echo "</tr></table>";
  213. }
  214. }
  215. }
  216. }else{
  217. for ($x=0; $x<($j-1); $x++) {
  218. if (($files[$x] != '.') and ($files[$x] != "..") and ($files[$x] != "Recycled") and ($files[$x] != "System Volume Information") and (substr($files[$x],0,1) != ".") and ($files[$x] != "lost+found")) {
  219. if (substr($line1[$x],0,1) == 'd'){
  220. $files1[$x] = $files[$x];
  221. if ($aaa!= ""){
  222. $files1[$x] = str_replace("sda", "HDD", $files1[$x]);
  223. $files1[$x] = str_replace("sdb1", "USB1", $files1[$x]);
  224. $files1[$x] = str_replace("sdc1", "USB2", $files1[$x]);
  225. $files1[$x] = str_replace("sdd1", "USB3", $files1[$x]);
  226. $files1[$x] = str_replace("sdb", "USB", $files1[$x]);
  227. $files1[$x] = str_replace("sdc", "USB", $files1[$x]);
  228. }else{
  229. $files1[$x] = str_replace("sda1", "USB1", $files1[$x]);
  230. $files1[$x] = str_replace("sdb1", "USB2", $files1[$x]);
  231. $files1[$x] = str_replace("sdc1", "USB3", $files1[$x]);
  232. $files1[$x] = str_replace("sdd1", "USB4", $files1[$x]);
  233. $files1[$x] = str_replace("sdb", "USB", $files1[$x]);
  234. $files1[$x] = str_replace("sdc", "USB", $files1[$x]);
  235. }
  236. echo '<table width="500" height="3" cellspacing="0" cellpadding="0" border="0" onMouseOver="this.style.backgroundImage= \'url(dlf/rollover_bar.png)\'" onMouseOut="this.style.backgroundImage=\'none\'">';
  237. echo "<tr> <td>";
  238. echo "<table cellspacing='1' cellpadding='0'><tr>";
  239. if ($mediapath != "")
  240. echo "<td><input type='checkbox' name='filelist[]' value=\"$files[$x]\">";
  241. echo "<td><img src='dlf/folder.png' align='center'>";
  242. echo "<td colspan='200'><font face='Arial'><a href='" . $_SERVER['PHP_SELF'] . "?dir=" . $mediapath . "/" . $files[$x] . "'>" . $files1[$x] . "</td>";
  243. echo "</tr></table>";
  244. echo "</td></tr></table>";
  245. }
  246. }
  247. }
  248. }
  249. //for NetShares
  250. if (($mediapath == "") and ($Netshare_path != "/tmp/myshare")){
  251. echo '<table width="500" height="3" cellspacing="0" cellpadding="0" border="0" onMouseOver="this.style.backgroundImage= \'url(dlf/rollover_bar.png)\'" onMouseOut="this.style.backgroundImage=\'none\'">';
  252. echo '<tr><td>';
  253. echo "<table cellspacing='1' cellpadding='0'><tr><td><img src='dlf/folder.png' align='center'>";
  254. echo "<td width=380><a href=\"" . $_SERVER['PHP_SELF'] . "?dir=/tmp/myshare\" class='rollover'>Network Shares</td>";
  255. echo "</tr></table>";
  256. echo "</td>";
  257. echo "<td width='370'></td>";
  258. echo "</tr></table>";
  259. }
  260. //for NetShares
  261. for ($x=0; $x<($j-1); $x++) {
  262. //if (($files[$x] != '.') and ($files[$x] != "..")) {
  263. //echo "<div>";
  264. //if(!is_dir($mydir . "/" . $files[$x])) {
  265. if ((substr($line1[$x],0,1) != 'd') and ($mydir != "/tmp/myshare")){
  266. if (($files[$x] != "mylist.All") and ($files[$x] != "mylist.Music") and ($files[$x] != "mylist.Picture") and ($files[$x] != "mylist.Video") and ($files[$x] != "keyword.data")){
  267. echo '<table width="500" cellspacing="0" cellpadding="0" border="0" onMouseOver="this.style.backgroundImage= \'url(dlf/rollover_bar.png)\'" onMouseOut="this.style.backgroundImage=\'none\'">';
  268. echo "<tr> <td>";
  269. echo "<table cellspacing='1' cellpadding='0'><tr><td><input type='checkbox' name='filelist[]' value=\"$files[$x]\">";
  270. echo "<td colspan='200'><font face='Arial' color='white' size='2'>" . $files[$x] . "</font></td>";
  271. echo "</tr></table>";
  272. echo "</td></tr></table>";
  273. }
  274. }
  275. //echo "</div>";
  276. //}
  277. }
  278. echo "</div>";
  279. ?>
  280. </td></tr></table>
  281. </td>
  282. </tr>
  283. </table>
  284. <table width="450" border="0" cellspacing="0" cellpadding="0">
  285. <?
  286. $mediapath1 = $mediapath;
  287. if ($aaa!= ""){
  288. $mediapath1 = str_replace("sda", "HDD", $mediapath1);
  289. $mediapath1 = str_replace("sdb1", "USB1", $mediapath1);
  290. $mediapath1 = str_replace("sdc1", "USB2", $mediapath1);
  291. $mediapath1 = str_replace("sdd1", "USB3", $mediapath1);
  292. $mediapath1 = str_replace("sdb", "USB", $mediapath1);
  293. $mediapath1 = str_replace("sdc", "USB", $mediapath1);
  294. $mediapath1 = str_replace("/tmp/myshare", "/NetShare", $mediapath1);
  295. }else{
  296. $mediapath1 = str_replace("sda1", "USB1", $mediapath1);
  297. $mediapath1 = str_replace("sdb1", "USB2", $mediapath1);
  298. $mediapath1 = str_replace("sdc1", "USB3", $mediapath1);
  299. $mediapath1 = str_replace("sdd1", "USB4", $mediapath1);
  300. $mediapath1 = str_replace("sdb", "USB", $mediapath1);
  301. $mediapath1 = str_replace("sdc", "USB", $mediapath1);
  302. $mediapath1 = str_replace("/tmp/myshare", "/NetShare", $mediapath1);
  303. }
  304. if (strlen($mediapath) > 40){
  305. $currentpath = "..." . substr($mediapath1, -36);
  306. }else{
  307. $currentpath = $mediapath1;
  308. }
  309. ?>
  310. <tr><td width=340>&nbsp <font color=white face='Arial' size='2'><?echo $currentpath; ?>/</td>
  311. <td><input type=button class='btn_2' onclick="javascript:change()" class="web-button" value="<?echo $STR_Delete;?>"> </td>
  312. &nbsp<td ><input type=button class='btn_2' onclick="window.close()" class="web-button" value="<?echo $STR_Close;?>"></td>
  313. </tr>
  314. </table>
  315. </form>
  316. <iframe name='gframe' width=0 height=0 style="display:none"></iframe>
  317. </body>
  318. </HTML>