|
|
1.1 ! root 1: /* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */ ! 2: ! 3: /* $Id: ConfigWizardUnit.cpp,v 1.21 2006/09/24 20:05:20 deuce Exp $ */ ! 4: ! 5: /**************************************************************************** ! 6: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 7: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 8: * * ! 9: * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html * ! 10: * * ! 11: * This program is free software; you can redistribute it and/or * ! 12: * modify it under the terms of the GNU General Public License * ! 13: * as published by the Free Software Foundation; either version 2 * ! 14: * of the License, or (at your option) any later version. * ! 15: * See the GNU General Public License for more details: gpl.txt or * ! 16: * http://www.fsf.org/copyleft/gpl.html * ! 17: * * ! 18: * Anonymous FTP access to the most recent released source is available at * ! 19: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 20: * * ! 21: * Anonymous CVS access to the development source and modification history * ! 22: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 23: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 24: * (just hit return, no password is necessary) * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 26: * * ! 27: * For Synchronet coding style and modification guidelines, see * ! 28: * http://www.synchro.net/source.html * ! 29: * * ! 30: * You are encouraged to submit any modifications (preferably in Unix diff * ! 31: * format) via e-mail to [email protected] * ! 32: * * ! 33: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 34: ****************************************************************************/ ! 35: //--------------------------------------------------------------------------- ! 36: ! 37: #include "sbbs.h" ! 38: #include <vcl.h> ! 39: #pragma hdrstop ! 40: ! 41: #include "MainFormUnit.h" ! 42: #include "ConfigWizardUnit.h" ! 43: #include <stdio.h> // sprintf ! 44: #include <winsock.h> // addresses and such ! 45: ! 46: //--------------------------------------------------------------------------- ! 47: #pragma package(smart_init) ! 48: #pragma resource "*.dfm" ! 49: ! 50: #define ILLEGAL_FILENAME_CHARS "\\/|<>+[]:=\";,%" ! 51: #define ILLEGAL_QWKID_CHARS "*?" ILLEGAL_FILENAME_CHARS ! 52: ! 53: char ctrl_dir[MAX_PATH+1]; ! 54: short tz_val[]= { ! 55: 0 ! 56: ,AST ! 57: ,EST ! 58: ,CST ! 59: ,MST ! 60: ,PST ! 61: ,YST ! 62: ,HST ! 63: ,BST ! 64: ,MID ! 65: ,VAN ! 66: ,EDM ! 67: ,WIN ! 68: ,BOG ! 69: ,CAR ! 70: ,RIO ! 71: ,FER ! 72: ,AZO ! 73: ,LON ! 74: ,BER ! 75: ,ATH ! 76: ,MOS ! 77: ,DUB ! 78: ,KAB ! 79: ,KAR ! 80: ,BOM ! 81: ,KAT ! 82: ,DHA ! 83: ,BAN ! 84: ,HON ! 85: ,TOK ! 86: ,SYD ! 87: ,NOU ! 88: ,WEL ! 89: }; ! 90: ! 91: char* tz_str[]={ ! 92: "Universal (UTC/GMT)" ! 93: ,"U.S. - Atlantic" ! 94: ,"U.S. - Eastern" ! 95: ,"U.S. - Central" ! 96: ,"U.S. - Mountain" ! 97: ,"U.S. - Pacific" ! 98: ,"U.S. - Yukon" ! 99: ,"U.S. - Hawaii/Alaska" ! 100: ,"U.S. - Bering" ! 101: ,"Midway" ! 102: ,"Vancouver" ! 103: ,"Edmonton" ! 104: ,"Winnipeg" ! 105: ,"Bogota" ! 106: ,"Caracas" ! 107: ,"Rio de Janeiro" ! 108: ,"Fernando de Noronha" ! 109: ,"Azores" ! 110: ,"London" ! 111: ,"Berlin" ! 112: ,"Athens" ! 113: ,"Moscow" ! 114: ,"Dubai" ! 115: ,"Kabul" ! 116: ,"Karachi" ! 117: ,"Bombay" ! 118: ,"Kathmandu" ! 119: ,"Dhaka" ! 120: ,"Bangkok" ! 121: ,"Hong Kong" ! 122: ,"Tokyo" ! 123: ,"Sydney" ! 124: ,"Noumea" ! 125: ,"Wellington" ! 126: }; ! 127: ! 128: //--------------------------------------------------------------------------- ! 129: __fastcall TConfigWizard::TConfigWizard(TComponent* Owner) ! 130: : TForm(Owner) ! 131: { ! 132: } ! 133: //--------------------------------------------------------------------------- ! 134: void __fastcall TConfigWizard::FormShow(TObject *Sender) ! 135: { ! 136: char str[512]; ! 137: int i; ! 138: int status; ! 139: ! 140: Application->BringToFront(); ! 141: ! 142: memset(&scfg,0,sizeof(scfg)); ! 143: SAFECOPY(scfg.ctrl_dir,MainForm->global.ctrl_dir); ! 144: scfg.size=sizeof(scfg); ! 145: char error[256]; ! 146: SAFECOPY(error,UNKNOWN_LOAD_ERROR); ! 147: if(!load_cfg(&scfg,NULL,FALSE,error)) { ! 148: Application->MessageBox(error,"ERROR Loadin Configuration" ! 149: ,MB_OK|MB_ICONEXCLAMATION); ! 150: Close(); ! 151: return; ! 152: } ! 153: ! 154: if(scfg.new_install) { ! 155: TIME_ZONE_INFORMATION tz; ! 156: memset(&tz,0,sizeof(tz)); ! 157: DWORD tzRet=GetTimeZoneInformation(&tz); ! 158: ! 159: /* Convert to SMB tz format */ ! 160: scfg.sys_timezone=0; ! 161: if(tz.Bias>0) { ! 162: switch(tz.Bias|US_ZONE) { ! 163: case AST: ! 164: case EST: ! 165: case CST: ! 166: case MST: ! 167: case PST: ! 168: case YST: ! 169: case HST: ! 170: case BST: ! 171: scfg.sys_timezone=tz.Bias|US_ZONE; ! 172: if(tzRet==TIME_ZONE_ID_DAYLIGHT) ! 173: scfg.sys_timezone|=DAYLIGHT; ! 174: break; ! 175: default: ! 176: scfg.sys_timezone=tz.Bias|WESTERN_ZONE; ! 177: break; ! 178: } ! 179: } else if(tz.Bias<0) ! 180: scfg.sys_timezone=(-tz.Bias)|EASTERN_ZONE; ! 181: #if 0 ! 182: /* Get DNS Server Address */ ! 183: str_list_t dns_list = getNameServerList(); ! 184: if(dns_list!=NULL) { ! 185: SAFECOPY(MainForm->mail_startup.dns_server,dns_list[0]); ! 186: freeNameServerList(dns_list); ! 187: } ! 188: #endif ! 189: } else { ! 190: SystemNameEdit->Text=AnsiString(scfg.sys_name); ! 191: SystemLocationEdit->Text=AnsiString(scfg.sys_location); ! 192: SysopNameEdit->Text=AnsiString(scfg.sys_op); ! 193: SystemPasswordEdit->Text=AnsiString(scfg.sys_pass); ! 194: InternetAddressComboBox->Text=AnsiString(scfg.sys_inetaddr); ! 195: QWKIDEdit->Text=AnsiString(scfg.sys_id); ! 196: QNetTaglineEdit->Text=AnsiString(scfg.qnet_tagline); ! 197: AllNodesTelnetCheckBox->Checked ! 198: =(scfg.sys_nodes==MainForm->bbs_startup.last_node); ! 199: } ! 200: ! 201: NewUsersCheckBox->Checked=!(scfg.sys_misc&SM_CLOSED); ! 202: FeedbackCheckBox->Checked=scfg.node_valuser; ! 203: AliasesCheckBox->Checked=scfg.uq&UQ_ALIASES; ! 204: NewUsersCheckBoxClick(Sender); ! 205: ! 206: if(scfg.sys_misc&SM_USRVDELM) ! 207: DeletedEmailYesButton->Checked=true; ! 208: else if(scfg.sys_misc&SM_SYSVDELM) ! 209: DeletedEmailSysopButton->Checked=true; ! 210: else ! 211: DeletedEmailNoButton->Checked=true; ! 212: ! 213: // DNSAddressEdit->Text=MainForm->mail_startup.dns_server; ! 214: MaxMailUpDown->Position=MainForm->mail_startup.max_clients; ! 215: MaxFtpUpDown->Position=MainForm->ftp_startup.max_clients; ! 216: MaxWebUpDown->Position=MainForm->web_startup.max_clients; ! 217: NodesUpDown->Position=scfg.sys_nodes; ! 218: ! 219: for(i=0;i<sizeof(tz_str)/sizeof(tz_str[0]);i++) { ! 220: char str[128]; ! 221: if(tz_val[i] && !(tz_val[i]&US_ZONE)) ! 222: sprintf(str,"%c%u:%02u %s" ! 223: ,tz_val[i]&WESTERN_ZONE ? '-':'+' ! 224: ,(tz_val[i]&0xfff)/60 ! 225: ,(tz_val[i]&0xfff)%60 ! 226: ,tz_str[i] ! 227: ); ! 228: else ! 229: strcpy(str,tz_str[i]); ! 230: TimeZoneComboBox->Items->Add(str); ! 231: } ! 232: sprintf(str,"Other (%s)",smb_zonestr(scfg.sys_timezone,NULL)); ! 233: TimeZoneComboBox->Items->Add(str); ! 234: ! 235: for(i=0;i<sizeof(tz_val)/sizeof(tz_val[0]);i++) ! 236: if((scfg.sys_timezone&((short)~DAYLIGHT))==tz_val[i]) ! 237: break; ! 238: TimeZoneComboBox->ItemIndex=i; ! 239: DaylightCheckBox->Enabled=scfg.sys_timezone&US_ZONE; ! 240: DaylightCheckBox->Checked=scfg.sys_timezone&DAYLIGHT; ! 241: if(scfg.sys_misc&SM_MILITARY) ! 242: Time24hrRadioButton->Checked=true; ! 243: else ! 244: Time12hrRadioButton->Checked=true; ! 245: if(scfg.sys_misc&SM_EURODATE) ! 246: DateEuRadioButton->Checked=true; ! 247: else ! 248: DateUsRadioButton->Checked=true; ! 249: ! 250: WizNotebook->PageIndex=0; ! 251: ProgressBar->Max=WizNotebook->Pages->Count-1; ! 252: IllegalCharsLabel->Caption="Illegal characters: '" ! 253: ILLEGAL_QWKID_CHARS "'"; ! 254: ! 255: NextButton->Enabled=true; ! 256: } ! 257: //--------------------------------------------------------------------------- ! 258: void __fastcall TConfigWizard::NextButtonClick(TObject *Sender) ! 259: { ! 260: if(ProgressBar->Position==ProgressBar->Max) /* Finished */ ! 261: { ! 262: // Write Registry keys ! 263: if(AllNodesTelnetCheckBox->Checked) ! 264: MainForm->bbs_startup.last_node=NodesUpDown->Position; ! 265: MainForm->ftp_startup.max_clients=MaxFtpUpDown->Position; ! 266: MainForm->mail_startup.max_clients=MaxMailUpDown->Position; ! 267: MainForm->web_startup.max_clients=MaxWebUpDown->Position; ! 268: // strcpy(MainForm->mail_startup.dns_server,DNSAddressEdit->Text.c_str()); ! 269: ! 270: MainForm->SaveIniSettings(Sender); ! 271: ! 272: // Write CNF files ! 273: strcpy(scfg.sys_name,SystemNameEdit->Text.c_str()); ! 274: strcpy(scfg.sys_id,QWKIDEdit->Text.c_str()); ! 275: strcpy(scfg.sys_location,SystemLocationEdit->Text.c_str()); ! 276: strcpy(scfg.sys_op,SysopNameEdit->Text.c_str()); ! 277: strcpy(scfg.sys_pass,SystemPasswordEdit->Text.c_str()); ! 278: strcpy(scfg.sys_inetaddr,InternetAddressComboBox->Text.c_str()); ! 279: strcpy(scfg.qnet_tagline,QNetTaglineEdit->Text.c_str()); ! 280: scfg.sys_nodes=NodesUpDown->Position; ! 281: if(TimeZoneComboBox->ItemIndex>=0 ! 282: && TimeZoneComboBox->ItemIndex<=sizeof(tz_val)/sizeof(tz_val[0])) ! 283: scfg.sys_timezone=tz_val[TimeZoneComboBox->ItemIndex]; ! 284: if(DaylightCheckBox->Checked) ! 285: scfg.sys_timezone|=DAYLIGHT; ! 286: if(Time24hrRadioButton->Checked) ! 287: scfg.sys_misc|=SM_MILITARY; ! 288: else ! 289: scfg.sys_misc&=~SM_MILITARY; ! 290: if(DateEuRadioButton->Checked) ! 291: scfg.sys_misc|=SM_EURODATE; ! 292: else ! 293: scfg.sys_misc&=~SM_EURODATE; ! 294: if(NewUsersCheckBox->Checked) ! 295: scfg.sys_misc&=~SM_CLOSED; ! 296: else ! 297: scfg.sys_misc|=SM_CLOSED; ! 298: if(AliasesCheckBox->Checked) ! 299: scfg.uq|=UQ_ALIASES; ! 300: else ! 301: scfg.uq&=~UQ_ALIASES; ! 302: scfg.node_valuser=FeedbackCheckBox->Checked; ! 303: ! 304: if(DeletedEmailYesButton->Checked) ! 305: scfg.sys_misc|=(SM_USRVDELM|SM_SYSVDELM); ! 306: else if(DeletedEmailNoButton->Checked) ! 307: scfg.sys_misc&=~(SM_USRVDELM|SM_SYSVDELM); ! 308: else { ! 309: scfg.sys_misc|=SM_SYSVDELM; ! 310: scfg.sys_misc&=~SM_USRVDELM; ! 311: } ! 312: ! 313: scfg.new_install=FALSE; ! 314: if(!save_cfg(&scfg,0)) { ! 315: Application->MessageBox("Error saving configuration" ! 316: ,"ERROR",MB_OK|MB_ICONEXCLAMATION); ! 317: } else ! 318: refresh_cfg(&scfg); ! 319: ! 320: Close(); ! 321: return; ! 322: } ! 323: WizNotebook->PageIndex++; ! 324: ProgressBar->Position=WizNotebook->PageIndex; ! 325: if(ProgressBar->Position==ProgressBar->Max) /* Last page */ ! 326: NextButton->Caption="&Finish"; ! 327: } ! 328: //--------------------------------------------------------------------------- ! 329: void __fastcall TConfigWizard::BackButtonClick(TObject *Sender) ! 330: { ! 331: WizNotebook->PageIndex--; ! 332: ProgressBar->Position=WizNotebook->PageIndex; ! 333: NextButton->Caption="&Next >"; ! 334: } ! 335: //--------------------------------------------------------------------------- ! 336: void __fastcall TConfigWizard::CancelButtonClick(TObject *Sender) ! 337: { ! 338: Close(); ! 339: } ! 340: //--------------------------------------------------------------------------- ! 341: void __fastcall TConfigWizard::LogoImageClick(TObject *Sender) ! 342: { ! 343: LogoImage->Visible=false; ! 344: ProgressBar->Visible=false; ! 345: } ! 346: //--------------------------------------------------------------------------- ! 347: void __fastcall TConfigWizard::TitleLabelClick(TObject *Sender) ! 348: { ! 349: LogoImage->Visible=true; ! 350: ProgressBar->Visible=true; ! 351: } ! 352: //--------------------------------------------------------------------------- ! 353: void __fastcall TConfigWizard::WizNotebookPageChanged(TObject *Sender) ! 354: { ! 355: TFont* current; ! 356: ! 357: switch(WizNotebook->PageIndex) { ! 358: case 0: ! 359: current=IntroductionLabel->Font; ! 360: NextButton->Enabled=true; ! 361: break; ! 362: case 1: ! 363: current=IdentificationLabel->Font; ! 364: // ActiveControl=SystemNameEdit; ! 365: if(!SysopNameEdit->Text.Length()) { ! 366: char username[41]; ! 367: DWORD len=sizeof(username)-1; ! 368: GetUserName(username,&len); ! 369: SysopNameEdit->Text=AnsiString(username); ! 370: } ! 371: if(!SystemNameEdit->Text.Length()) { ! 372: char bbsname[41]; ! 373: DWORD len=sizeof(bbsname)-1; ! 374: GetComputerName(bbsname,&len); ! 375: SystemNameEdit->Text=AnsiString(bbsname); ! 376: } ! 377: VerifyIdentification(Sender); ! 378: break; ! 379: case 2: ! 380: current=TimeLabel->Font; ! 381: NextButton->Enabled=true; ! 382: break; ! 383: case 3: ! 384: current=InternetLabel->Font; ! 385: if(!InternetAddressComboBox->Items->Count) { ! 386: WSADATA WSAData; ! 387: WSAStartup(MAKEWORD(1,1), &WSAData); /* req'd for gethostname */ ! 388: if(scfg.sys_inetaddr[0]) ! 389: InternetAddressComboBox->Items->Add(scfg.sys_inetaddr); ! 390: char hostname[128]; ! 391: gethostname(hostname,sizeof(hostname)-1); ! 392: if(hostname[0]) { ! 393: InternetAddressComboBox->Items->Add(hostname); ! 394: HOSTENT* host=gethostbyname(hostname); ! 395: SOCKADDR_IN addr; ! 396: for(int i=0;host && host->h_addr_list[i];i++) { ! 397: addr.sin_addr.s_addr ! 398: =*((DWORD*)host->h_addr_list[i]); ! 399: InternetAddressComboBox->Items->Add(inet_ntoa(addr.sin_addr)); ! 400: } ! 401: } ! 402: WSACleanup(); ! 403: InternetAddressComboBox->ItemIndex=0; ! 404: } ! 405: VerifyInternetAddresses(Sender); ! 406: break; ! 407: case 4: ! 408: current=QWKLabel->Font; ! 409: if(!QWKIDEdit->Text.Length()) { ! 410: char bbsname[41]; ! 411: char qwkid[9]; ! 412: int len=0; ! 413: strcpy(bbsname,SystemNameEdit->Text.UpperCase().c_str()); ! 414: for(char*p=bbsname;*p && len<8;p++) { ! 415: if(strchr(ILLEGAL_QWKID_CHARS,*p)) ! 416: continue; ! 417: if(!len && isdigit(*p)) ! 418: continue; ! 419: if(*p<=' ') ! 420: continue; ! 421: qwkid[len++]=*p; ! 422: } ! 423: qwkid[len]=0; ! 424: QWKIDEdit->Text=AnsiString(qwkid); ! 425: } ! 426: if(!QNetTaglineEdit->Text.Length()) { ! 427: QNetTaglineEdit->Text = SystemNameEdit->Text + ! 428: " - " + InternetAddressComboBox->Text; ! 429: } ! 430: VerifyQWK(Sender); ! 431: break; ! 432: case 5: ! 433: current=MaximumsLabel->Font; ! 434: NextButton->Enabled=true; ! 435: break; ! 436: case 6: ! 437: current=OptionsLabel->Font; ! 438: NextButton->Enabled=true; ! 439: break; ! 440: case 7: ! 441: current=VerifyLabel->Font; ! 442: VerifyPassword(Sender); ! 443: if(!NextButton->Enabled) ! 444: ActiveControl=SysPassVerifyEdit; ! 445: break; ! 446: case 8: ! 447: current=CompleteLabel->Font; ! 448: break; ! 449: default: ! 450: return; ! 451: } ! 452: ! 453: /* default to inactive */ ! 454: IntroductionLabel->Font->Color=clGray; ! 455: IdentificationLabel->Font->Color=clGray; ! 456: QWKLabel->Font->Color=clGray; ! 457: TimeLabel->Font->Color=clGray; ! 458: InternetLabel->Font->Color=clGray; ! 459: MaximumsLabel->Font->Color=clGray; ! 460: OptionsLabel->Font->Color=clGray; ! 461: VerifyLabel->Font->Color=clGray; ! 462: CompleteLabel->Font->Color=clGray; ! 463: ! 464: /* active */ ! 465: current->Color=clYellow; ! 466: ! 467: BackButton->Enabled=WizNotebook->PageIndex; ! 468: } ! 469: //--------------------------------------------------------------------------- ! 470: void __fastcall TConfigWizard::VerifyIdentification(TObject *Sender) ! 471: { ! 472: NextButton->Enabled=(SystemNameEdit->Text.Length() ! 473: && SystemLocationEdit->Text.Length() ! 474: && SysopNameEdit->Text.Length() ! 475: && SystemPasswordEdit->Text.Length() ! 476: ); ! 477: } ! 478: //--------------------------------------------------------------------------- ! 479: void __fastcall TConfigWizard::VerifyPassword(TObject *Sender) ! 480: { ! 481: NextButton->Enabled=(SystemPasswordEdit->Text==SysPassVerifyEdit->Text); ! 482: } ! 483: //--------------------------------------------------------------------------- ! 484: void __fastcall TConfigWizard::VerifyQWK(TObject *Sender) ! 485: { ! 486: char qwk_id[9]; ! 487: ! 488: SAFECOPY(qwk_id,QWKIDEdit->Text.c_str()); ! 489: NextButton->Enabled=( ! 490: strlen(qwk_id)>=2 ! 491: && isalpha(qwk_id[0]) ! 492: && strcspn(qwk_id,ILLEGAL_QWKID_CHARS)==strlen(qwk_id) ! 493: && QNetTaglineEdit->Text.Length()); ! 494: } ! 495: //--------------------------------------------------------------------------- ! 496: void __fastcall TConfigWizard::QNetTaglineEditKeyPress(TObject *Sender, ! 497: char &Key) ! 498: { ! 499: if(Key==1) /* Ctrl-A */ ! 500: QNetTaglineEdit->SetSelTextBuf("\1"); ! 501: } ! 502: //--------------------------------------------------------------------------- ! 503: ! 504: void __fastcall TConfigWizard::VerifyInternetAddresses(TObject *Sender) ! 505: { ! 506: NextButton->Enabled=(InternetAddressComboBox->Text.Length() ! 507: // && DNSAddressEdit->Text.Length() ! 508: ); ! 509: } ! 510: //--------------------------------------------------------------------------- ! 511: void __fastcall TConfigWizard::TimeZoneComboBoxChange(TObject *Sender) ! 512: { ! 513: if(TimeZoneComboBox->ItemIndex>=0 ! 514: && TimeZoneComboBox->ItemIndex<=sizeof(tz_val)/sizeof(tz_val[0])) ! 515: DaylightCheckBox->Enabled=tz_val[TimeZoneComboBox->ItemIndex]&US_ZONE; ! 516: else ! 517: DaylightCheckBox->Enabled=false; ! 518: if(!DaylightCheckBox->Enabled) ! 519: DaylightCheckBox->Checked=false; ! 520: } ! 521: //--------------------------------------------------------------------------- ! 522: ! 523: void __fastcall TConfigWizard::NewUsersCheckBoxClick(TObject *Sender) ! 524: { ! 525: AliasesCheckBox->Enabled=NewUsersCheckBox->Checked; ! 526: FeedbackCheckBox->Enabled=NewUsersCheckBox->Checked; ! 527: } ! 528: //--------------------------------------------------------------------------- ! 529:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.