Comprendre le code

Signaler
Messages postés
9
Date d'inscription
lundi 30 mars 2009
Statut
Membre
Dernière intervention
19 avril 2009
-
Messages postés
21042
Date d'inscription
jeudi 23 janvier 2003
Statut
Modérateur
Dernière intervention
21 août 2019
-
je veu comprendre ce classe Networc-config-Dlg et son principe et éxplication de ses fonctions.
 /**************************************************************************/

/* WIRE1x for Vista Version 1.0.1: An open-source IEEE 802.1x supplicant */

/* for Microsoft Windows based on Xsupplicant of Open1x. */

/* */

/* This code is released under both the GPL version 2 and BSD licenses. */

/* Either license may be used. */

/* */

/* Copyright (C) 2003-2008 WIRE Lab., National Tsing Hua University, */

/* Hsinchu, Taiwan, R.O.C. All Rights Reserved. */

/**************************************************************************/

// NETWORK_Config_Dlg.cpp

//

#include

"stdafx.h"#include

"WIRE1x_v.h"#include

"NETWORK_Config_Dlg.h"#include

"data_config.h"#include

"certdlg.h"#include

"USERINFO_Dlg.h"#include

"SIM_Setting_Dlg.h"#include

"User_cert_Dlg.h"extern

Network_config_data network_data;
// NETWORK_Config_Dlg

IMPLEMENT_DYNAMIC(NETWORK_Config_Dlg, CDialog)

NETWORK_Config_Dlg::NETWORK_Config_Dlg(CWnd* pParent

/*=NULL*/): CDialog(NETWORK_Config_Dlg::IDD, pParent)

{

}

NETWORK_Config_Dlg::~NETWORK_Config_Dlg()

{

}

void

NETWORK_Config_Dlg::DoDataExchange(CDataExchange* pDX){

CDialog::DoDataExchange(pDX);

DDX_Control(pDX, IDC_COMBO2, m_auth_type);

DDX_Control(pDX, IDC_COMBO3, m_dataencryp);

DDX_Control(pDX, IDC_EDIT1, m_key);

DDX_Control(pDX, IDC_CHECK_PW, m_pwcheck);

DDX_Control(pDX, IDC_EAP_COMBO, m_eap_method);

DDX_Control(pDX, IDC_VERIFY_CHECK, m_verify_check);

DDX_Control(pDX, IDC_TUNNEL_COMBO, m_tunnel_protocol);

DDX_Control(pDX, IDC_VERIFY_BUTTON, m_cert_setting);

DDX_Control(pDX, IDC_EAP_SETTING, m_eap_setting);

}

 

BEGIN_MESSAGE_MAP(NETWORK_Config_Dlg, CDialog)

ON_BN_CLICKED(IDC_VERIFY_BUTTON, &NETWORK_Config_Dlg::OnBnClickedVerifyButton)

ON_CBN_SELCHANGE(IDC_COMBO2, &NETWORK_Config_Dlg::OnCbnSelchangeCombo2)

ON_BN_CLICKED(IDC_CHECK_PW, &NETWORK_Config_Dlg::OnBnClickedCheckPw)

ON_BN_CLICKED(IDOK, &NETWORK_Config_Dlg::OnBnClickedOk)

ON_EN_CHANGE(IDC_EDIT1, &NETWORK_Config_Dlg::OnEnChangeEdit1)

ON_CBN_SELCHANGE(IDC_EAP_COMBO, &NETWORK_Config_Dlg::OnCbnSelchangeEapCombo)

ON_BN_CLICKED(IDC_VERIFY_CHECK, &NETWORK_Config_Dlg::OnBnClickedVerifyCheck)

ON_BN_CLICKED(IDC_EAP_SETTING, &NETWORK_Config_Dlg::OnBnClickedEapSetting)

ON_CBN_SELCHANGE(IDC_COMBO3, &NETWORK_Config_Dlg::OnCbnSelchangeCombo3)

END_MESSAGE_MAP()

 

// NETWORK_Config_Dlg

BOOL NETWORK_Config_Dlg::OnInitDialog()

