Section 10.1. Connecting to the Admin Service

10.1. Connecting to the Admin Service

Connecting to the Admin Service is nearly as simple as connecting to a FlashCom Server application. The connection to the Admin Service is protected with a username and password. These credentials are set in the Server.xml configuration file. This file is located in the conf directory in the Macromedia Flash Communication Server MX installation folder.

By default, the encrypt attribute in the Password node is true . This controls whether the password is encrypted in the configuration file. Since the password is encrypted by default, you cannot open the file to recover a lost password. To create a new password, you can set the encrypt attribute to " false " and enter a new password for the value of the node:

 <Server>   <UserList>     <User name="admin">       <Password encrypt="false">adminPassword</Password>     </User>   </UserList> </Server> 

After resetting the password, you can log on with the new password using the Administration Console ( admin.swf ). Then use the Administration Console to change your password, which will automatically rewrite the Server.xml configuration file with the new password encrypted. The password is always encrypted when set via the Server Management API with changePswd( ) .

The NetConnection class is used to create the connection to the Admin Service, and the username and password must be passed to the NetConnection.connect( ) method. The Admin Service listens on a different port than the FlashCom Server. The Admin Service listens on port 1111 and you must specify the port in the connection string passed to the connect( ) method. The options to change the Admin Service port are discussed later. The following example illustrates how to connect to the Admin Service on a FlashCom Server.

Example 10-1 shows how to connect to the Admin Service. You need to specify the port (1111) in the call to NetConnection.connect( ) so that Flash connects to the Admin Service and not a different FlashCom application. You do not need to specify any application name or instance path at the end of the RTMP string (in fact, if you do, it will be ignored), because there is only once instance of the Admin Service.

Example 10-1. Establishing the Admin Service connection
 adminConnection = new NetConnection(  ); adminConnection.onStatus = function (info) {   if (info.code == "NetConnection.Connect.Success") {     trace("The connection was successful");   } else {     trace(info.code + newline + info.description);   } }; adminConnection.connect("rtmp://host.com:1111", "username", "password"); 

The success code returned from the Admin Service in the information object passed to the onStatus( ) handler is "NetConnection.Connect.Success", the same string returned when establishing a FlashCom connection.

As stated earlier, the default port of the Admin Service is 1111, which there is no compelling reason to change. Nonetheless, this port can be changed in the Server.xml configuration file. The <HostPort> tag allows you to set the IP address and port to bind the Admin Service to:

 <HostPort>192.168.1.10:1111</HostPort> 

If your server has multiple IP addresses and you want the Admin Service to respond to all of them, omit the IP address, and just specify the port preceded by a colon :

 <HostPort>:1111</HostPort> 

Changing the port will not add any security to the Admin Service; it will only increase the amount of time an attacker needs to find the port. You definitely should restrict access to the Admin Service by either network configuration or system configuration so only the approved list of IP addresses can connect to the admin port. If you are hosting a public FlashCom Server, you can use a firewall to deny access to the Admin Service to either a single IP address or a range of IP addresses, depending on the capabilities of the firewall. Additional configuration settings for each admin user can be set to control access in the Server.xml . For example:

 <Server>   <UserList>     <User name="admin">       <Password encrypt="false">adminPassword</Password>     <Allow>192.168.1</Allow>     <Deny>192.168.1.100</Deny>     <Order>Allow,Deny</Order>     </User>   </UserList> </Server> 

The <Allow> tag lets you specify a domain name, a subnet, or IP addresses that can access the Admin Service with that username. You can specify multiple entries, separated by commas, in the <Allow> tag. The <Deny> tag has the opposite effect of the <Allow> tag; <Deny> lets you specify addresses that cannot access the Admin Service.

The <Order> tag controls how the <Allow> and <Deny> tags are applied. If the <Order> tag is set to Allow,Deny , all IP addresses listed in the <Allow> tag will have access except for those specified in the <Deny> tag. This lets you specify a broad subnet in the <Allow> tag and further restrict specific IP addresses in the <Deny> tag. If the <Order> tag is set to Deny,Allow , all connections will be allowed access unless they are specifically listed in the <Deny> tag. In this case, the <Allow> tag lets you specify IP addresses to which to grant access even if they are in a denied subnet.

Clearly, setting the <Order> tag to Allow,Deny provides greater security, as you have to then specify which IP addresses or ranges can access the Admin Service.

