home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 217 / DPCS0306DVD.ISO / Toolkit / Internet / FileZilla / Server / FileZilla_Server-0.9.11.exe / source / interface / OptionsAdminInterfacePage.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-01  |  6.6 KB  |  225 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 2002-2004 - Tim Kosse <tim.kosse@gmx.de>
  4.  
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. // OptionsAdminInterfacePage.cpp: Implementierungsdatei
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "filezilla server.h"
  24. #include "OptionsDlg.h"
  25. #include "OptionsPage.h"
  26. #include "OptionsAdminInterfacePage.h"
  27.  
  28. #if defined(_DEBUG) && !defined(MMGR)
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Dialogfeld COptionsAdminInterfacePage 
  36.  
  37.  
  38. COptionsAdminInterfacePage::COptionsAdminInterfacePage(COptionsDlg *pOptionsDlg, CWnd* pParent /*=NULL*/)
  39.     : COptionsPage(pOptionsDlg, COptionsAdminInterfacePage::IDD, pParent)
  40. {
  41.     //{{AFX_DATA_INIT(COptionsAdminInterfacePage)
  42.     m_Port = _T("");
  43.     m_IpAddresses = _T("");
  44.     m_IpBindings = _T("");
  45.     m_NewPass = _T("");
  46.     m_NewPass2 = _T("");
  47.     m_bChangePass = FALSE;
  48.     //}}AFX_DATA_INIT
  49. }
  50.  
  51.  
  52. void COptionsAdminInterfacePage::DoDataExchange(CDataExchange* pDX)
  53. {
  54.     COptionsPage::DoDataExchange(pDX);
  55.     //{{AFX_DATA_MAP(COptionsAdminInterfacePage)
  56.     DDX_Control(pDX, IDC_OPTIONS_ADMININTERFACE_CHANGEPASS, m_cChangePass);
  57.     DDX_Control(pDX, IDC_OPTIONS_ADMININTERFACE_NEWPASS2, m_cNewPass2);
  58.     DDX_Control(pDX, IDC_OPTIONS_ADMININTERFACE_NEWPASS, m_cNewPass);
  59.     DDX_Text(pDX, IDC_OPTIONS_ADMININTERFACE_PORT, m_Port);
  60.     DDV_MaxChars(pDX, m_Port, 5);
  61.     DDX_Text(pDX, IDC_OPTIONS_ADMININTERFACE_IPADDRESSES, m_IpAddresses);
  62.     DDX_Text(pDX, IDC_OPTIONS_ADMININTERFACE_IPBINDINGS, m_IpBindings);
  63.     DDX_Text(pDX, IDC_OPTIONS_ADMININTERFACE_NEWPASS, m_NewPass);
  64.     DDX_Text(pDX, IDC_OPTIONS_ADMININTERFACE_NEWPASS2, m_NewPass2);
  65.     DDX_Check(pDX, IDC_OPTIONS_ADMININTERFACE_CHANGEPASS, m_bChangePass);
  66.     //}}AFX_DATA_MAP
  67. }
  68.  
  69.  
  70. BEGIN_MESSAGE_MAP(COptionsAdminInterfacePage, COptionsPage)
  71.     //{{AFX_MSG_MAP(COptionsAdminInterfacePage)
  72.     ON_BN_CLICKED(IDC_OPTIONS_ADMININTERFACE_CHANGEPASS, OnOptionsAdmininterfaceChangepass)
  73.     //}}AFX_MSG_MAP
  74. END_MESSAGE_MAP()
  75.  
  76. /////////////////////////////////////////////////////////////////////////////
  77. // Behandlungsroutinen fⁿr Nachrichten COptionsAdminInterfacePage 
  78.  
  79. void COptionsAdminInterfacePage::OnOptionsAdmininterfaceChangepass() 
  80. {
  81.     UpdateData(TRUE);
  82.  
  83.     m_cNewPass.EnableWindow(m_bChangePass);
  84.     m_cNewPass2.EnableWindow(m_bChangePass);    
  85. }
  86.  
  87. BOOL COptionsAdminInterfacePage::OnInitDialog() 
  88. {
  89.     COptionsPage::OnInitDialog();
  90.     
  91.     if (m_NewPass != "")
  92.     {
  93.         m_NewPass = "";
  94.         m_bChangePass = TRUE;
  95.         UpdateData(FALSE);
  96.  
  97.         m_cChangePass.EnableWindow(FALSE);
  98.     }
  99.     m_cNewPass.EnableWindow(m_bChangePass);
  100.     m_cNewPass2.EnableWindow(m_bChangePass);
  101.     
  102.     return TRUE;  // return TRUE unless you set the focus to a control
  103.                   // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurⁿckgeben
  104. }
  105.  
  106. BOOL COptionsAdminInterfacePage::IsDataValid()
  107. {
  108.     if (!UpdateData(TRUE))
  109.         return FALSE;
  110.  
  111.     if (_ttoi(m_Port) < 1 || _ttoi(m_Port) > 65535)
  112.     {
  113.         m_pOptionsDlg->ShowPage(this);
  114.         GetDlgItem(IDC_OPTIONS_ADMININTERFACE_PORT)->SetFocus();
  115.         AfxMessageBox(_T("The port for the admin interface has to be in the range from 1 to 65535."));
  116.         return FALSE;
  117.     }
  118.  
  119.     CString bindIPs = m_IpBindings;
  120.     CString sub;
  121.     std::list<CString> ipBindList;
  122.     for (int i = 0; i<bindIPs.GetLength(); i++)
  123.     {
  124.         char cur = bindIPs[i];
  125.         if ((cur<'0' || cur>'9') && cur!='.')
  126.         {
  127.             if (sub=="" && cur=='*')
  128.             {
  129.                 ipBindList.clear();
  130.                 ipBindList.push_back("*");
  131.                 break;
  132.             }
  133.  
  134.             if (sub != "")
  135.             {
  136.                 //Parse IP
  137.                 SOCKADDR_IN sockAddr;
  138.                 memset(&sockAddr,0,sizeof(sockAddr));
  139.             
  140.                 sockAddr.sin_family = AF_INET;
  141.                 sockAddr.sin_addr.s_addr = inet_addr(sub);
  142.             
  143.                 if (sockAddr.sin_addr.s_addr != INADDR_NONE)
  144.                 {
  145.                     sub = inet_ntoa(sockAddr.sin_addr);
  146.                     std::list<CString>::iterator iter;
  147.                     for (iter = ipBindList.begin(); iter!=ipBindList.end(); iter++)
  148.                         if (*iter==sub)
  149.                             break;
  150.                     if (iter == ipBindList.end())
  151.                         ipBindList.push_back(sub);
  152.                 }
  153.                 sub = "";
  154.             }
  155.         }
  156.         else
  157.             sub += cur;
  158.     }
  159.     if (sub != "")
  160.     {
  161.         //Parse IP
  162.         SOCKADDR_IN sockAddr;
  163.         memset(&sockAddr,0,sizeof(sockAddr));
  164.         
  165.         sockAddr.sin_family = AF_INET;
  166.         sockAddr.sin_addr.s_addr = inet_addr(sub);
  167.         
  168.         if (sockAddr.sin_addr.s_addr != INADDR_NONE)
  169.         {
  170.             sub = inet_ntoa(sockAddr.sin_addr);
  171.             std::list<CString>::iterator iter;
  172.             for (iter = ipBindList.begin(); iter!=ipBindList.end(); iter++)
  173.                 if (*iter==sub)
  174.                     break;
  175.             if (iter == ipBindList.end())
  176.                 ipBindList.push_back(sub);
  177.         }
  178.         sub = "";
  179.     }
  180.     bindIPs = "";
  181.     for (std::list<CString>::iterator iter = ipBindList.begin(); iter!=ipBindList.end(); iter++)
  182.         if (*iter != "127.0.0.1")
  183.             bindIPs += *iter + " ";
  184.  
  185.     bindIPs.TrimRight(" ");
  186.                     
  187.     m_IpBindingsResult = bindIPs;
  188.  
  189.     if (m_bChangePass && m_IpAddresses!="")
  190.     {
  191.         if (m_NewPass.GetLength() < 6)
  192.         {
  193.             m_pOptionsDlg->ShowPage(this);
  194.             GetDlgItem(IDC_OPTIONS_ADMININTERFACE_NEWPASS)->SetFocus();
  195.             AfxMessageBox(_T("The admin password has to be at least 6 characters long,"));
  196.             return FALSE;
  197.         }
  198.         if (m_NewPass != m_NewPass2)
  199.         {
  200.             m_pOptionsDlg->ShowPage(this);
  201.             GetDlgItem(IDC_OPTIONS_ADMININTERFACE_NEWPASS)->SetFocus();
  202.             AfxMessageBox(_T("Admin passwords do not match."));
  203.             return FALSE;
  204.         }
  205.     }
  206.     return TRUE;
  207. }
  208.  
  209. void COptionsAdminInterfacePage::SaveData()
  210. {
  211.     m_pOptionsDlg->SetOption(OPTION_ADMINPORT, _ttoi(m_Port));
  212.     m_pOptionsDlg->SetOption(OPTION_ADMINIPBINDINGS, m_IpBindingsResult);
  213.     m_pOptionsDlg->SetOption(OPTION_ADMINIPADDRESSES, m_IpAddresses);
  214.     if (m_bChangePass)
  215.         m_pOptionsDlg->SetOption(OPTION_ADMINPASS, m_NewPass);
  216. }
  217.  
  218. void COptionsAdminInterfacePage::LoadData()
  219. {
  220.     m_Port.Format(_T("%d"), m_pOptionsDlg->GetOptionVal(OPTION_ADMINPORT));
  221.     m_IpBindings = m_pOptionsDlg->GetOption(OPTION_ADMINIPBINDINGS);
  222.     m_IpAddresses = m_pOptionsDlg->GetOption(OPTION_ADMINIPADDRESSES);
  223.     m_NewPass = m_pOptionsDlg->GetOption(OPTION_ADMINPASS);
  224. }
  225.