{

CDialog::OnInitDialog();

 

char mychar =
'*'; m_key.SetPasswordChar(mychar);

m_auth_type.AddString(

"Open"); m_auth_type.AddString(

"Shared");m_auth_type.AddString(

"WPA-Enterprise");m_auth_type.AddString(

"WPA-Personal");m_auth_type.AddString(

"WPA2-Enterprise");m_auth_type.AddString(

"WPA2-Personal");m_eap_method.AddString(

"EAP-TLS");m_eap_method.AddString(

"EAP-TTLS");m_eap_method.AddString(

"EAP-PEAP");m_eap_method.AddString(

"EAP-SIM");m_eap_method.AddString(

"EAP-AKA"); 

 

 

if(network_data.auth_type == open){ 

m_auth_type.SetCurSel(0);

m_dataencryp.AddString(

"NONE");m_dataencryp.AddString(

"WEP");

if(network_data.encryp_type== none){m_dataencryp.SetCurSel(0);

m_eap_method.EnableWindow(FALSE);

m_tunnel_protocol.EnableWindow(FALSE);

m_verify_check.EnableWindow(FALSE);

m_key.EnableWindow(FALSE);

}

else
if(network_data.encryp_type == wep){m_dataencryp.SetCurSel(1);

m_key.EnableWindow(TRUE);

}

}

else
if(network_data.auth_type == shared){ 

m_auth_type.SetCurSel(0);

m_dataencryp.AddString(

"NONE");m_dataencryp.AddString(

"WEP"); 

if(network_data.encryp_type== none){m_dataencryp.SetCurSel(0);

m_eap_method.EnableWindow(FALSE);

m_tunnel_protocol.EnableWindow(FALSE);

m_verify_check.EnableWindow(FALSE);

m_key.EnableWindow(FALSE);

}

else
if(network_data.encryp_type == wep){m_dataencryp.SetCurSel(1);

m_key.EnableWindow(TRUE);

}

}

else
if(network_data.auth_type == wpa){m_auth_type.SetCurSel(2);

m_dataencryp.AddString(

"TKIP");m_dataencryp.AddString(

"AES");m_eap_method.EnableWindow(TRUE);

m_tunnel_protocol.EnableWindow(TRUE);

m_eap_setting.EnableWindow(TRUE);

m_key.EnableWindow(FALSE);

if(network_data.encryp_type == tkip){m_dataencryp.SetCurSel(0);

}

else
if(network_data.encryp_type == aes){m_dataencryp.SetCurSel(1);

}

}

else
if(network_data.auth_type == wpapsk){m_auth_type.SetCurSel(3);

m_dataencryp.AddString(

"TKIP");m_dataencryp.AddString(

"AES");m_key.EnableWindow(TRUE);

m_pwcheck.EnableWindow(TRUE);

m_eap_method.EnableWindow(FALSE);

m_tunnel_protocol.EnableWindow(FALSE);

m_eap_setting.EnableWindow(FALSE);

m_key.EnableWindow(TRUE);

if(network_data.encryp_type == tkip){m_dataencryp.SetCurSel(0);

}

else
if(network_data.encryp_type == aes){m_dataencryp.SetCurSel(1);

}

}

else
if(network_data.auth_type == wpa2){m_auth_type.SetCurSel(4);

m_dataencryp.AddString(

"TKIP");m_dataencryp.AddString(

"AES");m_eap_method.EnableWindow(TRUE);

m_tunnel_protocol.EnableWindow(TRUE);

m_eap_setting.EnableWindow(TRUE);

m_key.EnableWindow(FALSE);

if(network_data.encryp_type == tkip){m_dataencryp.SetCurSel(0);

}

else
if(network_data.encryp_type == aes){m_dataencryp.SetCurSel(1);

}

}

else
if(network_data.auth_type == wpa2psk){m_auth_type.SetCurSel(5);

m_dataencryp.AddString(

"TKIP");m_dataencryp.AddString(

"AES");m_key.EnableWindow(TRUE);

m_pwcheck.EnableWindow(TRUE);

m_eap_method.EnableWindow(FALSE);

m_tunnel_protocol.EnableWindow(FALSE);

m_eap_setting.EnableWindow(FALSE);

m_key.EnableWindow(TRUE);

if(network_data.encryp_type == tkip){m_dataencryp.SetCurSel(0);

}

else
if(network_data.encryp_type == aes){m_dataencryp.SetCurSel(1);

}

}

if(network_data.eap_type == tls){

m_eap_method.SetCurSel(0);

m_verify_check.EnableWindow(TRUE);

m_verify_check.ShowWindow(1);

m_cert_setting.ShowWindow(1);

}

else
if(network_data.eap_type == peap){

m_eap_method.SetCurSel(2);

m_verify_check.EnableWindow(TRUE);

m_verify_check.ShowWindow(1);

m_cert_setting.ShowWindow(1);

m_tunnel_protocol.AddString(

"MSCHAPv2");m_tunnel_protocol.AddString(

"EAP-GTC");

if(network_data.eap_innertype == mschapv2){m_tunnel_protocol.SetCurSel(0);

}

else
if(network_data.eap_innertype == gtc){m_tunnel_protocol.SetCurSel(1);

}

}

else
if(network_data.eap_type == ttls){

m_eap_method.SetCurSel(1);

m_verify_check.EnableWindow(TRUE);

m_verify_check.ShowWindow(1);

m_cert_setting.ShowWindow(1);

m_tunnel_protocol.AddString(

"PAP");m_tunnel_protocol.AddString(

"EAP-MD5");m_tunnel_protocol.AddString(

"CHAP");m_tunnel_protocol.AddString(

"MSCHAP");m_tunnel_protocol.AddString(

"MSCHAPv2");

if(network_data.eap_innertype == pap){m_tunnel_protocol.SetCurSel(0);

}

else
if(network_data.eap_innertype == md5){m_tunnel_protocol.SetCurSel(1);

}

else
if(network_data.eap_innertype == chap){m_tunnel_protocol.SetCurSel(2);

}

else
if(network_data.eap_innertype == mschap){m_tunnel_protocol.SetCurSel(3);

}

else
if(network_data.eap_innertype == mschapv2){m_tunnel_protocol.SetCurSel(4);

}

}

else
if(network_data.eap_type == sim){

m_eap_method.SetCurSel(3);

m_verify_check.EnableWindow(FALSE);

}

else
if(network_data.eap_type == aka){

m_eap_method.SetCurSel(4);

m_verify_check.EnableWindow(FALSE);

}

else
if(network_data.eap_type == no_eap){m_eap_method.SetCurSel(1);

m_tunnel_protocol.AddString(

"PAP");m_tunnel_protocol.AddString(

"EAP-MD5");m_tunnel_protocol.AddString(

"CHAP");m_tunnel_protocol.AddString(

"MSCHAP");m_tunnel_protocol.AddString(

"MSCHAPv2");m_tunnel_protocol.SetCurSel(0);

m_verify_check.EnableWindow(FALSE);

}

 

 

if(network_data.verifycert == 1){m_verify_check.SetCheck(1);

if(IsDlgButtonChecked(IDC_VERIFY_CHECK)== FALSE){m_cert_setting.EnableWindow(FALSE);

}

elsem_cert_setting.EnableWindow(TRUE);

}

else{m_verify_check.EnableWindow(FALSE);

}

m_key.SetWindowTextA(network_data.key);

 

return TRUE;}

