fm_dir.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. require_once(MODULES."/litefm/functions.php");
  25. require_once(MODULES."/litefm/litefm.php");
  26. function exec_ogp_module()
  27. {
  28. $home_id = $_REQUEST['home_id'];
  29. if (empty($home_id))
  30. {
  31. print_failure( get_lang("home_id_missing") );
  32. return;
  33. }
  34. global $db, $view, $settings;
  35. $isAdmin = $db->isAdmin( $_SESSION['user_id'] );
  36. if($isAdmin)
  37. $home_cfg = $db->getGameHome($home_id);
  38. else
  39. $home_cfg = $db->getUserGameHome($_SESSION['user_id'],$home_id);
  40. if ($home_cfg === FALSE)
  41. {
  42. print_failure( get_lang("no_access_to_home") );
  43. return;
  44. }
  45. if ( preg_match("/f/",$home_cfg['access_rights']) != 1 )
  46. {
  47. print_failure( get_lang("no_rights") );
  48. echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id=".$home_cfg['home_id']."'><< ". get_lang("back") ."</a></td></tr></table>";
  49. return;
  50. }
  51. litefm_check($home_id);
  52. $remote = new OGPRemoteLibrary($home_cfg['agent_ip'], $home_cfg['agent_port'], $home_cfg['encryption_key'], $home_cfg['timeout']);
  53. $os_string = $remote->what_os();
  54. $os = preg_match("/Linux/i", $os_string) ? "linux" : "windows";
  55. // We must always add the home directory to the fm_cwd so that user
  56. // can not go out of the homedir.
  57. $path = clean_path($home_cfg['home_path']."/".@$_SESSION['fm_cwd_'.$home_id]);
  58. if (!$remote->rfile_exists($path))
  59. {
  60. while(!$remote->rfile_exists($path))
  61. {
  62. $_SESSION['fm_cwd_'.$home_id] = dirname($_SESSION['fm_cwd_'.$home_id]);
  63. $path = clean_path($home_cfg['home_path']."/".@$_SESSION['fm_cwd_'.$home_id]);
  64. if($path == clean_path($home_cfg['home_path']."/"))
  65. {
  66. print_failure(get_lang_f("dir_not_found",$path));
  67. echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id=".$home_cfg['home_id']."'><< ". back ."</a></td></tr></table>";
  68. return;
  69. }
  70. }
  71. }
  72. // Get File Operations Keys
  73. $fo_keys = get_file_operations_keys();
  74. // Get File Operations Settings
  75. $fo = get_fo_settings($settings,$fo_keys);
  76. $upload_folder_path = "modules/litefm/uploads/home_id_$home_id";
  77. // PHP post_max_size handling
  78. $PMS_bytes = return_bytes(ini_get('post_max_size'));
  79. if(isset($_SERVER['CONTENT_LENGTH']) AND $_SERVER['CONTENT_LENGTH'] > $PMS_bytes and $fo['upload'] == "1")
  80. {
  81. $error['post_max_size'] = "The uploaded file(s) size exceed the post_max_size directive in php.ini (".ini_get('post_max_size').").";
  82. echo json_encode( array( 'error' => $error ) );
  83. }
  84. // Get web to agent transfer progress
  85. elseif( isset( $_GET['pid'] ) and $_GET['pid'] != "" and $fo['upload'] == "1" )
  86. {
  87. $bytes = $_GET['size'];
  88. $totalsize = $bytes / 1024;
  89. $filename = $_GET['filename'];
  90. $kbytes = $remote->rsync_progress( clean_path( $path."/".$filename ) );
  91. list($totalsize,$mbytes,$pct) = explode(";",do_progress($kbytes,$totalsize));
  92. $totalmbytes = round($totalsize / 1024, 2);
  93. $pct = $pct > 100 ? 100 : $pct;
  94. $complete = false;
  95. if ( $remote->is_file_download_in_progress( $_GET['pid'] ) == 0 )
  96. {
  97. $dest_file_path = clean_path( $upload_folder_path . "/" . $filename . ".txt" );
  98. unlink($dest_file_path);
  99. $directory = dir($upload_folder_path);
  100. $directory_empty = TRUE;
  101. while ((FALSE !== ($item = $directory->read())) && ( ! isset($directory_not_empty)))
  102. {
  103. if ($item != '.' && $item != '..')
  104. {
  105. $directory_empty = FALSE;
  106. }
  107. }
  108. $directory->close();
  109. if( $directory_empty )
  110. rmdir( $upload_folder_path );
  111. $db->logger(get_lang("upload_complete") . ": " . clean_path( $path . "/" . $filename ));
  112. $complete = true;
  113. }
  114. echo json_encode(array('pct' => $pct,
  115. 'complete' => $complete));
  116. }
  117. // Upload File(s)
  118. elseif( isset( $_POST['upload'] ) and $fo['upload'] == "1" )
  119. {
  120. $error = FALSE;
  121. foreach ( $_FILES['files']['error'] as $i => $error_code )
  122. {
  123. if($error_code > 0)
  124. {
  125. $error['error_message'][$i] = codeToMessage($error_code,$_FILES['files']['name'][$i]);
  126. }
  127. }
  128. if( is_array($error) )
  129. {
  130. echo json_encode( array( 'error' => $error ) );
  131. }
  132. // Save uploaded file to the website and start file download from the agent
  133. else
  134. {
  135. if( ! file_exists( $upload_folder_path ) )
  136. {
  137. if( ! mkdir($upload_folder_path, 0777, true) )
  138. {
  139. echo json_encode(array('error' => get_lang_f('can_not_create_upload_folder_path', "\n(".$upload_folder_path.")" )));
  140. return;
  141. }
  142. }
  143. $count = 0;
  144. $s = ( isset($_SERVER['HTTPS']) and get_true_boolean($_SERVER['HTTPS']) ) ? "s" : "";
  145. $p = (isset($_SERVER['SERVER_PORT']) and $_SERVER['SERVER_PORT'] != "80") ? ":".$_SERVER['SERVER_PORT'] : "";
  146. $serverName = $_SERVER["SERVER_NAME"];
  147. if(empty($serverName) || $serverName == "_"){
  148. $serverName = $_SERVER['HTTP_HOST'];
  149. }
  150. $url = 'http'.$s.'://'.$serverName.$p.$_SERVER['SCRIPT_NAME'];
  151. // loop all files
  152. foreach ( $_FILES['files']['name'] as $i => $name )
  153. {
  154. // if file not uploaded then skip it
  155. if ( !is_uploaded_file($_FILES['files']['tmp_name'][$i]) )
  156. continue;
  157. // now we can move uploaded files
  158. $bad_chars = preg_replace( "/([[:alnum:]_\.-]*)/", "", $_FILES['files']['name'][$i] );
  159. $bad_arr = str_split( $bad_chars );
  160. $filename = str_replace( $bad_arr, "", $_FILES['files']['name'][$i] );
  161. $dest_file_path = clean_path( $upload_folder_path . "/" . $filename . ".txt" );
  162. $file_url = str_replace( "home.php", $dest_file_path, $url );
  163. if( file_exists( $dest_file_path ) )
  164. unlink($dest_file_path);
  165. if( move_uploaded_file( $_FILES["files"]["tmp_name"][$i], $dest_file_path ) )
  166. {
  167. $remote_file_path = clean_path( $path . "/" . $filename );
  168. if( $remote->rfile_exists($remote_file_path) )
  169. $remote->shell_action('remove_file', $remote_file_path);
  170. $pid = $remote->start_file_download( $file_url, $path, $filename );
  171. $files[$count] = array('filename' => $filename,
  172. 'size' => $_FILES['files']['size'][$i],
  173. 'pid' => $pid);
  174. $count++;
  175. }
  176. }
  177. echo json_encode(array('count' => $count,
  178. 'files' => $files));
  179. }
  180. }
  181. // Create Folder
  182. elseif( isset( $_POST['create_folder'] ) and $fo['create_folder'] == "1" )
  183. {
  184. $folder_name = stripslashes($_POST['folder_name']);
  185. $folder_path = clean_path( $path . "/" . $folder_name );
  186. $remote->shell_action('create_dir', $folder_path);
  187. $db->logger( get_lang("create_folder") . ": " . $folder_path );
  188. }
  189. // Delete File(s)
  190. elseif( isset( $_POST['remove'] ) and $fo['remove'] == "1" )
  191. {
  192. if( isset($_SESSION['fm_files_'.$home_id]) and !empty($_SESSION['fm_files_'.$home_id]) )
  193. {
  194. $files = "";
  195. foreach($_POST['items'] as $item)
  196. {
  197. if(isset($_SESSION['fm_files_'.$home_id][$item]))
  198. {
  199. if(!validate_path($_SESSION['fm_files_'.$home_id][$item])){
  200. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  201. continue;
  202. }
  203. $item_path = clean_path( $path . "/" . $_SESSION['fm_files_'.$home_id][$item] );
  204. if(preg_match("/\/\.\.\/|\||;/", $item_path)) {
  205. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  206. continue;
  207. }
  208. $files .= $item_path.";";
  209. }
  210. }
  211. echo $files;
  212. if($files != "")
  213. {
  214. $remote->shell_action('remove_recursive', $files);
  215. $files = str_replace('" "','"<br>"',$files);
  216. $db->logger( get_lang("remove") . ": " . $files );
  217. }
  218. }
  219. }
  220. // Rename File(s)/Folder(s)
  221. elseif( isset( $_POST['rename'] ) and $fo['rename'] == "1" )
  222. {
  223. if( isset($_SESSION['fm_files_'.$home_id]) and !empty($_SESSION['fm_files_'.$home_id]) )
  224. {
  225. foreach($_POST['items'] as $i => $item)
  226. {
  227. if(isset($_SESSION['fm_files_'.$home_id][$item]))
  228. {
  229. if(!validate_path($_SESSION['fm_files_'.$home_id][$item])){
  230. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  231. continue;
  232. }
  233. $item_path = clean_path( $path . "/" . $_SESSION['fm_files_'.$home_id][$item] );
  234. if(preg_match("/\/\.\.\/|\||;/", $item_path)) {
  235. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  236. continue;
  237. }
  238. $new_item = removeInvalidFileNameCharacters(stripslashes($_POST['values'][$i]));
  239. $new_item_path = clean_path( $path . "/" . $new_item );
  240. if ($item_path != $new_item_path)
  241. {
  242. $remote->shell_action('rename', "$item_path;$new_item_path");
  243. $db->logger( get_lang("rename") . ": $item_path " . get_lang("to") . " $new_item_path" );
  244. }
  245. }
  246. }
  247. }
  248. }
  249. // Move Files/Folders
  250. elseif( isset( $_POST['move'] ) and $fo['move'] == "1" )
  251. {
  252. $selected_path = preg_replace("#[/\.\./]+#","/", stripslashes($_POST['selected_path']));
  253. $destination = clean_path($home_cfg['home_path']. "/" . $selected_path);
  254. if($path != $destination)
  255. {
  256. if($remote->rfile_exists($destination))
  257. {
  258. foreach($_POST['items'] as $item)
  259. {
  260. if(isset($_SESSION['fm_files_'.$home_id][$item]))
  261. {
  262. if(!validate_path($_SESSION['fm_files_'.$home_id][$item])){
  263. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  264. continue;
  265. }
  266. $item_path = clean_path( $path . "/" . $_SESSION['fm_files_'.$home_id][$item] );
  267. if(preg_match("/\/\.\.\/|\||;/", $item_path)) {
  268. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  269. continue;
  270. }
  271. $destination = clean_path($destination . "/.");
  272. $remote->shell_action('move', "$item_path;$destination");
  273. $db->logger( get_lang("move") . ": $item_path " . get_lang("to") . " $destination" );
  274. }
  275. }
  276. }
  277. }
  278. }
  279. // Copy Files/Folders
  280. elseif( isset( $_POST['copy'] ) and $fo['copy'] == "1" )
  281. {
  282. $selected_path = preg_replace("#[/\.\./]+#","/", stripslashes($_POST['selected_path']));
  283. $destination = clean_path($home_cfg['home_path']. "/" . $selected_path);
  284. if($path != $destination)
  285. {
  286. if($remote->rfile_exists($destination))
  287. {
  288. foreach($_POST['items'] as $item)
  289. {
  290. if(isset($_SESSION['fm_files_'.$home_id][$item]))
  291. {
  292. if(!validate_path($_SESSION['fm_files_'.$home_id][$item])){
  293. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  294. continue;
  295. }
  296. $item_path = clean_path( $path . "/" . $_SESSION['fm_files_'.$home_id][$item] );
  297. if(preg_match("/\/\.\.\/|\||;/", $item_path)) {
  298. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  299. continue;
  300. }
  301. $destination = clean_path($destination . "/.");
  302. $remote->shell_action('copy', "$item_path;$destination");
  303. $db->logger( get_lang("copy") . ": $item_path " . get_lang("to") . " $destination" );
  304. }
  305. }
  306. }
  307. }
  308. }
  309. // Compress Files/Folders
  310. elseif( isset( $_POST['compress'] ) and $fo['compress'] == "1" )
  311. {
  312. $files_w_path = '';
  313. $items = '';
  314. foreach($_POST['items'] as $item)
  315. {
  316. if(isset($_SESSION['fm_files_'.$home_id][$item]))
  317. {
  318. if(!validate_path($_SESSION['fm_files_'.$home_id][$item])){
  319. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  320. continue;
  321. }
  322. $item_path = clean_path( $path . "/" . $_SESSION['fm_files_'.$home_id][$item] );
  323. if(preg_match("/\/\.\.\/|\||;/", $item_path)) {
  324. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  325. continue;
  326. }
  327. $files_w_path .= $item_path.'<br>';
  328. $items .= $_SESSION['fm_files_'.$home_id][$item].'\n';
  329. }
  330. }
  331. if($items != '')
  332. {
  333. $remote->compress_files($items,$path,$_POST['archive_name'],$_POST['archive_type']);
  334. $db->logger( get_lang("compress") . " " . $_POST['archive_type'] . ":<br>$files_w_path" );
  335. }
  336. }
  337. // uncompress
  338. elseif( isset( $_POST['uncompress'] ) and $fo['uncompress'] == "1" )
  339. {
  340. $selected_path = preg_replace("#[/\.\./]+#","/", stripslashes($_POST['selected_path']));
  341. $destination = clean_path($home_cfg['home_path']. "/" . $selected_path);
  342. if($remote->rfile_exists($destination))
  343. {
  344. foreach($_POST['items'] as $item)
  345. {
  346. if(isset($_SESSION['fm_files_'.$home_id][$item]))
  347. {
  348. if(!validate_path($_SESSION['fm_files_'.$home_id][$item])){
  349. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  350. continue;
  351. }
  352. $file_location = clean_path( $path . "/" . $_SESSION['fm_files_'.$home_id][$item] );
  353. if(preg_match("/\/\.\.\/|\||;/", $file_location)) {
  354. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  355. continue;
  356. }
  357. $remote->uncompress_file($file_location, $destination);
  358. $db->logger( get_lang("uncompress") . ": $file_location " . to . " $destination." );
  359. }
  360. }
  361. }
  362. }
  363. // Create file
  364. elseif( isset( $_POST['create_file'] ) and $fo['create_file'] == "1" )
  365. {
  366. $file_name = removeInvalidFileNameCharacters(stripslashes($_POST['file_name']));
  367. $destination = clean_path( $path . "/" . $file_name);
  368. $remote->shell_action('touch', $destination);
  369. $db->logger( get_lang("create_file") . ": $destination" );
  370. }
  371. // Send by email
  372. elseif( isset( $_POST['send_by_email'] ) and $fo['send_by_email'] == "1" )
  373. {
  374. $archive_name = $_POST['archive_name'];
  375. $archive_type = $_POST['archive_type'];
  376. $subject = $_POST['subject'];
  377. $message = $_POST['message'];
  378. $dest_email = $_POST['dest_email'];
  379. $items = '';
  380. foreach($_POST['items'] as $item)
  381. {
  382. if(isset($_SESSION['fm_files_'.$home_id][$item]))
  383. {
  384. if(!validate_path($_SESSION['fm_files_'.$home_id][$item])){
  385. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  386. continue;
  387. }
  388. $item_path = clean_path( $path . "/" . $_SESSION['fm_files_'.$home_id][$item] );
  389. if(preg_match("/\/\.\.\/|\||;/", $item_path)) {
  390. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$item]));
  391. continue;
  392. }
  393. $items .= $_SESSION['fm_files_'.$home_id][$item].'\n';
  394. }
  395. }
  396. if($items != '')
  397. {
  398. $retval = $remote->compress_files($items,$path,$archive_name,$archive_type);
  399. $archive = clean_path( $path . "/" . $archive_name . "." . $archive_type );
  400. if( $retval == 0 )
  401. {
  402. do{
  403. $size1 = $remote->shell_action('size', $archive);
  404. sleep( 2 );
  405. $size2 = $remote->shell_action('size', $archive);
  406. }while($size1 != $size2);
  407. }
  408. if( $retval != -1 and $remote->rfile_exists($archive) )
  409. {
  410. $mail_retval = $remote->exec( "(echo '" . esc_squote($message) . "' | mutt -a '" . esc_squote($archive) . "' -s '" . esc_squote($subject) . "' -- '" . esc_squote($dest_email) . "');echo \$?" );
  411. if($mail_retval == 0)
  412. {
  413. echo get_lang("mail_sent_successfully");
  414. $db->logger( get_lang("send_by_email") . ": '$archive'<br>Subject: '$subject'<br>to: '$dest_email'" );
  415. }
  416. else
  417. {
  418. echo "The email could not be sent,\n".
  419. "the package mutt or mutt-patched (a mail client)\n".
  420. "must be installed, and postfix should be configured\n".
  421. "in order to send large files.";
  422. }
  423. }
  424. }
  425. }
  426. // Secure File
  427. elseif( isset( $_POST['secure_file'] ) and $isAdmin )
  428. {
  429. if(isset($_SESSION['fm_files_'.$home_id][$_POST['item']]))
  430. {
  431. if(preg_match("/\/\.\.\/|\||;/", $_SESSION['fm_files_'.$home_id][$_POST['item']])) {
  432. print_failure(get_lang("unallowed_char") . " : " . htmlspecialchars($_SESSION['fm_files_'.$home_id][$_POST['item']]));
  433. return;
  434. }
  435. if($_POST['set_attr'] == '+i' or $_POST['set_attr'] == '-i')
  436. {
  437. $type = $_POST['set_attr'] == '+i' ? get_lang("chattr_locked") : get_lang("chattr_unlocked");
  438. $action = "chattr".$_POST['set_attr'];
  439. $file_path = clean_path( $path . "/" . $_SESSION['fm_files_'.$home_id][$_POST['item']] );
  440. $remote->secure_path($action, $file_path);
  441. $db->logger( "$type: $file_path" );
  442. }
  443. }
  444. }
  445. else
  446. {
  447. ?>
  448. <script type="text/javascript" src="js/jquery/plugins/jquery.form.min.js"></script>
  449. <script type="text/javascript" src="js/zlib/zlib.min.js"></script>
  450. <script type="text/javascript" src="js/modules/litefm.js"></script>
  451. <?php
  452. echo "<h2>";
  453. echo empty($home_cfg['home_name']) ? get_lang("not_available") : htmlentities($home_cfg['home_name']);
  454. echo "</h2>";
  455. $_SESSION['fm_files_'.$home_id] = array();
  456. $show_path = (isset($_SESSION['fm_cwd_'.$home_id])) ? clean_path($_SESSION['fm_cwd_'.$home_id]) : "/";
  457. if($isAdmin)
  458. $show_path = clean_path($home_cfg['home_path'].$show_path);
  459. echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id=".$home_cfg['home_id']."'><< ". get_lang("back") ."</a></td></tr></table>";
  460. if ($remote->rfile_exists($path))
  461. {
  462. echo "<table class='center' style='width:100%;' ><tr>\n".
  463. "<td colspan='3' ><h3>".
  464. get_lang_f('currently_viewing',$show_path)."</h3></td>".
  465. "</tr></table>\n";
  466. echo "<div class='file-operations' >\n";
  467. foreach($fo_keys as $key)
  468. {
  469. if($fo[$key] == "1")
  470. echo "<div class='operations-button' id='$key'><img src='" . check_theme_image("modules/litefm/action-images/$key.gif") . "' /><div>&nbsp;".get_lang($key)."</div></div>\n";
  471. }
  472. echo "</div>\n";
  473. $dirlist = $remote->remote_dirlistfm($path);
  474. if (!is_array($dirlist))
  475. {
  476. if(isset($_SESSION['fm_cwd_'.$home_id]))
  477. {
  478. unset($_SESSION['fm_cwd_'.$home_id]);
  479. $view->refresh("?m=litefm&amp;home_id=$home_id",0);
  480. return;
  481. }
  482. else
  483. {
  484. print_failure( get_lang("failed_list") );
  485. return;
  486. }
  487. }
  488. if ( empty($dirlist) )
  489. {
  490. echo "<table class='center' style='width:100%;' >\n".
  491. show_back($home_id)."</table>";
  492. echo "<p>" . get_lang("empty_directory") . "</p>";
  493. }
  494. else
  495. {
  496. echo "<table class='center' style='width:100%;' >\n"
  497. .show_back($home_id).
  498. "<tr>\n<td style='width:10px;' >".
  499. "<input type=checkbox name='switch' id='switch_check' />".
  500. "</td>\n<td align=left>".
  501. get_lang("filename") ."</td>\n";
  502. if( $os == "linux" )
  503. echo "<td>". get_lang("filesecure") ."</td>\n";
  504. echo "<td>". get_lang("filesize") ." [". get_lang("bytes") ."]</td>\n<td>".
  505. get_lang("owner") ." ". get_lang("group") ."</td>\n</tr>\n";
  506. $i = 0;
  507. if(isset($dirlist['directorys']) and is_array($dirlist['directorys']))
  508. {
  509. $dirlist['directorys'] = array_orderby($dirlist['directorys'], 'filename', SORT_ASC);
  510. foreach($dirlist['directorys'] as $directory)
  511. {
  512. $directory['filename'] = removeInvalidFileNameCharacters($directory['filename']);
  513. echo "<tr>\n".
  514. "<td>".
  515. "<input type=checkbox name='folder' data-item='$i' value=\"" . str_replace('"', "&quot;", $directory['filename']) . "\" class='item' />\n".
  516. "</td>".
  517. "<td align=left>".
  518. "<img class=\"viewitem\" src=\"" . check_theme_image("images/folder.png") . "\" alt=\"Directory\" /> ".
  519. "<a href=\"?m=litefm&amp;home_id=$home_id&amp;item=$i&amp;name=" . urlencode($directory['filename']) . "&amp;type=directory\">".
  520. $directory['filename'] . "</a></td>";
  521. if( $os == "linux" )
  522. echo "<td>-</td>";
  523. echo "<td>-</td> <td>" . $directory['user'] . " " . $directory['group']. "</td>\n".
  524. "</tr>\n";
  525. $_SESSION['fm_files_'.$home_id][$i] = $directory['filename'];
  526. $i++;
  527. }
  528. }
  529. if(isset($dirlist['files']) and is_array($dirlist['files']))
  530. {
  531. $dirlist['files'] = array_orderby($dirlist['files'], 'filename', SORT_ASC);
  532. foreach($dirlist['files'] as $file)
  533. {
  534. if(stripos($file['filename'], "OGP_HOME_") !== false && stripos($file['filename'], $home_id . "_startup_scr.sh") !== false){
  535. continue;
  536. }
  537. $file['filename'] = removeInvalidFileNameCharacters($file['filename']);
  538. if( $os == "linux" )
  539. {
  540. if($isAdmin){
  541. $secureFile = "<td><div data-item='$i' data-file_name=\"" . str_replace('"', "&quot;", $file['filename']) . "\" class='chattrButton ";
  542. if( preg_match( "/i/", $file['attr'] ) ){
  543. $secureFile .= "locked' data-set_attr='-i' ><i></i><span>". get_lang("chattr_no");
  544. }else{
  545. $secureFile .= "unlocked' data-set_attr='+i' ><i></i><span>". get_lang("chattr_yes");
  546. }
  547. $secureFile .= "</span></div></td>\n";
  548. }else{
  549. $secureFile = "<td><span class=";
  550. if( preg_match( "/i/", $file['attr'] ) ){
  551. $secureFile .= "'chattrLock'>". get_lang("chattr_locked");
  552. }else{
  553. $secureFile .= "'chattrUnlock'>". get_lang("chattr_unlocked");
  554. }
  555. $secureFile .= "</span></td>\n";
  556. }
  557. }
  558. else
  559. $secureFile = "";
  560. echo "<tr>\n".
  561. "<td>".
  562. "<input type=checkbox name='file' data-item='$i' value=\"" . str_replace('"', "&quot;", $file['filename']) . "\" class='item' />\n".
  563. "</td>".
  564. "<td align=left id='fileid$i' >";
  565. echo "<img class=\"viewitem\" src=\"" . check_theme_image("images/txt.png") . "\" alt=\"Text file\" /> ".
  566. "<a href=\"?m=litefm&amp;home_id=$home_id&amp;item=$i&amp;p=read_file&amp;name=" . urlencode($file['filename']) . "&amp;type=file\">". get_lang("button_edit") ."</a>".
  567. "<a href=\"javascript:downloadFile($home_id, $i, {$file['size']}, '".str_replace("'", "\'", $file['filename'])."');\" id=\"jsDwl$i\" >" .$file['filename'] . "</a>&nbsp;".
  568. "</td>$secureFile<td>" . $file['size'] . "</td> <td>" . $file['user'] . " " . $file['group']. "</td>\n";
  569. echo "</tr>\n";
  570. $_SESSION['fm_files_'.$home_id][$i] = $file['filename'];
  571. $i++;
  572. }
  573. }
  574. if(isset($dirlist['binarys']) and is_array($dirlist['binarys']))
  575. {
  576. $dirlist['binarys'] = array_orderby($dirlist['binarys'], 'filename', SORT_ASC);
  577. foreach($dirlist['binarys'] as $binary)
  578. {
  579. $binary['filename'] = removeInvalidFileNameCharacters($binary['filename']);
  580. if( $os == "linux" )
  581. {
  582. if($isAdmin){
  583. $secureFile = "<td><div data-item='$i' data-file_name=\"" . str_replace('"', "&quot;", $binary['filename']) . "\" class='chattrButton ";
  584. if( preg_match( "/i/", $binary['attr'] ) ){
  585. $secureFile .= "locked' data-set_attr='-i' ><i></i><span>". get_lang("chattr_no");
  586. }else{
  587. $secureFile .= "unlocked' data-set_attr='+i' ><i></i><span>". get_lang("chattr_yes");
  588. }
  589. $secureFile .= "</span></div></td>\n";
  590. }else{
  591. $secureFile = "<td><span class=";
  592. if( preg_match( "/i/", $binary['attr'] ) ){
  593. $secureFile .= "'chattrLock'>". get_lang("chattr_locked");
  594. }else{
  595. $secureFile .= "'chattrUnlock'>". get_lang("chattr_unlocked");
  596. }
  597. $secureFile .= "</span></td>\n";
  598. }
  599. }
  600. else
  601. $secureFile = "";
  602. echo "<tr>\n".
  603. "<td>".
  604. "<input type=checkbox name='binary' data-item='$i' value=\"" . str_replace('"', "&quot;", $binary['filename']) . "\" class='item' />\n".
  605. "</td>".
  606. "<td align=left id='fileid$i' >";
  607. echo "<img class=\"viewitem\" src=\"" . check_theme_image("images/exec.png") . "\" alt=\"Binary file\" /> ".
  608. "<a href=\"javascript:downloadFile($home_id, $i, {$binary['size']}, '".str_replace("'", "\'", $binary['filename'])."');\" id=\"jsDwl$i\" >" .$binary['filename'] . "</a>&nbsp;".
  609. "</td>$secureFile<td>" . $binary['size'] . "</td><td>" . $binary['user'] . " " . $binary['group']. "</td>\n";
  610. echo "</tr>\n";
  611. $_SESSION['fm_files_'.$home_id][$i] = $binary['filename'];
  612. $i++;
  613. }
  614. }
  615. echo "</table>\n";
  616. }
  617. }
  618. echo "<table class='center'><tr><td><a href='?m=gamemanager&amp;p=game_monitor&amp;home_id=".$home_cfg['home_id']."'><< ". get_lang("back") ."</a></td></tr></table>";
  619. // Dialog translation && info
  620. $user = $db->getUserById($_SESSION['user_id']);
  621. echo "<div id='dialog' ".
  622. "data-folder=\"" . clean_path("/".str_replace('"', "&quot;", @(string)$_SESSION['fm_cwd_'.$home_id])) . "\" " .
  623. "data-select_at_least_one_item='" . get_lang("select_at_least_one_item") . "' " .
  624. "data-ask_delete='" . get_lang("delete_item") . "' " .
  625. "data-ask_rename='" . get_lang("rename_item") . "' " .
  626. "data-ask_move='" . get_lang("move_item") . "' " .
  627. "data-ask_copy='" . get_lang("copy_item") . "' " .
  628. "data-ask_compress='" . get_lang("compress_item") . "' " .
  629. "data-ask_uncompress='" . get_lang("uncompress_item") . "' " .
  630. "data-archive_name='" . get_lang("archive_name") . "' " .
  631. "data-archive_type='" . get_lang("archive_type") . "' " .
  632. "data-file_name='" . get_lang("file_name") . "' " .
  633. "data-folder_name='" . get_lang("folder_name") . "' " .
  634. "data-compresses_files_separately='" . get_lang("compresses_files_separately") . "' " .
  635. "data-to='" . get_lang("to") . "' " .
  636. "data-yes='" . get_lang("yes") . "' " .
  637. "data-no='" . get_lang("no") . "' " .
  638. "data-max_file_uploads='" . ini_get('max_file_uploads') . "' " .
  639. "data-upload_to_web='" . get_lang("upload_to_web") . "' " .
  640. "data-transfer_to_server='" . get_lang("transfer_to_server") . "' " .
  641. "data-upload='" . get_lang("upload") . "' " .
  642. "data-ask_send_by_email='" . get_lang("send_item_by_email") . "' " .
  643. "data-subject='" . get_lang("subject") . "' " .
  644. "data-message='" . get_lang("message") . "' " .
  645. "data-dest_email='" . get_lang("dest_email") . "' " .
  646. "data-user_email='" . $user['users_email'] . "' ";
  647. if($isAdmin)
  648. echo "data-ask_change_attr=\"" . get_lang_f( 'secure_item', clean_path( str_replace('"', "&quot;", $path) . "/%file_name%" ) ) . "\" ";
  649. echo "></div>";
  650. }
  651. }
  652. ?>