PageRenderTime 101ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/patches/Servicios/sbin/www/copy.php

https://github.com/frisco82/HMR600.com-Firmware
PHP | 445 lines | 358 code | 67 blank | 20 comment | 90 complexity | e60819336d9cade23b15e9e01f293d9a MD5 | raw file
  1. <?php
  2. header('Content-Type: text/html; charset=utf-8');
  3. //This file will allow to copy/Move file.
  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. if ($_SESSION['newpath'] == ""){
  28. $newpath = "";
  29. }else{
  30. $newpath = $_SESSION['newpath'];
  31. }
  32. $Netshare_path = substr($_GET['dir'],0,12);
  33. if ($Netshare_path == "/tmp/myshare"){
  34. $mydir = $_GET['dir'];
  35. $mediapath = stripslashes($_GET['dir']);
  36. if ($mydir != "/tmp/myshare"){
  37. $uplink = substr_replace($_GET['dir'],'',strlen($_GET['dir'])-strlen(strrchr( $_GET['dir'],'/')));
  38. //check whether already mounted?
  39. $mydir1 = $mydir;
  40. $mydir1 = str_replace("(", "\(", $mydir1);
  41. $mydir1 = str_replace(")", "\)", $mydir1);
  42. $mydir1 = str_replace(" ", "\ ", $mydir1);
  43. $cmd = "mount |grep ".$mydir1;
  44. exec($cmd, $output1, $result1);
  45. if((substr($mydir, -4) == ".smb") || (substr($mydir, -4) == ".nfs") and ($output1[0] == "")){
  46. $ShareName = '/tmp/myshare/.cmd'.strrchr( $mydir,'/');
  47. $ShareName = str_replace("(", "\(", $ShareName);
  48. $ShareName = str_replace(")", "\)", $ShareName);
  49. $ShareName = str_replace(" ", "\ ", $ShareName);
  50. //mount
  51. $cmd = $ShareName . ' ' . $id . ' ' . $pass;
  52. exec($cmd, $output, $result);
  53. if ($result != 0){
  54. //$share = strrchr( $mydir,'/');
  55. //echo "<script>alert('Can not mount $share');</script>";
  56. //echo "<script>alert('mydirectory.....$mydir');</script>";
  57. echo "<script>window.open('smblogin.php?dir=$mydir', 'All', 'width=350,height=150');</script>";
  58. echo "<script>location.href='copy.php?dir=$uplink';</script>";
  59. }else if($id != ''){
  60. echo "<script>location.href='copy.php?dir=$mydir';</script>";
  61. }
  62. }
  63. $files = myscan($mydir);
  64. sort($files);
  65. //$mydir = str_replace("(", "\(", $mydir);
  66. //$mydir = str_replace(")", "\)", $mydir);
  67. $command = 'cd ' .$mydir1.';ls -alh > /tmp/aaa' ;
  68. shell_exec($command);
  69. $file1 = "/tmp/aaa";
  70. $fp1 = fopen($file1, 'r');
  71. //$fileData1 = fread($fp1, filesize($file1));
  72. $j=0;
  73. while (!feof($fp1)) {
  74. $line1[$j++] = fgets($fp1, 4096);
  75. }
  76. fclose($fp1);
  77. }else{
  78. $file = "/tmp/myshare/share.list";
  79. $fp = fopen($file, 'r');
  80. //$fileData = fread($fp, filesize($file));
  81. $j=0;
  82. while (!feof($fp)) {
  83. $files[$j++] = fgets($fp, 4096);
  84. }
  85. fclose($fp);
  86. }
  87. }else{
  88. $root = "/tmp/usbmounts";
  89. if ((substr($_GET['dir'],0,2) != '/.') and (substr($_GET['dir'],0,1) != '.') and ($_GET['dir'] != '')) {
  90. $mydir = $root . $_GET['dir'];
  91. $mediapath = stripslashes($_GET['dir']);
  92. }else{
  93. $mydir = $root;
  94. }
  95. $uplink = substr_replace($_GET['dir'],'',strlen($_GET['dir'])-strlen(strrchr( $_GET['dir'],'/')));
  96. $files = myscan($mydir);
  97. sort($files);
  98. $mydir1 = $mydir;
  99. $mydir1 = str_replace("(", "\(", $mydir1);
  100. $mydir1 = str_replace(")", "\)", $mydir1);
  101. $command = 'cd ' .str_replace(" ", "\ ", $mydir1).';ls -alh > /tmp/aaa' ;
  102. shell_exec($command);
  103. $file1 = "/tmp/aaa";
  104. $fp1 = fopen($file1, 'r');
  105. //$fileData1 = fread($fp1, filesize($file1));
  106. $j=0;
  107. while (!feof($fp1)) {
  108. $line1[$j++] = fgets($fp1, 4096);
  109. }
  110. fclose($fp1);
  111. }
  112. function myscan($dir) {
  113. $arrfiles = array();
  114. $arrfiles = opendir(stripslashes($dir));
  115. while (false !== ($filename = readdir($arrfiles))) {
  116. $files[] = $filename;
  117. }
  118. return $files;
  119. }
  120. //to deetct internal HDD exists or not
  121. $HDDInfo = shell_exec("df -h|grep /dev/scsi/host0/bus0/target0/lun0/part1");
  122. sscanf($HDDInfo,"%s %s %s %s", $aaa,$HDDTotal, $HDDUsed, $HDDFree);
  123. ?>
  124. <script language=javascript>
  125. checked=false;
  126. function checkedAll(filelist) {
  127. var aa= document.getElementById('filelist');
  128. if (checked == false)
  129. {
  130. checked = true
  131. }else{
  132. checked = false
  133. }
  134. for (var i =0; i < aa.elements.length; i++){
  135. aa.elements[i].checked = checked;
  136. }
  137. }
  138. function copyfile(){
  139. flg = 0;
  140. for(i=0;i<document.filelist.length;i++){
  141. if(document.filelist[i].checked == true){
  142. flg = 1;
  143. break;
  144. }else{
  145. flg = 0;
  146. }
  147. }
  148. if(flg == 0){
  149. alert('<? echo $STR_NoFileSelected;?>');
  150. }else if(!document.filelist.new_path.value){
  151. alert('<? echo $STR_SpecifyDestination;?>');
  152. }else{
  153. loadDivEl = document.getElementById("loadDiv");
  154. loadDivEl.style.visibility = 'visible';
  155. document.filelist.target = 'gframe';
  156. document.filelist.action="./copy_file.php?dir=<? echo $mediapath;?>";
  157. document.filelist.submit();
  158. }
  159. }
  160. function movefile(){
  161. flg = 0;
  162. for(i=0;i<document.filelist.length;i++){
  163. if(document.filelist[i].checked == true){
  164. flg = 1;
  165. break;
  166. }else{
  167. flg = 0;
  168. }
  169. }
  170. if(flg == 0){
  171. alert('<? echo $STR_NoFileSelected;?>');
  172. }else if(!document.filelist.new_path.value){
  173. alert('<? echo $STR_SpecifyDestination;?>');
  174. }else{
  175. loadDivEl = document.getElementById("loadDiv");
  176. loadDivEl.style.visibility = 'visible';
  177. document.filelist.target = 'gframe';
  178. document.filelist.action="./move_file.php?dir=<? echo $mediapath;?>";
  179. document.filelist.submit();
  180. }
  181. }
  182. </script>
  183. <HTML>
  184. <head>
  185. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  186. <title><? echo $STR_CopyTitle;?> </title>
  187. <link href="dlf/styles.css" rel="stylesheet" type="text/css">
  188. </head>
  189. <body marginwidth=0 marginheight=0 leftmargin=0 topmargin=0 oncontextmenu="return false;">
  190. <table width="987" height="60" background="dlf/top_menu.jpg" border="0" cellspacing="0" cellpadding="0">
  191. <tr> <td width=25%></td>
  192. <td width=40% align=middle><font face="arial" color="#ff0000"><h2>&nbsp&nbsp&nbsp&nbsp <? echo $STR_CopyTitle;?></h2></font></td>
  193. <td width=30%></td>
  194. </tr>
  195. </table>
  196. <center>
  197. <table cellspacing="0" cellpadding="0" border="0" width="880" height="500">
  198. <tr><td height="5"></td></tr>
  199. <tr>
  200. <td align=center><font face='Arial' size='2' color='#FFFFFF'><? echo $STR_CopySource;?></td>
  201. <td></td>
  202. <td align=center><font face='Arial' size='2' color='#FFFFFF'><? echo $STR_CopyDestination;?></td>
  203. </tr>
  204. <tr><td cellspacing="0" cellpadding="0" border="0" height=500 width=500 valign="top">
  205. <div id="listingcontainer1">
  206. <table cellspacing="0" cellpadding="0" border="0">
  207. <tr height=18><td></td></tr>
  208. <tr><td width=10></td>
  209. <td>
  210. <div id="listing1">
  211. <?
  212. echo "<form id='filelist' name='filelist' method='post' enctype='multipart/form-data'>";
  213. if ($mediapath != ''){
  214. echo "<input type='checkbox' name='selectall' onclick='checkedAll(filelist);'><font face='Arial' color='white' size='2'>" . $STR_SelectAll;
  215. }
  216. if(!$_GET["dir"]==''){
  217. 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>';
  218. echo "<table><tr><td><img src='dlf/dirup.png' align='center'>";
  219. echo "<td colspan='200'><a href='" . $_SERVER['PHP_SELF'] . "?dir=" . $uplink ."'>" . $STR_ParentDirectory . "</a></td></tr></table>";
  220. echo "</td></tr></table>";
  221. }
  222. if ($Netshare_path == "/tmp/myshare"){
  223. for ($x=0; $x<($j-1); $x++) {
  224. if ($mydir == "/tmp/myshare"){
  225. 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\'">';
  226. echo '<tr><td>';
  227. echo "<table><tr><td><img src='dlf/folder.png' align='center'>";
  228. echo "<td width=380><a href=\"" . $_SERVER['PHP_SELF'] . "?dir=" . $mediapath . "/" . $files[$x] . "\" class='rollover'>" . $files[$x] . "</td>";
  229. echo "</tr></table>";
  230. echo "</td></tr></table>";
  231. }else if(substr($line1[$x],0,1) == 'd'){
  232. 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")){
  233. 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\'">';
  234. echo "<tr> <td>";
  235. echo "<table cellspacing='1' cellpadding='0'><tr><td><input type='checkbox' name='filelist[]' value=\"$files[$x]\">";
  236. echo "<td><img src='dlf/folder.png' align='center'>";
  237. echo "<td width=380><a href=\"" . $_SERVER['PHP_SELF'] . "?dir=" . $mediapath . "/" . $files[$x] . "\" class='rollover'>" . $files[$x] . "</td>";
  238. echo "</tr></table>";
  239. echo "</td>";
  240. echo "<td width='370'></td>";
  241. echo "</tr></table>";
  242. }
  243. }
  244. }
  245. }else{
  246. for ($x=0; $x<($j-1); $x++) {
  247. 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")) {
  248. if (substr($line1[$x],0,1) == 'd'){
  249. $files1[$x] = $files[$x];
  250. if ($aaa!= ""){
  251. $files1[$x] = str_replace("sda", "HDD", $files1[$x]);
  252. $files1[$x] = str_replace("sdb1", "USB1", $files1[$x]);
  253. $files1[$x] = str_replace("sdc1", "USB2", $files1[$x]);
  254. $files1[$x] = str_replace("sdd1", "USB3", $files1[$x]);
  255. $files1[$x] = str_replace("sdb", "USB", $files1[$x]);
  256. $files1[$x] = str_replace("sdc", "USB", $files1[$x]);
  257. }else{
  258. $files1[$x] = str_replace("sda1", "USB1", $files1[$x]);
  259. $files1[$x] = str_replace("sdb1", "USB2", $files1[$x]);
  260. $files1[$x] = str_replace("sdc1", "USB3", $files1[$x]);
  261. $files1[$x] = str_replace("sdd1", "USB4", $files1[$x]);
  262. $files1[$x] = str_replace("sdb", "USB", $files1[$x]);
  263. $files1[$x] = str_replace("sdc", "USB", $files1[$x]);
  264. }
  265. 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\'">';
  266. echo "<tr><td>";
  267. echo "<table cellspacing='1' cellpadding='0' border='0'><tr>";
  268. if ($mediapath != "")
  269. echo "<td><input type='checkbox' name='filelist[]' value=\"$files[$x]\">";
  270. echo "<td><img src='dlf/folder.png' align='center'>";
  271. echo "<td colspan='200'><font face='Arial'><a href=\"" . $_SERVER['PHP_SELF'] . "?dir=" . $mediapath . "/" . $files[$x] . "\">" . $files1[$x] . "</td>";
  272. echo "</tr></table>";
  273. echo "</td></tr></table>";
  274. }
  275. }
  276. }
  277. }
  278. //for NetShares
  279. if (($mediapath == "") and ($Netshare_path != "/tmp/myshare")){
  280. 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\'">';
  281. echo '<tr><td>';
  282. echo "<table cellspacing='1' cellpadding='0'><tr><td><img src='dlf/folder.png' align='center'>";
  283. echo "<td width=380><a href=\"" . $_SERVER['PHP_SELF'] . "?dir=/tmp/myshare\" class='rollover'>Network Shares</td>";
  284. echo "</tr></table>";
  285. echo "</td>";
  286. echo "<td width='370'></td>";
  287. echo "</tr></table>";
  288. }
  289. //for NetShares
  290. for ($x=0; $x<($j-1); $x++) {
  291. //if (($files[$x] != '.') and ($files[$x] != "..")) {
  292. //echo "<div>";
  293. //if(!is_dir($mydir . "/" . $files[$x])) {
  294. if ((substr($line1[$x],0,1) != 'd') and ($mydir != "/tmp/myshare")){
  295. 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")){
  296. echo '<table width="500" cellspacing="0" cellpadding="0" border="0" onMouseOver="this.style.backgroundImage= \'url(dlf/rollover_bar.png)\'" onMouseOut="this.style.backgroundImage=\'none\'">';
  297. echo "<tr> <td>";
  298. echo "<table cellspacing='1' cellpadding='0' border='0'><tr><td><input type='checkbox' name='filelist[]' value=\"$files[$x]\">";
  299. echo "<td colspan='200'><font face='Arial' color='white' size='2'>" . $files[$x] . "</font></td>";
  300. echo "</tr></table>";
  301. echo "</td></tr></table>";
  302. }
  303. }
  304. //echo "</div>";
  305. //}
  306. }
  307. echo "</div>";
  308. ?>
  309. </td></tr></table>
  310. </td>
  311. <td height=500 align=middle>
  312. <font face='Arial' size='2' color='#FFFFFF'><? echo $STR_Copy;?>
  313. <input type="button" name="copy" class='btn_2' value=" => " onclick='javascript:copyfile();';>
  314. <? echo $STR_Move;?></font>
  315. <input type="button" class='btn_2' name="move" value=" => " onclick='javascript:movefile();';>
  316. </td>
  317. <td height=500 valign='top'>
  318. <div id="listingcontainer1">
  319. <table cellspacing="0" cellpadding="0" border="0">
  320. <tr height=18><td></td></tr>
  321. <tr><td width=10></td>
  322. <td>
  323. <!--div id="listing1"-->
  324. <iframe frameborder="0" framespacing="0" marginheight="0" marginwidth="0" name="tree" id="tree" scrolling="auto" vspace="0" width=430 height=472 src="destination.php?dir=<? echo $newpath;?>" ></iframe>
  325. </div>
  326. </td></tr></table>
  327. </td>
  328. </tr>
  329. </table>
  330. <table border=0 width=940>
  331. <?
  332. $mediapath1 = $mediapath;
  333. if ($aaa!= ""){
  334. $mediapath1 = str_replace("sda", "HDD", $mediapath1);
  335. $mediapath1 = str_replace("sdb1", "USB1", $mediapath1);
  336. $mediapath1 = str_replace("sdc1", "USB2", $mediapath1);
  337. $mediapath1 = str_replace("sdd1", "USB3", $mediapath1);
  338. $mediapath1 = str_replace("sdb", "USB", $mediapath1);
  339. $mediapath1 = str_replace("sdc", "USB", $mediapath1);
  340. $mediapath1 = str_replace("/tmp/myshare", "/NetShare", $mediapath1);
  341. }else{
  342. $mediapath1 = str_replace("sda1", "USB1", $mediapath1);
  343. $mediapath1 = str_replace("sdb1", "USB2", $mediapath1);
  344. $mediapath1 = str_replace("sdc1", "USB3", $mediapath1);
  345. $mediapath1 = str_replace("sdd1", "USB4", $mediapath1);
  346. $mediapath1 = str_replace("sdb", "USB", $mediapath1);
  347. $mediapath1 = str_replace("sdc", "USB", $mediapath1);
  348. $mediapath1 = str_replace("/tmp/myshare", "/NetShare", $mediapath1);
  349. }
  350. if (strlen($mediapath) > 55){
  351. $currentpath = "..." . substr($mediapath1, -51);
  352. }else{
  353. $currentpath = $mediapath1;
  354. }
  355. $_SESSION['newpath'] = "";
  356. ?>
  357. <tr><td width=440>&nbsp <font color=white face='Arial' size=2><?echo $currentpath; ?></td>
  358. <td width=45></td>
  359. <td><input style="background-color:transparent; color: #FFFFFF; border:0px; font-size:10pt; font-family:Arial;" type='text' name='new_path' id='new_path' size=53 value="" readonly>
  360. <input type='hidden' name='new_path1' id='new_path1' size=53 value="" readonly></td>
  361. <td align=right><input type=button class='btn_2' onclick="window.close()" class="web-button" value="<? echo $STR_Close;?>"></td>
  362. </tr>
  363. </table>
  364. </form>
  365. <iframe name='gframe' width=0 height=0 style="display:none"></iframe>
  366. <div id="loadDiv" name="loadDiv" style="position:absolute; visibility:hidden; left:290;top:140;width:200; height:100; z-index:1;">
  367. <table cellspacing="0" cellpadding="0" border="0" width=100% height=100%>
  368. <td valign=middle align=center>
  369. <table borde=0 align=center>
  370. <td align=center>
  371. <img src="dlf/upload.gif">
  372. </td>
  373. </table>
  374. </td>
  375. </table>
  376. </div>
  377. </body>
  378. </HTML>