Note that <Allow> , <Deny> , and <Order> tags also appear in the Adaptor.xml file, which has no direct relationship to the Server.xml file discussed here. Within the <UserList> tag of the Server.xml file, these tags determine the IP address(es) from which users can log into the Admin Service. In the Adaptor.xml file, these tags determine the IP address(es) from which users can log into other FlashCom applications.

You will also notice that no path to an application or instance is present in the connection string passed to the connect( ) method. Since there is only one instance of the Admin Service running on each FlashCom Server, you do not need to specify any additional application or instance information.

Example 10-2 shows the code for the FCSAdminConnector class, which is a convenient subclass of the NetConnection class, tailored to initialize an admin connection. This class and all related classes can be downloaded from the book's web site.

Example 10-2. The FCSAdminConnector class
 import com.oreilly.pfcs.FCSConstants; class com.oreilly.pfcs.admin.FCSAdminConnector extends NetConnection {   public  var dispatchEvent:Function;   public  var addEventListener:Function;   public  var removeEventListener:Function;   private var __username:String;   private var __password:String;   private var __host:String;   private var __port:Number = 1111;   function FCSAdminConnector (ahost, aport, auser, apass, aeventObj) {     super( );   // Call the superclass constructor.     mx.events.EventDispatcher.initialize(this);     host = ahost;     port = aport;     username = auser;     password = apass;     addEventListener("connect", aeventObj);     addEventListener("fault", aeventObj);   }   public function setCredentials (uname:String, pass:String):Void {     username = uname;   // Set the username.     password = pass;    // Set the password.   }   public function get username ( ):String {     return __username;   }   public function set username (uname:String):Void {     __username = uname;   }   public function get password ( ):String {     return __password;   }   public function set password (pass:String):Void {     __password = pass;   }   public function get host ( ):String {     return __host;   }   public function set host (ahost:String):Void {     __host = "rtmp://" + ahost;   }   public function get port ( ):Number {     return __port;   }   public function set port (aport:Number):Void {     __port = aport;   }      // See com.oreilly.pfcs.FCSConstants.as on the book's web site for the mapping of   // FCSConstants to the actual string codes returned from the server.    // For example, FCSConstants.SUCCESS  maps to "NetConnection.Connect.Success".   private function onStatus (info:Object):Void {     switch (info.code) {            // Key on the code.       case FCSConstants.SUCCESS:    // If the code is connection success.         info.type = "connect";      // Set the event type.         dispatchEvent(info);        // Send the event out to the listeners.         break;       default:         info.type = "fault";        // Default event type is "fault".         dispatchEvent(info);        // Send the event.         break;     }   }   public function connect (ahost, auser, apass):Void {     if (arguments.length == 3) {       super.connect.apply(super, arguments);     } else if (arguments.length == 1) {       super.connect(ahost, username, password);     } else {       var uri = host + ":" + port;       super.connect(uri, username, password);     }   } } 

The FCSAdminConnector class provides getter and setter methods for the host , port , username , and password properties so they can easily be set via ActionScript or data binding. The class also uses the methods defined in the EventDispatcher class to be consistent with the v2 UI components . The class will send two different events: connect and fault .

The onStatus( ) handler in Example 10-1 checks the info.code property against the raw response string typically returned by the FlashCom Server to indicate success ("NetConnection.Connect.Success"). In contrast, the onStatus( ) handler in Example 10-2 checks the info.code against the constant FCSConstants.SUCCESS . Why the difference? FCSConstants is a custom class included in the com.oreilly.pfcs package on the book's web site. As a convenience, it provides a property definition equivalent for each string status code that the FlashCom Server may return. This makes the code easier to read and is useful within intelligent development environments (IDEs) that provide syntax tips and code completion, so you don't have to memorize all the codes (as you do with their string equivalents, because code completion doesn't work with strings in most IDEs ).

Example 10-3 demonstrates how to create an admin connection with this class.

Example 10-3. Implementing the FCSAdminConnector Class
 import com.oreilly.pfcs.admin.FCSAdminConnector; listener = new Object( ); listener.connect = function (eo) {   // Handle the connection. }; listener.fault = function (eo) {   // Handle the connection failure. }; var adminConn = new FCSAdminConnector ("   www.yourhost.com   ",                   "1111",  "username", "password", listener); adminConn.connect( ); 

Now that you understand how to connect to the Admin Service, let's see how to use it to your benefit.



Programming Flash Communication Server
Programming Flash Communication Server
ISBN: 0596005040
EAN: 2147483647
Year: 2003
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net