home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best Internet Programs
/
BESTINTERNET.bin
/
internet
/
winftp
/
ws_host.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-07
|
51KB
|
1,401 lines
#include "ws_glob.h"
#include "winftp.h"
#include <stdlib.h>
#include <io.h>
#include <string.h>
#include <ctype.h>
#define MAXHOSTS 20
#define GET_CBOX_INDEX(wnd,id,str) (int) SendDlgItemMessage (wnd, id, CB_SELECTSTRING, (WPARAM) 0, (LPARAM) (LPCSTR) str)
LPVIEWERCFG lpViewer;
LPHOSTCONFIG lpHostCfg;
HANDLE hHostCfg;
BOOL bSaveUID=FALSE;
BOOL bSavePWD=FALSE;
BOOL bSaveDir;
char szCrypt[160];
LPSTR lpApp = "winftp";
LPSTR szUndecipher = "undecipherable";
LPSTR szAnony = "anonymous";
LPSTR szProfHostName = "HostName";
LPSTR szProfUserID = "UserID";
LPSTR szProfHostType = "HostType";
LPSTR szProfTimeOut = "TimeOut";
LPSTR szProfMailAddr = "MailAddr";
LPSTR szProfViewer = "Viewer";
LPSTR szProfTempDir = "TempDir";
LPSTR szProfAutoStart= "AutoStart";
LPSTR szProfRetain = "Retain";
LPSTR szProfConfigNum= "ConfigNum";
LPSTR szProfFlags = "Flags";
LPSTR szProfConfig = "Config";
LPSTR szProfPass = "Pass";
LPSTR szProfDir = "Dir";
LPSTR szProfScript = "Script";
LPSTR szProfFireWall = "FireWall";
LPSTR szProfLogFlag = "LogFlag";
LPSTR szProfLogFile = "LogFile";
LPSTR szProfDblClk = "DblClk";
LPSTR szProfViewPgm = "Viewer";
LPSTR szProfViewTyp = "Ext";
LPSTR szProfViewXfer = "Xfer";
LPSTR szProfSaveDir = "Save";
LPSTR szProfViewCount= "ViewerCount";
LPSTR szProfFireWallHost = "FireWallHost";
LPSTR szProfFireWallUser = "FireWallUser";
LPSTR szProfFireWallPass = "FireWallPass";
LPSTR lpHostTypes[] = { "AutoDetect", "Unix", "IBM VM", "VMS/Multinet",
"VMS/UCX", "FTP Software PCTCP", "CUTCP/NCSA",
"NOS/KA9Q", "WinQVT/Net", "IBMPC TCP/IP",
"CHAMELEON", "SuperTCP", "SI NT/FTPD", "IBM MVS",
"UniSys 5000" };
int nHostTypes = sizeof (lpHostTypes) / sizeof (char *);
LPSTR lpAcctTypes[] = { "Account not needed", "Account Type 1",
"Account Type 2", "Account Type 3",
"Account Type 4" };
extern BOOL bHELP;
//******************************************************************************
//******************************************************************************
LPSTR GetHostName (int nI)
{
if (lpHostCfg==NULL) return NULL;
if (nI>=nCfgNum) return NULL;
return lpHostCfg[nI].szHostName;
}
char szTmpHostType[40];
//******************************************************************************
//******************************************************************************
LPSTR GetHostType (int nI)
{
char szSection[200];
int nType;
if (lpHostCfg==NULL) return NULL;
if (nI>=nCfgNum) return NULL;
wsprintf (szSection, "%s:%s", lpApp, lpHostCfg[nI].szConfig);
GetPrivateProfileString (szSection, szProfHostType, NULL, szTmpHostType, 29, szIniFile);
if (!isdigit (szTmpHostType[0])) return (LPSTR) szTmpHostType;
nType = atoi (szTmpHostType);
if (nType==LB_ERR) nType = HOST_AUTO;
return lpHostTypes[nType];
}
//******************************************************************************
//******************************************************************************
LPSTR GetHostTypeValue (int nI)
{
if (nI>=nHostTypes) return NULL;
return lpHostTypes[nI];
}
//******************************************************************************
// this encryption is not secure nor is it intended to be
// this is just to keep the password from being plain text
// in the ini file. I'd really recommend people don't save
// their passwords
//******************************************************************************
LPSTR EnCrypt(LPSTR userid,LPSTR passwd)
{
int nIndex;
if(lstrcmp(userid,szAnony)==0)
return(passwd);
szCrypt[0]=0;
for(nIndex=0;nIndex<lstrlen(passwd);nIndex++)
{
wsprintf(&szCrypt[nIndex*2],"%02X",
((char)passwd[nIndex])+nIndex);
}
return(szCrypt);
}
//******************************************************************************
//******************************************************************************
int unhex(char c)
{
if(c>'9') return(c-'7');
return (c-'0');
}
//******************************************************************************
//******************************************************************************
LPSTR DeCrypt(LPSTR userid,LPSTR passwd)
{
int nIndex;
if(lstrcmp(userid,szAnony)==0)
return(passwd);
szCrypt[0]=0;
for(nIndex=0;nIndex<lstrlen(passwd);nIndex+=2)
{
(BYTE)szCrypt[nIndex/2]=
((unhex(passwd[nIndex])*16)+
unhex(passwd[nIndex+1]))-(nIndex/2);
szCrypt[nIndex/2+1]=0;
}
return(szCrypt);
}
//******************************************************************************
//******************************************************************************
void InitConfigLists (HWND hDlg)
{
LRESULT nI;
int nIndex;
SendDlgItemMessage (hDlg,DLG_EDT_CONFIG, CB_RESETCONTENT, 0, 0L);
SendDlgItemMessage (hDlg,DLG_EDT_HOST, CB_RESETCONTENT, 0, 0L);
if (nCfgNum==0) return;
for (nIndex=0; nIndex<nCfgNum; nIndex++)
{
if (lpHostCfg[nIndex].szConfig[0]!=0)
SendDlgItemMessage (hDlg, DLG_EDT_CONFIG, CB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpHostCfg[nIndex].szConfig);
if (lpHostCfg[nIndex].szHostName[0]!=0)
{
nI = SendDlgItemMessage (hDlg, DLG_EDT_HOST, CB_FINDSTRINGEXACT, (WPARAM) -1, (LPARAM)(LPCSTR) lpHostCfg[nIndex].szHostName);
if (nI==CB_ERR) SendDlgItemMessage (hDlg,DLG_EDT_HOST,CB_ADDSTRING,0,(LPARAM)(LPCSTR) lpHostCfg[nIndex].szHostName);
}
}
SendDlgItemMessage (hDlg, DLG_EDT_CONFIG, WM_SETTEXT, 0, (LPARAM) (LPCSTR) szConfig);
SendDlgItemMessage (hDlg, DLG_EDT_HOST, WM_SETTEXT, 0, (LPARAM) (LPCSTR) szRemoteHost);
for (nI=0; nI<5; nI++)
{
SendDlgItemMessage (hDlg, DLG_ACCOUNTTYPE, CB_ADDSTRING, 0, (LPARAM)(LPCSTR) lpAcctTypes[nI]);
}
SendDlgItemMessage (hDlg, DLG_ACCOUNTTYPE, CB_SELECTSTRING, 0, (LPARAM)(LPCSTR) lpAcctTypes[nAcctType]);
}
//******************************************************************************
//******************************************************************************
SetDefaultDlgStuff(HWND hDlg, int nIndex)
{
char szSection[80], szHostType[30], szFireWall[10];
HOSTINFO Host;
wsprintf (szSection, "%s:%s", lpApp, lpHostCfg[nIndex].szConfig);
memset (&Host, '\0', sizeof (HOSTINFO));
memset (szHostType, '\0', 30);
memset (szFireWall, '\0', 10);
GetPrivateProfileString (szSection, szProfUserID, NULL, Host.szUserID, 79, szIniFile);
GetPrivateProfileString (szSection, szProfPass, NULL, Host.szPassword, 79, szIniFile);
GetPrivateProfileString (szSection, szProfDir, NULL, Host.szInitDir, 79, szIniFile);
GetPrivateProfileString (szSection, szProfScript, NULL, Host.szScript, 79, szIniFile);
GetPrivateProfileString (szSection, szProfHostType, NULL, szHostType, 29, szIniFile);
GetPrivateProfileString (szSection, szProfFireWall, NULL, szFireWall, 9, szIniFile);
Host.nTimeOut = GetPrivateProfileInt (szSection, szProfTimeOut, 65, szIniFile);
Host.bSaveDir = GetPrivateProfileInt (szSection, szProfSaveDir, 0, szIniFile);
Host.bFireWall= (lstrcmpi (szFireWall, "Yes")==0)||(lstrcmp (szFireWall, "1")==0);
switch (isdigit (szHostType[0]))
{
case 0 : Host.nType = GET_CBOX_INDEX (hDlg, DLG_HOST_CBHOSTTYPE, szHostType); break;
default: Host.nType = atoi (szHostType);
}
if (Host.nType==LB_ERR) Host.nType = HOST_AUTO;
Host.nType = __max (HOST_AUTO, __min (Host.nType, (nHostTypes-1)));
SetDlgItemText (hDlg, DLG_EDT_SCRIPT, Host.szScript);
SetDlgItemText (hDlg, DLG_EDT_USERID, (Host.szUserID[0]!='\0')?Host.szUserID:szUserID);
SetDlgItemText (hDlg, DLG_EDT_PASSWD, DeCrypt (Host.szUserID, Host.szPassword));
GET_CBOX_INDEX (hDlg, DLG_HOST_CBHOSTTYPE, lpHostTypes[Host.nType]);
CheckDlgButton (hDlg, DLG_HOST_SAVEDIR, Host.bSaveDir);
CheckDlgButton (hDlg, DLG_HOST_FIREWALL, Host.bFireWall);
SetDlgItemText (hDlg, DLG_HOST_DIR, Host.szInitDir);