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

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