usr/src/java/vpanels/client/org/opensolaris/os/vp/client/swing/App.java
author Stephen Talley <stephen.talley@oracle.com>
Wed, 08 Dec 2010 14:11:58 -0500
changeset 616 b61fe1d9f00b
parent 603 71a20acea802
child 620 faf036da4417
permissions -rw-r--r--
17577 vp should be more forgiving of bad command-line login requests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     1
/*
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
     2
 * CDDL HEADER START
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     3
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     7
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    11
 * and limitations under the License.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    12
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    18
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    19
 * CDDL HEADER END
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    20
 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    21
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    22
/*
513
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
    23
 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    24
 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    25
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    26
package org.opensolaris.os.vp.client.swing;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    27
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    28
import java.io.*;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    29
import java.net.*;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    30
import java.util.*;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    31
import java.util.logging.*;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    32
import org.opensolaris.os.uds.*;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    33
import org.opensolaris.os.vp.client.common.*;
459
abb4563e4968 14804 panels should know about/recover from from lost connections to server
Stephen Talley <stephen.talley@sun.com>
parents: 396
diff changeset
    34
import org.opensolaris.os.vp.panel.common.*;
601
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
    35
import org.opensolaris.os.vp.panel.common.action.*;
40
d1412af1ae5b 3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents: 13
diff changeset
    36
import org.opensolaris.os.vp.panel.common.control.*;
220
696985231edf 6899 --topless/-t option should be changed to --undecorated
Stephen Talley <stephen.talley@sun.com>
parents: 219
diff changeset
    37
import org.opensolaris.os.vp.util.cli.*;
219
57841c113efe 6788 package names should share o.o.o.vp prefix
Stephen Talley <stephen.talley@sun.com>
parents: 217
diff changeset
    38
import org.opensolaris.os.vp.util.misc.*;
591
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
    39
import org.opensolaris.os.vp.util.misc.finder.Finder;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    40
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    41
/**
389
374730420407 13348 the App class should not be run as a daemon thread
Stephen Talley <stephen.talley@sun.com>
parents: 381
diff changeset
    42
 * The {@code App} class is a thread that listens for UDS connections from other
374730420407 13348 the App class should not be run as a daemon thread
Stephen Talley <stephen.talley@sun.com>
parents: 381
diff changeset
    43
 * processes.  Multiple addresses of panels to display, one per
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    44
 * newline-terminated lines, may be sent through these connections.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    45
 */
42
0870a1fd0ef2 3235 vp needs to be able to report a version to assist with testing
Stephen Talley <stephen.talley@sun.com>
parents: 40
diff changeset
    46
