PageRenderTime 54ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/patches/Servicios/sbin/www/unzip.php

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