// NETWORK_Config_Dlg

 

void

NETWORK_Config_Dlg::OnCbnSelchangeCombo2(){

char temp2[20];GetDlgItemText(IDC_COMBO2,temp2, 20);

if(strcmp(
"WPA-Enterprise",temp2) == 0){

m_dataencryp.ResetContent();

m_dataencryp.AddString(

"TKIP");m_dataencryp.AddString(

"AES");m_dataencryp.SetCurSel(0);

network_data.auth_type = wpa;

m_eap_method.EnableWindow(TRUE);

m_tunnel_protocol.EnableWindow(TRUE);

m_verify_check.EnableWindow(TRUE);

m_eap_setting.EnableWindow(TRUE);

m_key.EnableWindow(FALSE);

m_key.SetWindowTextA(

""); 

}

else
if(strcmp(
"WPA2-Enterprise",temp2) == 0){

m_dataencryp.ResetContent();

m_dataencryp.AddString(

"TKIP");m_dataencryp.AddString(

"AES");m_dataencryp.SetCurSel(0);

network_data.auth_type = wpa2;

m_eap_method.EnableWindow(TRUE);

m_tunnel_protocol.EnableWindow(TRUE);

m_verify_check.EnableWindow(TRUE);

m_eap_setting.EnableWindow(TRUE);

m_key.EnableWindow(FALSE);

m_key.SetWindowTextA(

""); 

}

else
if(strcmp(
"WPA-Personal",temp2) == 0){

m_dataencryp.ResetContent();

m_dataencryp.AddString(

"TKIP");m_dataencryp.AddString(

"AES");m_dataencryp.SetCurSel(0);

network_data.auth_type = wpapsk;

m_eap_method.EnableWindow(FALSE);

m_tunnel_protocol.EnableWindow(FALSE);

m_verify_check.EnableWindow(FALSE);

m_eap_setting.EnableWindow(FALSE);

m_key.EnableWindow(TRUE);

}

else
if(strcmp(
"WPA2-Personal",temp2) == 0){

m_dataencryp.ResetContent();

m_dataencryp.AddString(

"TKIP");m_dataencryp.AddString(

"AES");m_dataencryp.SetCurSel(0);

network_data.auth_type = wpa2psk;

m_eap_method.EnableWindow(FALSE);

m_tunnel_protocol.EnableWindow(FALSE);

m_verify_check.EnableWindow(FALSE);

m_eap_setting.EnableWindow(FALSE);

m_key.EnableWindow(TRUE);

}

else
if(strcmp(
"Open",temp2) == 0){

m_dataencryp.ResetContent();

m_dataencryp.AddString(

"NONE");m_dataencryp.AddString(

"WEP");m_dataencryp.SetCurSel(0);

network_data.auth_type = open;

network_data.encryp_type = none;

m_eap_method.EnableWindow(FALSE);

m_tunnel_protocol.EnableWindow(FALSE);

m_verify_check.EnableWindow(FALSE);

m_eap_setting.EnableWindow(FALSE);

m_key.EnableWindow(FALSE);

m_key.SetWindowTextA(

"");}

else
if(strcmp(
"Shared",temp2) == 0){

m_dataencryp.ResetContent();

m_dataencryp.AddString(

"NONE");m_dataencryp.AddString(

"WEP");m_dataencryp.SetCurSel(0);

network_data.auth_type = shared;

network_data.encryp_type = none;

m_eap_method.EnableWindow(FALSE);

m_tunnel_protocol.EnableWindow(FALSE);

m_verify_check.EnableWindow(FALSE);

m_eap_setting.EnableWindow(FALSE);

m_key.EnableWindow(FALSE);

m_key.SetWindowTextA(

"");}

}

 

