/hypervm/httpdocs/htmllib/lib/windowsfslib.php

https://github.com/yourhty/hypervm · PHP · 219 lines · 153 code · 47 blank · 19 comment · 17 complexity · 1b1a1f5ddbbab846db90c21f7e7444a2 MD5 · raw file

  1. <?php
  2. function lxshell_getzipcontent($path)
  3. {
  4. return lxshell_output("c:/Progra~1/7-zip/7z.exe", "l", $path);
  5. }
  6. function lxfile_adduser($path, $v)
  7. {
  8. }
  9. function lxfile_dirsize($path)
  10. {
  11. $path = expand_real_root($path);
  12. $t = 10000;
  13. return round($t/(1024), 1);
  14. }
  15. function lxfile_symlink($src, $dst)
  16. {
  17. log_filesys("Trying on Windows Linking $src to $dst");
  18. return;
  19. //symlink($src, $dst);
  20. }
  21. function lxshell_unzip($dir, $file, $filelist = null)
  22. {
  23. $dir = expand_real_root($dir);
  24. $file = expand_real_root($file);
  25. $command = "c:/Progra~1/7-zip/7z.exe x -y";
  26. if (!csa($file, ":")) {
  27. $fullpath = getcwd() . "/$file";
  28. } else {
  29. $fullpath = $file;
  30. }
  31. $oldir = getcwd();
  32. do_exec_system("__system__", $dir, "$command \"$fullpath\"", $out, $err, $ret, null);
  33. }
  34. function lxfile_rm_rec($file)
  35. {
  36. $obj = new COM("Scripting.FilesystemObject");
  37. $file = expand_real_root($file);
  38. $file = remove_extra_slash($file);
  39. $list = explode("/", $file);
  40. if (count($list) <= 2) {
  41. throw new lxException('recursive_removal_low_level_directories_not_allowed', '');
  42. }
  43. if (lxfile_exists($file)) {
  44. if (is_dir($file)) {
  45. $obj->deleteFolder($file);
  46. } else {
  47. $obj->deleteFile($file);
  48. }
  49. }
  50. }
  51. function lxfile_generic_chmod($file, $mod) {
  52. }
  53. function lxfile_generic_chmod_rec($file, $mod) { }
  54. function lxfile_generic_chown($file, $mod) {
  55. }
  56. function lxfile_generic_chown_rec($file, $mod) {
  57. }
  58. function lxfile_unix_chmod($file, $mod)
  59. {
  60. throw new lxException('unix_chmod_not_allowed_in_windows', '');
  61. }
  62. function lxfile_unix_chown($file, $mod)
  63. {
  64. throw new lxException('unix_chown_not_allowed_in_windows', '');
  65. }
  66. function lxfile_unix_chown_rec($file, $mod)
  67. {
  68. throw new lxException('unix_chown_rec_not_allowed_in_windows', '');
  69. }
  70. function lxfile_unix_chmod_rec($file, $mod)
  71. {
  72. throw new lxException('unix_chmod_rec_not_allowed_in_windows', '');
  73. }
  74. function lxfile_mv_rec($dirsource, $dirdest)
  75. {
  76. $obj = new COM("Scripting.FilesystemObject");
  77. $username = "__system__";
  78. $dirdest = expand_real_root($dirdest);
  79. $dirsource = expand_real_root($dirsource);
  80. if (lfile_exists($dirdest)) {
  81. $dirdest = $dirdest . "/" . basename($dirsource);
  82. }
  83. log_filesys("MvFolder $dirsource $dirdest");
  84. if (is_dir($dirsource)) {
  85. $obj->MoveFolder($dirsource, $dirdest);
  86. } else {
  87. $obj->MoveFile($dirsource, $dirdest);
  88. }
  89. }
  90. function lxfile_cp_rec($dirsource, $dirdest)
  91. {
  92. dprint("<b> I am here </b> ");
  93. $obj = new COM("Scripting.FilesystemObject");
  94. $username = "__system__";
  95. $dirdest = expand_real_root($dirdest);
  96. $dirsource = expand_real_root($dirsource);
  97. if (lfile_exists($dirdest) && is_dir($dirdest)) {
  98. $dirdest = $dirdest . "/" . basename($dirsource);
  99. }
  100. if (is_dir($dirsource)) {
  101. log_filesys("copyFolder $dirsource $dirdest");
  102. $obj->CopyFolder($dirsource, $dirdest);
  103. } else {
  104. log_filesys("copyFile $dirsource $dirdest");
  105. $obj->CopyFile($dirsource, $dirdest);
  106. }
  107. }
  108. function lxshell_background($cmd)
  109. {
  110. global $gbl, $sgbl, $login, $ghtml;
  111. $username = '__system__';
  112. $start = 1;
  113. eval($sgbl->arg_getting_string);
  114. $cmd = getShellCommand($cmd, $arglist);
  115. $sh = new COM("Wscript.shell");
  116. $cmdobject = $sh->Run($cmd, 1);
  117. return true;
  118. }
  119. function do_exec_system($username, $dir, $cmd, &$out, &$err, &$ret, $input)
  120. {
  121. global $gbl, $sgbl, $login, $ghtml;
  122. global $global_shell_out, $global_shell_error, $global_shell_ret;
  123. dprint("<hr> $dir <br> $cmd <hr> ");
  124. $path = "$sgbl->__path_lxmisc";
  125. $fename = tempnam($sgbl->__path_tmp, "system_errr");
  126. $execcmd = null;
  127. /*
  128. if ($username !== '__system__') {
  129. $execcmd = "$path -u $username";
  130. }
  131. */
  132. os_set_path();
  133. $sh = new COM("Wscript.shell");
  134. if ($dir) {
  135. if (!csa($dir, ':')) {
  136. $dir = getcwd() . "/$dir";
  137. }
  138. $sh->currentDirectory = $dir;
  139. }
  140. $out = null;
  141. $ret = 0;
  142. $err = null;
  143. dprint("\n ** mmmmmm $dir $cmd **\n");
  144. $cmdobject = $sh->Exec($cmd);
  145. if ($input) {
  146. $cmdobject->StdIn->Write($input);
  147. }
  148. $out = $cmdobject->StdOut->ReadAll();
  149. $err = $cmdobject->StdErr->ReadAll();
  150. $ret = 0;
  151. $sh->currentDirectory = $sgbl->__path_program_htmlbase;
  152. /*
  153. function ReadAllFromAny($ret)
  154. {
  155. if (!($ret->StdOut->AtEndOfStream)){
  156. $Ret=$ret->StdOut->ReadAll();
  157. return $Ret;
  158. }
  159. if (!($ret->StdErr->AtEndOfStream)){
  160. $Ret="STDERR: ".$ret->StdErr->ReadAll();
  161. return $Ret;
  162. }
  163. return -1;
  164. }*/
  165. if ($ret) {
  166. log_shell_error("$err: [($username:$dir) $cmd]");
  167. }
  168. log_shell("$ret: $err [($username:$dir) $cmd]");
  169. $global_shell_ret = $ret;
  170. $global_shell_out = $out;
  171. $global_shell_error = $err;
  172. }