Пример #1
0
function processDirectory($src, $dst)
{
    echo "Processing directory: {$src} -> {$dst}\n";
    $dir = opendir($src);
    if ($dir === false) {
        echo "Could not open directory: {$src}";
        return;
    }
    if (!file_exists($dst)) {
        mkdir($dst);
    }
    while (true) {
        $file = readdir($dir);
        if ($file === false) {
            break;
        }
        if ($file[0] == '.' || $file[0] == '_') {
            continue;
        }
        $srcFile = "{$src}/{$file}";
        $dstFile = "{$dst}/{$file}";
        if (!is_dir($srcFile)) {
            if (preg_match('/.*\\.(txt|md)/i', $file)) {
                convertFile($srcFile, $dstFile);
            } else {
                copy($srcFile, $dstFile);
            }
        } else {
            processDirectory($srcFile, $dstFile);
        }
    }
}
Пример #2
0
function processDirectory($startingDirectory)
{
    /*
     * Create a histogram for every file in the specified directory
     * and insert the histogram into the global histogram in the database.
     */
    if ($dObj = dir($startingDirectory)) {
        while ($thisEntry = $dObj->read()) {
            if ($thisEntry != "." && $thisEntry != "..") {
                $path = "{$startingDirectory}/{$thisEntry}";
                $file = fopen($path, 'r');
                $inputText = fread($file, filesize($path));
                //Generate a histogram for the file and insert it into the database
                $histogram = genHistogram($inputText);
                insertHistogramInDatabase($histogram);
                // If the entry is a directory, recursively call our function on it
                if ($thisEntry != 0 && is_dir($startingDirectory / $thisEntry)) {
                    processDirectory("{$startingDirectory}/{$thisEntry}");
                }
            } else {
                //ignore "." and ".." to prevent an infinite loop
            }
        }
    }
    return False;
}
Пример #3
0
<?php

