Forum Discussion

RobertColbert's avatar
RobertColbert
Icon for Nimbostratus rankNimbostratus
Oct 23, 2009

Feature Update - Login from command line

My company uses a visionapp Remote Desktop to manage our servers (windows, linux, F5) by connecting via RDP, SSH and HTTP. One of the features we wanted to take advantage of is their External Application config. This allows the tool to launch an external application and pass parameters like servername, username and password. Since we already manage our LTMs via web & SSH through this tool, I wanted to add the iRule Editor to the mix.

 

 

Below are some code changes I made to the source to read command line parameters and auto-connect if servername, username and password were all found. I'm sure there are other ways to do this but this is my example.

 

 

1st, add 3 module variables to the class:

 

 
         private string m_hostName = ""; 
         private string m_userName = "admin"; 
         private string m_password = ""; 
 

 

 

Next, add the following subroutine in the Initialization Methods region:

 

 
         protected void loadCommandArgs() 
         { 
             string lastarg = ""; 
             foreach (string arg in Environment.GetCommandLineArgs()) 
             { 
                 switch (lastarg.ToLower()) { 
                     case "/host": 
                     case "/hostname": 
                     case "/server": 
                         m_hostName = arg; 
                         break; 
  
                     case "/user": 
                     case "/username": 
                         m_userName = arg; 
                         break; 
  
                     case "/pass": 
                     case "/password": 
                         m_password = arg; 
                         break; 
                 } 
                 lastarg = arg; 
             } 
         } 
 

 

 

Next, remove the DoConnect() routine and replace it with the following:

 

 
         private void DoConnect() 
         { 
             if (DoDisconnect()) { return; } 
  
             //ConnectionDialog cd = new ConnectionDialog(); 
 iControl.Dialogs.ConnectionDialog cd = new iControl.Dialogs.ConnectionDialog(); 
 cd.ConnectionInfo = Clients.ConnectionInfo; 
  
             cd.centerX = this.Location.X + (this.Width / 2); 
             cd.centerY = this.Location.Y + (this.Height / 2); 
             DialogResult dr = cd.ShowDialog(this); 
  
             if (DialogResult.OK == dr) 
             { 
                 Clients.initialize(); 
  
                 if (Clients.Connected) 
                 { 
                     toolStripMenuItem_FileConnect.Text = "Dis&connect"; 
                     toolStripButton_Connect.Image = global::iRuler.Properties.Resources.ToolbarDisconnect; 
                     toolStripButton_Connect.Text = "Disconnect.  Click the Connect button..."; 
                     statusStripLabel_Connection.Text = "Connected to " + Clients.ConnectionInfo.hostname; 
                     setStatus(statusStripLabel_Connection.Text, getStatusVisible()); 
  
                     updatePartitionInfo(); 
                     refreshiRules(); 
                     showButtons(true); 
                     updateTitle(false); 
                 } 
             } 
             else 
             { 
                 setStatus("The host you have specified must be a v9.x BIG-IP", true); 
             } 
         } 
         private void DoConnect(string sHostname, string sUsername, string sPassword) 
         { 
             DoDisconnect(); 
             // Check to see if we received valid arguments and connect if possible 
             if (!string.IsNullOrEmpty(sHostname) && !string.IsNullOrEmpty(sUsername) && !string.IsNullOrEmpty(sPassword)) 
             { 
                 Clients.ConnectionInfo.hostname = sHostname; 
                 Clients.ConnectionInfo.username = sUsername; 
                 Clients.ConnectionInfo.password = sPassword; 
                 Clients.initialize(); 
  
                 if (Clients.Connected) 
                 { 
                     toolStripMenuItem_FileConnect.Text = "Dis&connect"; 
                     toolStripButton_Connect.Image = global::iRuler.Properties.Resources.ToolbarDisconnect; 
                     toolStripButton_Connect.Text = "Disconnect.  Click the Connect button..."; 
                     statusStripLabel_Connection.Text = "Connected to " + Clients.ConnectionInfo.hostname; 
                     setStatus(statusStripLabel_Connection.Text, getStatusVisible()); 
  
                     updatePartitionInfo(); 
                     refreshiRules(); 
                     showButtons(true); 
                     updateTitle(false); 
                 } 
             } 
         } 
         private bool DoDisconnect() 
         { 
             if (Clients.Connected) 
             { 
                 Clients.Connected = false; 
                 toolStripMenuItem_FileConnect.Text = "&Connect"; 
                 statusStripLabel_Connection.Text = "Disconnected. Click the Connect button..."; 
                 toolStripButton_Connect.Image = global::iRuler.Properties.Resources.ToolbarConnect; 
                 toolStripButton_Connect.Text = "Connect"; 
                 treeView_iRules.Nodes.Clear(); 
                 m_textEditor.Text = ""; 
                 m_lastTreeViewNode = null; 
                 showButtons(false); 
                 setStatus("Disconnected", getStatusVisible()); 
                 m_currentPartition = ""; 
                 updateTitle(false); 
                 return true; 
             } 
             return false; 
         } 
 

 

 

Finally, call the new LoadCommandlineParms and DoConnect(x,x,x) routines from the iRulerMain_Load routine. (The two lines with ++ are to be inserted in the block noted)

 

 
             if (initializeEditor()) 
             { 
                 m_textEditor.Focus(); 
                 splitContainer2.SplitterDistance = 0; 
                 showButtons(false); 
  
                 DateTime dt2 = DateTime.Now; 
                 DateTime dt1 = new DateTime(m_lastUpdate); 
                 TimeSpan ts = dt2 - dt1; 
                 if (ts.Days >= 1) 
                 { 
                     DoCheckForUpdates(true, false); 
                 } 
                 updateAutoCompleteList(); 
                 updateIndentionSettings(); 
                 viewStatus(m_showStatus); 
 ++                loadCommandArgs(); 
 ++                DoConnect(m_hostName, m_userName, m_password); 
             } 
             else 
 

 

 

I hope other people find this as useful as my team has.

 

 

-Robert
  • Robert, Thank you so much for your detailed patch! I'm currently working on some features for the Editor and I'll definitely get this rolled into the latest release that will hopefully go out in a week or so!

     

     

    -Joe