void

NETWORK_Config_Dlg::OnBnClickedCheckPw(){

// TODO: Add extra initialization here

char mychar =
'*';  

if(m_pwcheck.GetCheck() == BST_CHECKED){

m_key.SetPasswordChar(0);

}

else{

m_key.SetPasswordChar(mychar);

}

}

void

NETWORK_Config_Dlg::OnBnClickedOk(){

// TODO: Add extra initialization hereCString username;

CString password;

CString eap;

CString eap_inner;

CString key;

char temp[20];GetDlgItemText(IDC_COMBO3,temp, 10);

 

m_eap_method.GetWindowTextA(eap);

m_tunnel_protocol.GetWindowTextA(eap_inner);

m_key.GetWindowTextA(key);

 

 

if(strcmp("TKIP",temp) 0){network_data.encryp_type tkip;

}

else
if(strcmp("AES",temp) 0){network_data.encryp_type aes;

}

else
if(strcmp("NONE",temp) 0){network_data.encryp_type none;

}

else
if(strcmp("WEP",temp) 0){network_data.encryp_type wep;

}

if(strcmp("EAP-TLS",eap) 0){network_data.eap_type tls;

strcpy_s(network_data.password,

"WIRE1x8888");}

else
if(strcmp("EAP-TTLS",eap) 0){network_data.eap_type ttls;

}

else
if(strcmp("EAP-PEAP",eap) 0){network_data.eap_type peap;

}

else
if(strcmp("EAP-SIM",eap) 0){network_data.eap_type sim;

 

}

else
if(strcmp("EAP-AKA",eap) 0){network_data.eap_type aka;

}

if(strcmp("PAP",eap_inner) 0){network_data.eap_innertype pap;

}

else
if(strcmp("MSCHAPv2",eap_inner) 0){network_data.eap_innertype mschapv2;

}

else
if(strcmp("EAP-GTC",eap_inner) 0){network_data.eap_innertype gtc;

}

else
if(strcmp("EAP-MD5",eap_inner) 0){network_data.eap_innertype md5;

}

else
if(strcmp("CHAP",eap_inner) 0){network_data.eap_innertype chap;

}

else
if(strcmp("MSCHAP",eap_inner) 0){network_data.eap_innertype mschap;

}

else{network_data.eap_innertype = no_inner;

}
if(m_verify_check.GetCheck() BST_CHECKED){network_data.verifycert 1;

}

else{

network_data.verifycert = 0;

strcpy_s(network_data.rootcertname,

"");}

strcpy(network_data.key,key);

store_profile();

OnOK();

}

