Configurator.cs
上传用户:xuelanruo
上传日期:2015-04-02
资源大小:163k
文件大小:35k
源码类别:

Ftp服务器

开发平台:

C#

  1. /*
  2. Dot Net Ftp Gui Interface (configuration of the Dot Net Ftp Service)
  3. Copyright (C) 
  4. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
  5. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  6. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7. Last modification : 04/26/2004 by Simon FERQUEL
  8. */
  9. using System;
  10. using System.Drawing;
  11. using System.Collections;
  12. using System.ComponentModel;
  13. using System.Windows.Forms;
  14. using System.Data;
  15. using Microsoft.Win32;
  16. using System.Security.Permissions;
  17. using System.ServiceProcess;
  18. using System.Management;
  19. using System.Xml;
  20. using System.IO;
  21. using System.Xml.XPath;
  22. using System.Configuration;
  23. [assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum,
  24. All = "HKEY_LOCAL_MACHINE")]
  25. namespace FtpService
  26. {
  27. /// <summary>
  28. /// Description r閟um閑 de Form1.
  29. /// </summary>
  30. /// 
  31. public class FtpConfig : System.Windows.Forms.Form
  32. {
  33. private ServiceController _ftpSc = new ServiceController("MajordomoFtpService");
  34. private System.Windows.Forms.GroupBox groupBox1;
  35. private System.Windows.Forms.NumericUpDown CommandTimeOut;
  36. private System.Windows.Forms.GroupBox groupBox2;
  37. private System.Windows.Forms.NumericUpDown SessionTimeOut;
  38. private System.Windows.Forms.GroupBox groupBox3;
  39. private System.Windows.Forms.GroupBox groupBox4;
  40. private System.Windows.Forms.GroupBox groupBox5;
  41. private System.Windows.Forms.NumericUpDown Port;
  42. private System.Windows.Forms.ComboBox IPAddress;
  43. private System.Windows.Forms.NumericUpDown MaxThreads;
  44. private System.Windows.Forms.NumericUpDown MaxBadCommands;
  45. private System.Windows.Forms.GroupBox groupBox7;
  46. private System.Windows.Forms.Button ServiceStart;
  47. private System.Windows.Forms.Button ServiceStop;
  48. private System.Windows.Forms.Button ServiceRestart;
  49. private System.Windows.Forms.Button OkButton;
  50. private System.Windows.Forms.Button ApplyButton;
  51. private System.Windows.Forms.FolderBrowserDialog DefPathDialog;
  52. private System.Windows.Forms.TabControl tabControl1;
  53. private System.Windows.Forms.TabPage serverTab;
  54. private System.Windows.Forms.TabPage homesTab;
  55. private System.Windows.Forms.GroupBox groupBox6;
  56. private System.Windows.Forms.TextBox DefaultPath;
  57. private System.Windows.Forms.Button DefPathButton;
  58. private System.Windows.Forms.DataGrid homesGrid;
  59. private System.Data.DataView HomesView;
  60. private System.Windows.Forms.Button button1;
  61. private System.Windows.Forms.Button button2;
  62. private System.Windows.Forms.TabPage VPathTab;
  63. private System.Windows.Forms.Button button3;
  64. private System.Windows.Forms.Button button4;
  65. private System.Windows.Forms.DataGrid DefaultVPathsGrid;
  66. private System.Windows.Forms.DataGrid PrivateVPathsGrid;
  67. private System.Windows.Forms.ListBox VPathsUsersListBox;
  68. private System.Windows.Forms.TextBox VPathsNewUserTxtBox;
  69. private System.Windows.Forms.Button AddPersonalVpaths;
  70. private System.Data.DataSet VPathsDataSet;
  71. private System.Windows.Forms.GroupBox groupBox8;
  72. private System.Windows.Forms.GroupBox groupBox9;
  73. /// <summary>
  74. /// Variable n閏essaire au concepteur.
  75. /// </summary>
  76. private System.ComponentModel.Container components = null;
  77. private string _IPAddress
  78. {
  79. get
  80. {
  81. try
  82. {
  83. return ConfigurationManager.AppSettings["IPAddress"];
  84. }
  85. catch 
  86. {
  87. return "ALL";
  88. }
  89. }
  90. set
  91. {
  92. FtpServerLibrary.FtpServer.SetConfigValue("IPAddress", value);
  93. }
  94. }
  95. private int _maxBadCommands
  96. {
  97. get
  98. {
  99. try
  100. {
  101. return Convert.ToInt32(ConfigurationManager.AppSettings["MaxBadCommands"]);
  102. }
  103. catch
  104. {
  105. return 30;
  106. }
  107. }
  108. set
  109. {
  110. try
  111. {
  112. FtpServerLibrary.FtpServer.SetConfigValue("MaxBadCommands", value.ToString());
  113. }
  114. catch
  115. {}
  116. }
  117. }
  118. private int _port
  119. {
  120. get
  121. {
  122. try
  123. {
  124. return Convert.ToInt32(ConfigurationManager.AppSettings["Port"]);
  125. }
  126. catch
  127. {
  128. return 21;
  129. }
  130. }
  131. set
  132. {
  133. try
  134. {
  135. FtpServerLibrary.FtpServer.SetConfigValue("Port", value.ToString());
  136. }
  137. catch
  138. {}
  139. }
  140. }
  141. private int _maxThreads
  142. {
  143. get
  144. {
  145. try
  146. {
  147. return Convert.ToInt32(ConfigurationManager.AppSettings["MaxThreads"]);
  148. }
  149. catch
  150. {
  151. return 100;
  152. }
  153. }
  154. set
  155. {
  156. try
  157. {
  158. FtpServerLibrary.FtpServer.SetConfigValue("MaxThreads", value.ToString());
  159. }
  160. catch
  161. {}
  162. }
  163. }
  164. private int _sessionIdleTimeOut
  165. {
  166. get
  167. {
  168. try
  169. {
  170. return Convert.ToInt32(ConfigurationManager.AppSettings["SessionIdleTimeOut"]);
  171. }
  172. catch
  173. {
  174. return 800000;
  175. }
  176. }
  177. set
  178. {
  179. try
  180. {
  181. FtpServerLibrary.FtpServer.SetConfigValue("SessionIdleTimeOut", value.ToString());
  182. }
  183. catch
  184. {}
  185. }
  186. }
  187. private int _commandIdleTimeOut
  188. {
  189. get
  190. {
  191. try
  192. {
  193. return Convert.ToInt32(ConfigurationManager.AppSettings["CommandIdleTimeOut"]);
  194. }
  195. catch
  196. {
  197. return 60000;
  198. }
  199. }
  200. set
  201. {
  202. try
  203. {
  204. FtpServerLibrary.FtpServer.SetConfigValue("CommandIdleTimeOut", value.ToString());
  205. }
  206. catch
  207. {}
  208. }
  209. }
  210. private void ApplyHomes()
  211. {
  212. try
  213. {
  214. string xmlDoc="<?xml version="1.0" encoding="utf-8" ?>n";
  215. xmlDoc+="<Homes xmlns="http://tempuri.org/config.xsd">n";
  216. xmlDoc+="<Default home=""+this.DefaultPath.Text+"" />n";
  217. foreach(System.Data.DataRow row in this.HomesView.Table.Rows)
  218. {
  219. xmlDoc+="<Home user=""+(string)row[0]+"" path=""+row[1]+"" />n";
  220. }
  221. xmlDoc+="</Homes>n";
  222. FileStream fs = System.IO.File.Open(System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Homes.xml"), FileMode.Create, FileAccess.Write, FileShare.None);
  223. byte[] bytes=System.Text.Encoding.UTF8.GetBytes(xmlDoc);
  224. fs.Write(bytes,0,bytes.Length);
  225. fs.Close();
  226. }
  227. catch
  228. {}
  229. }
  230. private void FillVPathsDataSet()
  231. {
  232. try
  233. {
  234. XPathDocument doc = new XPathDocument(System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "VPaths.xml"));
  235. XPathNavigator nav=doc.CreateNavigator();
  236. if(nav.MoveToFirstChild())
  237. {
  238. if(nav.MoveToFirstChild())
  239. {
  240. this.VPathsDataSet.Tables.Add("default");
  241. this.VPathsDataSet.Tables["default"].Columns.Add("source");
  242. this.VPathsDataSet.Tables["default"].Columns.Add("target");
  243. if(nav.Name.ToLower()=="default")
  244. {
  245. if(nav.MoveToFirstChild())
  246. {
  247. string[] row=new string[2];
  248. row[0]=nav.GetAttribute("source","");
  249. row[1]=nav.GetAttribute("target","");
  250. this.VPathsDataSet.Tables["default"].Rows.Add(row);
  251. while(nav.MoveToNext())
  252. {
  253. row=new string[2];
  254. row[0]=nav.GetAttribute("source","");
  255. row[1]=nav.GetAttribute("target","");
  256. this.VPathsDataSet.Tables["default"].Rows.Add(row);
  257. }
  258. nav.MoveToParent();
  259. }
  260. }
  261. else if(nav.HasAttributes)
  262. {
  263. string curUser=nav.GetAttribute("user","");
  264. this.VPathsDataSet.Tables.Add(curUser);
  265. this.VPathsDataSet.Tables[curUser].Columns.Add("source");
  266. this.VPathsDataSet.Tables[curUser].Columns.Add("target");
  267. if(nav.MoveToFirstChild())
  268. {
  269. string[] row=new string[2];
  270. row[0]=nav.GetAttribute("source","");
  271. row[1]=nav.GetAttribute("target","");
  272. this.VPathsDataSet.Tables[curUser].Rows.Add(row);
  273. while(nav.MoveToNext())
  274. {
  275. row=new string[2];
  276. row[0]=nav.GetAttribute("source","");
  277. row[1]=nav.GetAttribute("target","");
  278. this.VPathsDataSet.Tables[curUser].Rows.Add(row);
  279. }
  280. nav.MoveToParent();
  281. }
  282. }
  283. while(nav.MoveToNext())
  284. {
  285. if(nav.Name.ToLower()=="default")
  286. {
  287. if(nav.MoveToFirstChild())
  288. {
  289. string[] row=new string[2];
  290. row[0]=nav.GetAttribute("source","");
  291. row[1]=nav.GetAttribute("target","");
  292. this.VPathsDataSet.Tables["default"].Rows.Add(row);
  293. while(nav.MoveToNext())
  294. {
  295. row=new string[2];
  296. row[0]=nav.GetAttribute("source","");
  297. row[1]=nav.GetAttribute("target","");
  298. this.VPathsDataSet.Tables["default"].Rows.Add(row);
  299. }
  300. nav.MoveToParent();
  301. }
  302. }
  303. else if(nav.HasAttributes)
  304. {
  305. string curUser=nav.GetAttribute("user","");
  306. this.VPathsDataSet.Tables.Add(curUser);
  307. this.VPathsDataSet.Tables[curUser].Columns.Add("source");
  308. this.VPathsDataSet.Tables[curUser].Columns.Add("target");
  309. if(nav.MoveToFirstChild())
  310. {
  311. string[] row=new string[2];
  312. row[0]=nav.GetAttribute("source","");
  313. row[1]=nav.GetAttribute("target","");
  314. this.VPathsDataSet.Tables[curUser].Rows.Add(row);
  315. while(nav.MoveToNext())
  316. {
  317. row=new string[2];
  318. row[0]=nav.GetAttribute("source","");
  319. row[1]=nav.GetAttribute("target","");
  320. this.VPathsDataSet.Tables[curUser].Rows.Add(row);
  321. }
  322. nav.MoveToParent();
  323. }
  324. }
  325. }
  326. }
  327. }
  328. this.DefaultVPathsGrid.DataSource=this.VPathsDataSet.Tables["default"];
  329. foreach(DataTable table in this.VPathsDataSet.Tables)
  330. {
  331. if(table.TableName!="default")
  332. this.VPathsUsersListBox.Items.Add(table.TableName);
  333. }
  334. }
  335. catch
  336. {}
  337. }
  338. private void SaveVPaths()
  339. {
  340. try
  341. {
  342. string xml="<?xml version="1.0" encoding="utf-8" ?>rn<VPaths xmlns="http://tempuri.org/config.xsd">";
  343. foreach(DataTable table in this.VPathsDataSet.Tables)
  344. {
  345. if(table.TableName=="default")
  346. {
  347. xml+="<default>rn";
  348. foreach(DataRow row in table.Rows)
  349. {
  350. xml+="<VPath source=""+(string)row.ItemArray[0]+"" target=""+(string)row.ItemArray[1]+"" />rn";
  351. }
  352. xml+="</default>rn";
  353. }
  354. else
  355. {
  356. xml+="<private user=""+table.TableName+"">rn";
  357. foreach(DataRow row in table.Rows)
  358. {
  359. xml+="<VPath source=""+(string)row.ItemArray[0]+"" target=""+(string)row.ItemArray[1]+"" />rn";
  360. }
  361. xml+="</private>rn";
  362. }
  363. }
  364. xml+="</VPaths>";
  365. FileStream fs = System.IO.File.Open(System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "VPaths.xml"), FileMode.Create, FileAccess.Write, FileShare.None);
  366. byte[] bytes=System.Text.Encoding.UTF8.GetBytes(xml);
  367. fs.Write(bytes,0,bytes.Length);
  368. fs.Close();
  369. }
  370. catch{}
  371. }
  372. private void FillHomesViewAndDefault()
  373. {
  374. try
  375. {
  376. string defaultHome="";
  377. System.Collections.Hashtable userHomes=new Hashtable();
  378. XPathDocument doc = new XPathDocument(System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Homes.xml"));
  379. XPathNavigator nav=doc.CreateNavigator();
  380. nav.MoveToFirstChild();
  381. nav.MoveToFirstChild();
  382. if(nav.Name.ToLower()=="default")
  383. {
  384. defaultHome=nav.GetAttribute("home","");
  385. }
  386. else if (nav.Name.ToLower()=="home")
  387. {
  388. userHomes.Add(nav.GetAttribute("user","").ToLower(),nav.GetAttribute("path",""));
  389. }
  390. while(nav.MoveToNext())
  391. {
  392. if(nav.Name.ToLower()=="default")
  393. {
  394. defaultHome=nav.GetAttribute("home","");
  395. }
  396. else if (nav.Name.ToLower()=="home")
  397. {
  398. userHomes.Add(nav.GetAttribute("user","").ToLower(),nav.GetAttribute("path",""));
  399. }
  400. }
  401. this.DefaultPath.Text=defaultHome;
  402. foreach(string user in userHomes.Keys)
  403. {
  404. string[] row = new string[2];
  405. row[0]=user;
  406. row[1]=(string)userHomes[user];
  407. this.HomesView.Table.Rows.Add(row);
  408. }
  409. }
  410. catch
  411. {
  412. }
  413. }
  414. public FtpConfig()
  415. {
  416. InitializeComponent();
  417. this.HomesView.Table=new DataTable("Homes");
  418. this.HomesView.Table.Columns.Add("User Name");
  419. this.HomesView.Table.Columns.Add("Path");
  420. this.HomesView.Table.Constraints.Add("UserNamePK",this.HomesView.Table.Columns["User Name"],true);
  421. this.FillHomesViewAndDefault();
  422. this.FillVPathsDataSet();
  423. this.UpdateServiceState();
  424. this.IPAddress.Items.Add("ALL");
  425. ManagementObjectSearcher query = null; 
  426. ManagementObjectCollection queryCollection = null; 
  427. try 
  428. query = new ManagementObjectSearcher("SELECT IPAddress FROM Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") ; 
  429. queryCollection = query.Get(); 
  430. foreach( ManagementObject mo in queryCollection ) 
  431. if(mo["IPAddress"] != null) 
  432. this.IPAddress.Items.Add(((string[])mo["IPAddress"])[0].ToString()); 
  433. }
  434. }
  435. catch
  436. {}
  437. this.DisplayValues();
  438. }
  439. private void DisplayValues()
  440. {
  441. this.IPAddress.SelectedItem=this._IPAddress.ToUpper();
  442. this.MaxBadCommands.Value=Convert.ToDecimal(this._maxBadCommands);
  443. this.Port.Value=this._port;
  444. this.MaxThreads.Value=this._maxThreads;
  445. this.SessionTimeOut.Value=this._sessionIdleTimeOut;
  446. this.CommandTimeOut.Value=this._commandIdleTimeOut;
  447. }
  448. private void ApplyValues()
  449. {
  450. try
  451. {
  452. this._commandIdleTimeOut=Convert.ToInt32(this.CommandTimeOut.Value);
  453. }
  454. catch
  455. {}
  456. try
  457. {
  458. this._IPAddress=(string)this.IPAddress.SelectedItem;
  459. }
  460. catch{}
  461. try
  462. {
  463. this._maxBadCommands=Convert.ToInt32(this.MaxBadCommands.Value);
  464. }
  465. catch{}
  466. try
  467. {
  468. this._maxThreads=Convert.ToInt32(this.MaxThreads.Value);
  469. }
  470. catch{}
  471. try
  472. {
  473. this._port=Convert.ToInt32(this.Port.Value);
  474. }
  475. catch{}
  476. try
  477. {
  478. this._sessionIdleTimeOut=Convert.ToInt32(this.SessionTimeOut.Value);
  479. }
  480. catch{}
  481. }
  482. private void UpdateServiceState()
  483. {
  484. if(this._ftpSc.Status==ServiceControllerStatus.Running)
  485. {
  486. this.ServiceRestart.Enabled=true;
  487. this.ServiceStop.Enabled=true;
  488. this.ServiceStart.Enabled=false;
  489. }
  490. else
  491. {
  492. this.ServiceRestart.Enabled=false;
  493. this.ServiceStop.Enabled=false;
  494. this.ServiceStart.Enabled=true;
  495. }
  496. }
  497. protected override void Dispose( bool disposing )
  498. {
  499. if( disposing )
  500. {
  501. if (components != null) 
  502. {
  503. components.Dispose();
  504. }
  505. }
  506. base.Dispose( disposing );
  507. }
  508. #region 窗体设计器生成的代码
  509. /// <summary>
  510. /// 设计器支持所需的方法 - 不要
  511. /// 使用代码编辑器修改此方法的内容。
  512. /// </summary>
  513. private void InitializeComponent()
  514. {
  515. this.groupBox1 = new System.Windows.Forms.GroupBox();
  516. this.CommandTimeOut = new System.Windows.Forms.NumericUpDown();
  517. this.groupBox2 = new System.Windows.Forms.GroupBox();
  518. this.SessionTimeOut = new System.Windows.Forms.NumericUpDown();
  519. this.groupBox3 = new System.Windows.Forms.GroupBox();
  520. this.MaxBadCommands = new System.Windows.Forms.NumericUpDown();
  521. this.groupBox4 = new System.Windows.Forms.GroupBox();
  522. this.MaxThreads = new System.Windows.Forms.NumericUpDown();
  523. this.groupBox5 = new System.Windows.Forms.GroupBox();
  524. this.Port = new System.Windows.Forms.NumericUpDown();
  525. this.IPAddress = new System.Windows.Forms.ComboBox();
  526. this.DefPathDialog = new System.Windows.Forms.FolderBrowserDialog();
  527. this.groupBox7 = new System.Windows.Forms.GroupBox();
  528. this.ServiceRestart = new System.Windows.Forms.Button();
  529. this.ServiceStop = new System.Windows.Forms.Button();
  530. this.ServiceStart = new System.Windows.Forms.Button();
  531. this.OkButton = new System.Windows.Forms.Button();
  532. this.ApplyButton = new System.Windows.Forms.Button();
  533. this.tabControl1 = new System.Windows.Forms.TabControl();
  534. this.serverTab = new System.Windows.Forms.TabPage();
  535. this.homesTab = new System.Windows.Forms.TabPage();
  536. this.button1 = new System.Windows.Forms.Button();
  537. this.button2 = new System.Windows.Forms.Button();
  538. this.homesGrid = new System.Windows.Forms.DataGrid();
  539. this.HomesView = new System.Data.DataView();
  540. this.groupBox6 = new System.Windows.Forms.GroupBox();
  541. this.DefPathButton = new System.Windows.Forms.Button();
  542. this.DefaultPath = new System.Windows.Forms.TextBox();
  543. this.VPathTab = new System.Windows.Forms.TabPage();
  544. this.AddPersonalVpaths = new System.Windows.Forms.Button();
  545. this.VPathsNewUserTxtBox = new System.Windows.Forms.TextBox();
  546. this.VPathsUsersListBox = new System.Windows.Forms.ListBox();
  547. this.DefaultVPathsGrid = new System.Windows.Forms.DataGrid();
  548. this.button3 = new System.Windows.Forms.Button();
  549. this.button4 = new System.Windows.Forms.Button();
  550. this.PrivateVPathsGrid = new System.Windows.Forms.DataGrid();
  551. this.VPathsDataSet = new System.Data.DataSet();
  552. this.groupBox8 = new System.Windows.Forms.GroupBox();
  553. this.groupBox9 = new System.Windows.Forms.GroupBox();
  554. this.groupBox1.SuspendLayout();
  555. ((System.ComponentModel.ISupportInitialize)(this.CommandTimeOut)).BeginInit();
  556. this.groupBox2.SuspendLayout();
  557. ((System.ComponentModel.ISupportInitialize)(this.SessionTimeOut)).BeginInit();
  558. this.groupBox3.SuspendLayout();
  559. ((System.ComponentModel.ISupportInitialize)(this.MaxBadCommands)).BeginInit();
  560. this.groupBox4.SuspendLayout();
  561. ((System.ComponentModel.ISupportInitialize)(this.MaxThreads)).BeginInit();
  562. this.groupBox5.SuspendLayout();
  563. ((System.ComponentModel.ISupportInitialize)(this.Port)).BeginInit();
  564. this.groupBox7.SuspendLayout();
  565. this.tabControl1.SuspendLayout();
  566. this.serverTab.SuspendLayout();
  567. this.homesTab.SuspendLayout();
  568. ((System.ComponentModel.ISupportInitialize)(this.homesGrid)).BeginInit();
  569. ((System.ComponentModel.ISupportInitialize)(this.HomesView)).BeginInit();
  570. this.groupBox6.SuspendLayout();
  571. this.VPathTab.SuspendLayout();
  572. ((System.ComponentModel.ISupportInitialize)(this.DefaultVPathsGrid)).BeginInit();
  573. ((System.ComponentModel.ISupportInitialize)(this.PrivateVPathsGrid)).BeginInit();
  574. ((System.ComponentModel.ISupportInitialize)(this.VPathsDataSet)).BeginInit();
  575. this.groupBox8.SuspendLayout();
  576. this.groupBox9.SuspendLayout();
  577. this.SuspendLayout();
  578. // 
  579. // groupBox1
  580. // 
  581. this.groupBox1.Controls.Add(this.CommandTimeOut);
  582. this.groupBox1.Location = new System.Drawing.Point(24, 16);
  583. this.groupBox1.Name = "groupBox1";
  584. this.groupBox1.Size = new System.Drawing.Size(344, 72);
  585. this.groupBox1.TabIndex = 0;
  586. this.groupBox1.TabStop = false;
  587. this.groupBox1.Text = "Command Time Out (maximum time to pass ftp command in ms)";
  588. // 
  589. // CommandTimeOut
  590. // 
  591. this.CommandTimeOut.Location = new System.Drawing.Point(104, 32);
  592. this.CommandTimeOut.Maximum = new System.Decimal(new int[] {
  593.    999999999,
  594.    0,
  595.    0,
  596.    0});
  597. this.CommandTimeOut.Name = "CommandTimeOut";
  598. this.CommandTimeOut.TabIndex = 0;
  599. // 
  600. // groupBox2
  601. // 
  602. this.groupBox2.Controls.Add(this.SessionTimeOut);
  603. this.groupBox2.Location = new System.Drawing.Point(24, 104);
  604. this.groupBox2.Name = "groupBox2";
  605. this.groupBox2.Size = new System.Drawing.Size(344, 72);
  606. this.groupBox2.TabIndex = 1;
  607. this.groupBox2.TabStop = false;
  608. this.groupBox2.Text = "Session Time Out (maximum idle time in ms)";
  609. // 
  610. // SessionTimeOut
  611. // 
  612. this.SessionTimeOut.Location = new System.Drawing.Point(104, 32);
  613. this.SessionTimeOut.Maximum = new System.Decimal(new int[] {
  614.    1410065407,
  615.    2,
  616.    0,
  617.    0});
  618. this.SessionTimeOut.Name = "SessionTimeOut";
  619. this.SessionTimeOut.TabIndex = 1;
  620. // 
  621. // groupBox3
  622. // 
  623. this.groupBox3.Controls.Add(this.MaxBadCommands);
  624. this.groupBox3.Location = new System.Drawing.Point(376, 16);
  625. this.groupBox3.Name = "groupBox3";
  626. this.groupBox3.Size = new System.Drawing.Size(384, 72);
  627. this.groupBox3.TabIndex = 2;
  628. this.groupBox3.TabStop = false;
  629. this.groupBox3.Text = "Max bad commands (maximum number of commands errors/session)";
  630. // 
  631. // MaxBadCommands
  632. // 
  633. this.MaxBadCommands.Location = new System.Drawing.Point(128, 32);
  634. this.MaxBadCommands.Maximum = new System.Decimal(new int[] {
  635.    99999,
  636.    0,
  637.    0,
  638.    0});
  639. this.MaxBadCommands.Name = "MaxBadCommands";
  640. this.MaxBadCommands.TabIndex = 2;
  641. // 
  642. // groupBox4
  643. // 
  644. this.groupBox4.Controls.Add(this.MaxThreads);
  645. this.groupBox4.Location = new System.Drawing.Point(376, 104);
  646. this.groupBox4.Name = "groupBox4";
  647. this.groupBox4.Size = new System.Drawing.Size(384, 72);
  648. this.groupBox4.TabIndex = 3;
  649. this.groupBox4.TabStop = false;
  650. this.groupBox4.Text = "Max Threads ( = max Clients)";
  651. // 
  652. // MaxThreads
  653. // 
  654. this.MaxThreads.Location = new System.Drawing.Point(128, 32);
  655. this.MaxThreads.Maximum = new System.Decimal(new int[] {
  656.    1410065407,
  657.    2,
  658.    0,
  659.    0});
  660. this.MaxThreads.Name = "MaxThreads";
  661. this.MaxThreads.TabIndex = 3;
  662. // 
  663. // groupBox5
  664. // 
  665. this.groupBox5.Controls.Add(this.Port);
  666. this.groupBox5.Controls.Add(this.IPAddress);
  667. this.groupBox5.Location = new System.Drawing.Point(24, 192);
  668. this.groupBox5.Name = "groupBox5";
  669. this.groupBox5.Size = new System.Drawing.Size(344, 72);
  670. this.groupBox5.TabIndex = 4;
  671. this.groupBox5.TabStop = false;
  672. this.groupBox5.Text = "IP Address and Port (listener address)";
  673. // 
  674. // Port
  675. // 
  676. this.Port.Location = new System.Drawing.Point(200, 32);
  677. this.Port.Maximum = new System.Decimal(new int[] {
  678.  64000,
  679.  0,
  680.  0,
  681.  0});
  682. this.Port.Name = "Port";
  683. this.Port.Size = new System.Drawing.Size(56, 20);
  684. this.Port.TabIndex = 4;
  685. // 
  686. // IPAddress
  687. // 
  688. this.IPAddress.Location = new System.Drawing.Point(40, 32);
  689. this.IPAddress.Name = "IPAddress";
  690. this.IPAddress.Size = new System.Drawing.Size(121, 21);
  691. this.IPAddress.TabIndex = 0;
  692. // 
  693. // groupBox7
  694. // 
  695. this.groupBox7.Controls.Add(this.ServiceRestart);
  696. this.groupBox7.Controls.Add(this.ServiceStop);
  697. this.groupBox7.Controls.Add(this.ServiceStart);
  698. this.groupBox7.Location = new System.Drawing.Point(376, 192);
  699. this.groupBox7.Name = "groupBox7";
  700. this.groupBox7.Size = new System.Drawing.Size(344, 80);
  701. this.groupBox7.TabIndex = 6;
  702. this.groupBox7.TabStop = false;
  703. this.groupBox7.Text = "Service Controls";
  704. // 
  705. // ServiceRestart
  706. // 
  707. this.ServiceRestart.Location = new System.Drawing.Point(224, 48);
  708. this.ServiceRestart.Name = "ServiceRestart";
  709. this.ServiceRestart.TabIndex = 2;
  710. this.ServiceRestart.Text = "Restart";
  711. this.ServiceRestart.Click += new System.EventHandler(this.ServiceRestart_Click);
  712. // 
  713. // ServiceStop
  714. // 
  715. this.ServiceStop.Location = new System.Drawing.Point(128, 48);
  716. this.ServiceStop.Name = "ServiceStop";
  717. this.ServiceStop.TabIndex = 1;
  718. this.ServiceStop.Text = "Stop";
  719. this.ServiceStop.Click += new System.EventHandler(this.ServiceStop_Click);
  720. // 
  721. // ServiceStart
  722. // 
  723. this.ServiceStart.Location = new System.Drawing.Point(40, 48);
  724. this.ServiceStart.Name = "ServiceStart";
  725. this.ServiceStart.TabIndex = 0;
  726. this.ServiceStart.Text = "Start";
  727. this.ServiceStart.Click += new System.EventHandler(this.ServiceStart_Click);
  728. // 
  729. // OkButton
  730. // 
  731. this.OkButton.Location = new System.Drawing.Point(280, 304);
  732. this.OkButton.Name = "OkButton";
  733. this.OkButton.TabIndex = 7;
  734. this.OkButton.Text = "Ok";
  735. this.OkButton.Click += new System.EventHandler(this.OkButton_Click);
  736. // 
  737. // ApplyButton
  738. // 
  739. this.ApplyButton.Location = new System.Drawing.Point(392, 304);
  740. this.ApplyButton.Name = "ApplyButton";
  741. this.ApplyButton.TabIndex = 8;
  742. this.ApplyButton.Text = "Apply";
  743. this.ApplyButton.Click += new System.EventHandler(this.ApplyButton_Click);
  744. // 
  745. // tabControl1
  746. // 
  747. this.tabControl1.Controls.Add(this.serverTab);
  748. this.tabControl1.Controls.Add(this.homesTab);
  749. this.tabControl1.Controls.Add(this.VPathTab);
  750. this.tabControl1.Location = new System.Drawing.Point(0, 0);
  751. this.tabControl1.Name = "tabControl1";
  752. this.tabControl1.SelectedIndex = 0;
  753. this.tabControl1.Size = new System.Drawing.Size(792, 376);
  754. this.tabControl1.TabIndex = 9;
  755. // 
  756. // serverTab
  757. // 
  758. this.serverTab.Controls.Add(this.groupBox1);
  759. this.serverTab.Controls.Add(this.groupBox2);
  760. this.serverTab.Controls.Add(this.groupBox3);
  761. this.serverTab.Controls.Add(this.groupBox4);
  762. this.serverTab.Controls.Add(this.groupBox5);
  763. this.serverTab.Controls.Add(this.groupBox7);
  764. this.serverTab.Controls.Add(this.OkButton);
  765. this.serverTab.Controls.Add(this.ApplyButton);
  766. this.serverTab.Location = new System.Drawing.Point(4, 22);
  767. this.serverTab.Name = "serverTab";
  768. this.serverTab.Size = new System.Drawing.Size(784, 350);
  769. this.serverTab.TabIndex = 0;
  770. this.serverTab.Text = "Server";
  771. // 
  772. // homesTab
  773. // 
  774. this.homesTab.Controls.Add(this.button1);
  775. this.homesTab.Controls.Add(this.button2);
  776. this.homesTab.Controls.Add(this.homesGrid);
  777. this.homesTab.Controls.Add(this.groupBox6);
  778. this.homesTab.Location = new System.Drawing.Point(4, 22);
  779. this.homesTab.Name = "homesTab";
  780. this.homesTab.Size = new System.Drawing.Size(784, 350);
  781. this.homesTab.TabIndex = 1;
  782. this.homesTab.Text = "Root Paths";
  783. // 
  784. // button1
  785. // 
  786. this.button1.Location = new System.Drawing.Point(288, 304);
  787. this.button1.Name = "button1";
  788. this.button1.TabIndex = 9;
  789. this.button1.Text = "Ok";
  790. this.button1.Click += new System.EventHandler(this.OkButton_Click);
  791. // 
  792. // button2
  793. // 
  794. this.button2.Location = new System.Drawing.Point(400, 304);
  795. this.button2.Name = "button2";
  796. this.button2.TabIndex = 10;
  797. this.button2.Text = "Apply";
  798. this.button2.Click += new System.EventHandler(this.ApplyButton_Click);
  799. // 
  800. // homesGrid
  801. // 
  802. this.homesGrid.CaptionVisible = false;
  803. this.homesGrid.DataMember = "";
  804. this.homesGrid.DataSource = this.HomesView;
  805. this.homesGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  806. this.homesGrid.Location = new System.Drawing.Point(8, 96);
  807. this.homesGrid.Name = "homesGrid";
  808. this.homesGrid.ParentRowsVisible = false;
  809. this.homesGrid.Size = new System.Drawing.Size(768, 192);
  810. this.homesGrid.TabIndex = 1;
  811. // 
  812. // groupBox6
  813. // 
  814. this.groupBox6.Controls.Add(this.DefPathButton);
  815. this.groupBox6.Controls.Add(this.DefaultPath);
  816. this.groupBox6.Location = new System.Drawing.Point(8, 16);
  817. this.groupBox6.Name = "groupBox6";
  818. this.groupBox6.Size = new System.Drawing.Size(456, 64);
  819. this.groupBox6.TabIndex = 0;
  820. this.groupBox6.TabStop = false;
  821. this.groupBox6.Text = "Default Path";
  822. // 
  823. // DefPathButton
  824. // 
  825. this.DefPathButton.Location = new System.Drawing.Point(368, 24);
  826. this.DefPathButton.Name = "DefPathButton";
  827. this.DefPathButton.TabIndex = 1;
  828. this.DefPathButton.Text = "Browse";
  829. // 
  830. // DefaultPath
  831. // 
  832. this.DefaultPath.Location = new System.Drawing.Point(8, 24);
  833. this.DefaultPath.Name = "DefaultPath";
  834. this.DefaultPath.Size = new System.Drawing.Size(336, 20);
  835. this.DefaultPath.TabIndex = 0;
  836. this.DefaultPath.Text = "";
  837. // 
  838. // VPathTab
  839. // 
  840. this.VPathTab.Controls.Add(this.groupBox9);
  841. this.VPathTab.Controls.Add(this.groupBox8);
  842. this.VPathTab.Controls.Add(this.AddPersonalVpaths);
  843. this.VPathTab.Controls.Add(this.VPathsNewUserTxtBox);
  844. this.VPathTab.Controls.Add(this.VPathsUsersListBox);
  845. this.VPathTab.Controls.Add(this.button3);
  846. this.VPathTab.Controls.Add(this.button4);
  847. this.VPathTab.Location = new System.Drawing.Point(4, 22);
  848. this.VPathTab.Name = "VPathTab";
  849. this.VPathTab.Size = new System.Drawing.Size(784, 350);
  850. this.VPathTab.TabIndex = 2;
  851. this.VPathTab.Text = "Virtual Paths";
  852. // 
  853. // AddPersonalVpaths
  854. // 
  855. this.AddPersonalVpaths.Location = new System.Drawing.Point(32, 288);
  856. this.AddPersonalVpaths.Name = "AddPersonalVpaths";
  857. this.AddPersonalVpaths.Size = new System.Drawing.Size(136, 23);
  858. this.AddPersonalVpaths.TabIndex = 16;
  859. this.AddPersonalVpaths.Text = "Add";
  860. this.AddPersonalVpaths.Click += new System.EventHandler(this.AddPersonalVpaths_Click);
  861. // 
  862. // VPathsNewUserTxtBox
  863. // 
  864. this.VPathsNewUserTxtBox.Location = new System.Drawing.Point(32, 256);
  865. this.VPathsNewUserTxtBox.Name = "VPathsNewUserTxtBox";
  866. this.VPathsNewUserTxtBox.Size = new System.Drawing.Size(136, 20);
  867. this.VPathsNewUserTxtBox.TabIndex = 15;
  868. this.VPathsNewUserTxtBox.Text = "";
  869. // 
  870. // VPathsUsersListBox
  871. // 
  872. this.VPathsUsersListBox.Location = new System.Drawing.Point(32, 160);
  873. this.VPathsUsersListBox.Name = "VPathsUsersListBox";
  874. this.VPathsUsersListBox.Size = new System.Drawing.Size(136, 82);
  875. this.VPathsUsersListBox.TabIndex = 14;
  876. this.VPathsUsersListBox.SelectedIndexChanged += new System.EventHandler(this.VPathsUsersListBox_SelectedIndexChanged);
  877. // 
  878. // DefaultVPathsGrid
  879. // 
  880. this.DefaultVPathsGrid.DataMember = "";
  881. this.DefaultVPathsGrid.DataSource = this.VPathsDataSet;
  882. this.DefaultVPathsGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  883. this.DefaultVPathsGrid.Location = new System.Drawing.Point(8, 16);
  884. this.DefaultVPathsGrid.Name = "DefaultVPathsGrid";
  885. this.DefaultVPathsGrid.PreferredColumnWidth = 350;
  886. this.DefaultVPathsGrid.Size = new System.Drawing.Size(720, 112);
  887. this.DefaultVPathsGrid.TabIndex = 13;
  888. // 
  889. // button3
  890. // 
  891. this.button3.Location = new System.Drawing.Point(280, 304);
  892. this.button3.Name = "button3";
  893. this.button3.TabIndex = 11;
  894. this.button3.Text = "Ok";
  895. this.button3.Click += new System.EventHandler(this.OkButton_Click);
  896. // 
  897. // button4
  898. // 
  899. this.button4.Location = new System.Drawing.Point(392, 304);
  900. this.button4.Name = "button4";
  901. this.button4.TabIndex = 12;
  902. this.button4.Text = "Apply";
  903. this.button4.Click += new System.EventHandler(this.ApplyButton_Click);
  904. // 
  905. // PrivateVPathsGrid
  906. // 
  907. this.PrivateVPathsGrid.DataMember = "";
  908. this.PrivateVPathsGrid.DataSource = this.VPathsDataSet;
  909. this.PrivateVPathsGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  910. this.PrivateVPathsGrid.Location = new System.Drawing.Point(8, 16);
  911. this.PrivateVPathsGrid.Name = "PrivateVPathsGrid";
  912. this.PrivateVPathsGrid.PreferredColumnWidth = 275;
  913. this.PrivateVPathsGrid.Size = new System.Drawing.Size(552, 112);
  914. this.PrivateVPathsGrid.TabIndex = 13;
  915. // 
  916. // VPathsDataSet
  917. // 
  918. this.VPathsDataSet.DataSetName = "VPaths";
  919. this.VPathsDataSet.Locale = new System.Globalization.CultureInfo("fr-FR");
  920. // 
  921. // groupBox8
  922. // 
  923. this.groupBox8.Controls.Add(this.DefaultVPathsGrid);
  924. this.groupBox8.Location = new System.Drawing.Point(16, 8);
  925. this.groupBox8.Name = "groupBox8";
  926. this.groupBox8.Size = new System.Drawing.Size(736, 136);
  927. this.groupBox8.TabIndex = 17;
  928. this.groupBox8.TabStop = false;
  929. this.groupBox8.Text = "Global Virtual Paths";
  930. // 
  931. // groupBox9
  932. // 
  933. this.groupBox9.Controls.Add(this.PrivateVPathsGrid);
  934. this.groupBox9.Location = new System.Drawing.Point(184, 152);
  935. this.groupBox9.Name = "groupBox9";
  936. this.groupBox9.Size = new System.Drawing.Size(568, 136);
  937. this.groupBox9.TabIndex = 18;
  938. this.groupBox9.TabStop = false;
  939. this.groupBox9.Text = "Personal Virtual Paths";
  940. // 
  941. // SharpFtpConfig
  942. // 
  943. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  944. this.ClientSize = new System.Drawing.Size(792, 374);
  945. this.Controls.Add(this.tabControl1);
  946. this.Name = "SharpFtpConfig";
  947. this.Text = "Ftp Dot Net Configurator";
  948. this.groupBox1.ResumeLayout(false);
  949. ((System.ComponentModel.ISupportInitialize)(this.CommandTimeOut)).EndInit();
  950. this.groupBox2.ResumeLayout(false);
  951. ((System.ComponentModel.ISupportInitialize)(this.SessionTimeOut)).EndInit();
  952. this.groupBox3.ResumeLayout(false);
  953. ((System.ComponentModel.ISupportInitialize)(this.MaxBadCommands)).EndInit();
  954. this.groupBox4.ResumeLayout(false);
  955. ((System.ComponentModel.ISupportInitialize)(this.MaxThreads)).EndInit();
  956. this.groupBox5.ResumeLayout(false);
  957. ((System.ComponentModel.ISupportInitialize)(this.Port)).EndInit();
  958. this.groupBox7.ResumeLayout(false);
  959. this.tabControl1.ResumeLayout(false);
  960. this.serverTab.ResumeLayout(false);
  961. this.homesTab.ResumeLayout(false);
  962. ((System.ComponentModel.ISupportInitialize)(this.homesGrid)).EndInit();
  963. ((System.ComponentModel.ISupportInitialize)(this.HomesView)).EndInit();
  964. this.groupBox6.ResumeLayout(false);
  965. this.VPathTab.ResumeLayout(false);
  966. ((System.ComponentModel.ISupportInitialize)(this.DefaultVPathsGrid)).EndInit();
  967. ((System.ComponentModel.ISupportInitialize)(this.PrivateVPathsGrid)).EndInit();
  968. ((System.ComponentModel.ISupportInitialize)(this.VPathsDataSet)).EndInit();
  969. this.groupBox8.ResumeLayout(false);
  970. this.groupBox9.ResumeLayout(false);
  971. this.ResumeLayout(false);
  972. }
  973. #endregion
  974. private void ServiceStart_Click(object sender, System.EventArgs e)
  975. {
  976. this._ftpSc.Start();
  977. this._ftpSc.WaitForStatus(ServiceControllerStatus.Running);
  978. this.UpdateServiceState();
  979. }
  980. private void ServiceStop_Click(object sender, System.EventArgs e)
  981. {
  982. this._ftpSc.Stop();
  983. this._ftpSc.WaitForStatus(ServiceControllerStatus.Stopped);
  984. this.UpdateServiceState();
  985. }
  986. private void ServiceRestart_Click(object sender, System.EventArgs e)
  987. {
  988. this._ftpSc.Stop();
  989. this._ftpSc.WaitForStatus(ServiceControllerStatus.Stopped);
  990. this._ftpSc.Start();
  991. this._ftpSc.WaitForStatus(ServiceControllerStatus.Running);
  992. this.UpdateServiceState();
  993. }
  994. private void ApplyButton_Click(object sender, System.EventArgs e)
  995. {
  996. this.ApplyValues();
  997. this.ApplyHomes();
  998. this.SaveVPaths();
  999. this.DisplayValues();
  1000. }
  1001. private void OkButton_Click(object sender, System.EventArgs e)
  1002. {
  1003. this.ApplyValues();
  1004. this.ApplyHomes();
  1005. this.SaveVPaths();
  1006. this.DisplayValues();
  1007. Application.Exit();
  1008. }
  1009. private void AddPersonalVpaths_Click(object sender, System.EventArgs e)
  1010. {
  1011. if(this.VPathsNewUserTxtBox.Text.Trim()!="")
  1012. {
  1013. this.VPathsUsersListBox.Items.Add(this.VPathsNewUserTxtBox.Text);
  1014. }
  1015. }
  1016. private void VPathsUsersListBox_SelectedIndexChanged(object sender, System.EventArgs e)
  1017. {
  1018. ListBox list=(ListBox)sender;
  1019. if(this.VPathsDataSet.Tables.Contains((string)list.SelectedItem))
  1020. this.PrivateVPathsGrid.DataMember=(string)list.SelectedItem;
  1021. else
  1022. {
  1023. this.VPathsDataSet.Tables.Add((string)list.SelectedItem);
  1024. this.VPathsDataSet.Tables[(string)list.SelectedItem].Columns.Add("source");
  1025. this.VPathsDataSet.Tables[(string)list.SelectedItem].Columns.Add("target");
  1026. this.PrivateVPathsGrid.DataMember=(string)list.SelectedItem;
  1027. }
  1028. }
  1029. }
  1030. }