define('ACCESS', true);
include_once 'function.php';
if (IS_LOGIN) {
    $title = 'Sửa dòng';
    $page = array('current' => 0, 'paramater_0' => null, 'paramater_1' => null);
    $page['current'] = isset($_GET['page']) ? intval($_GET['page']) : 1;
    $page['current'] = $page['current'] <= 0 ? 1 : $page['current'];
    include_once 'header.php';
    echo '<div class="title">' . $title . '</div>';
    if ($dir == null || $name == null || !is_file(processDirectory($dir . '/' . $name))) {
        echo '<div class="list"><span>Đường dẫn không tồn tại</span></div>
            <div class="title">Chức năng</div>
            <ul class="list">
                <li><img src="icon/list.png"/> <a href="index.php' . $pages['paramater_0'] . '">Danh sách</a></li>
            </ul>';
    } else {
        if (!isFormatText($name) && !isFormatUnknown($name)) {
            echo '<div class="list"><span>Tập tin này không phải dạng văn bản</span></div>
            <div class="title">Chức năng</div>
            <ul class="list">
                <li><img src="icon/list.png"/> <a href="index.php?dir=' . $dirEncode . $pages['paramater_1'] . '">Danh sách</a></li>
            </ul>';
        } else {
            function process()
            {
                global $content, $lines, $count, $path;
                $content = file_get_contents($path);
                if (strlen($content) > 0) {
                    $content = str_replace("\r\n", "\n", $content);
Пример #4
0
<?php

define('ACCESS', true);
include_once 'function.php';
if (IS_LOGIN) {
    $title = 'Tải tập tin';
    if ($dir == null || $name == null || !is_file(processDirectory($dir . '/' . $name))) {
        include_once 'header.php';
        echo '<div class="title">' . $title . '</div>';
        echo '<div class="list"><span>Đường dẫn không tồn tại</span></div>
            <div class="title">Chức năng</div>
            <ul class="list">
                <li><img src="icon/list.png"/> <a href="index.php">Danh sách</a></li>
            </ul>';
        include_once 'footer.php';
    } else {
        $dir = processDirectory($dir);
        $path = $dir . '/' . $name;
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: inline; filename=' . $name);
        header('Content-Length: ' . filesize($path));
        readfile($path);
    }
} else {
    goURL('login.php');
}
Пример #5
0
if (IS_INSTALL_ROOT_DIRECTORY || IS_ACCESS_FILE_IN_FILE_MANAGER || $script != '.' && $script != '/' && isPathNotPermission(processDirectory($dir)) || $script != '.' && $script != '/' && $name != null && isPathNotPermission(processDirectory($dir . '/' . $name))) {
    define('NOT_PERMISSION', true);
} else {
    define('NOT_PERMISSION', false);
}
if (!defined('INDEX') && !defined('LOGIN') && NOT_PERMISSION) {
    goURL('index.php?not');
}
if (NOT_PERMISSION) {
    $dir = null;
    $dirEncode = null;
}
if ($dir != null) {
    define('IS_ACCESS_PARENT_PATH_FILE_MANAGER', strtolower(processDirectory($dir)) == strtolower(processDirectory(PARENT_PATH_FILE_MANAGER)));
} else {
    define('IS_ACCESS_PARENT_PATH_FILE_MANAGER', strtolower(processDirectory(PARENT_PATH_FILE_MANAGER)) == strtolower(processDirectory($_SERVER['DOCUMENT_ROOT'])));
}
function isPathNotPermission($path, $isUseName = false)
{
    if ($path != null && empty($path) == false) {
        $reg = $isUseName ? NAME_DIRECTORY_INSTALL_FILE_MANAGER : PATH_FILE_MANAGER;
        $reg = $reg != null ? strtolower($reg) : null;
        $path = str_replace('\\', '/', $path);
        $path = strtolower($path);
        if (preg_match('#^' . $reg . '$#si', $path)) {
            return true;
        } else {
            if (preg_match('#^' . $reg . '/(^\\/+|^\\+)(.*?)$#si', $path)) {
                return true;
            } else {
                if (preg_match('#^' . $reg . '/(.*?)$#si', $path)) {
Пример #6
0
function moves($entrys, $dir, $path)
{
    foreach ($entrys as $e) {
        $pa = $dir . '/' . $e;
        if (isPathNotPermission(processDirectory($path . '/' . $e))) {
            /* Entry not permission */
        } else {
            if (@is_file($pa)) {
                if (!@copy($pa, $path . '/' . $e)) {
                    return false;
                }
                @unlink($pa);
            } else {
                if (@is_dir($pa)) {
                    if (!movedir($pa, $path)) {
                        return false;
                    }
                } else {
                    return false;
                }
            }
        }
    }
    return true;
}
Пример #7
0
         </ul>';
 } else {
     $dir = processDirectory($dir);
     $format = getFormat($name);
     if (isset($_POST['submit'])) {
         echo '<div class="notice_failure">';
         if (empty($_POST['path'])) {
             echo 'Chưa nhập đầy đủ thông tin';
         } else {
             if ($dir == processDirectory($_POST['path'])) {
                 echo 'Đường dẫn mới phải khác đường dẫn hiện tại';
             } else {
                 if (isPathNotPermission(processDirectory($_POST['path']))) {
                     echo 'Bạn không thể sao chép tập tin tới đường dẫn của File Manager';
                 } else {
                     if (!@copy($dir . '/' . $name, processDirectory($_POST['path']) . '/' . $name)) {
                         echo 'Sao chép tập tin thất bại';
                     } else {
                         goURL('index.php?dir=' . $dirEncode . $pages['paramater_1']);
                     }
                 }
             }
         }
         echo '</div>';
     }
     echo '<div class="list">
             <span class="bull">&bull;</span><span>' . printPath($dir . '/' . $name) . '</span><hr/>
             <form action="file_copy.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '" method="post">
                 <span class="bull">&bull;</span>Đường dẫn tập tin mới:<br/>
                 <input type="text" name="path" value="' . (isset($_POST['path']) ? $_POST['path'] : $dir) . '" size="18"/><br/>
                 <input type="submit" name="submit" value="Sao chép"/>
Пример #8
0
             echo '<div class="title">' . $title . '</div>';
             if (isset($_POST['submit']) && isset($_POST['is_action'])) {
                 echo '<div class="notice_failure">';
                 if (empty($_POST['name']) || empty($_POST['path'])) {
                     echo 'Chưa nhập đầy đủ thông tin';
                 } else {
                     if (isset($_POST['is_delete']) && processDirectory($_POST['path']) == $dir . '/' . $name) {
                         echo 'Nếu chọn xóa thư mục bạn không thể lưu tập tin nén ở đó';
                     } else {
                         if (isPathNotPermission(processDirectory($_POST['path']))) {
                             echo 'Bạn không thể nén tập tin zip tới đường dẫn của File Manager';
                         } else {
                             if (isNameError($_POST['name'])) {
                                 echo 'Tên tập tin zip không hợp lệ';
                             } else {
                                 if (!zips($dir, $entry, processDirectory($_POST['path'] . '/' . processName($_POST['name'])), isset($_POST['is_delete']))) {
                                     echo 'Nén zip thất bại';
                                 } else {
                                     goURL('index.php?dir=' . $dirEncode . $pages['paramater_1']);
                                 }
                             }
                         }
                     }
                 }
                 echo '</div>';
             }
             echo $entryHtmlList;
             echo '<div class="list">
 <span>' . printPath($dir, true) . '</span><hr/>
 <form action="action.php?dir=' . $dirEncode . $pages['paramater_1'] . '" method="post">
     <span class="bull">&bull;</span>Tên tập tin nén:<br/>
Пример #9
0
function processDirectory($srcIndex)
{
    if (!$srcIndex) {
        return;
    }
    global $srcDir, $dstDir, $mdIndex;
    foreach ($srcIndex as $name => $items) {
        echo "Rendering {$name}\n";
        $pageFilename = "{$srcDir}/{$name}.md";
        $htmlFilename = "{$dstDir}/{$name}.html";
        if (is_dir("{$srcDir}/{$name}")) {
            if (!file_exists("{$dstDir}/{$name}")) {
                mkdir("{$dstDir}/{$name}");
            }
            processDirectory($items);
        } else {
            $output = renderPage($mdIndex, $pageFilename);
            file_put_contents($htmlFilename, $output);
        }
    }
}
Пример #10
0
     if (empty($_POST['path'])) {
         echo 'Chưa nhập đầy đủ thông tin';
     } else {
         if (!is_dir(processDirectory($_POST['path']))) {
             echo 'Đường dẫn giải nén không tồn tại';
         } else {
             if (isPathNotPermission(processDirectory($_POST['path']))) {
                 echo 'Bạn không thể giải nén tập tin zip tới đường dẫn của File Manager';
             } else {
                 include 'pclzip.class.php';
                 $zip = new PclZip($dir . '/' . $name);
                 function callback_pre_extract($event, $header)
                 {
                     return isPathNotPermission($header['filename']) == false ? 1 : 0;
                 }
                 if ($zip->extract(PCLZIP_OPT_PATH, processDirectory($_POST['path']), PCLZIP_CB_PRE_EXTRACT, 'callback_pre_extract') != false) {
                     if (isset($_POST['is_delete'])) {
                         @unlink($dir . '/' . $name);
                     }
                     goURL('index.php?dir=' . $dirEncode . $pages['paramater_1']);
                 } else {
                     echo 'Giải nén tập tin lỗi';
                 }
             }
         }
     }
     echo '</div>';
 }
 echo '<div class="list">
     <span class="bull">&bull;</span><span>' . printPath($dir . '/' . $name) . '</span><hr/>
     <form action="file_unzip.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '" method="post">
Пример #11
0
 $dir = processDirectory($dir);
 if (isset($_POST['submit'])) {
     echo '<div class="notice_failure">';
     if (empty($_POST['name']) || empty($_POST['path'])) {
         echo 'Chưa nhập đầy đủ thông tin';
     } else {
         if (isset($_POST['is_delete']) && processDirectory($_POST['path']) == $dir . '/' . $name) {
             echo 'Nếu chọn xóa thư mục bạn không thể lưu tập tin nén ở đó';
         } else {
             if (isPathNotPermission(processDirectory($_POST['path']))) {
                 echo 'Bạn không thể nén tập tin zip tới đường dẫn của File Manager';
             } else {
                 if (isNameError($_POST['name'])) {
                     echo 'Tên tập tin zip không hợp lệ';
                 } else {
                     if (!zipdir($dir . '/' . $name, processDirectory($_POST['path'] . '/' . processName($_POST['name'])), isset($_POST['is_delete']) == 1)) {
                         echo 'Nén zip thư mục thất bại';
                     } else {
                         goURL('index.php?dir=' . $dirEncode . $pages['paramater_1']);
                     }
                 }
             }
         }
     }
     echo '</div>';
 }
 echo '<div class="list">
         <span class="bull">&bull;</span><span>' . printPath($dir . '/' . $name, true) . '</span><hr/>
         <form action="folder_zip.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '" method="post">
             <span class="bull">&bull;</span>Tên tập tin nén:<br/>
             <input type="text" name="name" value="' . (isset($_POST['name']) ? $_POST['name'] : $name . '.zip') . '" size="18"/><br/>
Пример #12
0
     if (empty($_POST['path'])) {
         echo 'Chưa nhập đầy đủ thông tin';
     } else {
         if ($dir == processDirectory($_POST['path'])) {
             echo 'Đường dẫn mới phải khác đường dẫn hiện tại';
         } else {
             if (!is_dir($_POST['path'])) {
                 echo 'Đường dẫn mới không tồn tại';
             } else {
                 if (isPathNotPermission(processDirectory($_POST['path']))) {
                     echo 'Bạn không thể sao chép thư mục tới đường dẫn của File Manager';
                 } else {
                     if (isPathNotPermission(processDirectory($_POST['path'] . '/' . $name))) {
                         echo 'Bạn không thể sao chép thư mục giống tên tới thư mục chứa thư mục của File Manager';
                     } else {
                         if (!copydir($dir . '/' . $name, processDirectory($_POST['path']))) {
                             echo 'Sao chép thư mục thất bại';
                         } else {
                             goURL('index.php?dir=' . $dirEncode . $pages['paramater_1']);
                         }
                     }
                 }
             }
         }
     }
     echo '</div>';
 }
 echo '<div class="list">
         <span class="bull">&bull;</span><span>' . printPath($dir . '/' . $name, true) . '</span><hr/>
         <form action="folder_copy.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '" method="post">
             <span class="bull">&bull;</span>Đường dẫn thư mục mới:<br/>