void

NETWORK_Config_Dlg::OnEnChangeEdit1(){

CString key;

char key_char[100];m_key.GetWindowTextA(key);

strcpy_s(key_char,key);
if((network_data.auth_type open || network_data.auth_type shared) && network_data.encryp_type == wep){

if(strcmp(key_char,
"") != 0){m_eap_method.EnableWindow(FALSE);

m_eap_setting.EnableWindow(FALSE);

m_tunnel_protocol.EnableWindow(FALSE);

m_verify_check.EnableWindow(FALSE);

}

else{m_eap_method.EnableWindow(TRUE);

m_eap_setting.EnableWindow(TRUE);

m_tunnel_protocol.EnableWindow(TRUE);

m_verify_check.EnableWindow(TRUE);

}

}

}

void

NETWORK_Config_Dlg::OnCbnSelchangeEapCombo(){

char temp[20];GetDlgItemText(IDC_EAP_COMBO,temp, 20);

strcpy_s(network_data.username,

"");strcpy_s(network_data.password,

"");network_data.store_name_pswd = 0;

if(strcmp(
"EAP-TLS",temp) == 0){m_tunnel_protocol.ResetContent();

m_verify_check.EnableWindow(TRUE);

m_verify_check.ShowWindow(1);

m_cert_setting.ShowWindow(1);

}

else
if(strcmp(
"EAP-TTLS",temp) == 0){m_tunnel_protocol.ResetContent();

m_tunnel_protocol.AddString(

"PAP");m_tunnel_protocol.AddString(

"EAP-MD5");m_tunnel_protocol.AddString(

"CHAP");m_tunnel_protocol.AddString(

"MSCHAP");m_tunnel_protocol.AddString(

"MSCHAPv2");m_tunnel_protocol.SetCurSel(0);

m_verify_check.EnableWindow(TRUE);

m_verify_check.ShowWindow(1);

m_cert_setting.ShowWindow(1);

}

else
if(strcmp(
"EAP-PEAP",temp) == 0){m_tunnel_protocol.ResetContent();

m_tunnel_protocol.AddString(

"MSCHAPv2");m_tunnel_protocol.AddString(

"EAP-GTC");m_tunnel_protocol.SetCurSel(0);

m_verify_check.EnableWindow(TRUE);

m_verify_check.ShowWindow(1);

m_cert_setting.ShowWindow(1);

}

else
if(strcmp(
"EAP-SIM",temp) == 0){m_tunnel_protocol.ResetContent();

m_verify_check.EnableWindow(FALSE);

m_cert_setting.EnableWindow(FALSE);

m_verify_check.ShowWindow(0);

m_cert_setting.ShowWindow(0);

}

else
if(strcmp(
"EAP-AKA",temp) == 0){m_tunnel_protocol.ResetContent();

m_verify_check.EnableWindow(FALSE);

m_cert_setting.EnableWindow(FALSE);

m_verify_check.ShowWindow(0);

m_cert_setting.ShowWindow(0);

}

}