public class App extends Thread implements AppConstants {
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    47
    //
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    48
    // Inner classes
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    49
    //
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    50
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    51
    public static class CommandLineOptionsBean {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    52
	//
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    53
	// Instance data
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    54
	//
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    55
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
    56
	private String host = RadLoginManager.LOCAL_HOST;
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
    57
	private String user = RadLoginManager.LOCAL_USER;
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    58
	private String role;
285
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
    59
	private String address = null;
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    60
	private boolean newJVM;
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    61
	private HelpFormatter help;
366
610ee2561491 10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents: 365
diff changeset
    62
	private Properties properties = new Properties();
285
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
    63
	private boolean inParam = false;
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    64
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    65
	//
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    66
	// Constructors
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    67
	//
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    68
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    69
	public CommandLineOptionsBean(HelpFormatter help) {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    70
	    this.help = help;
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    71
	}
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    72
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    73
	//
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    74
	// CommandLineOptionsBean methods
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    75
	//
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    76
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    77
	public String getAddress() {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    78
	    return address;
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    79
	}
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    80
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    81
	public String getHost() {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    82
	    return host;
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    83
	}
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    84
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    85
	public boolean getNewjvm() {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    86
	    return newJVM;
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    87
	}
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    88
279
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
    89
	public Properties getProperties() {
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
    90
	    return properties;
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
    91
	}
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
    92
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    93
	public String getRole() {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    94
	    return role;
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    95
	}
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    96
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    97
	public String getUser() {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    98
	    return user;
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
    99
	}
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   100
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   101
	public void setAddress(String address) {
285
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   102
	    boolean absolute = address.startsWith("/");
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   103
	    if (this.address == null) {
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   104
		if (!absolute) {
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   105
		    // Assume non-relative path is a standalone shortcut
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   106
		    address = String.format("/%s/%s",
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   107
			Control.encode(AppRootControl.ID, null), address);
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   108
		}
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   109
		this.address = address;
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   110
	    } else {
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   111
		/*
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   112
		 * If the address has already been set, we accumulate
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   113
		 * additional operands as query parameters or subsequent
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   114
		 * path elements.
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   115
		 */
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   116
		if (absolute) {
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   117
		    this.address = this.address + address;
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   118
		    inParam = false;
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   119
		} else {
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   120
		    try {
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   121
			/*
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   122
			 * Ideally we'd use Control.encode, but mapping
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   123
			 * from our input to what it requires would be
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   124
			 * much less straightforward than what follows.
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   125
			 */
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   126
			String[] parts = address.split("=", 2);
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   127
			StringBuffer b = new StringBuffer(this.address);
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   128
			b.append(inParam ? "&" : "?");
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   129
			b.append(URLEncoder.encode(parts[0], Control.ENCODING));
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   130
			b.append('=');
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   131
			if (parts.length > 1)
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   132
			    b.append(URLEncoder.encode(parts[1],
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   133
				Control.ENCODING));
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   134
			this.address = b.toString();
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   135
			inParam = true;
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   136
		    } catch (UnsupportedEncodingException ex) {
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   137
		    }
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   138
		}
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   139
	    }
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   140
	}
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   141
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   142
	public void setHelp() {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   143
	    System.out.println(help.getHelp());
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   144
	    System.exit(0);
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   145
	}
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   146
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   147
	public void setHost(String host) {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   148
	    this.host = host;
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   149
	}
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   150
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   151
	public void setNewjvm() {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   152
	    newJVM = true;
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   153
	}
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   154
279
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   155
	public void setProperty(String property) {
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   156
	    String value;
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   157
	    int index = property.indexOf("=");
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   158
	    if (index == -1) {
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   159
		value = "";
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   160
	    } else {
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   161
		value = property.substring(index + 1);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   162
		property = property.substring(0, index - 1);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   163
	    }
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   164
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   165
	    properties.setProperty(property, value);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   166
	}
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   167
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   168
	public void setRole(String role) {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   169
	    this.role = role;
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   170
	}
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   171
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   172
	public void setUser(String user) {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   173
	    this.user = user;
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   174
	}
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   175
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   176
	public void setVersion() {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   177
	    showVersion();
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   178
	    System.exit(0);
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   179
	}
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   180
    }
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   181
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   182
    //
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   183
    // Static data
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   184
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   185
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   186
    private static final String ARG_NONOPT_ADDRESS = "address";
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   187
    private static final String ARG_SHORT_HOST = "h";
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   188
    private static final String ARG_LONG_HOST = "host";
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   189
    private static final String ARG_SHORT_NEWJVM = "j";
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   190
    private static final String ARG_LONG_NEWJVM = "newjvm";
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   191
    private static final String ARG_SHORT_USER = "u";
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   192
    private static final String ARG_LONG_USER = "user";
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   193
    private static final String ARG_SHORT_ROLE = "r";
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   194
    private static final String ARG_LONG_ROLE = "role";
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   195
    private static final String ARG_SHORT_VERSION = "v";
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   196
    private static final String ARG_LONG_VERSION = "version";
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   197
    private static final String ARG_SHORT_HELP = "?";
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   198
    private static final String ARG_LONG_HELP = "help";
279
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   199
    private static final String ARG_SHORT_PROPERTY = "D";
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   200
    private static final String ARG_LONG_PROPERTY = "property";
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   201
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   202
    private static final String COMMAND_NAME = "vp";
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   203
    private static final String COMMAND_DESC =
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   204
	Finder.getString("cli.description");
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   205
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   206
    private static OptionChoiceGroup options;
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   207
    static {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   208
	OptionElement addressOption = new NoOptOptionElement(
285
12385adc74f4 8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents: 284
diff changeset
   209
	    true, ARG_NONOPT_ADDRESS, Finder.getString("cli.arg.address"), -1);
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   210
279
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   211
	OptionElement propOption = new OptionElement(ARG_SHORT_PROPERTY,
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   212
	    ARG_LONG_PROPERTY, false, "property", "");
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   213
	propOption.setDocumented(false);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   214
	propOption.setUseLimit(-1);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   215
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   216
	OptionElement hostOption = new OptionElement(ARG_SHORT_HOST,
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   217
	    ARG_LONG_HOST, false, "host", Finder.getString("cli.arg.host"));
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   218
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   219
	OptionElement newJVMOption = new OptionElement(ARG_SHORT_NEWJVM,
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   220
	    ARG_LONG_NEWJVM, false, Finder.getString("cli.arg.newjvm"));
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   221
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   222
	OptionElement userOption = new OptionElement(ARG_SHORT_USER,
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   223
	    ARG_LONG_USER, false, "user", Finder.getString("cli.arg.user"));
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   224
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   225
	OptionElement roleOption = new OptionElement(ARG_SHORT_ROLE,
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   226
	    ARG_LONG_ROLE, false, "role", Finder.getString("cli.arg.role"));
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   227
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   228
	OptionElement versionOption = new OptionElement(ARG_SHORT_VERSION,
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   229
	    ARG_LONG_VERSION, false, Finder.getString("cli.arg.version"));
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   230
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   231
	OptionElement helpOption = new OptionElement(ARG_SHORT_HELP,
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   232
	    ARG_LONG_HELP, false, Finder.getString("cli.arg.help"));
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   233
220
696985231edf 6899 --topless/-t option should be changed to --undecorated
Stephen Talley <stephen.talley@sun.com>
parents: 219
diff changeset
   234
	OptionListGroup mainGroup = new OptionListGroup(false,
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   235
	    propOption, hostOption, userOption, roleOption, newJVMOption,
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   236
	    addressOption);
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   237
217
b5a0a305991e 6773 panel registration has vestigial dependencies on categories
Stephen Talley <stephen.talley@sun.com>
parents: 213
diff changeset
   238
	options = new OptionChoiceGroup(true, mainGroup, versionOption,
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   239
	    helpOption);
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   240
    }
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   241
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   242
    public static final String URI_SCHEME = "vp";
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   243
    public static final String URI_USER_ROLE_SEPARATOR = ":";
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   244
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   245
    public static final String VP_USER_DIR =
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   246
	System.getProperty("user.home") + File.separator + ".vp";
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   247
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   248
    static {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   249
	// Set up client logging
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   250
	String fileName = VP_USER_DIR + File.separator + "log";
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   251
513
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   252
	// Root Logger
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   253
	Logger log = Logger.getLogger("");
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   254
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   255
	try {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   256
	    File parent = new File(fileName).getParentFile();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   257
	    if (!parent.exists()) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   258
		if (!parent.mkdirs()) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   259
		    throw new IOException(
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   260
			"could not create directory: " +
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   261
			parent.getAbsolutePath());
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   262
		}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   263
	    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   264
513
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   265
	    Handler fHandler = new FileHandler(fileName);
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   266
	    fHandler.setFormatter(new SimpleFormatter());
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   267
	    log.addHandler(fHandler);
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   268
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   269
	    // Don't output to the console by default
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   270
	    for (Handler cHandler : log.getHandlers()) {
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   271
		if (cHandler instanceof ConsoleHandler) {
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   272
		    log.removeHandler(cHandler);
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   273
		}
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   274
	    }
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   275
	} catch (IOException e) {
591
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   276
	    Logger.getLogger(App.class.getName()).log(Level.WARNING,
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   277
		"unable to create log file: " + fileName);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   278
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   279
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   280
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   281
    public static final File TRUSTSTORE_FILE =
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   282
	new File(VP_USER_DIR, "truststore");
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   283
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   284
    public static final File VP_UDS;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   285
    static {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   286
	String hostName = NetUtil.getHostName();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   287
	if (hostName == null) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   288
	    hostName = "localhost";
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   289
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   290
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   291
	// May be null or malformed if not an X client
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   292
	String display = System.getenv("DISPLAY");
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   293
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   294
	if (display != null && !display.matches(".*:\\d+(\\.\\d)?$")) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   295
	    String error = "invalid DISPLAY environment variable: " + display;
513
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   296
	    Logger.getLogger(App.class.getName()).log(Level.WARNING, error);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   297
	    display = null;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   298
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   299
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   300
	if (display == null) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   301
	    display = ":0.0";
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   302
	} else {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   303
	    if (display.matches(".*:\\d+$")) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   304
		display += ".0";
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   305
	    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   306
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   307
	    if (display.startsWith(hostName)) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   308
		display = display.substring(hostName.length());
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   309
	    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   310
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   311
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   312
	String name = String.format(".uds-%s-%s", hostName, display);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   313
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   314
	VP_UDS = new File(VP_USER_DIR, name);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   315
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   316
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   317
    public static final String VP_USER_PREFS =
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   318
	VP_USER_DIR + File.separator + "vp.init";
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   319
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   320
    private static final Preferences prefs = new Preferences(VP_USER_PREFS);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   321
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   322
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   323
    // Instance data
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   324
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   325
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   326
    private UDSocketServer server;
314
8decc90a3ec6 9416 more fully featured FMRI type (fix lint)
David Powell <David.Powell@sun.com>
parents: 300
diff changeset
   327
    private final List<AppInstance> instances = new ArrayList<AppInstance>();
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   328
    private ConnectionManager connManager = new ConnectionManager();
603
71a20acea802 17449 AppLoginHistory's factory method ignores its argument at times
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 601
diff changeset
   329
    private LoginHistoryManager loginHistoryManager =
71a20acea802 17449 AppLoginHistory's factory method ignores its argument at times
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 601
diff changeset
   330
	new LoginHistoryManager(connManager, new File(VP_USER_DIR, "history"));
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   331
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   332
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   333
    // Constructors
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   334
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   335
366
610ee2561491 10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents: 365
diff changeset
   336
    public App() {
43
e7573475aac8 3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents: 42
diff changeset
   337
	addVersionToThreadName(this);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   338
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   339
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   340
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   341
    // Runnable methods
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   342
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   343
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   344
    @Override
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   345
    public void run() {
513
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   346
        Logger log = Logger.getLogger(getClass().getName());
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   347
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   348
	// Start singleton application instance...
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   349
	try {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   350
	    server = UnixDomainSocket.bind(VP_UDS, 0600);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   351
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   352
	    while (true) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   353
		final UDSocket socket = server.accept();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   354
		String peerUser = socket.getPeerUser();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   355
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   356
		if (!RadLoginManager.LOCAL_USER.equals(peerUser)) {
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   357
		    String error = String.format(
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   358
			"user %s attempted to connect as %s", peerUser,
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   359
			RadLoginManager.LOCAL_USER);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   360
		    log.log(Level.WARNING, error);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   361
		} else {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   362
		    // Spawn on a separate thread so as not to block other
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   363
		    // incoming to conections -- not so much because we
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   364
		    // anticipate a lot of traffic, but because we can't
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   365
		    // guarantee that some poorly-behaved client won't keep its
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   366
		    // connection open indefinitely.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   367
		    new Thread() {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   368
			@Override
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   369
			public void run() {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   370
			    readFully(socket);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   371
			}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   372
		    }.start();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   373
		}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   374
	    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   375
	} catch (UDSNotSupportedException e) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   376
	    // Bummer
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   377
	    return;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   378
	} catch (IOException e) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   379
	    // Major bummer
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   380
	    log.log(Level.SEVERE, "error creating daemon", e);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   381
	    return;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   382
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   383
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   384
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   385
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   386
    // App methods
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   387
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   388
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   389
    public void abortableExit() throws ActionAbortedException {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   390
	synchronized (instances) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   391
	    for (int i = instances.size() - 1; i >= 0; i--) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   392
		// Throws ActionAbortedException
356
379b8150bb93 11379 apache: unable to cancel app with bad data in outstanding changes
Stephen Talley <stephen.talley@sun.com>
parents: 344
diff changeset
   393
		instances.get(i).closeInstance(false);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   394
	    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   395
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   396
	exit();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   397
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   398
601
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   399
    public void exit(int exitCode) {
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   400
	try {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   401
	    if (server != null) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   402
		server.close();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   403
	    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   404
	} catch (IOException ignore) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   405
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   406
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   407
	try {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   408
	    prefs.store();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   409
	} catch (IOException e) {
513
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   410
	    Logger.getLogger(getClass().getName()).log(Level.WARNING,
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   411
		"could not write preferences", e);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   412
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   413
601
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   414
	System.exit(exitCode);
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   415
    }
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   416
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   417
    public void exit() {
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   418
	exit(0);
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   419
    }
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   420
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   421
    private void exitIfNoIntances(int exitCode) {
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   422
	if (instances.isEmpty()) {
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   423
	    exit(exitCode);
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   424
	}
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   425
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   426
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   427
    public ConnectionManager getConnectionManager() {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   428
	return connManager;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   429
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   430
603
71a20acea802 17449 AppLoginHistory's factory method ignores its argument at times
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 601
diff changeset
   431
    public LoginHistoryManager getLoginHistoryManager() {
71a20acea802 17449 AppLoginHistory's factory method ignores its argument at times
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 601
diff changeset
   432
	return loginHistoryManager;
71a20acea802 17449 AppLoginHistory's factory method ignores its argument at times
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 601
diff changeset
   433
    }
71a20acea802 17449 AppLoginHistory's factory method ignores its argument at times
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 601
diff changeset
   434
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   435
    protected Preferences getPreferences() {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   436
	return prefs;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   437
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   438
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   439
    protected void instanceClosed(AppInstance instance) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   440
	synchronized (instances) {
601
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   441
	    if (instances.remove(instance)) {
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   442
		exitIfNoIntances(0);
376
da611bd28519 12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents: 373
diff changeset
   443
	    }
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   444
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   445
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   446
381
2bae201e9d41 svcs: clicking "Close" kills all panel instances, not just that one
Stephen Talley <stephen.talley@sun.com>
parents: 376
diff changeset
   447
    protected void instanceCreated(AppInstance instance) {
2bae201e9d41 svcs: clicking "Close" kills all panel instances, not just that one
Stephen Talley <stephen.talley@sun.com>
parents: 376
diff changeset
   448
	synchronized (instances) {
2bae201e9d41 svcs: clicking "Close" kills all panel instances, not just that one
Stephen Talley <stephen.talley@sun.com>
parents: 376
diff changeset
   449
	    instances.add(instance);
2bae201e9d41 svcs: clicking "Close" kills all panel instances, not just that one
Stephen Talley <stephen.talley@sun.com>
parents: 376
diff changeset
   450
	}
2bae201e9d41 svcs: clicking "Close" kills all panel instances, not just that one
Stephen Talley <stephen.talley@sun.com>
parents: 376
diff changeset
   451
    }
2bae201e9d41 svcs: clicking "Close" kills all panel instances, not just that one
Stephen Talley <stephen.talley@sun.com>
parents: 376
diff changeset
   452
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   453
    public void newInstance(Properties properties, URI uri) {
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   454
	String hostVal = uri.getHost();
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   455
	String roleVal = null;
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   456
	String userVal = uri.getUserInfo();
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   457
	int i = userVal.indexOf(URI_USER_ROLE_SEPARATOR);
366
610ee2561491 10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents: 365
diff changeset
   458
	if (i != -1) {
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   459
	    roleVal = userVal.substring(i + 1);
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   460
	    userVal = userVal.substring(0, i);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   461
	}
323
497a785649eb 10071 apply new design to SMF panel
David Powell <David.Powell@sun.com>
parents: 317
diff changeset
   462
376
da611bd28519 12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents: 373
diff changeset
   463
	AppInstance instance = null;
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   464
	boolean success = false;
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   465
376
da611bd28519 12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents: 373
diff changeset
   466
	try {
600
c16a7e34499d 17304 - Implement password type
Shadrack Kilemba <Shadrack.Kilemba@Oracle.COM>
parents: 591
diff changeset
   467
	    StringLoginProperty host = new StringLoginProperty(hostVal, false);
616
b61fe1d9f00b 17577 vp should be more forgiving of bad command-line login requests
Stephen Talley <stephen.talley@oracle.com>
parents: 603
diff changeset
   468
	    host.setEditableOnError(true);
b61fe1d9f00b 17577 vp should be more forgiving of bad command-line login requests
Stephen Talley <stephen.talley@oracle.com>
parents: 603
diff changeset
   469
600
c16a7e34499d 17304 - Implement password type
Shadrack Kilemba <Shadrack.Kilemba@Oracle.COM>
parents: 591
diff changeset
   470
	    StringLoginProperty user = new StringLoginProperty(userVal, false);
616
b61fe1d9f00b 17577 vp should be more forgiving of bad command-line login requests
Stephen Talley <stephen.talley@oracle.com>
parents: 603
diff changeset
   471
	    user.setEditableOnError(true);
b61fe1d9f00b 17577 vp should be more forgiving of bad command-line login requests
Stephen Talley <stephen.talley@oracle.com>
parents: 603
diff changeset
   472
600
c16a7e34499d 17304 - Implement password type
Shadrack Kilemba <Shadrack.Kilemba@Oracle.COM>
parents: 591
diff changeset
   473
	    StringLoginProperty role = new StringLoginProperty(roleVal, false);
616
b61fe1d9f00b 17577 vp should be more forgiving of bad command-line login requests
Stephen Talley <stephen.talley@oracle.com>
parents: 603
diff changeset
   474
	    role.setEditableOnError(true);
b61fe1d9f00b 17577 vp should be more forgiving of bad command-line login requests
Stephen Talley <stephen.talley@oracle.com>
parents: 603
diff changeset
   475
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   476
	    LoginRequest request = new LoginRequest(host, user, role);
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   477
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   478
	    instance = new AppInstance(this, properties, request);
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   479
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   480
	    SimpleNavigable[] path = Navigator.toArray(uri.getPath());
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   481
	    instance.getNavigator().goToAsyncAndWait(true, null, path);
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   482
	    success = true;
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   483
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   484
	// User is aware of this because he explicitly caused it
376
da611bd28519 12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents: 373
diff changeset
   485
	} catch (ActionAbortedException e) {
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   486
601
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   487
	// User has been advised of this by RadLoginManager
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   488
	} catch (ActionFailedException e) {
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   489
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   490
	// User has been advised of this by SwingNavigator
376
da611bd28519 12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents: 373
diff changeset
   491
	} catch (NavigationException e) {
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   492
581
c1b6248742a7 12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents: 513
diff changeset
   493
	// Unexpected error - write to log
c1b6248742a7 12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents: 513
diff changeset
   494
	} catch (RuntimeException e) {
c1b6248742a7 12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents: 513
diff changeset
   495
	    Logger log = Logger.getLogger(getClass().getName());
c1b6248742a7 12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents: 513
diff changeset
   496
	    log.log(Level.SEVERE, "could not launch: " + uri, e);
c1b6248742a7 12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents: 513
diff changeset
   497
c1b6248742a7 12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents: 513
diff changeset
   498
	// Unexpected error - write to log
c1b6248742a7 12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents: 513
diff changeset
   499
	} catch (Error e) {
c1b6248742a7 12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents: 513
diff changeset
   500
	    Logger log = Logger.getLogger(getClass().getName());
c1b6248742a7 12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents: 513
diff changeset
   501
	    log.log(Level.SEVERE, "could not launch: " + uri, e);
c1b6248742a7 12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents: 513
diff changeset
   502
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   503
	} finally {
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   504
	    if (!success && instance != null &&
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   505
		// Partial navigation failures aren't deal-breakers
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   506
		!NavigationUtil.isPanelStarted(instance.getNavigator())) {
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   507
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   508
		instance.close();
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   509
	    }
376
da611bd28519 12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents: 373
diff changeset
   510
	}
323
497a785649eb 10071 apply new design to SMF panel
David Powell <David.Powell@sun.com>
parents: 317
diff changeset
   511
    }
497a785649eb 10071 apply new design to SMF panel
David Powell <David.Powell@sun.com>
parents: 317
diff changeset
   512
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   513
    public void readFully(UDSocket socket) {
366
610ee2561491 10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents: 365
diff changeset
   514
	BufferedReader reader = null;
513
691122ca7b6f 15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents: 473
diff changeset
   515
        Logger log = Logger.getLogger(getClass().getName());
366
610ee2561491 10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents: 365
diff changeset
   516
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   517
	try {
366
610ee2561491 10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents: 365
diff changeset
   518
	    reader = new BufferedReader(
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   519
		new InputStreamReader(socket.getInputStream()));
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   520
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   521
	    String line;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   522
	    while ((line = reader.readLine()) != null) {
279
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   523
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   524
		// Format of each line is "<uri>[ <properties>]"
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   525
		String[] parts = line.split("\\s+");
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   526
		URI uri = new URI(parts[0]);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   527
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   528
		Properties properties = null;
284
255095584c55 8351 need way to build without building javadoc
David Powell <David.Powell@sun.com>
parents: 279
diff changeset
   529
		if (parts.length > 1) {
279
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   530
		    String decodedProps = URLDecoder.decode(parts[1],
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   531
			Control.ENCODING);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   532
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   533
		    StringReader propReader = new StringReader(decodedProps);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   534
		    properties = new Properties();
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   535
		    properties.load(propReader);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   536
		}
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   537
366
610ee2561491 10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents: 365
diff changeset
   538
		newInstance(properties, uri);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   539
	    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   540
279
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   541
	} catch (IllegalArgumentException e) {
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   542
	    log.log(Level.SEVERE, "malformed Unicode escape sequence", e);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   543
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   544
	} catch (IOException e) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   545
	    log.log(Level.SEVERE, "I/O error", e);
279
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   546
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   547
	} catch (URISyntaxException e) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   548
	    log.log(Level.WARNING, "remote request with invalid URI", e);
366
610ee2561491 10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents: 365
diff changeset
   549
610ee2561491 10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents: 365
diff changeset
   550
	} finally {
610ee2561491 10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents: 365
diff changeset
   551
	    IOUtil.closeIgnore(reader);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   552
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   553
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   554
459
abb4563e4968 14804 panels should know about/recover from from lost connections to server
Stephen Talley <stephen.talley@sun.com>
parents: 396
diff changeset
   555
    //
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   556
    // Static methods
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   557
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   558
43
e7573475aac8 3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents: 42
diff changeset
   559
    private static void addVersionToThreadName(Thread thread) {
e7573475aac8 3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents: 42
diff changeset
   560
	// Add useful information to a thread dump
e7573475aac8 3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents: 42
diff changeset
   561
	String name = String.format(
e7573475aac8 3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents: 42
diff changeset
   562
	    "%s (app version %s)", thread.getName(), VERSION);
e7573475aac8 3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents: 42
diff changeset
   563
e7573475aac8 3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents: 42
diff changeset
   564
	thread.setName(name);
e7573475aac8 3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents: 42
diff changeset
   565
    }
e7573475aac8 3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents: 42
diff changeset
   566
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   567
    public static void showVersion() {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   568
	System.out.println(Finder.getString("cli.error.version", VERSION));
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   569
    }
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   570
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   571
    public static URI createURI(String host, String user, String role,
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   572
	String address) throws URISyntaxException {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   573
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   574
	if (role != null) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   575
	    user += URI_USER_ROLE_SEPARATOR + role;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   576
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   577
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   578
	return new URI(URI_SCHEME, user, host, -1, address, null, null);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   579
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   580
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   581
    public static void main(String args[]) {
43
e7573475aac8 3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents: 42
diff changeset
   582
	addVersionToThreadName(Thread.currentThread());
e7573475aac8 3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents: 42
diff changeset
   583
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   584
	CommandLineParser parser = new PosixCommandLineParser();
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   585
	UsageFormatter usage = new UsageFormatter(
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   586
	    COMMAND_NAME, options, parser.getOptionFormatter());
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   587
	HelpFormatter help = new HelpFormatter(COMMAND_DESC, usage);
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   588
	CommandLineOptionsBean bean = new CommandLineOptionsBean(help);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   589
42
0870a1fd0ef2 3235 vp needs to be able to report a version to assist with testing
Stephen Talley <stephen.talley@sun.com>
parents: 40
diff changeset
   590
	if (System.getProperty("vpanels.debug.version") != null) {
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   591
	    showVersion();
42
0870a1fd0ef2 3235 vp needs to be able to report a version to assist with testing
Stephen Talley <stephen.talley@sun.com>
parents: 40
diff changeset
   592
	}
0870a1fd0ef2 3235 vp needs to be able to report a version to assist with testing
Stephen Talley <stephen.talley@sun.com>
parents: 40
diff changeset
   593
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   594
	try {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   595
	    // Populate bean
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   596
	    CommandLineProcessor.process(args, options, parser, bean);
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   597
	}
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   598
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   599
	catch (Exception e) {
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   600
	    CommandUtil.exit(e, usage);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   601
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   602
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   603
	String address = bean.getAddress();
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   604
	URI uri = null;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   605
	try {
300
7f3357de9250 8810 incomplete support for port specification
David Powell <David.Powell@sun.com>
parents: 285
diff changeset
   606
	    uri = createURI(bean.getHost(), bean.getUser(), bean.getRole(),
473
18f221b572ce 14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents: 459
diff changeset
   607
		address);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   608
	} catch (URISyntaxException e) {
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   609
	    System.err.println(Finder.getString("cli.error.uri", e.getInput()));
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   610
	    System.exit(1);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   611
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   612
279
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   613
	Properties properties = bean.getProperties();
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   614
	if (!bean.getNewjvm()) {
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   615
	    // Check for running instance
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   616
	    try {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   617
		UDSocket socket = UnixDomainSocket.connect(VP_UDS);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   618
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   619
		// Send arguments to running instance...
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   620
		PrintWriter out = new PrintWriter(socket.getOutputStream());
279
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   621
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   622
		// Format of each line is "<uri>[ <properties>]"
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   623
		out.print(uri);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   624
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   625
		try {
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   626
		    if (properties != null) {
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   627
			StringWriter propWriter = new StringWriter();
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   628
			properties.store(propWriter, null);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   629
			String props = propWriter.toString();
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   630
			String encodedProps = URLEncoder.encode(props,
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   631
			    Control.ENCODING);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   632
			out.print(' ');
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   633
			out.print(encodedProps);
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   634
		    }
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   635
		} catch (IOException e) {
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   636
		    // Unlikely
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   637
		}
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   638
b82f64a1f586 8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents: 243
diff changeset
   639
		out.println();
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   640
		out.close();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   641
		System.exit(0);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   642
	    } catch (UDSNotSupportedException e) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   643
		// UDS not supported on this platform
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   644
	    } catch (IOException e) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   645
		// We are the only running instance
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   646
	    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   647
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   648
591
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   649
	try {
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   650
	    URL policy = Finder.getResource("panel.policy");
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   651
	    if (policy == null) {
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   652
		throw new IOException("panel.policy not found");
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   653
	    }
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   654
	    PanelClassLoader.loadPermissions(policy);
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   655
	} catch (IOException e) {
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   656
	    Logger.getLogger(App.class.getName()).log(Level.SEVERE,
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   657
		"unable to read panel.policy", e);
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   658
	    String message = Finder.getString("init.error.security.io");
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   659
	    System.err.println(message);
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   660
	    System.exit(1);
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   661
	} catch (PermissionParseException e) {
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   662
	    Logger.getLogger(App.class.getName()).log(Level.SEVERE,
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   663
		"unable to parse panel.policy", e);
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   664
	    String message = Finder.getString("init.error.security.parse");
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   665
	    System.err.println(message);
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   666
	    System.exit(1);
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   667
	}
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   668
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   669
	System.setSecurityManager(new SecurityManager());
7c5752b99fd6 12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents: 581
diff changeset
   670
366
610ee2561491 10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents: 365
diff changeset
   671
	App app = new App();
376
da611bd28519 12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents: 373
diff changeset
   672
	app.newInstance(properties, uri);
601
9d4e3e0ee603 7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents: 600
diff changeset
   673
	app.exitIfNoIntances(1);
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   674
78
6336fcea8db0 2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents: 43
diff changeset
   675
	if (!bean.getNewjvm()) {
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   676
	    // Start daemon thread listening for connections
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   677
	    app.start();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   678
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   679
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   680
}