home *** CD-ROM | disk | FTP | other *** search
/ The Best Internet Programs / BESTINTERNET.bin / internet / winftp / ws_host.c < prev    next >
C/C++ Source or Header  |  1994-01-07  |  51KB  |  1,401 lines

  1. #include "ws_glob.h"
  2. #include "winftp.h"
  3. #include <stdlib.h>  
  4. #include <io.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7.  
  8. #define MAXHOSTS 20
  9. #define GET_CBOX_INDEX(wnd,id,str) (int) SendDlgItemMessage (wnd, id, CB_SELECTSTRING, (WPARAM) 0, (LPARAM) (LPCSTR) str)
  10.  
  11. LPVIEWERCFG lpViewer;
  12. LPHOSTCONFIG lpHostCfg;
  13. HANDLE hHostCfg;
  14.  
  15. BOOL bSaveUID=FALSE;
  16. BOOL bSavePWD=FALSE;
  17. BOOL bSaveDir;
  18.  
  19. char szCrypt[160];
  20.  
  21. LPSTR lpApp          = "winftp";
  22. LPSTR szUndecipher   = "undecipherable";
  23. LPSTR szAnony        = "anonymous";
  24. LPSTR szProfHostName = "HostName";
  25. LPSTR szProfUserID   = "UserID";
  26. LPSTR szProfHostType = "HostType";
  27. LPSTR szProfTimeOut  = "TimeOut";
  28. LPSTR szProfMailAddr = "MailAddr";
  29. LPSTR szProfViewer   = "Viewer";
  30. LPSTR szProfTempDir  = "TempDir";
  31. LPSTR szProfAutoStart= "AutoStart";
  32. LPSTR szProfRetain   = "Retain";
  33. LPSTR szProfConfigNum= "ConfigNum";
  34. LPSTR szProfFlags    = "Flags";
  35. LPSTR szProfConfig   = "Config";
  36. LPSTR szProfPass     = "Pass";
  37. LPSTR szProfDir      = "Dir";
  38. LPSTR szProfScript   = "Script";
  39. LPSTR szProfFireWall = "FireWall";
  40. LPSTR szProfLogFlag  = "LogFlag";
  41. LPSTR szProfLogFile  = "LogFile";
  42. LPSTR szProfDblClk   = "DblClk";
  43. LPSTR szProfViewPgm  = "Viewer";
  44. LPSTR szProfViewTyp  = "Ext";
  45. LPSTR szProfViewXfer = "Xfer";
  46. LPSTR szProfSaveDir  = "Save";
  47. LPSTR szProfViewCount= "ViewerCount";
  48.  
  49. LPSTR szProfFireWallHost = "FireWallHost";
  50. LPSTR szProfFireWallUser = "FireWallUser";
  51. LPSTR szProfFireWallPass = "FireWallPass";
  52.  
  53. LPSTR lpHostTypes[] = { "AutoDetect",  "Unix",    "IBM VM",  "VMS/Multinet",
  54.                         "VMS/UCX", "FTP Software PCTCP", "CUTCP/NCSA", 
  55.                         "NOS/KA9Q", "WinQVT/Net", "IBMPC TCP/IP",
  56.                         "CHAMELEON", "SuperTCP", "SI NT/FTPD", "IBM MVS", 
  57.                         "UniSys 5000" };
  58.  
  59. int nHostTypes = sizeof (lpHostTypes) / sizeof (char *);
  60.  
  61. LPSTR lpAcctTypes[] = { "Account not needed", "Account Type 1", 
  62.                         "Account Type 2", "Account Type 3", 
  63.                         "Account Type 4" };
  64.  
  65. extern BOOL bHELP;
  66.  
  67. //******************************************************************************
  68. //******************************************************************************
  69. LPSTR GetHostName (int nI)
  70. {
  71.   if (lpHostCfg==NULL) return NULL;
  72.   if (nI>=nCfgNum) return NULL;
  73.   return lpHostCfg[nI].szHostName;
  74. }
  75.  
  76. char szTmpHostType[40];
  77.  
  78. //******************************************************************************
  79. //******************************************************************************
  80. LPSTR GetHostType (int nI)
  81. {
  82.   char szSection[200];
  83.   int nType;
  84.   
  85.   if (lpHostCfg==NULL) return NULL;
  86.   if (nI>=nCfgNum) return NULL;
  87.   wsprintf (szSection, "%s:%s", lpApp, lpHostCfg[nI].szConfig);
  88.   GetPrivateProfileString (szSection, szProfHostType, NULL, szTmpHostType, 29, szIniFile);
  89.   if (!isdigit (szTmpHostType[0])) return (LPSTR) szTmpHostType;
  90.   nType = atoi (szTmpHostType); 
  91.   if (nType==LB_ERR) nType = HOST_AUTO;
  92.   return lpHostTypes[nType];
  93. }
  94.  
  95. //******************************************************************************
  96. //******************************************************************************
  97. LPSTR GetHostTypeValue (int nI)
  98. {
  99.   if (nI>=nHostTypes) return NULL;
  100.   return lpHostTypes[nI];
  101. }
  102.  
  103. //******************************************************************************
  104. // this encryption is not secure nor is it intended to be
  105. // this is just to keep the password from being plain text
  106. // in the ini file.  I'd really recommend people don't save
  107. // their passwords
  108. //******************************************************************************
  109. LPSTR EnCrypt(LPSTR userid,LPSTR passwd)
  110. {
  111.   int nIndex;
  112.   if(lstrcmp(userid,szAnony)==0)
  113.     return(passwd);
  114.   szCrypt[0]=0;
  115.   for(nIndex=0;nIndex<lstrlen(passwd);nIndex++) 
  116.   {
  117.     wsprintf(&szCrypt[nIndex*2],"%02X",
  118.       ((char)passwd[nIndex])+nIndex);
  119.   }
  120.   return(szCrypt);
  121. }
  122.  
  123. //******************************************************************************
  124. //******************************************************************************
  125. int unhex(char c) 
  126. {
  127.   if(c>'9') return(c-'7');
  128.   return (c-'0');
  129. }
  130.  
  131. //******************************************************************************
  132. //******************************************************************************
  133. LPSTR DeCrypt(LPSTR userid,LPSTR passwd)
  134. {
  135.   int nIndex;
  136.   if(lstrcmp(userid,szAnony)==0)
  137.     return(passwd);
  138.   szCrypt[0]=0;
  139.   for(nIndex=0;nIndex<lstrlen(passwd);nIndex+=2) 
  140.   {
  141.     (BYTE)szCrypt[nIndex/2]=
  142.       ((unhex(passwd[nIndex])*16)+
  143.        unhex(passwd[nIndex+1]))-(nIndex/2);
  144.     szCrypt[nIndex/2+1]=0;
  145.   }
  146.   return(szCrypt);
  147. }
  148.  
  149. //******************************************************************************
  150. //******************************************************************************
  151. void InitConfigLists (HWND hDlg)
  152. {
  153.   LRESULT nI;
  154.   int nIndex;
  155.  
  156.   SendDlgItemMessage (hDlg,DLG_EDT_CONFIG, CB_RESETCONTENT, 0, 0L);
  157.   SendDlgItemMessage (hDlg,DLG_EDT_HOST,   CB_RESETCONTENT, 0, 0L);
  158.   if (nCfgNum==0) return;
  159.   for (nIndex=0; nIndex<nCfgNum; nIndex++)
  160.   {
  161.     if (lpHostCfg[nIndex].szConfig[0]!=0)
  162.        SendDlgItemMessage (hDlg, DLG_EDT_CONFIG, CB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpHostCfg[nIndex].szConfig);
  163.     if (lpHostCfg[nIndex].szHostName[0]!=0)
  164.     {
  165.       nI = SendDlgItemMessage (hDlg, DLG_EDT_HOST, CB_FINDSTRINGEXACT, (WPARAM) -1, (LPARAM)(LPCSTR) lpHostCfg[nIndex].szHostName);
  166.       if (nI==CB_ERR) SendDlgItemMessage (hDlg,DLG_EDT_HOST,CB_ADDSTRING,0,(LPARAM)(LPCSTR) lpHostCfg[nIndex].szHostName);
  167.     }
  168.   }
  169.   SendDlgItemMessage (hDlg, DLG_EDT_CONFIG, WM_SETTEXT, 0, (LPARAM) (LPCSTR) szConfig);
  170.   SendDlgItemMessage (hDlg, DLG_EDT_HOST,   WM_SETTEXT, 0, (LPARAM) (LPCSTR) szRemoteHost);
  171.   for (nI=0; nI<5; nI++)
  172.   {
  173.     SendDlgItemMessage (hDlg, DLG_ACCOUNTTYPE, CB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpAcctTypes[nI]);
  174.   }
  175.   SendDlgItemMessage (hDlg, DLG_ACCOUNTTYPE, CB_SELECTSTRING, 0, (LPARAM)(LPCSTR) lpAcctTypes[nAcctType]);
  176. }
  177.  
  178. //******************************************************************************
  179. //******************************************************************************
  180. SetDefaultDlgStuff(HWND hDlg, int nIndex) 
  181. {
  182.   char szSection[80], szHostType[30], szFireWall[10];
  183.   HOSTINFO Host;
  184.   
  185.   wsprintf (szSection, "%s:%s", lpApp, lpHostCfg[nIndex].szConfig);
  186.   memset (&Host, '\0', sizeof (HOSTINFO));
  187.   memset (szHostType, '\0', 30);
  188.   memset (szFireWall, '\0', 10);
  189.   GetPrivateProfileString (szSection, szProfUserID,   NULL, Host.szUserID,   79, szIniFile);
  190.   GetPrivateProfileString (szSection, szProfPass,     NULL, Host.szPassword, 79, szIniFile);
  191.   GetPrivateProfileString (szSection, szProfDir,      NULL, Host.szInitDir,  79, szIniFile);
  192.   GetPrivateProfileString (szSection, szProfScript,   NULL, Host.szScript,   79, szIniFile);
  193.   GetPrivateProfileString (szSection, szProfHostType, NULL, szHostType,      29, szIniFile);
  194.   GetPrivateProfileString (szSection, szProfFireWall, NULL, szFireWall,       9, szIniFile);
  195.  
  196.   Host.nTimeOut = GetPrivateProfileInt (szSection, szProfTimeOut,  65, szIniFile);
  197.   Host.bSaveDir = GetPrivateProfileInt (szSection, szProfSaveDir,   0, szIniFile);
  198.   Host.bFireWall= (lstrcmpi (szFireWall, "Yes")==0)||(lstrcmp (szFireWall, "1")==0);
  199.   switch (isdigit (szHostType[0]))
  200.   {
  201.     case 0 : Host.nType = GET_CBOX_INDEX (hDlg, DLG_HOST_CBHOSTTYPE, szHostType); break;
  202.     default: Host.nType = atoi (szHostType); 
  203.   }
  204.   if (Host.nType==LB_ERR) Host.nType = HOST_AUTO;
  205.   Host.nType = __max (HOST_AUTO, __min (Host.nType, (nHostTypes-1)));
  206.   
  207.   SetDlgItemText (hDlg, DLG_EDT_SCRIPT, Host.szScript);
  208.   SetDlgItemText (hDlg, DLG_EDT_USERID, (Host.szUserID[0]!='\0')?Host.szUserID:szUserID);
  209.   SetDlgItemText (hDlg, DLG_EDT_PASSWD, DeCrypt (Host.szUserID, Host.szPassword));
  210.   GET_CBOX_INDEX (hDlg, DLG_HOST_CBHOSTTYPE, lpHostTypes[Host.nType]);
  211.   
  212.   CheckDlgButton (hDlg, DLG_HOST_SAVEDIR, Host.bSaveDir);
  213.   CheckDlgButton (hDlg, DLG_HOST_FIREWALL, Host.bFireWall);
  214.   SetDlgItemText (hDlg, DLG_HOST_DIR, Host.szInitDir);