void

NETWORK_Config_Dlg::OnBnClickedVerifyCheck(){

if(IsDlgButtonChecked(IDC_VERIFY_CHECK)== FALSE){m_cert_setting.EnableWindow(FALSE);

}

elsem_cert_setting.EnableWindow(TRUE);

}

void

NETWORK_Config_Dlg::OnBnClickedVerifyButton(){

Certdlg certconfig;

certconfig.dlgstyle = 2;

//open root certicate storecertconfig.DoModal();

if(certconfig.choice == 1){strcpy(network_data.rootcertname,certconfig.certname);

m_verify_check.SetCheck(1);

}

else{m_verify_check.SetCheck(0);

}

}

 

void

NETWORK_Config_Dlg::OnBnClickedEapSetting(){

// TODO:

char temp[20];GetDlgItemText(IDC_EAP_COMBO,temp, 20);

if(strcmp(
"EAP-TLS",temp) == 0){User_cert_Dlg Config;

Config.DoModal();

}

else
if(strcmp(
"EAP-TTLS",temp) == 0){USERINFO_Dlg Config;

Config.DoModal();

}

else
if(strcmp(
"EAP-PEAP",temp) == 0){USERINFO_Dlg Config;

Config.DoModal();

}

else
if(strcmp(
"EAP-SIM",temp) == 0){SIM_Setting_Dlg Config;

Config.DoModal();

}

else
if(strcmp(
"EAP-AKA",temp) == 0){SIM_Setting_Dlg Config;

Config.DoModal();

}

}

void

NETWORK_Config_Dlg::OnCbnSelchangeCombo3(){

char temp[10];

char temp2[20];GetDlgItemText(IDC_COMBO3,temp, 10);

GetDlgItemText(IDC_COMBO2,temp2, 20);

if(strcmp("TKIP",temp) 0){network_data.encryp_type tkip;

m_dataencryp.SetCurSel(0);

}

else
if(strcmp("AES",temp) 0){network_data.encryp_type aes;

m_dataencryp.SetCurSel(1);

}

else
if(strcmp(
"NONE",temp) == 0){m_eap_method.EnableWindow(FALSE);

m_eap_setting.EnableWindow(FALSE);

m_tunnel_protocol.EnableWindow(FALSE);

m_verify_check.EnableWindow(FALSE);

m_key.EnableWindow(FALSE);

network_data.encryp_type = none;

m_dataencryp.SetCurSel(0);

}

else
if(strcmp(
"WEP",temp) == 0){m_key.EnableWindow(TRUE);

m_eap_method.EnableWindow(TRUE);

m_eap_setting.EnableWindow(TRUE);

m_tunnel_protocol.EnableWindow(TRUE);

m_verify_check.EnableWindow(TRUE);

network_data.encryp_type = wep;

m_dataencryp.SetCurSel(1);

}

}

1 réponse

Messages postés
21042
Date d'inscription
jeudi 23 janvier 2003
Statut
Modérateur
Dernière intervention
21 août 2019
27
Faut cesser de nous balancer tous les listings que tu trouves.
Soit tu apprends MFC et tu lis la doc de tes biblis, soit tu laches l'affaire.


Comme dit par rt15 dans le post précédent, c'est codé à la bourrin.


Exemples:
strcpy_s(network_data.rootcertname, "");
un boucle pour 1 octet...


les strcmp() en série quand une simple comparaison suffisait:
switch(*((DWORD*) temp) {
  case 'PEW':
    // CODE ICI
    break;
  case 'ENON':
    // CODE ICI
    break;
  //etc...
}

ciao...
BruNews, MVP VC++