📄 networkexplorer.java
字号:
out.println( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" );
out.println( "<html><head><title>Network Explorer</title>" );
out.println( "<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">" );
out.println( "<style TYPE=\"text/css\">" );
out.println( style );
if( dirents.length < 200 ) {
out.println( " a:hover {" );
out.println( " background: #a2ff01;" );
out.println( " }" );
}
out.println( "</STYLE>" );
out.println( "</head><body>" );
out.print( "<a class=\"sort\" style=\"width: " + maxLen + ";\" href=\"?fmt=detail&sort=name\">Name</a>" );
out.println( "<a class=\"sort\" href=\"?fmt=detail&sort=size\">Size</a>" );
out.println( "<a class=\"sort\" href=\"?fmt=detail&sort=type\">Type</a>" );
out.println( "<a class=\"sort\" style=\"width: 180\" href=\"?fmt=detail&sort=date\">Modified</a><br clear='all'><p>" );
path = dir.getCanonicalPath();
if( path.length() < 7 ) {
out.println( "<b><big>smb://</big></b><br>" );
path = ".";
} else {
out.println( "<b><big>" + path + "</big></b><br>" );
path = "../";
}
out.println( (dirCount + fileCount) + " objects (" + dirCount + " directories, " + fileCount + " files)<br>" );
out.println( "<b><a class=\"plain\" href=\".\">normal</a> | <a class=\"plain\" href=\"?fmt=detail\">detailed</a></b>" );
out.println( "<p><table border='0' cellspacing='0' cellpadding='0'><tr><td>" );
out.print( "<A style=\"width: " + maxLen );
out.print( "; height: 18;\" HREF=\"" );
out.print( path );
out.println( "\"><b>↑</b></a>" );
if( fmt.equals( "detail" )) {
out.println( "<br clear='all'>" );
}
if( path.length() == 1 || dir.getType() != SmbFile.TYPE_WORKGROUP ) {
path = "";
}
iter = sorted.listIterator();
while( iter.hasNext() ) {
f = (SmbFile)iter.next();
name = f.getName();
if( fmt.equals( "detail" )) {
out.print( "<A style=\"width: " + maxLen );
out.print( "; height: 18;\" HREF=\"" );
out.print( path );
out.print( name );
if( f.isDirectory() ) {
out.print( "?fmt=detail\"><b>" );
out.print( name );
out.print( "</b></a>" );
} else {
out.print( "\"><b>" );
out.print( name );
out.print( "</b></a><div align='right'>" );
out.print( (f.length() / 1024) + " KB </div><div>" );
i = name.lastIndexOf( '.' ) + 1;
if( i > 1 && (name.length() - i) < 6 ) {
out.print( name.substring( i ).toUpperCase() + "</div class='ext'>" );
} else {
out.print( " </div>" );
}
out.print( "<div style='width: 180'>" );
out.print( sdf.format( new Date( f.lastModified() )));
out.print( "</div>" );
}
out.println( "<br clear='all'>" );
} else {
out.print( "<A style=\"width: " + maxLen );
if( f.isDirectory() ) {
out.print( "; height: 18;\" HREF=\"" );
out.print( path );
out.print( name );
out.print( "\"><b>" );
out.print( name );
out.print( "</b></a>" );
} else {
out.print( ";\" HREF=\"" );
out.print( path );
out.print( name );
out.print( "\"><b>" );
out.print( name );
out.print( "</b><br><small>" );
out.print( (f.length() / 1024) + "KB <br>" );
out.print( sdf.format( new Date( f.lastModified() )));
out.print( "</small>" );
out.println( "</a>" );
}
}
}
out.println( "</td></tr></table>" );
out.println( "</BODY></HTML>" );
out.close();
}
private String parseServerAndShare( String pathInfo ) {
char[] out = new char[256];
char ch;
int len, p, i;
if( pathInfo == null ) {
return null;
}
len = pathInfo.length();
p = i = 0;
while( p < len && pathInfo.charAt( p ) == '/' ) {
p++;
}
if( p == len ) {
return null;
}
/* collect server name */
while ( p < len && ( ch = pathInfo.charAt( p )) != '/' ) {
out[i++] = ch;
p++;
}
while( p < len && pathInfo.charAt( p ) == '/' ) {
p++;
}
if( p < len ) { /* then there must be a share */
out[i++] = '/';
do { /* collect the share name */
out[i++] = (ch = pathInfo.charAt( p++ ));
} while( p < len && ch != '/' );
}
return new String( out, 0, i );
}
public void doGet( HttpServletRequest req,
HttpServletResponse resp ) throws IOException, ServletException {
UniAddress dc;
String msg, pathInfo, server = null;
boolean offerBasic, possibleWorkgroup = true;
NtlmPasswordAuthentication ntlm = null;
HttpSession ssn = req.getSession( false );
if(( pathInfo = req.getPathInfo() ) != null ) {
int i;
server = parseServerAndShare( pathInfo );
if( server != null && ( i = server.indexOf( '/' )) > 0 ) {
server = server.substring( 0, i ).toLowerCase();
possibleWorkgroup = false;
}
}
msg = req.getHeader( "Authorization" );
offerBasic = enableBasic && (insecureBasic || req.isSecure());
if( msg != null && (msg.startsWith( "NTLM " ) ||
(offerBasic && msg.startsWith("Basic ")))) {
if( msg.startsWith("NTLM ")) {
byte[] challenge;
if( pathInfo == null || server == null ) {
String mb = NbtAddress.getByName( NbtAddress.MASTER_BROWSER_NAME, 0x01, null ).getHostAddress();
dc = UniAddress.getByName( mb );
} else {
dc = UniAddress.getByName( server, possibleWorkgroup );
}
req.getSession(); /* ensure session id is set for cluster env. */
challenge = SmbSession.getChallenge( dc );
if(( ntlm = NtlmSsp.authenticate( req, resp, challenge )) == null ) {
return;
}
} else { /* Basic */
String auth = new String( Base64.decode( msg.substring(6) ), "US-ASCII" );
int index = auth.indexOf( ':' );
String user = (index != -1) ? auth.substring(0, index) : auth;
String password = (index != -1) ? auth.substring(index + 1) : "";
index = user.indexOf('\\');
if (index == -1) index = user.indexOf('/');
String domain = (index != -1) ? user.substring(0, index) : defaultDomain;
user = (index != -1) ? user.substring(index + 1) : user;
ntlm = new NtlmPasswordAuthentication(domain, user, password);
}
req.getSession().setAttribute( "npa-" + server, ntlm );
} else if( !credentialsSupplied ) {
if( ssn != null ) {
ntlm = (NtlmPasswordAuthentication)ssn.getAttribute( "npa-" + server );
}
if( ntlm == null ) {
resp.setHeader( "WWW-Authenticate", "NTLM" );
if (offerBasic) {
resp.addHeader( "WWW-Authenticate", "Basic realm=\"" + realm + "\"");
}
resp.setHeader( "Connection", "close" );
resp.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
resp.flushBuffer();
return;
}
}
try {
SmbFile file;
if( ntlm != null ) {
file = new SmbFile( "smb:/" + pathInfo , ntlm );
} else if( server == null ) {
file = new SmbFile( "smb://" );
} else {
file = new SmbFile( "smb:/" + pathInfo );
}
if( file.isDirectory() ) {
doDirectory( req, resp, file );
} else {
doFile( req, resp, file );
}
} catch( SmbAuthException sae ) {
if( ssn != null ) {
ssn.removeAttribute( "npa-" + server );
}
if( sae.getNtStatus() == sae.NT_STATUS_ACCESS_VIOLATION ) {
/* Server challenge no longer valid for
* externally supplied password hashes.
*/
resp.sendRedirect( req.getRequestURL().toString() );
return;
}
resp.setHeader( "WWW-Authenticate", "NTLM" );
if (offerBasic) {
resp.addHeader( "WWW-Authenticate", "Basic realm=\"" + realm + "\"");
}
resp.setHeader( "Connection", "close" );
resp.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
resp.flushBuffer();
return;
} catch( DfsReferral dr ) {
StringBuffer redir = req.getRequestURL();
String qs = req.getQueryString();
redir = new StringBuffer( redir.substring( 0, redir.length() - req.getPathInfo().length() ));
redir.append( dr.node.replace( '\\', '/' ));
redir.append( '/' );
if( qs != null ) {
redir.append( req.getQueryString() );
}
resp.sendRedirect( redir.toString() );
resp.flushBuffer();
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -