UIpublic class UI extends org.gudy.azureus2.ui.common.UITemplateHeadless implements org.gudy.azureus2.ui.common.IUserInterfacethis is a telnet UI that starts up a server socket that listens for new connections
on a (configurable) port. when an incoming connection is recieved, we check the host
against our list of allowed hosts and if this host is permitted, we start a new
command line interface for that connection. |
Fields Summary |
---|
private org.gudy.azureus2.ui.console.multiuser.UserManager | userManager |
Methods Summary |
---|
public void | createNewConsoleInput(java.lang.String consoleName, java.io.InputStream inputStream, java.io.PrintStream outputStream, org.gudy.azureus2.ui.console.UserProfile profile)creates a new console input using the specified input/output streams.
we create the new input in non-controlling mode because we don't want the 'quit'
command to shut down the whole interface - simply this clients connection.
ConsoleInput console;
if( userManager != null )
{
MultiUserConsoleInput muc = new MultiUserConsoleInput(consoleName, UIConst.getAzureusCore(), new InputStreamReader(inputStream), outputStream, Boolean.FALSE, profile);
muc.registerCommand( new UserCommand(userManager) );
console = muc;
}
else
{
console = new ConsoleInput(consoleName, UIConst.getAzureusCore(), new InputStreamReader(inputStream), outputStream, Boolean.FALSE, profile);
System.out.println( "TelnetUI: console input instanciated" );
}
console.printconsolehelp();
| private org.gudy.azureus2.ui.console.multiuser.UserManager | initUserManager()
if( System.getProperty("azureus.console.multiuser") != null )
return UserManager.getInstance(UIConst.getAzureusCore().getPluginManager().getDefaultPluginInterface());
else
return null;
| public void | openTorrent(java.lang.String fileName)shamelessly copied from the console ui. could this be extracted into a static utility method?
if( fileName.toUpperCase().startsWith( "HTTP://" ) ) {
System.out.println( "Downloading torrent from url: " + fileName );
TorrentDownloaderFactory.downloadManaged( fileName );
return;
}
try {
if (!TorrentUtils.isTorrentFile(fileName)) {//$NON-NLS-1$
Logger.getLogger("azureus2.ui.telnet").error(fileName+" doesn't seem to be a torrent file. Not added.");
return;
}
} catch (Exception e) {
Logger.getLogger("azureus2.ui.telnet").error("Something is wrong with "+fileName+". Not added. (Reason: "+e.getMessage()+")");
return;
}
if (UIConst.getGlobalManager()!=null) {
try {
UIConst.getGlobalManager().addDownloadManager(fileName, COConfigurationManager.getDirectoryParameter("Default save path"));
} catch (Exception e) {
Logger.getLogger("azureus2.ui.telnet").error("The torrent "+fileName+" could not be added.", e);
}
}
| public java.lang.String[] | processArgs(java.lang.String[] args)
return args;
| public void | startUI()start up a server socket thread on an appropriate port as obtained from the configuration manager.
if( ! isStarted() )
{
try {
int telnetPort = COConfigurationManager.getIntParameter("Telnet_iPort", 57006);
String allowedHostsStr = COConfigurationManager.getStringParameter("Telnet_sAllowedHosts", "127.0.0.1,titan");
StringTokenizer st = new StringTokenizer(allowedHostsStr, ",");
Set allowedHosts = new HashSet();
while( st.hasMoreTokens() )
allowedHosts.add(st.nextToken().toLowerCase());
int maxLoginAttempts = COConfigurationManager.getIntParameter("Telnet_iMaxLoginAttempts", 3);
userManager = initUserManager();
Thread thread = new Thread(new SocketServer(this, telnetPort, allowedHosts, userManager, maxLoginAttempts), "Telnet Socket Server Thread");
thread.setDaemon(true);
thread.start();
} catch (IOException e) {
e.printStackTrace();
}
}
super.startUI();
|
|