📄 usercommand.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: UserCommand.java
package org.gudy.azureus2.ui.console.multiuser.commands;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.*;
import org.apache.commons.cli.*;
import org.gudy.azureus2.ui.console.ConsoleInput;
import org.gudy.azureus2.ui.console.UserProfile;
import org.gudy.azureus2.ui.console.commands.*;
import org.gudy.azureus2.ui.console.multiuser.UserManager;
public class UserCommand extends IConsoleCommand
{
private final class AddUserCommand extends OptionsConsoleCommand
{
final UserCommand this$0;
public void execute(String commandName, ConsoleInput ci, CommandLine commandLine)
{
String userName = commandLine.getOptionValue('u');
if (userName == null)
{
ci.out.println("> AddUser: (u)sername option not specified");
return;
}
String password = commandLine.getOptionValue('p');
if (password == null)
{
ci.out.println("> AddUser: (p)assword option not specified");
return;
}
String userType = commandLine.getOptionValue('t', "admin");
if (!UserProfile.isValidUserType(userType.toLowerCase()))
{
ci.out.println((new StringBuilder()).append("> AddUser: invalid profile type '").append(userType).append("'. Valid values are: ").append("admin").append(",").append("user").append(",").append("guest").toString());
return;
}
if (getUserManager().getUser(userName) != null)
{
ci.out.println((new StringBuilder()).append("> AddUser error: user '").append(userName).append("' already exists").toString());
return;
} else
{
UserProfile profile = new UserProfile(userName, userType);
profile.setPassword(password);
String defaultSaveDirectory = commandLine.getOptionValue('d', null);
profile.setDefaultSaveDirectory(defaultSaveDirectory);
getUserManager().addUser(profile);
ci.out.println((new StringBuilder()).append("> AddUser: user '").append(userName).append("' added").toString());
saveUserManagerConfig(ci.out);
return;
}
}
public String getCommandDescriptions()
{
return "add [-u user] <options>\t\ta\tadds a new user";
}
public AddUserCommand()
{
this$0 = UserCommand.this;
super("add", "a");
getOptions().addOption(new Option("u", "username", true, "name of new user"));
getOptions().addOption(new Option("p", "password", true, "password for new user"));
getOptions().addOption(new Option("t", "type", true, "user type (Admin / User / Guest)"));
getOptions().addOption(new Option("d", "savedirectory", true, "default torrent save directory for this user"));
}
}
private final class DeleteUserCommand extends OptionsConsoleCommand
{
final UserCommand this$0;
public void execute(String commandName, ConsoleInput ci, CommandLine commandLine)
{
String userName = commandLine.getOptionValue('u');
if (userName == null)
{
ci.out.println("> DeleteUser: (u)sername option not specified");
return;
}
if (getUserManager().getUser(userName) == null)
{
ci.out.println((new StringBuilder()).append("> DeleteUser: error - user '").append(userName).append("' not found").toString());
return;
} else
{
getUserManager().deleteUser(userName);
ci.out.println((new StringBuilder()).append("> DeleteUser: user '").append(userName).append("' deleted").toString());
saveUserManagerConfig(ci.out);
return;
}
}
public String getCommandDescriptions()
{
return "delete [-u user]\t\td\tdeletes a user";
}
public DeleteUserCommand()
{
this$0 = UserCommand.this;
super("delete", "d");
getOptions().addOption(new Option("u", "username", true, "name of user to delete"));
}
}
private final class ListUsersCommand extends IConsoleCommand
{
final UserCommand this$0;
public void execute(String commandName, ConsoleInput ci, List args)
{
ci.out.println("> -----");
ci.out.println("> Username\tProfile\t\tSave Directory");
UserProfile profile;
String saveDir;
for (Iterator iter = getUserManager().getUsers().iterator(); iter.hasNext(); ci.out.println((new StringBuilder()).append("> ").append(profile.getUsername()).append("\t\t").append(profile.getUserType()).append("\t\t").append(saveDir).toString()))
{
profile = (UserProfile)iter.next();
saveDir = profile.getDefaultSaveDirectory();
if (saveDir == null)
saveDir = "(default)";
}
ci.out.println("> -----");
}
public String getCommandDescriptions()
{
return "list \t\t\t\tl\tlists all users";
}
public ListUsersCommand()
{
this$0 = UserCommand.this;
super("list", "l");
}
}
private final class ModifyUserCommand extends OptionsConsoleCommand
{
final UserCommand this$0;
public void execute(String commandName, ConsoleInput ci, CommandLine commandLine)
{
String userName = commandLine.getOptionValue('u');
if (userName == null)
{
ci.out.println("> ModifyUser: (u)sername option not specified");
return;
}
UserProfile profile = getUserManager().getUser(userName);
if (profile == null)
{
ci.out.println((new StringBuilder()).append("> ModifyUser: error - user '").append(userName).append("' not found").toString());
return;
}
boolean modified = false;
String userType = commandLine.getOptionValue('t');
if (userType != null)
if (UserProfile.isValidUserType(userType.toLowerCase()))
{
profile.setUserType(userType.toLowerCase());
modified = true;
} else
{
ci.out.println((new StringBuilder()).append("> ModifyUser: invalid profile type '").append(userType).append("'. Valid values are: ").append("admin").append(",").append("user").append(",").append("guest").toString());
return;
}
String password = commandLine.getOptionValue('p');
if (password != null)
{
profile.setPassword(password);
modified = true;
}
String defaultSaveDirectory = commandLine.getOptionValue('d');
if (defaultSaveDirectory != null)
{
modified = true;
if (defaultSaveDirectory.length() > 0)
profile.setDefaultSaveDirectory(defaultSaveDirectory);
else
profile.setDefaultSaveDirectory(null);
}
if (modified)
{
ci.out.println((new StringBuilder()).append("> ModifyUser: user '").append(userName).append("' modified").toString());
saveUserManagerConfig(ci.out);
} else
{
printHelp(ci.out, commandLine.getArgList());
}
}
public String getCommandDescriptions()
{
return "modify [-u user] <options>\tm\tmodifies a user";
}
public ModifyUserCommand()
{
this$0 = UserCommand.this;
super("modify", "m");
getOptions().addOption(new Option("u", "username", true, "name of user to modify"));
getOptions().addOption(new Option("p", "password", true, "password for new user"));
getOptions().addOption(new Option("t", "type", true, "user type (Admin / User / Guest)"));
getOptions().addOption(new Option("d", "savedirectory", true, "default torrent save directory for this user"));
}
}
private final CommandCollection subCommands = new CommandCollection();
private final UserManager userManager;
public UserCommand(UserManager userManager)
{
super("user");
this.userManager = userManager;
subCommands.add(new AddUserCommand());
subCommands.add(new DeleteUserCommand());
subCommands.add(new ModifyUserCommand());
subCommands.add(new ListUsersCommand());
}
private UserManager getUserManager()
{
return userManager;
}
private void saveUserManagerConfig(PrintStream out)
{
try
{
userManager.save();
out.println("> User Manager config saved");
}
catch (FileNotFoundException e)
{
out.println((new StringBuilder()).append("> Error saving User Manager config: ").append(e).toString());
e.printStackTrace(out);
}
}
public String getCommandDescriptions()
{
return "user add|delete|list|modify <options>\tmanage users able to log in via telnet ui";
}
public void execute(String commandName, ConsoleInput ci, List args)
{
if (args.isEmpty())
{
printHelp(ci.out, args);
} else
{
commandName = (String)args.remove(0);
subCommands.execute(commandName, ci, args);
}
}
public void printHelpExtra(PrintStream out, List args)
{
out.println("> -----");
out.println("'user' syntax:");
if (args.size() > 0)
{
String command = (String)args.remove(0);
IConsoleCommand cmd = subCommands.get(command);
if (cmd != null)
cmd.printHelp(out, args);
return;
}
out.println("user <command> <command options>");
out.println();
out.println("Available <command>s:");
IConsoleCommand cmd;
for (Iterator iter = subCommands.iterator(); iter.hasNext(); out.println(cmd.getCommandDescriptions()))
cmd = (IConsoleCommand)iter.next();
out.println("try 'help user <command>' for more information about a particular user command");
out.println("> -----");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -