📄 list.csp
字号:
<% @b
@include <stdlib.h>
@include <undef.h>
@ifdef WIN32
@ include <windows.h>
@ include <direct.h>
@ include <sys/types.h>
@ include <sys/stat.h>
@else
@ include <sys/types.h>
@ include <sys/stat.h>
@ include <dirent.h>
@ include <unistd.h>
@ include <stddef.h>
@endif
@include <ebdef.h>
@include <ebio.h>
#ifdef WIN32
# define DIR_TYPE HANDLE
# define DIRENT WIN32_FIND_DATA _data, *
# define opendir(path) FindFirstFile(strcat(path, "*.*"), &_data)
# define readdir(pdir) (path[strlen(path)-3]='\0', &_data)
# define d_name cFileName
# define readnextdir(p,r) (void*)FindNextFile(p, r)
# define closedir(p) FindClose(p)
#else
# define DIR_TYPE DIR *
# define DIRENT struct dirent *
# define readnextdir(p,r) ((r) = readdir(p))
#endif
DIR_TYPE pdir;
DIRENT pfile;
struct stat st;
char path[512] = "";
char filename[64];
char * pname = NULL;
int nowpage = atoi(G("page")); /* current pages */
int files = 0; /* file counter */
int maxshow = 15; /* max nuber to show in one page */
if (nowpage <= 0)
nowpage = 1;
get_root_dir(path, sizeof(path)/2);
/* open directory */
pdir=opendir(path);
if(pdir==NULL)
{
ebSendError(400, "*** error: when open directory(%s).\n", path);
page_exit(ERROR);
}
if((pfile = readdir(pdir))==NULL)
{
ebSendError(400, "*** error: when read directory(%s).\n", pdir);
page_exit(ERROR);
}
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>Index of <% =path %></title>
<link href="style.css" rel=stylesheet type=text/css>
<script language="javascript" src="page.js"></script>
<script language="javascript">
<!--
var files =0;
function showpage(where1, where2, files, maxshow, nowpage){
page.construct(files,maxshow,'<% =thisCgiPrefix() %>&path=<% =urlEncode(G("path")) %>&page=',nowpage);
where1.innerHTML = '(共计 ' + files + ' 个)' +page.show(1);
where2.innerHTML = where1.innerHTML;
}
-->
</script>
</head>
<body onload="showpage(divtop, divbot, files, <% =$maxshow %>, <% =$nowpage %>);">
<table>
<tr>
<td colspan=2><H3>当前目录: <% =path %></H3></td>
<tr>
<td width=300 nowrap>
[<A href="uploadc.csp?path=<% =urlEncode(path) %>">上传文件到当前目录]</A>
[<A href="exec.csp?path=<% =urlEncode(path) %>">在当前目录执行命令]</A>
<td align=right><div id=divtop></div></td>
<tr>
<td colspan=2>
<TABLE>
<TR>
<TD width=20><IMG alt="Icon " src="img/blank.gif">
<TD width=200><b>目录名称</b></TD>
<TD width=100 align=right><b>文件大小</b></TD>
<TD width=200 align=right>最后修改日期</b></TD>
<%
do {
char fsize[32] = "";
char ftime[32] = "";
char fullname[256] = "";
char dirname[512]="";
if (++files <= (nowpage-1)*maxshow)
continue;
if (files >nowpage*maxshow)
continue;
sprintf(dirname, "%s%s", path, pfile->d_name);
if(stat(dirname, &st)==-1)
{
ebLogFMsg(400, ("*** error: when get stat file(%s).\n", dirname));
continue;
}
/* file size */
if(st.st_size>=1024*1024)
sprintf(fsize, "%13.2f M", st.st_size/(1024*1024.0));
else if(st.st_size>=1024)
sprintf(fsize, "%13.2f K", st.st_size/(1024.0));
else
sprintf(fsize, "%10d.00 ", (int)st.st_size);
sprintf(ftime, "%.12s ",4+ctime(&st.st_mtime));
/* file name is too long */
if(strlen(pfile->d_name)>63)
sprintf(pname=filename, "%.*s...", 60,pfile->d_name);
else
pname=pfile->d_name;
/* make fullname */
sprintf(fullname, "%s%s", path, pfile->d_name);
/* reduce '.' and ".." */
trimpath(fullname);
%>
<TR>
<% if (S_ISDIR(st.st_mode)) { %>
<TD><IMG alt=[DIR] src="img/folder.gif">
<TD><A href="list.csp?path=<% =urlEncode(fullname) %>"><% =pname %>/</A>
<TD align=right>
<% } else { %>
<TD><IMG alt=[TXT] src="img/text.gif">
<TD><A href="download.csp?file=<% =urlEncode(fullname) %>"><% =pname %></A>
<TD align=right><% =fsize %>
<% } %>
<TD align=right><% =ftime %>
</TR>
<% } while(NULL != readnextdir(pdir, pfile));
closedir(pdir);
%>
</TABLE>
</td>
</tr>
<tr>
<td colspan=2 align=right><div id=divbot></div></td>
</tr>
</table>
<script language="javascript">
<!--
files =<% =$files %>;
-->
</script>
</BODY>
</HTML>
<% @g
static char * get_root_dir(char * path, int size)
{
int len;
/* get path to list,
* choose current directory while has no path set
*/
strcpy(path, getParameter("path"));
/* has not path,
* set current path as root dir
*/
if ('\0' == path[0])
getcwd(path, size-1);
/* reduce '.' and ".." */
trimpath(path);
/* make that what is to list */
len = strlen(path);
if ('\\' != path[len-1] && '/' != path[len-1])
strcat(path, "/");
return path;
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -