Skip to content

Commit

Permalink
Merge pull request #422 from SysVoid/patch-1
Browse files Browse the repository at this point in the history
Removed closing PHP tags
  • Loading branch information
serghey-rodin committed Oct 22, 2015
2 parents 6b96058 + de6fcff commit 97a368a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 78 deletions.
2 changes: 0 additions & 2 deletions web/api/index.php
Expand Up @@ -78,5 +78,3 @@
}
}
}

?>
107 changes: 40 additions & 67 deletions web/file_manager/files.php
Expand Up @@ -4,25 +4,18 @@
//define(LISTING_TIMEOUT, 0.000001);
define(LISTING_TIMEOUT, 5);




//echo 'files: ';
//$files = scandir(__DIR__);


//echo '<pre>';
//print_r($files);


//$_REQUEST['sort_field'] = 'size';
$_REQUEST['sort_field'] = 'name';
//$_REQUEST['sort_field'] = 'atime';
//$_REQUEST['sort_field'] = 'mtime';
$_REQUEST['sort_desc'] = 1;



/*
+- copy file / dir [ recursive ]
+- rename(move) file / dir
Expand All @@ -33,7 +26,7 @@
+- create dir
*/

switch($_REQUEST['action']){
switch($_REQUEST['action']) {
case 'copy': fm_copy($_REQUEST['source'], $_REQUEST['dest']); break;
case 'rename': fm_rename($_REQUEST['source'], $_REQUEST['dest']); break;
case 'delete': fm_delete($_REQUEST['source']); break;
Expand All @@ -53,24 +46,12 @@
break;
}






//echo $_GET['sort_field'];

// if(in_array($_GET['sort_field'], $available_sort_fields)){
// echo '1';
// }








/*
upload_file
Expand All @@ -87,67 +68,66 @@
download file / image
*/



function fm_create_file($filename){
function fm_create_file($filename)
{
if(is_file($filename))
return array('error' => 'file exists', 'code' => 1);

return !!fopen($filename, 'w');
return (bool) fopen($filename, 'w'); // (bool) > !!, sorry
}


function fm_create_dir($dirname){
function fm_create_dir($dirname)
{
if(is_dir($filename))
return array('error' => 'directory exists', 'code' => 1);

// TODO set parent directory mode
return mkdir($dirname);
}


function fm_chown($filename, $recursive = 0, $uid = FALSE, $gid = FALSE){
if(is_dir($filename) && $recursive){
function fm_chown($filename, $recursive = 0, $uid = FALSE, $gid = FALSE)
{
if (is_dir($filename) && $recursive) {
$dir_handle = opendir($dir);
while ($item = readdir($dir_handle)){
if (!in_array($item, array('.','..'))){
while ($item = readdir($dir_handle)) {
if (!in_array($item, array('.','..'))) {
$new_item = $filename.'/'.$item;

if($uid !== FALSE) chown($new_item, (int)$uid);
if($gid !== FALSE) chgrp($new_item, (int)$gid);
if ($uid !== FALSE) chown($new_item, (int)$uid);
if ($gid !== FALSE) chgrp($new_item, (int)$gid);

if(is_dir($new_item)){
if (is_dir($new_item)) {
fm_chown($new_item, $recursive, $uid, $gid);
}
}
}
}else{
} else {
if($uid !== FALSE) chown($filename, (int)$uid);
if($gid !== FALSE) chgrp($filename, (int)$gid);
}
}


function fm_chmod($filename, $recursive = 0, $mode){
if(is_dir($filename) && $recursive){
function fm_chmod($filename, $recursive = 0, $mode)
{
if(is_dir($filename) && $recursive) {
$dir_handle = opendir($dir);
while ($item = readdir($dir_handle)){
if (!in_array($item, array('.','..'))){
while ($item = readdir($dir_handle)) {
if (!in_array($item, array('.','..'))) {
$new_item = $filename.'/'.$item;
chmod($new_item, octdec($mode));

if(is_dir($new_item)){
if (is_dir($new_item)) {
fm_chmod($new_item, $recursive, $mode);
}
}
}
}else{
} else {
chmod($filename, octdec($mode));
}
}


function fm_delete($filename){
function fm_delete($filename)
{
if(is_dir($filename)){
foreach (
$iterator = new RecursiveIteratorIterator(
Expand All @@ -162,19 +142,21 @@ function fm_delete($filename){
// copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
}
}
}else{
} else {
return unlink($filename);
}
}


function fm_rename($source, $dest){
function fm_rename($source, $dest)
{
return rename($source, $dest);
}


function fm_copy($source, $dest){
if(is_dir($source)){
function fm_copy($source, $dest)
{
if (is_dir($source)) {
foreach (
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
Expand All @@ -187,14 +169,13 @@ function fm_copy($source, $dest){
copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
}
}

}else{
return copy($source, $dest);
}
}


function list_dir(){
function list_dir()
{
$dir_iterator = new RecursiveDirectoryIterator("/path");
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
// could use CHILD_FIRST if you so wish
Expand All @@ -214,12 +195,9 @@ function list_dir(){
echo "\nTotal file size: ", $size, " bytes\n";
}




/// fast removing directory
function rmrf($dir) {
function rmrf($dir)
{
foreach (glob($dir) as $file) {
if (is_dir($file)) {
rmrf("$file/*");
Expand All @@ -230,9 +208,6 @@ function rmrf($dir) {
}
}




function dir_list($dir, $sort = 0)
{
$sort_order_for_filename = SORT_ASC;
Expand All @@ -252,7 +227,7 @@ function dir_list($dir, $sort = 0)
if (!in_array($object, array('.','..'))){
$filename = $dir . $object;
$time = microtime(true) - $start;
if($time <= LISTING_TIMEOUT){
if ($time <= LISTING_TIMEOUT) {
$stats = stat($filename);
$mode = explain_mode($stats['mode']);
$perms = decoct(fileperms($filename));
Expand All @@ -274,8 +249,11 @@ function dir_list($dir, $sort = 0)
);
}else{
$listing['timeout_exeeded'] = TRUE;
if(is_dir($filename)){ $type = 'd';
}else{ $type = '-'; }
if (is_dir($filename)) {
$type = 'd';
} else {
$type = '-';
}

$item = array(
'name' => $object,
Expand All @@ -294,7 +272,6 @@ function dir_list($dir, $sort = 0)
);
}


$listing['count']++;

if($item['type'] == 'd'){
Expand All @@ -311,7 +288,6 @@ function dir_list($dir, $sort = 0)
}
$listing['time'] = microtime(TRUE) - $start;


if(!$listing['timeout_exeeded']){
if(in_array($_REQUEST['sort_field'], $available_sort_fields)){
if($_REQUEST['sort_desc']){
Expand All @@ -324,7 +300,6 @@ function dir_list($dir, $sort = 0)

return $listing;
}


function explain_mode($mode)
{
Expand Down Expand Up @@ -355,5 +330,3 @@ function explain_mode($mode)

return $info;
}

?>
2 changes: 0 additions & 2 deletions web/generate/ssl/index.php
Expand Up @@ -108,5 +108,3 @@
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_ssl.html');
include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');
unset($_SESSION['ok_msg']);

?>
2 changes: 0 additions & 2 deletions web/inc/mail-wrapper.php
Expand Up @@ -32,5 +32,3 @@
if ((!empty($to)) && (!empty($subject))) {
send_email($to,$subject,$mailtext,$from);
}

?>
1 change: 0 additions & 1 deletion web/inc/main.php
Expand Up @@ -344,4 +344,3 @@ function list_timezones() {
}
return $timezone_list;
}
?>
1 change: 0 additions & 1 deletion web/index.php
Expand Up @@ -5,4 +5,3 @@
} else {
header("Location: /login/");
}
?>
4 changes: 1 addition & 3 deletions web/login/index.php
Expand Up @@ -20,7 +20,7 @@

// Login as someone else
if (isset($_SESSION['user'])) {
if ($_SESSION['user'] == 'admin' && !empty($_GET['loginas'])) {
if ($_SESSION['user'] == 'admin' && !empty($_GET['loginas'])) {
exec (VESTA_CMD . "v-list-user ".escapeshellarg($_GET['loginas'])." json", $output, $return_var);
if ( $return_var == 0 ) {
$data = json_decode(implode('', $output), true);
Expand Down Expand Up @@ -96,5 +96,3 @@
require_once($_SERVER['DOCUMENT_ROOT'].'/inc/i18n/'.$_SESSION['language'].'.php');
require_once('../templates/header.html');
require_once('../templates/login.html');

?>

0 comments on commit 97a368a

Please sign in to comment.