wfrm_SecurityEntry.cs
上传用户:horngjaan
上传日期:2009-12-12
资源大小:2882k
文件大小:23k
源码类别:

Email服务器

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Net;
  8. namespace LumiSoft.MailServer
  9. {
  10. /// <summary>
  11. /// Summary description for Security_Frm.
  12. /// </summary>
  13. public class wfrm_SecurityEntry : System.Windows.Forms.Form
  14. {
  15. private LumiSoft.UI.Controls.WLabel mt_description;
  16. private LumiSoft.UI.Controls.WLabel mt_protocol;
  17. private LumiSoft.UI.Controls.WLabel mt_type;
  18. private LumiSoft.UI.Controls.WLabel mt_action;
  19. private LumiSoft.UI.Controls.WLabel mt_ipaddress;
  20. private LumiSoft.UI.Controls.WLabel mt_domain;
  21. private LumiSoft.UI.Controls.WEditBox m_pDescription;
  22. private LumiSoft.UI.Controls.WComboBox m_pProtocol;
  23. private LumiSoft.UI.Controls.WComboBox m_pType;
  24. private LumiSoft.UI.Controls.WComboBox m_pAction;
  25. private LumiSoft.UI.Controls.WEditBox m_pStartIP;
  26. private LumiSoft.UI.Controls.WEditBox m_pEndIP;
  27. private LumiSoft.UI.Controls.WEditBox m_pDomain;
  28. private LumiSoft.UI.Controls.WButton m_pOk;
  29. private LumiSoft.UI.Controls.WButton m_pCancel;
  30. /// <summary>
  31. /// Required designer variable.
  32. /// </summary>
  33. private System.ComponentModel.Container components = null;
  34. private string  m_Description = "";
  35. private string  m_Protocol    = "";
  36. private string  m_Type        = "";
  37. private string  m_Action      = "";
  38. private string  m_Content     = "";
  39. private long    m_StartIP     = 0;
  40. private long    m_EndIP       = 0;
  41. /// <summary>
  42. /// Default constructor.
  43. /// </summary>
  44. /// <param name="ds"></param>
  45. public wfrm_SecurityEntry()
  46. {
  47. //
  48. // Required for Windows Form Designer support
  49. //
  50. InitializeComponent();
  51. //
  52. // TODO: Add any constructor code after InitializeComponent call
  53. //
  54.             FillCombos();
  55. }
  56. /// <summary>
  57. /// 
  58. /// </summary>
  59. /// <param name="ds"></param>
  60. /// <param name="dr"></param>
  61. public wfrm_SecurityEntry(DataRow dr)
  62. {
  63. //
  64. // Required for Windows Form Designer support
  65. //
  66. InitializeComponent();
  67. //
  68. // TODO: Add any constructor code after InitializeComponent call
  69. //
  70. FillCombos();
  71. try
  72. {
  73. m_pDescription.Text = dr["Description"].ToString();
  74. m_pProtocol.Text    = dr["Protocol"].ToString();
  75. m_pType.Text        = dr["Type"].ToString();
  76. m_pAction.Text      = dr["Action"].ToString();
  77. if(m_pType.Text == "IP" || m_pType.Text == "Domain"){
  78. m_pStartIP.Text = dr["Content"].ToString();
  79. }
  80. if(m_pType.Text == "IP Range"){
  81. string content = dr["Content"].ToString();
  82. string[] iprange =  content.Split(new Char[]{'-'});
  83. m_pStartIP.Text = iprange[0];
  84. m_pEndIP.Text   = iprange[1];
  85. m_pEndIP.Visible = true;
  86. }
  87. }
  88. catch(Exception x)
  89. {
  90. MessageBox.Show("error:" + x.Message);
  91. }
  92. }
  93. #region function Dispose
  94. /// <summary>
  95. /// Clean up any resources being used.
  96. /// </summary>
  97. protected override void Dispose( bool disposing )
  98. {
  99. if( disposing )
  100. {
  101. if(components != null)
  102. {
  103. components.Dispose();
  104. }
  105. }
  106. base.Dispose( disposing );
  107. }
  108. #endregion
  109. #region Windows Form Designer generated code
  110. /// <summary>
  111. /// Required method for Designer support - do not modify
  112. /// the contents of this method with the code editor.
  113. /// </summary>
  114. private void InitializeComponent()
  115. {
  116. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(wfrm_SecurityEntry));
  117. this.mt_description = new LumiSoft.UI.Controls.WLabel();
  118. this.mt_protocol = new LumiSoft.UI.Controls.WLabel();
  119. this.mt_type = new LumiSoft.UI.Controls.WLabel();
  120. this.mt_action = new LumiSoft.UI.Controls.WLabel();
  121. this.mt_ipaddress = new LumiSoft.UI.Controls.WLabel();
  122. this.mt_domain = new LumiSoft.UI.Controls.WLabel();
  123. this.m_pDescription = new LumiSoft.UI.Controls.WEditBox();
  124. this.m_pProtocol = new LumiSoft.UI.Controls.WComboBox();
  125. this.m_pType = new LumiSoft.UI.Controls.WComboBox();
  126. this.m_pAction = new LumiSoft.UI.Controls.WComboBox();
  127. this.m_pStartIP = new LumiSoft.UI.Controls.WEditBox();
  128. this.m_pEndIP = new LumiSoft.UI.Controls.WEditBox();
  129. this.m_pDomain = new LumiSoft.UI.Controls.WEditBox();
  130. this.m_pOk = new LumiSoft.UI.Controls.WButton();
  131. this.m_pCancel = new LumiSoft.UI.Controls.WButton();
  132. ((System.ComponentModel.ISupportInitialize)(this.m_pDescription)).BeginInit();
  133. ((System.ComponentModel.ISupportInitialize)(this.m_pProtocol)).BeginInit();
  134. ((System.ComponentModel.ISupportInitialize)(this.m_pType)).BeginInit();
  135. ((System.ComponentModel.ISupportInitialize)(this.m_pAction)).BeginInit();
  136. ((System.ComponentModel.ISupportInitialize)(this.m_pStartIP)).BeginInit();
  137. ((System.ComponentModel.ISupportInitialize)(this.m_pEndIP)).BeginInit();
  138. ((System.ComponentModel.ISupportInitialize)(this.m_pDomain)).BeginInit();
  139. ((System.ComponentModel.ISupportInitialize)(this.m_pOk)).BeginInit();
  140. ((System.ComponentModel.ISupportInitialize)(this.m_pCancel)).BeginInit();
  141. this.SuspendLayout();
  142. // 
  143. // mt_description
  144. // 
  145. this.mt_description.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  146. this.mt_description.Location = new System.Drawing.Point(8, 8);
  147. this.mt_description.Name = "mt_description";
  148. this.mt_description.Size = new System.Drawing.Size(72, 16);
  149. this.mt_description.TabIndex = 9;
  150. this.mt_description.Text = "Description";
  151. this.mt_description.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
  152. this.mt_description.UseStaticViewStyle = true;
  153. // 
  154. // mt_protocol
  155. // 
  156. this.mt_protocol.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  157. this.mt_protocol.Location = new System.Drawing.Point(8, 56);
  158. this.mt_protocol.Name = "mt_protocol";
  159. this.mt_protocol.Size = new System.Drawing.Size(72, 16);
  160. this.mt_protocol.TabIndex = 10;
  161. this.mt_protocol.Text = "Protocol";
  162. this.mt_protocol.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
  163. this.mt_protocol.UseStaticViewStyle = true;
  164. // 
  165. // mt_type
  166. // 
  167. this.mt_type.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  168. this.mt_type.Location = new System.Drawing.Point(120, 56);
  169. this.mt_type.Name = "mt_type";
  170. this.mt_type.Size = new System.Drawing.Size(72, 16);
  171. this.mt_type.TabIndex = 11;
  172. this.mt_type.Text = "Type";
  173. this.mt_type.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
  174. this.mt_type.UseStaticViewStyle = true;
  175. // 
  176. // mt_action
  177. // 
  178. this.mt_action.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  179. this.mt_action.Location = new System.Drawing.Point(232, 56);
  180. this.mt_action.Name = "mt_action";
  181. this.mt_action.Size = new System.Drawing.Size(72, 16);
  182. this.mt_action.TabIndex = 12;
  183. this.mt_action.Text = "Action";
  184. this.mt_action.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
  185. this.mt_action.UseStaticViewStyle = true;
  186. // 
  187. // mt_ipaddress
  188. // 
  189. this.mt_ipaddress.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  190. this.mt_ipaddress.Location = new System.Drawing.Point(8, 96);
  191. this.mt_ipaddress.Name = "mt_ipaddress";
  192. this.mt_ipaddress.Size = new System.Drawing.Size(72, 16);
  193. this.mt_ipaddress.TabIndex = 13;
  194. this.mt_ipaddress.Text = "IP Address";
  195. this.mt_ipaddress.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
  196. this.mt_ipaddress.UseStaticViewStyle = true;
  197. // 
  198. // mt_domain
  199. // 
  200. this.mt_domain.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  201. this.mt_domain.Location = new System.Drawing.Point(8, 136);
  202. this.mt_domain.Name = "mt_domain";
  203. this.mt_domain.Size = new System.Drawing.Size(72, 16);
  204. this.mt_domain.TabIndex = 14;
  205. this.mt_domain.Text = "Domain";
  206. this.mt_domain.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
  207. this.mt_domain.UseStaticViewStyle = true;
  208. this.mt_domain.Visible = false;
  209. // 
  210. // m_pDescription
  211. // 
  212. this.m_pDescription.DecimalPlaces = 2;
  213. this.m_pDescription.DecMaxValue = new System.Decimal(new int[] {
  214.    999999999,
  215.    0,
  216.    0,
  217.    0});
  218. this.m_pDescription.DecMinValue = new System.Decimal(new int[] {
  219.    999999999,
  220.    0,
  221.    0,
  222.    -2147483648});
  223. this.m_pDescription.Lines = new string[0];
  224. this.m_pDescription.Location = new System.Drawing.Point(8, 24);
  225. this.m_pDescription.Mask = LumiSoft.UI.Controls.WEditBox_Mask.Text;
  226. this.m_pDescription.MaxLength = 32767;
  227. this.m_pDescription.Multiline = false;
  228. this.m_pDescription.Name = "m_pDescription";
  229. this.m_pDescription.PasswordChar = '';
  230. this.m_pDescription.ReadOnly = false;
  231. this.m_pDescription.ScrollBars = System.Windows.Forms.ScrollBars.None;
  232. this.m_pDescription.Size = new System.Drawing.Size(320, 20);
  233. this.m_pDescription.TabIndex = 1;
  234. this.m_pDescription.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
  235. this.m_pDescription.UseStaticViewStyle = true;
  236. // 
  237. // m_pProtocol
  238. // 
  239. this.m_pProtocol.AcceptsPlussKey = true;
  240. this.m_pProtocol.BackColor = System.Drawing.Color.White;
  241. this.m_pProtocol.ButtonIcon = ((System.Drawing.Icon)(resources.GetObject("m_pProtocol.ButtonIcon")));
  242. this.m_pProtocol.ButtonWidth = 18;
  243. this.m_pProtocol.DropDownWidth = 96;
  244. this.m_pProtocol.Location = new System.Drawing.Point(8, 72);
  245. this.m_pProtocol.Mask = LumiSoft.UI.Controls.WEditBox_Mask.Text;
  246. this.m_pProtocol.MaxLength = 32767;
  247. this.m_pProtocol.Name = "m_pProtocol";
  248. this.m_pProtocol.ReadOnly = false;
  249. this.m_pProtocol.SelectedIndex = -1;
  250. this.m_pProtocol.Size = new System.Drawing.Size(96, 20);
  251. this.m_pProtocol.TabIndex = 2;
  252. this.m_pProtocol.UseStaticViewStyle = true;
  253. this.m_pProtocol.VisibleItems = 5;
  254. this.m_pProtocol.SelectedIndexChanged += new System.EventHandler(this.m_pProtocol_SelectedIndexChanged);
  255. // 
  256. // m_pType
  257. // 
  258. this.m_pType.AcceptsPlussKey = true;
  259. this.m_pType.BackColor = System.Drawing.Color.White;
  260. this.m_pType.ButtonIcon = ((System.Drawing.Icon)(resources.GetObject("m_pType.ButtonIcon")));
  261. this.m_pType.ButtonWidth = 18;
  262. this.m_pType.DropDownWidth = 96;
  263. this.m_pType.Location = new System.Drawing.Point(120, 72);
  264. this.m_pType.Mask = LumiSoft.UI.Controls.WEditBox_Mask.Text;
  265. this.m_pType.MaxLength = 32767;
  266. this.m_pType.Name = "m_pType";
  267. this.m_pType.ReadOnly = false;
  268. this.m_pType.SelectedIndex = -1;
  269. this.m_pType.Size = new System.Drawing.Size(96, 20);
  270. this.m_pType.TabIndex = 3;
  271. this.m_pType.UseStaticViewStyle = true;
  272. this.m_pType.VisibleItems = 5;
  273. this.m_pType.SelectedIndexChanged += new System.EventHandler(this.m_pType_SelectedIndexChanged);
  274. // 
  275. // m_pAction
  276. // 
  277. this.m_pAction.AcceptsPlussKey = true;
  278. this.m_pAction.BackColor = System.Drawing.Color.White;
  279. this.m_pAction.ButtonIcon = ((System.Drawing.Icon)(resources.GetObject("m_pAction.ButtonIcon")));
  280. this.m_pAction.ButtonWidth = 18;
  281. this.m_pAction.DropDownWidth = 96;
  282. this.m_pAction.Location = new System.Drawing.Point(232, 72);
  283. this.m_pAction.Mask = LumiSoft.UI.Controls.WEditBox_Mask.Text;
  284. this.m_pAction.MaxLength = 32767;
  285. this.m_pAction.Name = "m_pAction";
  286. this.m_pAction.ReadOnly = false;
  287. this.m_pAction.SelectedIndex = -1;
  288. this.m_pAction.Size = new System.Drawing.Size(96, 20);
  289. this.m_pAction.TabIndex = 4;
  290. this.m_pAction.UseStaticViewStyle = true;
  291. this.m_pAction.VisibleItems = 5;
  292. // 
  293. // m_pStartIP
  294. // 
  295. this.m_pStartIP.DecimalPlaces = 2;
  296. this.m_pStartIP.DecMaxValue = new System.Decimal(new int[] {
  297.    999999999,
  298.    0,
  299.    0,
  300.    0});
  301. this.m_pStartIP.DecMinValue = new System.Decimal(new int[] {
  302.    999999999,
  303.    0,
  304.    0,
  305.    -2147483648});
  306. this.m_pStartIP.Lines = new string[0];
  307. this.m_pStartIP.Location = new System.Drawing.Point(8, 112);
  308. this.m_pStartIP.Mask = LumiSoft.UI.Controls.WEditBox_Mask.Text;
  309. this.m_pStartIP.MaxLength = 32767;
  310. this.m_pStartIP.Multiline = false;
  311. this.m_pStartIP.Name = "m_pStartIP";
  312. this.m_pStartIP.PasswordChar = '';
  313. this.m_pStartIP.ReadOnly = false;
  314. this.m_pStartIP.ScrollBars = System.Windows.Forms.ScrollBars.None;
  315. this.m_pStartIP.Size = new System.Drawing.Size(100, 20);
  316. this.m_pStartIP.TabIndex = 5;
  317. this.m_pStartIP.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
  318. this.m_pStartIP.UseStaticViewStyle = true;
  319. // 
  320. // m_pEndIP
  321. // 
  322. this.m_pEndIP.DecimalPlaces = 2;
  323. this.m_pEndIP.DecMaxValue = new System.Decimal(new int[] {
  324.  999999999,
  325.  0,
  326.  0,
  327.  0});
  328. this.m_pEndIP.DecMinValue = new System.Decimal(new int[] {
  329.  999999999,
  330.  0,
  331.  0,
  332.  -2147483648});
  333. this.m_pEndIP.Lines = new string[0];
  334. this.m_pEndIP.Location = new System.Drawing.Point(120, 112);
  335. this.m_pEndIP.Mask = LumiSoft.UI.Controls.WEditBox_Mask.Text;
  336. this.m_pEndIP.MaxLength = 32767;
  337. this.m_pEndIP.Multiline = false;
  338. this.m_pEndIP.Name = "m_pEndIP";
  339. this.m_pEndIP.PasswordChar = '';
  340. this.m_pEndIP.ReadOnly = false;
  341. this.m_pEndIP.ScrollBars = System.Windows.Forms.ScrollBars.None;
  342. this.m_pEndIP.Size = new System.Drawing.Size(100, 20);
  343. this.m_pEndIP.TabIndex = 6;
  344. this.m_pEndIP.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
  345. this.m_pEndIP.UseStaticViewStyle = true;
  346. this.m_pEndIP.Visible = false;
  347. // 
  348. // m_pDomain
  349. // 
  350. this.m_pDomain.DecimalPlaces = 2;
  351. this.m_pDomain.DecMaxValue = new System.Decimal(new int[] {
  352.   999999999,
  353.   0,
  354.   0,
  355.   0});
  356. this.m_pDomain.DecMinValue = new System.Decimal(new int[] {
  357.   999999999,
  358.   0,
  359.   0,
  360.   -2147483648});
  361. this.m_pDomain.Lines = new string[0];
  362. this.m_pDomain.Location = new System.Drawing.Point(8, 152);
  363. this.m_pDomain.Mask = LumiSoft.UI.Controls.WEditBox_Mask.Text;
  364. this.m_pDomain.MaxLength = 32767;
  365. this.m_pDomain.Multiline = false;
  366. this.m_pDomain.Name = "m_pDomain";
  367. this.m_pDomain.PasswordChar = '';
  368. this.m_pDomain.ReadOnly = false;
  369. this.m_pDomain.ScrollBars = System.Windows.Forms.ScrollBars.None;
  370. this.m_pDomain.Size = new System.Drawing.Size(100, 20);
  371. this.m_pDomain.TabIndex = 7;
  372. this.m_pDomain.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
  373. this.m_pDomain.UseStaticViewStyle = true;
  374. this.m_pDomain.Visible = false;
  375. // 
  376. // m_pOk
  377. // 
  378. this.m_pOk.Location = new System.Drawing.Point(168, 152);
  379. this.m_pOk.Name = "m_pOk";
  380. this.m_pOk.Size = new System.Drawing.Size(72, 24);
  381. this.m_pOk.TabIndex = 8;
  382. this.m_pOk.Text = "OK";
  383. this.m_pOk.UseStaticViewStyle = true;
  384. this.m_pOk.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pOk_Click);
  385. // 
  386. // m_pCancel
  387. // 
  388. this.m_pCancel.Location = new System.Drawing.Point(248, 152);
  389. this.m_pCancel.Name = "m_pCancel";
  390. this.m_pCancel.Size = new System.Drawing.Size(72, 24);
  391. this.m_pCancel.TabIndex = 0;
  392. this.m_pCancel.Text = "Cancel";
  393. this.m_pCancel.UseStaticViewStyle = true;
  394. this.m_pCancel.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pCancel_ButtonPressed);
  395. // 
  396. // wfrm_SecurityEntry
  397. // 
  398. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  399. this.ClientSize = new System.Drawing.Size(338, 183);
  400. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  401.   this.m_pCancel,
  402.   this.m_pOk,
  403.   this.m_pDomain,
  404.   this.m_pEndIP,
  405.   this.m_pStartIP,
  406.   this.m_pAction,
  407.   this.m_pType,
  408.   this.m_pProtocol,
  409.   this.m_pDescription,
  410.   this.mt_domain,
  411.   this.mt_ipaddress,
  412.   this.mt_action,
  413.   this.mt_type,
  414.   this.mt_protocol,
  415.   this.mt_description});
  416. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  417. this.MaximizeBox = false;
  418. this.MinimizeBox = false;
  419. this.Name = "wfrm_SecurityEntry";
  420. this.ShowInTaskbar = false;
  421. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  422. this.Text = "Security";
  423. ((System.ComponentModel.ISupportInitialize)(this.m_pDescription)).EndInit();
  424. ((System.ComponentModel.ISupportInitialize)(this.m_pProtocol)).EndInit();
  425. ((System.ComponentModel.ISupportInitialize)(this.m_pType)).EndInit();
  426. ((System.ComponentModel.ISupportInitialize)(this.m_pAction)).EndInit();
  427. ((System.ComponentModel.ISupportInitialize)(this.m_pStartIP)).EndInit();
  428. ((System.ComponentModel.ISupportInitialize)(this.m_pEndIP)).EndInit();
  429. ((System.ComponentModel.ISupportInitialize)(this.m_pDomain)).EndInit();
  430. ((System.ComponentModel.ISupportInitialize)(this.m_pOk)).EndInit();
  431. ((System.ComponentModel.ISupportInitialize)(this.m_pCancel)).EndInit();
  432. this.ResumeLayout(false);
  433. }
  434. #endregion
  435. #region Events handling
  436. #region function m_pProtocol_SelectedIndexChanged
  437. private void m_pProtocol_SelectedIndexChanged(object sender, System.EventArgs e)
  438. {
  439. if(m_pProtocol.Text == "SMTP"){
  440. m_pAction.Items.Clear();
  441. m_pAction.Items.Add("Allow");
  442. m_pAction.Items.Add("Allow Relay");
  443. m_pAction.Items.Add("Deny");
  444. m_pAction.Items.Add("Deny Realy");
  445. }
  446. if(m_pProtocol.Text == "POP3"){
  447. m_pAction.Items.Clear();
  448. m_pAction.Items.Add("Allow");
  449. m_pAction.Items.Add("Deny");
  450. }
  451. m_pAction.SelectedIndex = 0;
  452. }
  453. #endregion
  454. #region function m_pType_SelectedIndexChanged
  455. private void m_pType_SelectedIndexChanged(object sender, System.EventArgs e)
  456. {
  457. if(m_pType.Text == "IP"){
  458. m_pStartIP.Visible = true;
  459. mt_ipaddress.Visible      = true;
  460. m_pEndIP.Visible   = false;
  461. m_pDomain.Visible  = false;
  462. mt_domain.Visible  = false;
  463. }
  464. if(m_pType.Text == "IP Range"){
  465. m_pStartIP.Visible = true;
  466. m_pEndIP.Visible   = true;
  467. mt_ipaddress.Visible      = true;
  468. m_pDomain.Visible  = false;
  469. mt_domain.Visible  = false;
  470. }
  471. if(m_pType.Text == "Domain"){
  472. m_pDomain.Visible  = true;
  473. mt_domain.Visible  = true;
  474. m_pStartIP.Visible = false;
  475. m_pEndIP.Visible   = false;
  476. mt_ipaddress.Visible      = false;
  477. }
  478. }
  479. #endregion
  480. #region function m_pOk_Click
  481. private void m_pOk_Click(object sender, System.EventArgs e)
  482. {
  483. try
  484. {
  485. string content = "";
  486. long   StartIP = 0;
  487. long   EndIP   = 0;
  488. if(m_pType.Text == "IP"){
  489. content = m_pStartIP.Text;
  490. if(!IsIpValid(content)){
  491. MessageBox.Show("IP address isn't valid !");
  492. return;
  493. }
  494. StartIP = IP_to_long(m_pStartIP.Text);
  495. EndIP   = IP_to_long(m_pStartIP.Text);
  496. }
  497. if(m_pType.Text == "IP Range"){
  498. content = m_pStartIP.Text + "-" + m_pEndIP.Text;
  499. if(!IsIpValid(m_pStartIP.Text)){
  500. MessageBox.Show("Start IP address isn't valid !");
  501. return;
  502. }
  503. if(!IsIpValid(m_pEndIP.Text)){
  504. MessageBox.Show("End IP address isn't valid !");
  505. return;
  506. }
  507. StartIP = IP_to_long(m_pStartIP.Text);
  508. EndIP   = IP_to_long(m_pEndIP.Text);
  509. }
  510. if(m_pType.Text == "Domain"){
  511. content = m_pDomain.Text;
  512. }
  513. m_Description = m_pDescription.Text;
  514. m_Protocol    = m_pProtocol.Text;
  515. m_Type        = m_pType.Text;
  516. m_Action      = m_pAction.Text;
  517. m_Content     = content;
  518. m_StartIP     = StartIP;
  519. m_EndIP       = EndIP;
  520. }
  521. catch(Exception x)
  522. {
  523. wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
  524. frm.ShowDialog(this);
  525. }
  526. this.DialogResult = DialogResult.OK;
  527. this.Close();
  528. }
  529. #endregion
  530. #region function m_pCancel_ButtonPressed
  531. private void m_pCancel_ButtonPressed(object sender, System.EventArgs e)
  532. {
  533. this.DialogResult = DialogResult.Cancel;
  534. this.Close();
  535. }
  536. #endregion
  537. #endregion
  538. #region function FillCombos
  539. private void FillCombos()
  540. {
  541. m_pProtocol.Items.Add("SMTP");
  542. m_pProtocol.Items.Add("POP3");
  543. m_pProtocol.VisibleItems = 2;
  544. m_pType.Items.Add("IP");
  545. m_pType.Items.Add("IP Range");
  546. m_pType.VisibleItems = 2;
  547. m_pAction.Items.Add("Allow");
  548. m_pAction.Items.Add("Allow Relay");
  549. m_pAction.Items.Add("Deny");
  550. m_pAction.Items.Add("Deny Relay");
  551. m_pAction.VisibleItems = 4;
  552. m_pProtocol.SelectedIndex = 0;
  553. m_pType.SelectedIndex     = 0;
  554. m_pAction.SelectedIndex   = 0;
  555. }
  556. #endregion
  557. #region function IP_to_long
  558. /// <summary>
  559. /// Removes points from ip and fill all blocks eg.(10.0.0.1 = 10 000 000 001).
  560. /// </summary>
  561. /// <param name="ip"></param>
  562. /// <returns></returns>
  563. private long IP_to_long(string ip)
  564. {
  565. string retVal = "";
  566. string[] str = ip.Split(new char[]{'.'});
  567. // loop through all ip blocks.
  568. foreach(string ipBlock in str){
  569. string buff = ipBlock;
  570. // If block size is smaller than 3, append '0' at the beginning of string.
  571. if(ipBlock.Length < 3){
  572. for(int i=0;i<3;i++){
  573. if(buff.Length >= 3){
  574. break;
  575. }
  576. buff = "0" + buff;
  577. }
  578. }
  579. retVal += buff;
  580. }
  581. return Convert.ToInt64(retVal);
  582. }
  583. #endregion
  584. #region function IsIpValid
  585. private bool IsIpValid(string IP)
  586. {
  587. try
  588. {
  589. string[] ipBlocks = IP.Split(new char[]{'.'});
  590. if(ipBlocks.Length != 4){
  591. return false;
  592. }
  593. System.Net.IPAddress ip = System.Net.IPAddress.Parse(IP);
  594. return true;
  595. }
  596. catch(Exception x)
  597. {
  598. return false;
  599. }
  600. }
  601. #endregion
  602. #region Properties Implementation
  603. /// <summary>
  604. /// 
  605. /// </summary>
  606. public string wp_Description
  607. {
  608. get{ return m_Description; }
  609. }
  610. /// <summary>
  611. /// 
  612. /// </summary>
  613. public string wp_Protocol
  614. {
  615. get{ return m_Protocol; }
  616. }
  617. /// <summary>
  618. /// 
  619. /// </summary>
  620. public string wp_Type
  621. {
  622. get{ return m_Type; }
  623. }
  624. /// <summary>
  625. /// 
  626. /// </summary>
  627. public string wp_Action
  628. {
  629. get{ return m_Action; }
  630. }
  631. /// <summary>
  632. /// 
  633. /// </summary>
  634. public string wp_Content
  635. {
  636. get{ return m_Content; }
  637. }
  638. /// <summary>
  639. /// 
  640. /// </summary>
  641. public long wp_StartIP
  642. {
  643. get{ return m_StartIP; }
  644. }
  645. /// <summary>
  646. /// 
  647. /// </summary>
  648. public long wp_EndIP
  649. {
  650. get{ return m_EndIP; }
  651. }
  652. #endregion
  653. }
  654. }