function GetSFileList($dir, $content, $re = 0) { global $filedata, $j, $nowpath, $writabledb; !$j && ($j = 1); if ($dh = opendir($dir)) { while ($file = readdir($dh)) { $ext = getextension($file); $f = str_replace('//', '/', $dir . '/' . $file); if ($file != '.' && $file != '..' && is_dir($f)) { GetSFileList($f, $content, $re = 0); } elseif ($file != '.' && $file != '..' && is_file($f) && in_array($ext, explode(',', $writabledb))) { $find = 0; if ($re) { if (preg_match('@' . $content . '@', $file) || preg_match('@' . $content . '@', @file_get_contents($f))) { $find = 1; } } else { if (strstr($file, $content) || strstr(@file_get_contents($f), $content)) { $find = 1; } } if ($find) { $filedata[$j]['filename'] = str_replace($nowpath, '', $f); $filedata[$j]['size'] = sizecount(@filesize($f)); $filedata[$j]['mtime'] = @date('Y-m-d H:i:s', filemtime($f)); $filedata[$j]['filechmod'] = getChmod($f); $filedata[$j]['fileperm'] = getPerms($f); $filedata[$j]['fileowner'] = getUser($f); $filedata[$j]['dirlink'] = $dir; $filedata[$j]['server_link'] = $f; $filedata[$j]['client_link'] = ue($f); $j++; } } } closedir($dh); clearstatcache(); return $filedata; } else { return array(); } }
function GetWFileList($dir) { global $filedata, $j, $nowpath; !$j && ($j = 1); if ($dh = opendir($dir)) { while ($file = readdir($dh)) { $ext = getextension($file); $f = str_replace('//', '/', $dir . '/' . $file); if ($file != '.' && $file != '..' && is_dir($f)) { GetWFileList($f); } elseif ($file != '.' && $file != '..' && is_file($f)) { if (is_writable($f)) { $filedata[$j]['filename'] = str_replace($nowpath, '', $f); $filedata[$j]['size'] = sizecount(@filesize($f)); $filedata[$j]['mtime'] = @date('Y-m-d H:i:s', filemtime($f)); $filedata[$j]['filechmod'] = getChmod($f); $filedata[$j]['fileperm'] = getPerms($f); $filedata[$j]['fileowner'] = getUser($f); $filedata[$j]['dirlink'] = $dir; $filedata[$j]['server_link'] = $f; $filedata[$j]['client_link'] = ue($f); $j++; } } } closedir($dh); clearstatcache(); return $filedata; } else { return array(); } }
function GetList($dir) { global $dirdata, $j, $nowpath; !$j && ($j = 1); if ($dh = opendir($dir)) { while ($file = readdir($dh)) { $f = str_replace('//', '/', $dir . '/' . $file); if ($file != '.' && $file != '..' && is_dir($f)) { if (is_writable($f)) { $dirdata[$j]['filename'] = str_replace($nowpath, '', $f); $dirdata[$j]['mtime'] = @date('Y-m-d H:i:s', filemtime($f)); $dirdata[$j]['dirchmod'] = getChmod($f); $dirdata[$j]['dirperm'] = getPerms($f); $dirdata[$j]['dirlink'] = ue($dir); $dirdata[$j]['server_link'] = $f; $dirdata[$j]['client_link'] = ue($f); $j++; } GetList($f); } } closedir($dh); clearstatcache(); return $dirdata; } else { return array(); } }
closedir($a); foreach ($dirs as $d) { $d2 = ($dire == ".//" ? "" : $dire) . $d; $d3 = $dir != $root ? "dir=" . $dir . "&" : ""; print "<tr><td><a href=\"?dir=" . $d2 . "\">" . $d . "</a></td><td>Directory</td>"; print "<td>" . getPerms($d2) . "</td><td>" . dirsize($d2) . " kb</td><td>" . getLastModific($d2) . "</td>"; print "<td><a href=\"?" . $d3 . "mode=deletedir&d=" . $d . "\">D</a> "; print "<a href=\"?" . $d3 . "mode=rename&file=" . $d . "\">R</a></td></tr>"; } foreach ($files as $file) { $file2 = $dire . $file; $d3 = $dir != $root ? "dir=" . $dir . "&" : ""; print "<tr><td><a target=\"_blank\" href=\"" . $file2 . "\">" . $file . "</a></td>"; $ex = pathinfo($file2); print "<td>File " . (empty($ex['extension']) ? "sconosciuto" : $ex['extension']) . "</td>"; print "<td>" . getPerms($file2) . "</td><td>" . Size($file2) . " kb</td><td>" . getLastModific($file2) . "</td>"; print "<td><a title='Edit' href=\"?" . $d3 . "mode=edit&file=" . $file . "\">E</a> "; print "<a title='Delete' href=\"?" . $d3 . "mode=delete&file=" . $file . "\">D</a> "; print "<a title='Rename' href=\"?" . $d3 . "mode=rename&file=" . $file . "\">R</a> "; //print "<a title='Move' href=\"?".$d3."mode=move&file=".$file."\">M</a></td></tr>"; } ?> </table> <?php if (isset($_GET['mode']) && $_GET['mode'] == "rename") { ?> <form action="" name="rename" method="post">
function PermsColor($f) { if (!is_readable($f)) { return '<span class="red">' . getPerms($f) . '</span>'; } elseif (!is_writable($f)) { return '<span class="black">' . getPerms($f) . '</span>'; } else { return '<span class="green">' . getPerms($f) . '</span>'; } }
function copyFolder($folder, $dir_destin, $dir_source) { global $conn_id; global $serverTmp; global $lang_folder_cant_access; global $lang_folder_exists; global $lang_folder_cant_chmod; global $lang_folder_cant_make; global $lang_server_error_down; global $lang_file_cant_chmod; global $lang_chmod_no_support; $isError = 0; // Check if ftp_chmod() exists if (!function_exists('ftp_chmod')) { $_SESSION["errors"][] = $lang_chmod_no_support; } // Check source folder exists if (!@ftp_chdir($conn_id, $dir_source . "/" . $folder)) { if (checkFirstCharTilde($dir_source) == 1) { if (!@ftp_chdir($conn_id, replaceTilde($dir_source) . "/" . $folder)) { recordFileError("folder", tidyFolderPath($dir_destin, $folder), $lang_folder_cant_access); $isError = 1; } } else { recordFileError("folder", tidyFolderPath($dir_destin, $folder), $lang_folder_cant_access); $isError = 1; } } if ($isError == 0) { // Check if destination folder exists if (checkFileExists("d", $folder, $dir_destin) == 1) { recordFileError("folder", tidyFolderPath($dir_destin, $folder), $lang_folder_exists); } else { // Create the new folder if (!@ftp_mkdir($conn_id, $dir_destin . "/" . $folder)) { if (checkFirstCharTilde($dir_destin) == 1) { if (!@ftp_mkdir($conn_id, replaceTilde($dir_destin) . "/" . $folder)) { recordFileError("folder", tidyFolderPath($dir_destin, $folder), $lang_folder_cant_make); $isError = 1; } } else { recordFileError("folder", tidyFolderPath($dir_destin, $folder), $lang_folder_cant_make); $isError = 1; } } } } if ($isError == 0) { // Copy permissions (Lin) if ($_SESSION["win_lin"] == "lin" || $_SESSION["win_lin"] == "mac") { $mode = getPerms($dir_source, $folder); $lang_folder_cant_chmod = str_replace("[perms]", $mode, $lang_folder_cant_chmod); if (function_exists('ftp_chmod')) { if (!@ftp_chmod($conn_id, $mode, $dir_destin . "/" . $folder)) { if (checkFirstCharTilde($dir_destin) == 1) { if (!@ftp_chmod($conn_id, $mode, replaceTilde($dir_destin) . "/" . $folder)) { recordFileError("folder", $folder, $lang_folder_cant_chmod); } } else { recordFileError("folder", $folder, $lang_folder_cant_chmod); } } } } // Go through array of files/folders $ftp_rawlist = getFtpRawList($dir_source . "/" . $folder); if (is_array($ftp_rawlist)) { $count = 0; foreach ($ftp_rawlist as $ff) { $count++; $isDir = 0; $isError = 0; // Split up array into values (Lin) if ($_SESSION["win_lin"] == "lin") { $ff = preg_split("/[\\s]+/", $ff, 9); $perms = $ff[0]; $file = $ff[8]; if (getFileType($perms) == "d") { $isDir = 1; } } // Split up array into values (Mac) // skip first line if ($_SESSION["win_lin"] == "mac") { if ($count == 1) { continue; } $ff = preg_split("/[\\s]+/", $ff, 9); $perms = $ff[0]; $file = $ff[8]; if (getFileType($perms) == "d") { $isDir = 1; } } // Split up array into values (Win) if ($_SESSION["win_lin"] == "win") { $ff = preg_split("/[\\s]+/", $ff, 4); $size = $ff[2]; $file = $ff[3]; if ($size == "<DIR>") { $isDir = 1; } } if ($file != "." && $file != "..") { // Check for sub folders and then perform this function if (getFileType($perms) == "d") { copyFolder($file, $dir_destin . "/" . $folder, $dir_source . "/" . $folder); } else { $fp1 = tempnam($serverTmp, "monsta-"); $fp2 = $dir_source . "/" . $folder . "/" . $file; $fp3 = $dir_destin . "/" . $folder . "/" . $file; register_shutdown_function('shutdown_unlinkTempFile', $fp1); ensureFtpConnActive(); // Download if (!@ftp_get($conn_id, $fp1, $fp2, FTP_BINARY)) { if (checkFirstCharTilde($fp2) == 1) { if (!@ftp_get($conn_id, $fp1, replaceTilde($fp2), FTP_BINARY)) { recordFileError("file", $file, $lang_server_error_down); $isError = 1; } } else { recordFileError("file", $file, $lang_server_error_down); $isError = 1; } } // Upload if ($isError == 0) { ensureFtpConnActive(); if (!@ftp_put($conn_id, $fp3, $fp1, FTP_BINARY)) { if (checkFirstCharTilde($fp3) == 1) { if (!@ftp_put($conn_id, replaceTilde($fp3), $fp1, FTP_BINARY)) { recordFileError("file", $file, $lang_server_error_down); $isError = 1; } } else { recordFileError("file", $file, $lang_server_error_down); $isError = 1; } } } if ($isError == 0) { // Chmod files (Lin) if ($_SESSION["win_lin"] == "lin" || $_SESSION["win_lin"] == "mac") { $perms = getChmodNumber($perms); $mode = formatChmodNumber($perms); $lang_file_cant_chmod = str_replace("[perms]", $perms, $lang_file_cant_chmod); if (function_exists('ftp_chmod')) { if (!@ftp_chmod($conn_id, $mode, $fp3)) { if (checkFirstCharTilde($fp3) == 1) { if (!@ftp_chmod($conn_id, $mode, replaceTilde($fp3))) { recordFileError("file", $file, $lang_server_error_down); } } else { recordFileError("file", $file, $lang_server_error_down); } } } } } // Delete tmp file unlink($fp1); } } } } } }
$_SESSION['pefi_user'] = $user; // will redirect page redirect(isset($_GET['redirect_to']) ? $_GET['redirect_to'] : ''); } else { $_PEFI->view->content .= get_form("Try again!"); } } elseif ($todo == 'logout') { unset($_SESSION['pefi_user']); redirect(isset($_GET['redirect_to']) ? $_GET['redirect_to'] : ''); } elseif (strpos($todo, 'manage') === 0) { if (!$_PEFI->crdntls->can('user', 'list')) { redirect_to_login($_PEFI->route->page); } include "{$_PEFI->path}/form/form.php"; if ($todo == 'manage_pass') { $label = 'Manage User Passwords'; $elements = array(new PrimaryKeyElement(array('prop' => 'id', 'label' => 'PrimKey', 'isOrderable' => true)), new TextElement(array('prop' => 'name', 'label' => 'User', 'isEditable' => false, 'isOrderable' => true, 'isDefOrder' => true, 'isFilterable' => true, 'isOrderable' => true, 'allowEmpty' => false)), new PasswordElement(array('prop' => 'pass', 'label' => 'Password', 'isListable' => false, 'allowEmpty' => false, 'defVal' => 'Abcd123!'))); } else { $label = 'Manage Users'; $elements = array(new PrimaryKeyElement(array('prop' => 'id', 'label' => 'PrimKey', 'isOrderable' => true)), new TextElement(array('prop' => 'name', 'label' => 'User', 'isOrderable' => true, 'isDefOrder' => true, 'isFilterable' => true, 'allowEmpty' => false)), new TextElement(array('prop' => 'lang', 'label' => 'Default Language', 'isFilterable' => true, 'isOrderable' => true, 'defSearchOp' => '=', 'allowEmpty' => false, 'defVal' => 'en')), new ScolonSepListGroupElement(array('prop' => 'perms', 'label' => 'Permissions', 'items' => getPerms(), 'isSearchMulti' => true))); } $form = new TableForm(array('label' => $label, 'elements' => $elements, 'table' => new OneTableDB($_PEFI->db, "{$_PEFI->dbpref}user"), 'lock' => $_PEFI->lock, 'logger' => new Logger(Logger::INFO, array(new FileLoggerOutput('_log/user.log'))), 'credentials' => $_PEFI->crdntls, 'canDelete' => true, 'filter' => $_GET, 'decorator' => isset($_GET['json']) ? JsonDecorator::get() : HtmlDecorator::get())); $_PEFI->view->head = $_PEFI->form->head; $_PEFI->view->head .= '<script type="text/javascript">PEFI.CRUD.edit_mode="popup";</script>'; $_PEFI->view->content = $form->handle($_SERVER['REQUEST_METHOD'], $_POST); } elseif ($_PEFI->user) { // will redirect page redirect(); } else { $_PEFI->view->content .= get_form(); }
function copyFolder($folder, $dir_destin, $dir_source) { global $conn_id; global $serverTmp; global $lang_folder_cant_access; global $lang_folder_exists; global $lang_folder_cant_chmod; global $lang_folder_cant_make; global $lang_server_error_down; global $lang_file_cant_chmod; // Check folder exists if (!@ftp_chdir($conn_id, $dir_source . "/" . $folder)) { $_SESSION["errors"][] = str_replace("[folder]", "<strong>" . tidyFolderPath($dir_destin, $folder) . "</strong>", $lang_folder_cant_access); } else { $ftp_rawlist = getFtpRawList($dir_source . "/" . $folder); // Check if folder exists if (checkFileExists("d", $folder, $dir_destin) == 1) { $_SESSION["errors"][] = str_replace("[folder]", "<strong>" . tidyFolderPath($dir_destin, $folder) . "</strong>", $lang_folder_exists); } else { // Create the new folder if (@ftp_mkdir($conn_id, $dir_destin . "/" . $folder)) { // Copy permissions (Lin) if ($_SESSION["win_lin"] == "lin") { $mode = getPerms($dir_source, $folder); if (!@ftp_chmod($conn_id, $mode, $dir_destin . "/" . $folder)) { $lang_folder_cant_chmod = str_replace("[perms]", $perms, $lang_folder_cant_chmod); $lang_folder_cant_chmod = str_replace("[folder]", $folder, $lang_folder_cant_chmod); $_SESSION["errors"][] = $lang_folder_cant_chmod; } } } else { $_SESSION["errors"][] = str_replace("[folder]", "<strong>" . tidyFolderPath($dir_destin, $folder) . "</strong>", $lang_folder_cant_make); } } // Go through array of files/folders foreach ($ftp_rawlist as $ff) { $isDir = 0; // Split up array into values (Lin) if ($_SESSION["win_lin"] == "lin") { $ff = preg_split("/[\\s]+/", $ff, 9); $perms = $ff[0]; $file = $ff[8]; if (getFileType($perms) == "d") { $isDir = 1; } } // Split up array into values (Win) if ($_SESSION["win_lin"] == "win") { $ff = preg_split("/[\\s]+/", $ff, 4); $size = $ff[2]; $file = $ff[3]; if ($size == "<DIR>") { $isDir = 1; } } if ($file != "." && $file != "..") { // Check for sub folders and then perform this function if (getFileType($perms) == "d") { copyFolder($file, $dir_destin . "/" . $folder, $dir_source . "/" . $folder); } else { $fp1 = $serverTmp . "/" . $file; $fp2 = $dir_source . "/" . $folder . "/" . $file; $fp3 = $dir_destin . "/" . $folder . "/" . $file; if (!@ftp_get($conn_id, $fp1, $fp2, FTP_BINARY)) { $_SESSION["errors"][] = str_replace("[file]", "<strong>" . $file . "</strong>", $lang_server_error_down); } else { if (@ftp_put($conn_id, $fp3, $fp1, FTP_BINARY)) { // Chmod files (Lin) if ($_SESSION["win_lin"] == "lin") { $perms = getChmodNumber($perms); $mode = formatChmodNumber($perms); if (!@ftp_chmod($conn_id, $mode, $fp3)) { $lang_file_cant_chmod = str_replace("[perms]", $perms, $lang_file_cant_chmod); $lang_file_cant_chmod = str_replace("[file]", $file, $lang_file_cant_chmod); $_SESSION["errors"][] = $lang_file_cant_chmod; } } } else { $_SESSION["errors"][] = str_replace("[file]", "<strong>" . $file . "</strong>", $lang_server_error_up); } } } } } } }