예제 #1
0
    public function displaydir($file_list, $srvid, $filename = false, $tpl_browse = false)
    {
        if (GPXDEBUG) {
            echo "DEBUG: Server ID: {$srvid}, Filename: {$filename}, Browsing Templates: {$tpl_browse}<br>";
        }
        // Use correct img path
        if (isset($_SESSION['gpx_admin'])) {
            $bk_path = '../';
        } else {
            $bk_path = '';
        }
        // Setup language
        require DOCROOT . '/lang.php';
        #$back_link  = '<span class="links" onClick="javascript:load_dir('.$srvid.',\'\',1);" title="Go Back">&lt; Go Back</span><br /><br />';
        $back_link = '<div class="links" style="margin-top:10px;margin-bottom:5px;" onClick="javascript:load_dir(' . $srvid . ',\'\',1,' . $tpl_browse . ');"><img src="' . $bk_path . 'images/icons/small/back.png" width="28" height="28" border="0" style="margin-top:5px;" /> ' . $lang['go_back'] . '</div>';
        // Unable to read due to permissions etc
        if ($file_list == 'err_opendir') {
            die($back_link . '<br />Sorry, unable to read this directory.');
        }
        ####################################################
        // Not a directory; show file contents
        if (!is_array($file_list)) {
            if ($tpl_browse) {
                return 'Sorry, cannot edit files in template browse mode.';
            }
            # require(DOCROOT.'/lang.php');
            echo '<div class="infobox" style="display:none;"></div> ' . $back_link . '<textarea id="filecontent_cur" class="txteditor" style="white-space:pre;">' . $file_list . '</textarea><br />
            <div class="button" onClick="javascript:file_savecontent(' . $srvid . ',\'' . $filename . '\');">' . $lang['save'] . '</div>';
            exit;
        }
        ####################################################
        // Setup file/dir sorting
        $arr_files = array();
        $arr_dirs = array();
        #echo '<pre>';
        #var_dump($file_list);
        #echo '</pre>';
        #exit;
        foreach ($file_list as $filename => $file_arr) {
            $file_type = $file_arr['type'];
            #$filename  = strval($filename);
            if (is_numeric($filename)) {
                $filename .= ' ';
            }
            #echo "Name: $filename<br>";
            if ($file_type == '1') {
                $arr_files[$filename][] = $file_arr;
            } else {
                $arr_dirs[$filename][] = $file_arr;
            }
        }
        // Sort arrays by filename
        ksort($arr_files);
        ksort($arr_dirs);
        # Combine, dirs first
        $file_list = array_merge($arr_dirs, $arr_files);
        // OLD/unorganized - Make new array to sort directories together
        #$array = array($file_list,array_keys($file_list));
        #array_multisort($array[0], SORT_DESC,  $array[1], SORT_DESC);
        #$file_list = array_combine($array[1], $array[0]);
        #unset($array);
        ####################################################
        // Check if server is local
        $Network = new Network();
        $is_local = $Network->islocal($srvid);
        // Setup language
        #require(DOCROOT.'/lang.php');
        ####################################################
        // File Uploads - Allow if local
        if ($is_local) {
            echo '<div align="center">
                      <div id="file_up"></div>
                  </div>
                  
                  <script type="text/javascript">
                  $(document).ready(function(){
                      createUploader();
                  });
                  </script>';
        }
        ####################################################
        // Allow back button
        if (!empty($_SESSION['curdir'])) {
            // If tpl browsing, add "use this directory" option
            if ($tpl_browse) {
                $cur_dir = $_SESSION['curdir'];
                echo '<div align="center"><span class="links" onClick="javascript:template_browse_select(\'' . $cur_dir . '\');">Click to use this folder for this template</span></div>';
            }
            #$backdir  = $_SESSION['curdir']; //dirname($_SESSION['curdir']);
            echo $back_link;
        }
        // Show current directory
        if ($_SESSION['curdir']) {
            echo '<div style="width:100%;height:20px;line-height:20px;font-family:Arial;font-size:11pt;color:#777;"><b>' . $lang['working_dir'] . ':</b> ' . htmlspecialchars(stripslashes($_SESSION['curdir'])) . '</div>';
        }
        echo '<div class="infobox" style="display:none;"></div>';
        echo '<div class="box">
        <div class="box_title" id="box_servers_title">' . $lang['files'] . '</div>
        <div class="box_content" id="box_servers_content">

        <table border="0" cellpadding="0" cellspacing="0" align="center" width="900" class="box_table" style="text-align:center;" id="files_table">
          <tr>
            <td width="50">&nbsp;</td>
            <td width="350" align="left"><b>' . $lang['name'] . '</b></td>
            <td width="120"><b>' . $lang['modified'] . '</b></td>
            <td width="120"><b>' . $lang['accessed'] . '</b></td>
            <td width="120"><b>' . $lang['size'] . '</b></td>
            <td width="60"><b>' . $lang['delete'] . '</b></td>
          </tr>';
        // Loop through files
        $file_cnt = 0;
        foreach ($file_list as $file => $key) {
            if (!preg_match('/^\\.+/', $file)) {
                $file_mtime = date('M jS', $key[0]['mtime']);
                $file_atime = date('M jS', $key[0]['atime']);
                $file_size = $key[0]['size'];
                $file_perms = $key[0]['permissions'];
                $file_type = $key[0]['type'];
                $file_owner = $key[0]['uid'];
                // Trim off space on numeric array names
                $file = trim($file);
                if ($tpl_browse) {
                    $add_tplb = ',\'1\'';
                } else {
                    $add_tplb = '';
                }
                $editable_link = '<span class="links" onClick="javascript:load_dir(' . $srvid . ',\'' . $file . '\',0' . $add_tplb . ');">' . $file . '</span>';
                $editable_img = ' style="cursor:pointer;" onClick="javascript:load_dir(' . $srvid . ',\'' . $file . '\',0' . $add_tplb . ');"';
                // Files
                if ($file_type == 1 || $file_type == '1') {
                    $icon = 'file.png';
                    // Editable File Types
                    if (preg_match('/\\.(txt|cfg|rc|log|ini|inf|vdf|yml|properties|json|conf)$/i', $file) && !$tpl_browse) {
                        $edit_link = $editable_link;
                        $img_link = $editable_img;
                    } else {
                        $edit_link = '<span class="links" style="font-weight:normal;cursor:default;text-decoration:none;">' . $file . '</span>';
                        $img_link = '';
                    }
                    // Allow deleting files
                    if (!$tpl_browse) {
                        $delete_add = '<img src="' . $bk_path . 'images/icons/medium/error.png" width="25" height="25" border="0" title="Delete" style="cursor:pointer;" onClick="javascript:confirm_delete_file(' . $srvid . ',\'' . $file . '\',' . $file_cnt . ');" />';
                    } else {
                        $delete_add = '&nbsp;';
                    }
                } else {
                    $icon = 'folder.png';
                    $edit_link = $editable_link;
                    $img_link = $editable_img;
                    // Can't delete entire directories for safety
                    $delete_add = '&nbsp;';
                }
                # <td width="50" align="left" style="cursor:default;"><img src="images/icons/medium/error.png" width="25" height="25" border="0" title="Delete" style="cursor:pointer;" onClick="javascript:server_confirm_del_startup('.$s_id.','.$url_id.');" /></td>
                echo '<tr id="file_' . $file_cnt . '" style="cursor:default;" class="filerows">
                          <td><img src="' . $bk_path . 'images/icons/medium/' . $icon . '" border="0" width="28" height="28" ' . $img_link . '/></td>
                          <td align="left">' . $edit_link . '</td>
                          <td>' . $file_mtime . '</td>
                          <td>' . $file_atime . '</td>
                          <td>' . $file_size . '</td>
                          <td style="cursor:default;">' . $delete_add . '</td>
                        </tr>';
                $file_cnt++;
            }
        }
        echo '</table>
          </div>
          </div>';
        // Only admins can add files or directories
        if (isset($_SESSION['gpx_admin']) && !$tpl_browse) {
            echo '<div style="width:100%;margin-bottom:30px;">
                        <span onClick="javascript:file_show_addfile(' . $srvid . ');" class="links"><img src="' . $bk_path . '/images/icons/medium/add.png" border="0" width="28" height="28" /> Add File</span><br />
                        <span onClick="javascript:file_show_add_dir(' . $srvid . ');" class="links"><img src="' . $bk_path . '/images/icons/medium/add.png" border="0" width="28" height="28" /> Add Directory</span><br />';
            // Allow directory deletion if empty
            if (count($file_list) == 0) {
                echo '<span class="links" onClick="javascript:confirm_delete_dir(' . $srvid . ',\'' . $filename . '\');"><img src="' . $bk_path . 'images/icons/medium/error.png" width="25" height="25" border="0" title="Delete" style="cursor:pointer;" /> Remove this directory</span><br />';
            }
            echo '</div>';
        }
    }