📄 webplugin.java
字号:
file_root = (new StringBuilder()).append(SystemProperties.getUserPath()).append("web").toString();
} else
if (root_dir.startsWith(File.separator) || root_dir.indexOf(":") != -1)
file_root = root_dir;
else
file_root = (new StringBuilder()).append(SystemProperties.getUserPath()).append("web").append(File.separator).append(root_dir).toString();
File f_root = new File(file_root);
if (!f_root.exists())
{
String error = (new StringBuilder()).append("WebPlugin: root dir '").append(file_root).append("' doesn't exist").toString();
log.log(3, error);
throw new PluginException(error);
}
if (!f_root.isDirectory())
{
String error = (new StringBuilder()).append("WebPlugin: root dir '").append(file_root).append("' isn't a directory").toString();
log.log(3, error);
throw new PluginException(error);
}
welcome_files = new File[welcome_pages.length];
for (int i = 0; i < welcome_pages.length; i++)
welcome_files[i] = new File((new StringBuilder()).append(file_root).append(File.separator).append(welcome_pages[i]).toString());
final int port = param_port.getValue();
String protocol_str = param_protocol.getValue().trim();
String bind_ip_str = param_bind.getValue().trim();
InetAddress bind_ip = null;
if (bind_ip_str.length() > 0)
try
{
bind_ip = InetAddress.getByName(bind_ip_str);
}
catch (Throwable e)
{
log.log(3, (new StringBuilder()).append("Bind IP parameter '").append(bind_ip_str).append("' is invalid").toString());
}
int protocol = protocol_str.equalsIgnoreCase("HTTP") ? 1 : 2;
log.log(1, (new StringBuilder()).append("Initialisation: port = ").append(port).append(bind_ip != null ? (new StringBuilder()).append(", bind = ").append(bind_ip_str).append(")").toString() : "").append(", protocol = ").append(protocol_str).append(root_dir.length() != 0 ? (new StringBuilder()).append(", root = ").append(root_dir).toString() : "").toString());
String access_str = param_access.getValue().trim();
if (access_str.length() > 7 && Character.isDigit(access_str.charAt(0)))
{
ip_range = plugin_interface.getIPFilter().createRange(true);
int sep = access_str.indexOf("-");
if (sep == -1)
{
ip_range.setStartIP(access_str);
ip_range.setEndIP(access_str);
} else
{
ip_range.setStartIP(access_str.substring(0, sep).trim());
ip_range.setEndIP(access_str.substring(sep + 1).trim());
}
ip_range.checkValid();
if (!ip_range.isValid())
{
log.log(3, (new StringBuilder()).append("Access parameter '").append(access_str).append("' is invalid").toString());
ip_range = null;
}
} else
if (access_str.equalsIgnoreCase("all"))
ip_range_all = true;
log.log(1, (new StringBuilder()).append("acceptable IP range = ").append(ip_range != null ? (new StringBuilder()).append(ip_range.getStartIP()).append(" - ").append(ip_range.getEndIP()).toString() : ip_range_all ? "all" : "local").toString());
try
{
TrackerWebContext context = tracker.createWebContext((new StringBuilder()).append(plugin_interface.getAzureusName()).append(" - ").append(plugin_interface.getPluginName()).toString(), port, protocol, bind_ip);
context.addPageGenerator(this);
context.addAuthenticationListener(new TrackerAuthenticationAdapter() {
String last_pw;
byte last_hash[];
AEMonitor this_mon;
final BooleanParameter val$pw_enable;
final StringParameter val$user_name;
final PasswordParameter val$password;
final WebPlugin this$0;
public boolean authenticate(URL resource, String user, String pw)
{
boolean flag;
this_mon.enter();
if (pw_enable.getValue())
break MISSING_BLOCK_LABEL_32;
flag = true;
this_mon.exit();
return flag;
if (user.equals(user_name.getValue()))
break MISSING_BLOCK_LABEL_61;
flag = false;
this_mon.exit();
return flag;
boolean flag1;
byte hash[] = last_hash;
if (!last_pw.equals(pw))
{
hash = plugin_interface.getUtilities().getSecurityManager().calculateSHA1(pw.getBytes());
last_pw = pw;
last_hash = hash;
}
flag1 = Arrays.equals(hash, password.getValue());
this_mon.exit();
return flag1;
Exception exception1;
exception1;
this_mon.exit();
throw exception1;
}
{
this$0 = WebPlugin.this;
pw_enable = booleanparameter;
user_name = stringparameter;
password = passwordparameter;
super();
last_pw = "";
last_hash = new byte[0];
this_mon = new AEMonitor("WebPlugin:auth");
}
});
}
catch (TrackerException e)
{
log.log("Plugin Initialisation Fails", e);
}
plugin_interface.addListener(new PluginListener() {
final BooleanParameter val$upnp_enable;
final int val$port;
final WebPlugin this$0;
public void initializationComplete()
{
PluginInterface pi_upnp = plugin_interface.getPluginManager().getPluginInterfaceByClass(com/aelitis/azureus/plugins/upnp/UPnPPlugin);
if (pi_upnp == null)
log.log("No UPnP plugin available, not attempting port mapping");
else
if (upnp_enable.getValue())
((UPnPPlugin)pi_upnp.getPlugin()).addMapping(plugin_interface.getPluginName(), true, port, true);
else
log.log("UPnP disabled for the plugin, not attempting port mapping");
}
public void closedownInitiated()
{
}
public void closedownComplete()
{
}
{
this$0 = WebPlugin.this;
upnp_enable = booleanparameter;
port = i;
super();
}
});
return;
}
public boolean generateSupport(TrackerWebPageRequest request, TrackerWebPageResponse response)
throws IOException
{
return false;
}
public boolean generate(TrackerWebPageRequest request, TrackerWebPageResponse response)
throws IOException
{
String client;
if (ip_range_all)
break MISSING_BLOCK_LABEL_213;
client = request.getClientAddress();
boolean valid_ip = true;
InetAddress ia = InetAddress.getByName(client);
if (ip_range == null)
{
if (!ia.isLoopbackAddress())
{
log.log(3, (new StringBuilder()).append("Client '").append(client).append("' is not local, rejecting").toString());
valid_ip = false;
}
} else
if (!ip_range.isInRange(ia.getHostAddress()))
{
log.log(3, (new StringBuilder()).append("Client '").append(client).append("' (").append(ia.getHostAddress()).append(") is not in range, rejecting").toString());
valid_ip = false;
}
if (valid_ip)
break MISSING_BLOCK_LABEL_213;
response.setReplyStatus(403);
response.setContentType("text/plain");
PrintWriter pw = new PrintWriter(response.getOutputStream());
pw.println("Cannot access resource from this IP address.");
pw.flush();
pw.close();
return true;
Throwable e;
e;
Debug.printStackTrace(e);
return false;
String type;
InputStream is;
if (request.getURL().toString().endsWith(".class"))
System.out.println((new StringBuilder()).append("WebPlugin::generate:").append(request.getURL()).toString());
if (generateSupport(request, response))
return true;
String url = request.getURL();
if (url.equals("/"))
if (home_page != null)
{
url = home_page;
} else
{
int i = 0;
do
{
if (i >= welcome_files.length)
break;
if (welcome_files[i].exists())
{
url = (new StringBuilder()).append("/").append(welcome_pages[i]).toString();
break;
}
i++;
} while (true);
}
if (response.useFile(file_root, url))
return true;
String resource_name = url;
if (resource_name.startsWith("/"))
resource_name = resource_name.substring(1);
int pos = resource_name.lastIndexOf(".");
if (pos == -1)
break MISSING_BLOCK_LABEL_528;
type = resource_name.substring(pos + 1);
ClassLoader cl = plugin_interface.getPluginClassLoader();
is = cl.getResourceAsStream(resource_name);
if (is == null && resource_root != null)
{
resource_name = (new StringBuilder()).append(resource_root).append("/").append(resource_name).toString();
is = cl.getResourceAsStream(resource_name);
}
if (is == null)
break MISSING_BLOCK_LABEL_528;
response.useStream(type, is);
is.close();
break MISSING_BLOCK_LABEL_526;
Exception exception;
exception;
is.close();
throw exception;
return true;
return false;
}
protected BasicPluginConfigModel getConfigModel()
{
return config_model;
}
protected BasicPluginViewModel getViewModel()
{
return view_model;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -