odsdotnet-commit Mailing List for ods-dotNet
Status: Alpha
Brought to you by:
geniusj
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: <ge...@us...> - 2006-08-05 02:51:59
|
Revision: 17 Author: geniusj Date: 2006-08-04 19:51:53 -0700 (Fri, 04 Aug 2006) ViewCVS: http://svn.sourceforge.net/odsdotnet/?rev=17&view=rev Log Message: ----------- Rudimentary hosts/domains listing support. Uses a TreeView. Not bad, but needs to be faster. That'll come next. Modified Paths: -------------- trunk/OdsClient/HostsController.Designer.cs trunk/OdsClient/HostsController.cs trunk/OdsClient/HostsController.resx trunk/OdsClient/ODSController.cs Modified: trunk/OdsClient/HostsController.Designer.cs =================================================================== --- trunk/OdsClient/HostsController.Designer.cs 2006-08-05 02:51:39 UTC (rev 16) +++ trunk/OdsClient/HostsController.Designer.cs 2006-08-05 02:51:53 UTC (rev 17) @@ -29,56 +29,166 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - this.button1 = new System.Windows.Forms.Button(); - this.hostsListBox = new System.Windows.Forms.ListBox(); + this.doneButton = new System.Windows.Forms.Button(); + this.odsHostsView = new System.Windows.Forms.TreeView(); this.odsRRBindingSource = new System.Windows.Forms.BindingSource(this.components); + this.hostnameField = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.typeComboBox = new System.Windows.Forms.ComboBox(); + this.label3 = new System.Windows.Forms.Label(); + this.ttlField = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.targetField = new System.Windows.Forms.TextBox(); + this.updateHostsButton = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.odsRRBindingSource)).BeginInit(); this.SuspendLayout(); // - // button1 + // doneButton // - this.button1.Location = new System.Drawing.Point(211, 328); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 23); - this.button1.TabIndex = 2; - this.button1.Text = "Done"; - this.button1.UseVisualStyleBackColor = true; + this.doneButton.Location = new System.Drawing.Point(274, 328); + this.doneButton.Name = "doneButton"; + this.doneButton.Size = new System.Drawing.Size(75, 23); + this.doneButton.TabIndex = 2; + this.doneButton.Text = "Done"; + this.doneButton.UseVisualStyleBackColor = true; + this.doneButton.Click += new System.EventHandler(this.doneButton_click); // - // hostsListBox + // odsHostsView // - this.hostsListBox.DataSource = this.odsRRBindingSource; - this.hostsListBox.DisplayMember = "Record"; - this.hostsListBox.FormattingEnabled = true; - this.hostsListBox.Location = new System.Drawing.Point(12, 12); - this.hostsListBox.Name = "hostsListBox"; - this.hostsListBox.Size = new System.Drawing.Size(471, 303); - this.hostsListBox.TabIndex = 3; - this.hostsListBox.ValueMember = "Host"; + this.odsHostsView.Location = new System.Drawing.Point(13, 13); + this.odsHostsView.Name = "odsHostsView"; + this.odsHostsView.Size = new System.Drawing.Size(360, 309); + this.odsHostsView.TabIndex = 3; + this.odsHostsView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.odsHostsView_AfterSelect); // // odsRRBindingSource // this.odsRRBindingSource.DataSource = typeof(Ods.OdsRR); // + // hostnameField + // + this.hostnameField.Location = new System.Drawing.Point(379, 29); + this.hostnameField.MaxLength = 32; + this.hostnameField.Name = "hostnameField"; + this.hostnameField.Size = new System.Drawing.Size(231, 20); + this.hostnameField.TabIndex = 4; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(376, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(58, 13); + this.label1.TabIndex = 5; + this.label1.Text = "Hostname:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(376, 52); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(34, 13); + this.label2.TabIndex = 6; + this.label2.Text = "Type:"; + // + // typeComboBox + // + this.typeComboBox.FormattingEnabled = true; + this.typeComboBox.Items.AddRange(new object[] { + "A", + "CNAME", + "MX", + "NS", + "PTR", + "TXT", + "URL"}); + this.typeComboBox.Location = new System.Drawing.Point(379, 68); + this.typeComboBox.Name = "typeComboBox"; + this.typeComboBox.Size = new System.Drawing.Size(86, 21); + this.typeComboBox.TabIndex = 7; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(472, 52); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(30, 13); + this.label3.TabIndex = 8; + this.label3.Text = "TTL:"; + // + // ttlField + // + this.ttlField.Location = new System.Drawing.Point(475, 68); + this.ttlField.MaxLength = 6; + this.ttlField.Name = "ttlField"; + this.ttlField.Size = new System.Drawing.Size(135, 20); + this.ttlField.TabIndex = 9; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(376, 92); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(41, 13); + this.label4.TabIndex = 10; + this.label4.Text = "Target:"; + // + // targetField + // + this.targetField.Location = new System.Drawing.Point(379, 108); + this.targetField.Name = "targetField"; + this.targetField.Size = new System.Drawing.Size(231, 20); + this.targetField.TabIndex = 11; + // + // updateHostsButton + // + this.updateHostsButton.Location = new System.Drawing.Point(380, 145); + this.updateHostsButton.Name = "updateHostsButton"; + this.updateHostsButton.Size = new System.Drawing.Size(230, 29); + this.updateHostsButton.TabIndex = 12; + this.updateHostsButton.Text = "Update"; + this.updateHostsButton.UseVisualStyleBackColor = true; + // // HostsController // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(495, 359); - this.Controls.Add(this.hostsListBox); - this.Controls.Add(this.button1); + this.ClientSize = new System.Drawing.Size(622, 360); + this.Controls.Add(this.updateHostsButton); + this.Controls.Add(this.targetField); + this.Controls.Add(this.label4); + this.Controls.Add(this.ttlField); + this.Controls.Add(this.label3); + this.Controls.Add(this.typeComboBox); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.hostnameField); + this.Controls.Add(this.odsHostsView); + this.Controls.Add(this.doneButton); this.Name = "HostsController"; this.Text = "Hosts"; this.Load += new System.EventHandler(this.HostsController_Load); ((System.ComponentModel.ISupportInitialize)(this.odsRRBindingSource)).EndInit(); this.ResumeLayout(false); + this.PerformLayout(); } #endregion - private System.Windows.Forms.Button button1; - private System.Windows.Forms.ListBox hostsListBox; + private System.Windows.Forms.Button doneButton; private System.Windows.Forms.BindingSource odsRRBindingSource; + private System.Windows.Forms.TreeView odsHostsView; + private System.Windows.Forms.TextBox hostnameField; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.ComboBox typeComboBox; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox ttlField; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox targetField; + private System.Windows.Forms.Button updateHostsButton; } Modified: trunk/OdsClient/HostsController.cs =================================================================== --- trunk/OdsClient/HostsController.cs 2006-08-05 02:51:39 UTC (rev 16) +++ trunk/OdsClient/HostsController.cs 2006-08-05 02:51:53 UTC (rev 17) @@ -11,33 +11,63 @@ { public partial class HostsController : Form { - private ArrayList hosts; + private ArrayList domains; public HostsController() { InitializeComponent(); - this.hosts = new ArrayList(); + this.domains = new ArrayList(); } - public HostsController(ArrayList hosts) + public HostsController(ArrayList domains) { InitializeComponent(); - this.hosts = hosts; + this.domains = domains; } private void HostsController_Load(object sender, EventArgs e) { - foreach (OdsRR host in this.hosts) + TreeNode rootDomainsNode, rootHostsNode, domainNode, hostNode, hostNodeClone; + + rootDomainsNode = odsHostsView.Nodes.Add("Domains"); + rootHostsNode = odsHostsView.Nodes.Add("Hosts"); + foreach (OdsDomain domain in this.domains) { - try + domainNode = rootDomainsNode.Nodes.Add(domain.DomainName); + foreach (OdsRR host in domain.Hosts) { - odsRRBindingSource.Add(host); + hostNode = new TreeNode(host.ToString()); + hostNode.Tag = host; + hostNodeClone = (TreeNode)hostNode.Clone(); + domainNode.Nodes.Add(hostNode); + rootHostsNode.Nodes.Add(hostNodeClone); } - catch (Exception ex) - { - System.Console.WriteLine(ex.Message); - } } } + + private void doneButton_click(object sender, EventArgs e) + { + this.Close(); + } + + private void odsHostsView_AfterSelect(object sender, TreeViewEventArgs e) + { + OdsRR host; + host = (OdsRR)e.Node.Tag; + + if (host != null) + { + hostnameField.Text = host.Host; + typeComboBox.SelectedIndex = typeComboBox.FindStringExact(host.RRType); + ttlField.Text = host.TTL; + targetField.Text = host.Target; + } + else + { + hostnameField.Text = ""; + ttlField.Text = ""; + targetField.Text = ""; + } + } } } \ No newline at end of file Modified: trunk/OdsClient/HostsController.resx =================================================================== --- trunk/OdsClient/HostsController.resx 2006-08-05 02:51:39 UTC (rev 16) +++ trunk/OdsClient/HostsController.resx 2006-08-05 02:51:53 UTC (rev 17) @@ -118,9 +118,6 @@ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> <metadata name="odsRRBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> - <value>17, 17</value> + <value>16, 16</value> </metadata> - <metadata name="odsRRBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> - <value>17, 17</value> - </metadata> </root> \ No newline at end of file Modified: trunk/OdsClient/ODSController.cs =================================================================== --- trunk/OdsClient/ODSController.cs 2006-08-05 02:51:39 UTC (rev 16) +++ trunk/OdsClient/ODSController.cs 2006-08-05 02:51:53 UTC (rev 17) @@ -67,7 +67,7 @@ private void editHostsButton_Click(object sender, EventArgs e) { OdsConnection odsconn; - ArrayList hosts; + ArrayList domains; HostsController hc; if (ValidateForm()) @@ -79,15 +79,13 @@ usernameField.Text, passwordField.Text); - hosts = odsconn.GetRRList(); - hc = new HostsController(hosts); - hc.Visible = true; + domains = odsconn.GetRRListByDomain(); + hc = new HostsController(domains); + hc.Show(); } catch (OdsServerException ex) { - odsStatusLabel.Text = ex.Message; - hc = new HostsController(); - hc.Show(); + MessageBox.Show(ex.Message); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ge...@us...> - 2006-08-05 02:51:44
|
Revision: 16 Author: geniusj Date: 2006-08-04 19:51:39 -0700 (Fri, 04 Aug 2006) ViewCVS: http://svn.sourceforge.net/odsdotnet/?rev=16&view=rev Log Message: ----------- Rudimentary hosts/domains listing support. Uses a TreeView. Not bad, but needs to be faster. That'll come next. Modified Paths: -------------- trunk/Ods/Ods.cs Modified: trunk/Ods/Ods.cs =================================================================== --- trunk/Ods/Ods.cs 2006-08-03 06:02:28 UTC (rev 15) +++ trunk/Ods/Ods.cs 2006-08-05 02:51:39 UTC (rev 16) @@ -77,7 +77,6 @@ public OdsRR() { } - /// <summary> /// Create an ODS RR /// </summary> @@ -89,7 +88,6 @@ string ttl) { } - private string hostValue; /// <summary> /// ODS Hostname @@ -99,7 +97,6 @@ get { return hostValue; } set { hostValue = value; } } - private string rrtypeValue; /// <summary> /// RR Type @@ -109,7 +106,6 @@ get { return rrtypeValue; } set { rrtypeValue = value; } } - private string targetValue; /// <summary> /// Target (IP Address for A records, Host for CNAMEs, etc) @@ -119,7 +115,6 @@ get { return targetValue; } set { targetValue = value; } } - private string ttlValue; /// <summary> /// Time to Live for record @@ -129,7 +124,6 @@ get { return ttlValue; } set { ttlValue = value; } } - /// <summary> /// String representation /// </summary> @@ -143,7 +137,6 @@ return toReturn; } - /// <summary> /// Returns ToString() /// </summary> @@ -154,12 +147,64 @@ } /// <summary> + /// A Domain containing OdsRR(s) + /// </summary> + public class OdsDomain + { + private string domainNameValue; + private ArrayList hostsValue; + + /// <summary> + /// Initialize an OdsDomain + /// </summary> + public OdsDomain() + { + } + /// <summary> + /// Initialize an OdsDomain + /// </summary> + /// <param name="domainName">Domain name</param> + public OdsDomain(string domainName) + { + this.domainNameValue = domainName; + } + /// <summary> + /// Initialize an OdsDomain + /// </summary> + /// <param name="domainName">Domain name</param> + /// <param name="hosts">ArrayList of OdsRR objects</param> + public OdsDomain(string domainName, ArrayList hosts) + { + this.domainNameValue = domainName; + this.hostsValue = hosts; + } + /// <summary> + /// Get/Set Domain Name + /// </summary> + public string DomainName + { + get { return domainNameValue; } + set { domainNameValue = value; } + } + /// <summary> + /// Get/Set Hosts List (ArrayList of OdsRRs) + /// </summary> + public ArrayList Hosts + { + get { return hostsValue; } + set { hostsValue = value; } + } + } + + /// <summary> /// Class for handling ODS connections and communicating with ODS. /// </summary> public class OdsConnection { private TcpClient client; private NetworkStream stream; + private StreamReader sr; + private StreamWriter sw; private String username; private String password; private String server; @@ -337,24 +382,93 @@ /// OdsConnection odsconnect = new OdsConnection(user, pass); /// ArrayList hosts = odsconnect.GetRRList(); /// - /// foreach (Hashtable host in hosts) + /// foreach (OdsRR host in hosts) /// { /// Console.Write("Host: {0} Type: {1} Target: {2} TTL: {3}\r\n", - /// host["host"], host["type"], host["target"], host["ttl"]); + /// host.Host, host.RRType, host.Target, host.TTL); /// } /// </code> /// </example> public ArrayList GetRRList() { + // Return all RRs + return (GetFilteredRRList("")); + } + public ArrayList GetRRListByDomain() + { + ArrayList domainList = new ArrayList(); + String cmdStr = "DOMAINS\r\n"; + String domainStr; + + // Make sure we're connected and open a StreamReader + ReConnect(); + + // Send our command to the ODS server + Send(cmdStr); + + // Retrieve our result + while (!(domainStr = sr.ReadLine()).StartsWith("189")) + { + // Check to see if domain list is empty or we're not logged in + if (domainStr.StartsWith("300")) + break; + + // We've found the meat of the output - Parse it out.. + if (domainStr.StartsWith("181") || domainStr.StartsWith("183")) + { + OdsDomain domainObj = new OdsDomain(domainStr.Substring(4)); + + domainList.Add(domainObj); + } + } + + // Get a list of hosts for all of our domains. + foreach (OdsDomain domainObj in domainList) + { + domainObj.Hosts = GetFilteredRRList(domainObj.DomainName); + } + + return (domainList); + } + // TODO: Add overloaded GetRRList() for limiting to a specific domain/pattern + /// <summary> + /// Get current internet facing IP (uses ODS server port 7069) + /// </summary> + /// <returns>String containing current internet facing IP</returns> + public String GetCurrentIP() + { + String ipaddr; + TcpClient ipClient = new TcpClient(this.server, 7069); + NetworkStream ipStream = ipClient.GetStream(); + StreamReader ipsr = new StreamReader(ipStream); + + ipaddr = ipsr.ReadLine(); + ipaddr.Trim(); + + ipStream.Close(); + ipClient.Close(); + + return (ipaddr); + } + /// <summary> + /// Get RR list using ODS filter syntax + /// </summary> + /// <param name="filter">Filter to use: e.g. domain.com, or s:domain, or an empty string</param> + /// <returns></returns> + private ArrayList GetFilteredRRList(string filter) + { ArrayList rrList = new ArrayList(); Regex rrSeparator = new Regex(" +"); - String cmdStr = "LISTRR\r\n"; - String rrStr; + String rrStr, cmdStr; + if (filter.Length == 0) + cmdStr = "LISTRR\r\n"; + else + cmdStr = String.Format("LISTRR {0}\r\n", filter); + // Make sure we're connected and open a StreamReader ReConnect(); - StreamReader sr = new StreamReader(stream); - + // Send our command to the ODS server Send(cmdStr); @@ -396,27 +510,7 @@ return (rrList); } - // TODO: Add overloaded GetRRList() for limiting to a specific domain/pattern /// <summary> - /// Get current internet facing IP (uses ODS server port 7069) - /// </summary> - /// <returns>String containing current internet facing IP</returns> - public String GetCurrentIP() - { - String ipaddr; - TcpClient ipClient = new TcpClient(this.server, 7069); - NetworkStream ipStream = ipClient.GetStream(); - StreamReader sr = new StreamReader(ipStream); - - ipaddr = sr.ReadLine(); - ipaddr.Trim(); - - ipStream.Close(); - ipClient.Close(); - - return (ipaddr); - } - /// <summary> /// Disconnect from ODS. It's a good idea to call this whenever you're done for a while. /// </summary> public void Disconnect() @@ -424,32 +518,25 @@ this.stream.Close(); this.client.Close(); } - private void Send(String command) { - byte[] writeBuf = Encoding.ASCII.GetBytes(command); - // If we've been disconnected, reconnect ReConnect(); - stream.Write(writeBuf, 0, writeBuf.Length); + sw.Write(command); return; } private void SendAndVerify(String command, UInt16 returncode) { String resultstr; - Int32 readlen; - byte[] result = new Byte[256]; - byte[] writeBuf = Encoding.ASCII.GetBytes(command); // If we've been disconnected, reconnect ReConnect(); - stream.Write(writeBuf, 0, writeBuf.Length); - readlen = stream.Read(result, 0, result.Length); + sw.Write(command); - resultstr = Encoding.ASCII.GetString(result, 0, readlen); + resultstr = sr.ReadLine(); // Verify that command was successful if (!CheckStringForReturnCode(resultstr, returncode)) @@ -460,7 +547,6 @@ private void Connect() { // Buffer for our read data - Byte[] buf = new Byte[256]; String bufstr; try @@ -469,11 +555,12 @@ // Initialize stream for socket this.stream = this.client.GetStream(); + this.sr = new StreamReader(this.stream); + this.sw = new StreamWriter(this.stream); + this.sw.AutoFlush = true; - Int32 bytes = this.stream.Read(buf, 0, buf.Length); + bufstr = this.sr.ReadLine(); - bufstr = Encoding.ASCII.GetString(buf, 0, bytes); - if (!CheckStringForReturnCode(bufstr, 100)) { throw new OdsServerException("No connection banner!? Wrong protocol??"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |