use of gnu.getopt.Getopt in project narchy by automenta.
the class RDPClientChooser method RunMacRemoteDesktopConnection.
//
// Private Class method to run the Microsoft MAC OS X Remote Desktop
// Connection (RDP) Client
//
/**
* Private method to run the Mac OS RDP client provided by Microsoft
*
* @param args
* Arguments to provide to native client
*/
private boolean RunMacRemoteDesktopConnection(String[] args) throws IOException {
logger.info("RunMacRemoteDesktopConnection()");
LongOpt[] alo = new LongOpt[4];
int c;
String arg;
Options.windowTitle = "Remote Desktop Connection";
// Process arguments (there are more than we need now - need to reduce -
// also need to check for correct args)
Getopt g = new Getopt("properJavaRDP", args, "bc:d:f::g:k:l:n:p:s:t:T:u:", alo);
while ((c = g.getopt()) != -1) {
switch(c) {
case 'd':
Options.domain = g.getOptarg();
break;
case 'n':
Options.hostname = g.getOptarg();
break;
case 'p':
Options.password = g.getOptarg();
break;
case 't':
arg = g.getOptarg();
try {
Options.port = Integer.parseInt(arg);
} catch (Exception e) {
}
break;
case 'T':
Options.windowTitle = g.getOptarg().replace('_', ' ');
break;
case 'u':
Options.username = g.getOptarg();
break;
case '?':
default:
break;
}
}
// Obtain Server name and possibly port from command args
String server = null;
if (g.getOptind() < args.length) {
int colonat = args[args.length - 1].indexOf(':', 0);
if (colonat == -1) {
server = args[args.length - 1];
} else {
server = args[args.length - 1].substring(0, colonat);
Options.port = Integer.parseInt(args[args.length - 1].substring(colonat + 1));
}
} else {
logger.warn("Server name required");
return false;
}
// Create a temporary directory from which to run RDC - we do this so
// that
// we can run multiple instances
String rdproot = "/var/tmp/RDP-" + Options.hostname + '-' + Options.port;
try {
new File(rdproot).mkdir();
} catch (Exception e) {
logger.warn("Failed to create directory " + rdproot);
return false;
}
// Dynamically create the RDP config file based on args passed.
logger.info("Creating RDP Config in " + rdproot);
FileWriter rdpConfigFile = new FileWriter(rdproot + "/Default.rdp");
rdpConfigFile.write("screen mode id:i:0\n");
rdpConfigFile.write("startdisplay:i:0\n");
// full screen - this
rdpConfigFile.write("desktop size id:i:6\n");
// needs to be mapped
// from geometry param
// passed in TBD
rdpConfigFile.write("desktopwidth:i:1280\n");
rdpConfigFile.write("desktopheight:i:854\n");
rdpConfigFile.write("autoshowmenu:i:1\n");
rdpConfigFile.write("desktopallowresize:i:1\n");
// 256 colors
rdpConfigFile.write("session bpp:i:8\n");
rdpConfigFile.write("winposstr:s:0,3,0,0,800,600\n");
rdpConfigFile.write("auto connect:i:1\n");
rdpConfigFile.write("full address:s:" + server + ':' + Options.port + '\n');
rdpConfigFile.write("compression:i:1\n");
rdpConfigFile.write("rightclickmodifiers:i:4608\n");
rdpConfigFile.write("altkeyreplacement:i:0\n");
rdpConfigFile.write("audiomode:i:1\n");
rdpConfigFile.write("redirectdrives:i:1\n");
rdpConfigFile.write("redirectprinters:i:1\n");
rdpConfigFile.write("username:s:" + Options.username + '\n');
rdpConfigFile.write("clear password:s:" + Options.password + '\n');
rdpConfigFile.write("domain:s:" + Options.domain + '\n');
rdpConfigFile.write("alternate shell:s:\n");
rdpConfigFile.write("shell working directory:s:\n");
rdpConfigFile.write("preference flag id:i:2\n");
rdpConfigFile.write("disable wallpaper:i:1\n");
rdpConfigFile.write("disable full window drag:i:0\n");
rdpConfigFile.write("disable menu anims:i:0\n");
rdpConfigFile.write("disable themes:i:0\n");
rdpConfigFile.write("disable cursor setting:i:0\n");
rdpConfigFile.write("bitmapcachepersistenable:i:1\n");
rdpConfigFile.write("Min Send Interval:i:5\n");
rdpConfigFile.write("Order Draw Threshold:i:5\n");
rdpConfigFile.write("Max Event Count:i:150\n");
rdpConfigFile.write("Normal Event Count:i:150\n");
rdpConfigFile.write("BitMapCacheSize:i:3500\n");
rdpConfigFile.write("Keyboard Layout:i:en-uk\n");
rdpConfigFile.close();
if (new File(System.getProperty("user.home") + "/Library/Preferences/Microsoft/RDC Client").exists()) {
FileWriter recentServersFile = new FileWriter(System.getProperty("user.home") + "/Library/Preferences/Microsoft/RDC Client/Recent Servers");
recentServersFile.write(server + "\r1\r");
recentServersFile.close();
}
// Copy the RDP Client application to a temporary directory to allow
// multiple copies to run. Note here that we use the MAC OS X ditto
// command because
// a normal copy of the executable would not copy the advanced OS X
// attributes which (among other things) denote the file as an
// "application".
String[] appcopycmd = { "/bin/sh", "-c", "ditto -rsrc /Applications/Remote\\ Desktop\\ Connection/Remote\\ Desktop\\ Connection " + rdproot + "/ >/dev/null 2>/dev/null" };
try {
Runtime.getRuntime().exec(appcopycmd);
} catch (IOException e) {
logger.warn("Unable to copy application to temporary directory");
return false;
}
try {
Process p = Runtime.getRuntime().exec(appcopycmd);
logger.warn("RDP Client copied to " + rdproot);
try {
// Wait for the command to complete
p.waitFor();
} catch (InterruptedException e) {
logger.warn("Unable to wait for application to copy");
return false;
}
} catch (IOException e) {
logger.warn("Unable to copy application to temporary directory");
return false;
}
// Move the application to the name of the title so that the running
// application shows when using ALT-TAB etc.
String[] mvcmd = { "/bin/sh", "-c", "mv " + rdproot + "/Remote\\ Desktop\\ Connection '" + rdproot + '/' + Options.windowTitle + "' >/dev/null 2>/dev/null" };
try {
Process p = Runtime.getRuntime().exec(mvcmd);
try {
// Wait for the mv command to complete
p.waitFor();
} catch (InterruptedException e) {
logger.warn("Unable to wait for application to run");
return false;
}
} catch (IOException e) {
logger.warn("Unable to move application");
return false;
}
// Run an instance of the RDP Client using the Mac OS X "open" command
String[] rdpcmd = { "/bin/sh", "-c", "open -a '" + rdproot + '/' + Options.windowTitle + "' " + rdproot + "/Default.rdp >/dev/null 2>/dev/null" };
try {
Process p = Runtime.getRuntime().exec(rdpcmd);
logger.info("RDP Client Launched from " + rdproot);
try {
// Wait for the open command to complete
p.waitFor();
} catch (InterruptedException e) {
logger.warn("Unable to wait for application to run");
return false;
}
} catch (IOException e) {
logger.warn("Unable to open (run) application");
return false;
}
try {
Thread.sleep(10000);
} catch (Exception e) {
logger.info("Unable to wait for 10 seconds");
return false;
}
// Remove the tempory directory
String[] rmcmd = { "/bin/sh", "-c", "rm -r " + rdproot + " >/dev/null 2>/dev/null" };
try {
Runtime.getRuntime().exec(rmcmd);
} catch (IOException e) {
logger.warn("Unable to remove temporary directory " + rdproot);
return true;
}
logger.warn("RDP Client Completed");
return true;
}
use of gnu.getopt.Getopt in project narchy by automenta.
the class Rdesktop method main.
/**
* @param args
* @throws OrderException
* @throws RdesktopException
*/
public static void main(String[] args) throws RdesktopException {
// Ensure that static variables are properly initialised
keep_running = true;
loggedon = false;
readytosend = false;
showTools = false;
mapFile = "en-us";
keyMapLocation = "";
toolFrame = null;
BasicConfigurator.configure();
logger.setLevel(Level.WARN);
Logger.getRootLogger().setLevel(Level.INFO);
// Attempt to run a native RDP Client
// RDPClientChooser Chooser = new RDPClientChooser();
/*
if (Chooser.RunNativeRDPClient(args)) {
if (!Common.underApplet)
System.exit(0);
}
*/
// Failed to run native client, drop back to Java client instead.
// parse arguments
int logonflags = Rdp.RDP_LOGON_NORMAL;
boolean fKdeHack = false;
int c;
String arg;
StringBuffer sb = new StringBuffer();
LongOpt[] alo = new LongOpt[15];
alo[0] = new LongOpt("debug_key", LongOpt.NO_ARGUMENT, null, 0);
alo[1] = new LongOpt("debug_hex", LongOpt.NO_ARGUMENT, null, 0);
alo[2] = new LongOpt("no_paste_hack", LongOpt.NO_ARGUMENT, null, 0);
alo[3] = new LongOpt("log4j_config", LongOpt.REQUIRED_ARGUMENT, sb, 0);
alo[4] = new LongOpt("packet_tools", LongOpt.NO_ARGUMENT, null, 0);
alo[5] = new LongOpt("quiet_alt", LongOpt.NO_ARGUMENT, sb, 0);
alo[6] = new LongOpt("no_remap_hash", LongOpt.NO_ARGUMENT, null, 0);
alo[7] = new LongOpt("no_encryption", LongOpt.NO_ARGUMENT, null, 0);
alo[8] = new LongOpt("use_rdp4", LongOpt.NO_ARGUMENT, null, 0);
alo[9] = new LongOpt("use_ssl", LongOpt.NO_ARGUMENT, null, 0);
alo[10] = new LongOpt("enable_menu", LongOpt.NO_ARGUMENT, null, 0);
alo[11] = new LongOpt("console", LongOpt.NO_ARGUMENT, null, 0);
alo[12] = new LongOpt("load_licence", LongOpt.NO_ARGUMENT, null, 0);
alo[13] = new LongOpt("save_licence", LongOpt.NO_ARGUMENT, null, 0);
alo[14] = new LongOpt("persistent_caching", LongOpt.NO_ARGUMENT, null, 0);
String progname = "properJavaRDP";
Getopt g = new Getopt("properJavaRDP", args, "bc:d:f::g:k:l:m:n:p:s:t:T:u:o:r:", alo);
ClipChannel clipChannel = new ClipChannel();
SoundChannel soundChannel = new SoundChannel();
DiskChannel diskChannel = new DiskChannel();
while ((c = g.getopt()) != -1) {
switch(c) {
case 0:
switch(g.getLongind()) {
case 0:
Options.debug_keyboard = true;
break;
case 1:
Options.debug_hexdump = true;
break;
case 2:
break;
case 3:
arg = g.getOptarg();
PropertyConfigurator.configure(arg);
logger.info("Log4j using config file " + arg);
break;
case 4:
showTools = true;
break;
case 5:
Options.altkey_quiet = true;
break;
case 6:
Options.remap_hash = false;
break;
case 7:
Options.packet_encryption = false;
break;
case 8:
Options.use_rdp5 = false;
// Options.server_bpp = 8;
Options.set_bpp(8);
break;
case 9:
Options.use_ssl = true;
break;
case 10:
Options.enable_menu = true;
break;
case 11:
Options.console_session = true;
break;
case 12:
Options.load_licence = true;
break;
case 13:
Options.save_licence = true;
break;
case 14:
Options.persistent_bitmap_caching = true;
break;
default:
usage();
}
break;
case 'o':
Options.set_bpp(Integer.parseInt(g.getOptarg()));
break;
case 'b':
Options.low_latency = false;
break;
case 'm':
mapFile = g.getOptarg();
break;
case 'c':
Options.directory = g.getOptarg();
break;
case 'd':
Options.domain = g.getOptarg();
break;
case 'f':
Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
// ensure width a multiple of 4
Options.width = screen_size.width & ~3;
Options.height = screen_size.height;
Options.fullscreen = true;
arg = g.getOptarg();
if (arg != null) {
if (arg.charAt(0) == 'l')
fKdeHack = true;
else {
System.err.println(progname + ": Invalid fullscreen option '" + arg + '\'');
usage();
}
}
break;
case 'g':
arg = g.getOptarg();
int cut = arg.indexOf('x', 0);
if (cut == -1) {
System.err.println(progname + ": Invalid geometry: " + arg);
usage();
}
Options.width = Integer.parseInt(arg.substring(0, cut)) & ~3;
Options.height = Integer.parseInt(arg.substring(cut + 1));
break;
case 'k':
arg = g.getOptarg();
// Options.keylayout = KeyLayout.strToCode(arg);
if (Options.keylayout == -1) {
System.err.println(progname + ": Invalid key layout: " + arg);
usage();
}
break;
case 'l':
arg = g.getOptarg();
switch(arg.charAt(0)) {
case 'd':
case 'D':
logger.setLevel(Level.DEBUG);
break;
case 'i':
case 'I':
logger.setLevel(Level.INFO);
break;
case 'w':
case 'W':
logger.setLevel(Level.WARN);
break;
case 'e':
case 'E':
logger.setLevel(Level.ERROR);
break;
case 'f':
case 'F':
logger.setLevel(Level.FATAL);
break;
default:
System.err.println(progname + ": Invalid debug level: " + arg.charAt(0));
usage();
}
break;
case 'n':
Options.hostname = g.getOptarg();
break;
case 'p':
Options.password = g.getOptarg();
logonflags |= Rdp.RDP_LOGON_AUTO;
break;
case 's':
Options.command = g.getOptarg();
break;
case 'u':
Options.username = g.getOptarg();
break;
case 't':
arg = g.getOptarg();
try {
Options.port = Integer.parseInt(arg);
} catch (NumberFormatException nex) {
System.err.println(progname + ": Invalid port number: " + arg);
usage();
}
break;
case 'T':
Options.windowTitle = g.getOptarg().replace('_', ' ');
break;
case 'r':
Options.licence_path = g.getOptarg();
break;
case '?':
default:
usage();
break;
}
}
if (fKdeHack) {
Options.height -= 46;
}
String server = null;
if (g.getOptind() < args.length) {
int colonat = args[args.length - 1].indexOf(':', 0);
if (colonat == -1) {
server = args[args.length - 1];
} else {
server = args[args.length - 1].substring(0, colonat);
Options.port = Integer.parseInt(args[args.length - 1].substring(colonat + 1));
}
} else {
System.err.println(progname + ": A server name is required!");
usage();
}
VChannels channels = new VChannels();
// Initialise all RDP5 channels
if (Options.use_rdp5) {
// TODO: implement all relevant channels
if (Options.map_clipboard) {
channels.register(clipChannel);
}
channels.register(soundChannel);
channels.register(diskChannel);
}
// Now do the startup...
logger.info("properJavaRDP version " + Version.version);
if (args.length == 0)
usage();
logger.info("Java version is " + System.getProperty("java.specification.version"));
String os = System.getProperty("os.name");
String osvers = System.getProperty("os.version");
if (os.equals("Windows 2000") || os.equals("Windows XP"))
Options.built_in_licence = true;
logger.info("Operating System is " + os + " version " + osvers);
if (os.startsWith("Linux"))
Constants.OS = Constants.LINUX;
else if (os.startsWith("Windows"))
Constants.OS = Constants.WINDOWS;
else if (os.startsWith("Mac"))
Constants.OS = Constants.MAC;
if (Constants.OS == Constants.MAC)
Options.caps_sends_up_and_down = false;
Rdp5 RdpLayer = null;
Common.rdp = RdpLayer;
RdesktopFrame window = new RdesktopFrame_Localised();
window.setClip(clipChannel);
// Configure a keyboard layout
KeyCode_FileBased keyMap = null;
try {
// logger.info("looking for: " + "/" + keyMapPath + mapFile);
InputStream istr = Rdesktop.class.getResourceAsStream('/' + keyMapPath + mapFile);
// logger.info("istr = " + istr);
if (istr == null) {
logger.debug("Loading keymap from filename");
keyMap = new KeyCode_FileBased_Localised(keyMapPath + mapFile);
} else {
logger.debug("Loading keymap from InputStream");
keyMap = new KeyCode_FileBased_Localised(istr);
}
if (istr != null)
istr.close();
Options.keylayout = keyMap.getMapCode();
} catch (Exception kmEx) {
String[] msg = { (kmEx.getClass() + ": " + kmEx.getMessage()) };
window.showErrorDialog(msg);
kmEx.printStackTrace();
Rdesktop.exit(0, null, null, true);
}
logger.debug("Registering keyboard...");
if (keyMap != null)
window.registerKeyboard(keyMap);
boolean[] deactivated = new boolean[1];
int[] ext_disc_reason = new int[1];
logger.debug("keep_running = " + keep_running);
while (keep_running) {
logger.debug("Initialising RDP layer...");
RdpLayer = new Rdp5(channels);
Common.rdp = RdpLayer;
logger.debug("Registering drawing surface...");
RdpLayer.registerDrawingSurface(window);
logger.debug("Registering comms layer...");
window.registerCommLayer(RdpLayer);
loggedon = false;
readytosend = false;
logger.info("Connecting to " + server + ':' + Options.port + " ...");
if (server.equalsIgnoreCase("localhost"))
server = "127.0.0.1";
if (RdpLayer != null) {
// Attempt to connect to server on port Options.port
try {
RdpLayer.connect(Options.username, InetAddress.getByName(server), logonflags, Options.domain, Options.password, Options.command, Options.directory);
// Remove to get rid of sendEvent tool
if (showTools) {
toolFrame = new SendEvent(RdpLayer);
toolFrame.show();
}
if (keep_running) {
/*
* By setting encryption to False here, we have an
* encrypted login packet but unencrypted transfer of
* other packets
*/
if (!Options.packet_encryption)
Options.encryption = false;
logger.info("Connection successful");
// now show window after licence negotiation
RdpLayer.mainLoop(deactivated, ext_disc_reason);
if (deactivated[0]) {
/* clean disconnect */
Rdesktop.exit(0, RdpLayer, window, true);
// return 0;
} else {
if (ext_disc_reason[0] == exDiscReasonAPIInitiatedDisconnect || ext_disc_reason[0] == exDiscReasonAPIInitiatedLogoff) {
/*
* not so clean disconnect, but nothing to worry
* about
*/
Rdesktop.exit(0, RdpLayer, window, true);
// return 0;
}
if (ext_disc_reason[0] >= 2) {
String reason = textDisconnectReason(ext_disc_reason[0]);
String[] msg = { "Connection terminated", reason };
window.showErrorDialog(msg);
logger.warn("Connection terminated: " + reason);
Rdesktop.exit(0, RdpLayer, window, true);
}
}
// exited main loop
keep_running = false;
if (!readytosend) {
// maybe the licence server was having a comms
// problem, retry?
String msg1 = "The terminal server disconnected before licence negotiation completed.";
String msg2 = "Possible cause: terminal server could not issue a licence.";
String[] msg = { msg1, msg2 };
logger.warn(msg1);
logger.warn(msg2);
window.showErrorDialog(msg);
}
}
// Remove to get rid of tool window
if (showTools)
toolFrame.dispose();
// End
} catch (ConnectionException e) {
String[] msg = { "Connection Exception", e.getMessage() };
window.showErrorDialog(msg);
Rdesktop.exit(0, RdpLayer, window, true);
} catch (UnknownHostException e) {
error(e, RdpLayer, window, true);
} catch (SocketException s) {
if (RdpLayer.isConnected()) {
logger.fatal(s.getClass().getName() + ' ' + s.getMessage());
s.printStackTrace();
error(s, RdpLayer, window, true);
Rdesktop.exit(0, RdpLayer, window, true);
}
} catch (RdesktopException e) {
String msg1 = e.getClass().getName();
String msg2 = e.getMessage();
logger.fatal(msg1 + ": " + msg2);
e.printStackTrace(System.err);
if (!readytosend) {
// maybe the licence server was having a comms
// problem, retry?
String[] msg = { "The terminal server reset connection before licence negotiation completed.", "Possible cause: terminal server could not connect to licence server.", "Retry?" };
boolean retry = window.showYesNoErrorDialog(msg);
if (!retry) {
logger.info("Selected not to retry.");
Rdesktop.exit(0, RdpLayer, window, true);
} else {
if (RdpLayer != null && RdpLayer.isConnected()) {
logger.info("Disconnecting ...");
RdpLayer.disconnect();
logger.info("Disconnected");
}
logger.info("Retrying connection...");
// retry
keep_running = true;
continue;
}
} else {
String[] msg = { e.getMessage() };
window.showErrorDialog(msg);
Rdesktop.exit(0, RdpLayer, window, true);
}
} catch (Exception e) {
logger.warn(e.getClass().getName() + ' ' + e.getMessage());
e.printStackTrace();
error(e, RdpLayer, window, true);
}
} else {
// closing bracket to if(!rdp==null)
logger.fatal("The communications layer could not be initiated!");
}
}
Rdesktop.exit(0, RdpLayer, window, true);
}
use of gnu.getopt.Getopt in project revapi by revapi.
the class Main method main.
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
if (args.length < 2) {
usage(null);
System.exit(1);
}
String scriptFileName = args[0];
String baseDir = args[1];
String[] realArgs = new String[args.length - 2];
System.arraycopy(args, 2, realArgs, 0, realArgs.length);
String[] extensionGAVs = null;
String[] oldArchivePaths = null;
String[] oldGavs = null;
String[] newArchivePaths = null;
String[] newGavs = null;
String[] oldSupplementaryArchivePaths = null;
String[] newSupplementaryArchivePaths = null;
Map<String, String> additionalConfigOptions = new HashMap<>();
String[] configFiles = null;
File cacheDir = new File(baseDir, "cache");
LongOpt[] longOpts = new LongOpt[12];
longOpts[0] = new LongOpt("usage", LongOpt.NO_ARGUMENT, null, 'u');
longOpts[1] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
longOpts[2] = new LongOpt("extensions", LongOpt.REQUIRED_ARGUMENT, null, 'e');
longOpts[3] = new LongOpt("old", LongOpt.REQUIRED_ARGUMENT, null, 'o');
longOpts[4] = new LongOpt("new", LongOpt.REQUIRED_ARGUMENT, null, 'n');
longOpts[5] = new LongOpt("old-supplementary", LongOpt.REQUIRED_ARGUMENT, null, 's');
longOpts[6] = new LongOpt("new-supplementary", LongOpt.REQUIRED_ARGUMENT, null, 't');
longOpts[7] = new LongOpt("D", LongOpt.REQUIRED_ARGUMENT, null, 'D');
longOpts[8] = new LongOpt("config-files", LongOpt.REQUIRED_ARGUMENT, null, 'c');
longOpts[9] = new LongOpt("cache-dir", LongOpt.REQUIRED_ARGUMENT, null, 'd');
longOpts[10] = new LongOpt("old-gavs", LongOpt.REQUIRED_ARGUMENT, null, 'a');
longOpts[11] = new LongOpt("new-gavs", LongOpt.REQUIRED_ARGUMENT, null, 'b');
Getopt opts = new Getopt(scriptFileName, realArgs, "uhe:o:n:s:t:D:c:d:a:b:", longOpts);
int c;
while ((c = opts.getopt()) != -1) {
switch(c) {
case 'u':
case 'h':
usage(scriptFileName);
System.exit(0);
case 'e':
extensionGAVs = opts.getOptarg().split(",");
break;
case 'o':
oldArchivePaths = opts.getOptarg().split(",");
break;
case 'n':
newArchivePaths = opts.getOptarg().split(",");
break;
case 's':
oldSupplementaryArchivePaths = opts.getOptarg().split(",");
break;
case 't':
newSupplementaryArchivePaths = opts.getOptarg().split(",");
break;
case 'c':
configFiles = opts.getOptarg().split(",");
break;
case 'D':
String[] keyValue = opts.getOptarg().split("=");
additionalConfigOptions.put(keyValue[0], keyValue.length > 1 ? keyValue[1] : null);
break;
case 'd':
cacheDir = new File(opts.getOptarg());
break;
case 'a':
oldGavs = opts.getOptarg().split(",");
break;
case 'b':
newGavs = opts.getOptarg().split(",");
break;
case ':':
System.err.println("Argument required for option " + (char) opts.getOptopt());
break;
case '?':
System.err.println("The option '" + (char) opts.getOptopt() + "' is not valid");
System.exit(1);
break;
default:
System.err.println("getopt() returned " + c);
System.exit(1);
break;
}
}
if (extensionGAVs == null || (oldArchivePaths == null && oldGavs == null) || (newArchivePaths == null && newGavs == null)) {
usage(scriptFileName);
System.exit(1);
}
List<FileArchive> oldArchives = null;
List<FileArchive> newArchives = null;
List<FileArchive> oldSupplementaryArchives = null;
List<FileArchive> newSupplementaryArchives = null;
LOG.info("Downloading checked archives");
if (oldArchivePaths == null) {
ArchivesAndSupplementaryArchives res = convertGavs(oldGavs, "Old API Maven artifact", cacheDir);
oldArchives = res.archives;
oldSupplementaryArchives = res.supplementaryArchives;
} else {
oldArchives = convertPaths(oldArchivePaths, "Old API files");
oldSupplementaryArchives = oldSupplementaryArchivePaths == null ? emptyList() : convertPaths(oldSupplementaryArchivePaths, "Old API supplementary files");
}
if (newArchivePaths == null) {
ArchivesAndSupplementaryArchives res = convertGavs(newGavs, "New API Maven artifact", cacheDir);
newArchives = res.archives;
newSupplementaryArchives = res.supplementaryArchives;
} else {
newArchives = convertPaths(newArchivePaths, "New API files");
newSupplementaryArchives = newSupplementaryArchivePaths == null ? emptyList() : convertPaths(newSupplementaryArchivePaths, "New API supplementary files");
}
try {
run(cacheDir, extensionGAVs, oldArchives, oldSupplementaryArchives, newArchives, newSupplementaryArchives, configFiles, additionalConfigOptions);
} catch (Exception e) {
e.printStackTrace();
}
System.exit(0);
}
use of gnu.getopt.Getopt in project smscgateway by RestComm.
the class Main method processCommandLine.
private void processCommandLine(String[] args) {
String programName = System.getProperty("program.name", "Mobicents Media Server");
int c;
String arg;
LongOpt[] longopts = new LongOpt[2];
longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
longopts[1] = new LongOpt("host", LongOpt.REQUIRED_ARGUMENT, null, 'b');
Getopt g = new Getopt("SMSC", args, "-:b:h", longopts);
// We'll do our own error handling
g.setOpterr(false);
//
while ((c = g.getopt()) != -1) {
switch(c) {
//
case 'b':
arg = g.getOptarg();
System.setProperty(SMSC_HLR_BIND_ADDRESS, arg);
break;
case 'h':
System.out.println("usage: " + programName + " [options]");
System.out.println();
System.out.println("options:");
System.out.println(" -h, --help Show this help message");
System.out.println(" -b, --host=<host or ip> Bind address for all Mobicents SMSC services");
System.out.println();
System.exit(0);
break;
case ':':
System.out.println("You need an argument for option " + (char) g.getOptopt());
System.exit(0);
break;
//
case '?':
System.out.println("The option '" + (char) g.getOptopt() + "' is not valid");
System.exit(0);
break;
//
default:
System.out.println("getopt() returned " + c);
break;
}
}
if (System.getProperty(SMSC_HLR_BIND_ADDRESS) == null) {
System.setProperty(SMSC_HLR_BIND_ADDRESS, "127.0.0.1");
}
}
use of gnu.getopt.Getopt in project narchy by automenta.
the class Rdesktop method RDPwindow.
public static RdesktopFrame RDPwindow(String... args) throws RdesktopException {
// Ensure that static variables are properly initialised
keep_running = true;
loggedon = false;
readytosend = false;
showTools = false;
mapFile = "en-us";
keyMapLocation = "";
toolFrame = null;
// BasicConfigurator.configure();
// logger.setLevel(Level.INFO);
// Attempt to run a native RDP Client
RDPClientChooser Chooser = new RDPClientChooser();
if (RDPClientChooser.RunNativeRDPClient(args)) {
if (!Common.underApplet)
System.exit(0);
}
// Failed to run native client, drop back to Java client instead.
// parse arguments
int logonflags = Rdp.RDP_LOGON_NORMAL;
boolean fKdeHack = false;
int c;
String arg;
StringBuffer sb = new StringBuffer();
LongOpt[] alo = new LongOpt[15];
alo[0] = new LongOpt("debug_key", LongOpt.NO_ARGUMENT, null, 0);
alo[1] = new LongOpt("debug_hex", LongOpt.NO_ARGUMENT, null, 0);
alo[2] = new LongOpt("no_paste_hack", LongOpt.NO_ARGUMENT, null, 0);
alo[3] = new LongOpt("log4j_config", LongOpt.REQUIRED_ARGUMENT, sb, 0);
alo[4] = new LongOpt("packet_tools", LongOpt.NO_ARGUMENT, null, 0);
alo[5] = new LongOpt("quiet_alt", LongOpt.NO_ARGUMENT, sb, 0);
alo[6] = new LongOpt("no_remap_hash", LongOpt.NO_ARGUMENT, null, 0);
alo[7] = new LongOpt("no_encryption", LongOpt.NO_ARGUMENT, null, 0);
alo[8] = new LongOpt("use_rdp4", LongOpt.NO_ARGUMENT, null, 0);
alo[9] = new LongOpt("use_ssl", LongOpt.NO_ARGUMENT, null, 0);
alo[10] = new LongOpt("enable_menu", LongOpt.NO_ARGUMENT, null, 0);
alo[11] = new LongOpt("console", LongOpt.NO_ARGUMENT, null, 0);
alo[12] = new LongOpt("load_licence", LongOpt.NO_ARGUMENT, null, 0);
alo[13] = new LongOpt("save_licence", LongOpt.NO_ARGUMENT, null, 0);
alo[14] = new LongOpt("persistent_caching", LongOpt.NO_ARGUMENT, null, 0);
String progname = "properJavaRDP";
Getopt g = new Getopt("properJavaRDP", args, "bc:d:f::g:k:l:m:n:p:s:t:T:u:o:r:", alo);
ClipChannel clipChannel = new ClipChannel();
SoundChannel soundChannel = new SoundChannel();
while ((c = g.getopt()) != -1) {
switch(c) {
case 0:
switch(g.getLongind()) {
case 0:
Options.debug_keyboard = true;
break;
case 1:
Options.debug_hexdump = true;
break;
case 2:
break;
// break;
case 4:
showTools = true;
break;
case 5:
Options.altkey_quiet = true;
break;
case 6:
Options.remap_hash = false;
break;
case 7:
Options.packet_encryption = false;
break;
case 8:
Options.use_rdp5 = false;
// Options.server_bpp = 8;
Options.set_bpp(8);
break;
case 9:
Options.use_ssl = true;
break;
case 10:
Options.enable_menu = true;
break;
case 11:
Options.console_session = true;
break;
case 12:
Options.load_licence = true;
break;
case 13:
Options.save_licence = true;
break;
case 14:
Options.persistent_bitmap_caching = true;
break;
default:
usage();
}
break;
case 'o':
Options.set_bpp(Integer.parseInt(g.getOptarg()));
break;
case 'b':
Options.low_latency = false;
break;
case 'm':
mapFile = g.getOptarg();
break;
case 'c':
Options.directory = g.getOptarg();
break;
case 'd':
Options.domain = g.getOptarg();
break;
case 'f':
Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
// ensure width a multiple of 4
Options.width = screen_size.width & ~3;
Options.height = screen_size.height;
Options.fullscreen = true;
arg = g.getOptarg();
if (arg != null) {
if (arg.charAt(0) == 'l')
fKdeHack = true;
else {
System.err.println(progname + ": Invalid fullscreen option '" + arg + '\'');
usage();
}
}
break;
case 'g':
arg = g.getOptarg();
int cut = arg.indexOf('x', 0);
if (cut == -1) {
System.err.println(progname + ": Invalid geometry: " + arg);
usage();
}
Options.width = Integer.parseInt(arg.substring(0, cut)) & ~3;
Options.height = Integer.parseInt(arg.substring(cut + 1));
break;
case 'k':
arg = g.getOptarg();
// Options.keylayout = KeyLayout.strToCode(arg);
if (Options.keylayout == -1) {
System.err.println(progname + ": Invalid key layout: " + arg);
usage();
}
break;
// break;
case 'n':
Options.hostname = g.getOptarg();
break;
case 'p':
Options.password = g.getOptarg();
logonflags |= Rdp.RDP_LOGON_AUTO;
break;
case 's':
Options.command = g.getOptarg();
break;
case 'u':
Options.username = g.getOptarg();
break;
case 't':
arg = g.getOptarg();
try {
Options.port = Integer.parseInt(arg);
} catch (NumberFormatException nex) {
System.err.println(progname + ": Invalid port number: " + arg);
usage();
}
break;
case 'T':
Options.windowTitle = g.getOptarg().replace('_', ' ');
break;
case 'r':
Options.licence_path = g.getOptarg();
break;
case '?':
default:
usage();
break;
}
}
if (fKdeHack) {
Options.height -= 46;
}
VChannels channels = new VChannels();
final String[] server = { null };
if (g.getOptind() < args.length) {
int colonat = args[args.length - 1].indexOf(':', 0);
if (colonat == -1) {
server[0] = args[args.length - 1];
} else {
server[0] = args[args.length - 1].substring(0, colonat);
Options.port = Integer.parseInt(args[args.length - 1].substring(colonat + 1));
}
} else {
System.err.println(progname + ": A server name is required!");
usage();
}
// Initialise all RDP5 channels
if (Options.use_rdp5) {
// TODO: implement all relevant channels
if (Options.map_clipboard) {
channels.register(clipChannel);
}
channels.register(soundChannel);
// channels.register(diskChannel);
}
// Now do the startup...
logger.info("properJavaRDP version " + Version.version);
if (args.length == 0)
usage();
String java = System.getProperty("java.specification.version");
logger.info("Java version is {}", java);
String os = System.getProperty("os.name");
String osvers = System.getProperty("os.version");
if (os.equals("Windows 2000") || os.equals("Windows XP"))
Options.built_in_licence = true;
logger.info("Operating System is {} version {}", os, osvers);
if (os.startsWith("Linux"))
Constants.OS = Constants.LINUX;
else if (os.startsWith("Windows"))
Constants.OS = Constants.WINDOWS;
else if (os.startsWith("Mac"))
Constants.OS = Constants.MAC;
if (Constants.OS == Constants.MAC)
Options.caps_sends_up_and_down = false;
RdesktopFrame window = new RdesktopFrame_Localised();
int finalLogonflags = logonflags;
new Thread(() -> {
Rdp5 RdpLayer = null;
Common.rdp = RdpLayer;
window.setClip(clipChannel);
// Configure a keyboard layout
KeyCode_FileBased keyMap = null;
try {
// logger.info("looking for: " + "/" + keyMapPath + mapFile);
InputStream istr = Rdesktop.class.getClassLoader().getResourceAsStream(keyMapPath + mapFile);
// // logger.info("istr = " + istr);
// if (istr == null) {
// logger.debug("Loading keymap from filename");
// keyMap = new KeyCode_FileBased_Localised(keyMapPath + mapFile);
// } else {
logger.debug("Loading keymap from InputStream");
keyMap = new KeyCode_FileBased_Localised(istr);
// }
if (istr != null)
istr.close();
Options.keylayout = keyMap.getMapCode();
} catch (Exception kmEx) {
String[] msg = { (kmEx.getClass() + ": " + kmEx.getMessage()) };
window.showErrorDialog(msg);
kmEx.printStackTrace();
Rdesktop.exit(0, null, null, true);
}
logger.debug("Registering keyboard...");
if (keyMap != null)
window.registerKeyboard(keyMap);
boolean[] deactivated = new boolean[1];
int[] ext_disc_reason = new int[1];
logger.debug("keep_running = {}", keep_running);
while (keep_running) {
logger.debug("Initialising RDP layer...");
RdpLayer = new Rdp5(channels);
Common.rdp = RdpLayer;
logger.debug("Registering drawing surface...");
RdpLayer.registerDrawingSurface(window);
logger.debug("Registering comms layer...");
window.registerCommLayer(RdpLayer);
loggedon = false;
readytosend = false;
logger.info("Connecting to {}" + ':' + "{} ...", server[0], Options.port);
if (server[0].equalsIgnoreCase("localhost"))
server[0] = "127.0.0.1";
if (RdpLayer != null) {
// Attempt to connect to server on port Options.port
try {
RdpLayer.connect(Options.username, InetAddress.getByName(server[0]), finalLogonflags, Options.domain, Options.password, Options.command, Options.directory);
// Remove to get rid of sendEvent tool
if (showTools) {
toolFrame = new SendEvent(RdpLayer);
toolFrame.show();
}
if (keep_running) {
/*
* By setting encryption to False here, we have an
* encrypted login packet but unencrypted transfer of
* other packets
*/
if (!Options.packet_encryption)
Options.encryption = false;
logger.info("Connection successful");
// now show window after licence negotiation
RdpLayer.mainLoop(deactivated, ext_disc_reason);
if (deactivated[0]) {
/* clean disconnect */
Rdesktop.exit(0, RdpLayer, window, true);
// return 0;
} else {
if (ext_disc_reason[0] == exDiscReasonAPIInitiatedDisconnect || ext_disc_reason[0] == exDiscReasonAPIInitiatedLogoff) {
/*
* not so clean disconnect, but nothing to worry
* about
*/
Rdesktop.exit(0, RdpLayer, window, true);
// return 0;
}
if (ext_disc_reason[0] >= 2) {
String reason = textDisconnectReason(ext_disc_reason[0]);
String[] msg = { "Connection terminated", reason };
window.showErrorDialog(msg);
logger.warn("Connection terminated: {}", reason);
Rdesktop.exit(0, RdpLayer, window, true);
}
}
// exited main loop
keep_running = false;
if (!readytosend) {
// maybe the licence server was having a comms
// problem, retry?
String msg1 = "The terminal server disconnected before licence negotiation completed.";
String msg2 = "Possible cause: terminal server could not issue a licence.";
String[] msg = { msg1, msg2 };
logger.warn(msg1);
logger.warn(msg2);
window.showErrorDialog(msg);
}
}
// Remove to get rid of tool window
if (showTools)
toolFrame.dispose();
// End
} catch (ConnectionException e) {
String[] msg = { "Connection Exception", e.getMessage() };
window.showErrorDialog(msg);
Rdesktop.exit(0, RdpLayer, window, true);
} catch (UnknownHostException e) {
error(e, RdpLayer, window, true);
} catch (SocketException s) {
if (RdpLayer.isConnected()) {
logger.error("{}" + ' ' + "{}", s.getClass().getName(), s.getMessage());
s.printStackTrace();
error(s, RdpLayer, window, true);
Rdesktop.exit(0, RdpLayer, window, true);
}
} catch (RdesktopException e) {
String msg1 = e.getClass().getName();
String msg2 = e.getMessage();
logger.error("{}: {}", msg1, msg2);
e.printStackTrace(System.err);
if (!readytosend) {
// maybe the licence server was having a comms
// problem, retry?
String[] msg = { "The terminal server reset connection before licence negotiation completed.", "Possible cause: terminal server could not connect to licence server.", "Retry?" };
boolean retry = window.showYesNoErrorDialog(msg);
if (!retry) {
logger.info("Selected not to retry.");
Rdesktop.exit(0, RdpLayer, window, true);
} else {
if (RdpLayer != null && RdpLayer.isConnected()) {
logger.info("Disconnecting ...");
RdpLayer.disconnect();
logger.info("Disconnected");
}
logger.info("Retrying connection...");
// retry
keep_running = true;
continue;
}
} else {
String[] msg = { e.getMessage() };
window.showErrorDialog(msg);
Rdesktop.exit(0, RdpLayer, window, true);
}
} catch (Exception e) {
logger.warn("{}" + ' ' + "{}", e.getClass().getName(), e.getMessage());
e.printStackTrace();
error(e, RdpLayer, window, true);
}
} else {
// closing bracket to if(!rdp==null)
logger.error("The communications layer could not be initiated!");
}
}
Rdesktop.exit(0, RdpLayer, window, true);
}).start();
return window;
}
Aggregations