1// Security.cpp : implementation file
2//
3
4#include "stdafx.h"
5#include "winsock2.h"
6
7#include "FileSharing.h"
8#include "Security.h"
9
10#ifdef _DEBUG
11#define new DEBUG_NEW
12#undef THIS_FILE
13static char THIS_FILE[] = __FILE__;
14#endif
15
16/////////////////////////////////////////////////////////////////////////////
17// CSecurity dialog
18
19
20CSecurity::CSecurity(CWnd* pParent /*=NULL*/)
21	: CDialog(CSecurity::IDD, pParent)
22{
23	//{{AFX_DATA_INIT(CSecurity)
24	m_server = _T("");
25	//}}AFX_DATA_INIT
26}
27
28
29void CSecurity::DoDataExchange(CDataExchange* pDX)
30{
31	CDialog::DoDataExchange(pDX);
32	//{{AFX_DATA_MAP(CSecurity)
33	DDX_Control(pDX, IDOK, m_okayBtn);
34	DDX_Control(pDX, IDC_SECURITY_TYPE, m_type);
35	DDX_Control(pDX, IDC_SECURITY_SERVER, m_serverCtrl);
36	DDX_Text(pDX, IDC_SECURITY_SERVER, m_server);
37	//}}AFX_DATA_MAP
38}
39
40
41BEGIN_MESSAGE_MAP(CSecurity, CDialog)
42	//{{AFX_MSG_MAP(CSecurity)
43	ON_EN_CHANGE(IDC_SECURITY_SERVER, OnChangeSecurityServer)
44	ON_CBN_SELCHANGE(IDC_SECURITY_TYPE, OnSelchangeSecurityType)
45	//}}AFX_MSG_MAP
46END_MESSAGE_MAP()
47
48/////////////////////////////////////////////////////////////////////////////
49// CSecurity message handlers
50
51BOOL CSecurity::OnInitDialog()
52{
53	extern char authServerName[];
54	extern unsigned int authServerIP;
55
56	CDialog::OnInitDialog();
57
58	if (authServerIP)
59	{
60		m_type.SelectString(-1, "BeSure Authentication Server");
61		m_server = authServerName;
62		UpdateData(FALSE);
63		m_serverCtrl.EnableWindow(TRUE);
64	}
65	else
66		m_type.SelectString(-1, "No Authentication Required");
67
68	m_type.SetFocus();
69
70	return FALSE;
71}
72
73void CSecurity::OnChangeSecurityServer()
74{
75	UpdateData(TRUE);
76	m_okayBtn.EnableWindow(!m_server.IsEmpty());
77}
78
79void CSecurity::OnSelchangeSecurityType()
80{
81	CString typeName;
82	int nType = m_type.GetCurSel();
83
84	m_type.GetLBText(nType, typeName);
85	if (typeName.CompareNoCase("No Authentication Required") == 0)
86	{
87		m_serverCtrl.EnableWindow(FALSE);
88		m_okayBtn.EnableWindow(TRUE);
89	}
90	else
91	{
92		m_serverCtrl.EnableWindow(TRUE);
93		UpdateData(TRUE);
94		m_okayBtn.EnableWindow(!m_server.IsEmpty());
95	}
96}
97
98void CSecurity::OnOK()
99{
100	extern char authServerName[];
101	extern unsigned int authServerIP;
102	struct hostent *ent;
103
104	CDialog::OnOK();
105
106	strcpy(authServerName, m_server);
107	ent = gethostbyname(authServerName);
108	if (ent == NULL)
109	{
110		unsigned long addr = inet_addr(authServerName);
111		authServerIP = ntohl(addr);
112	}
113	else
114		authServerIP = ntohl(*((unsigned int *) ent->h_addr));
115}
116