|
|
1.1 root 1: /* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */
2:
1.1.1.2 ! root 3: /* $Id: MainFormUnit.cpp,v 1.182 2011/09/09 08:13:41 rswindell Exp $ */
1.1 root 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: * *
1.1.1.2 ! root 9: * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 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" // unixtodstr()
38: #include <vcl.h>
39: #include <vcl/Registry.hpp> /* TRegistry */
40: #pragma hdrstop
41: #include <winsock.h> // IPPORT_TELNET, INADDR_ANY
42: #include <process.h> // _beginthread()
43: #include <io.h>
44: #include <stdio.h>
45: #include <sys/stat.h>
46: #include <sys/locking.h>
47: #include <fcntl.h>
48: #include <share.h>
49:
50: #include "MainFormUnit.h"
51: #include "TelnetFormUnit.h"
52: #include "EventsFormUnit.h"
53: #include "ServicesFormUnit.h"
54: #include "FtpFormUnit.h"
55: #include "WebFormUnit.h"
56: #include "MailFormUnit.h"
57: #include "NodeFormUnit.h"
58:
59: #include "StatsFormUnit.h"
60: #include "ClientFormUnit.h"
61: #include "CtrlPathDialogUnit.h"
62: #include "TelnetCfgDlgUnit.h"
63: #include "MailCfgDlgUnit.h"
64: #include "FtpCfgDlgUnit.h"
65: #include "WebCfgDlgUnit.h"
66: #include "ServicesCfgDlgUnit.h"
67: #include "AboutBoxFormUnit.h"
68: #include "CodeInputFormUnit.h"
69: #include "TextFileEditUnit.h"
70: #include "UserListFormUnit.h"
71: #include "PropertiesDlgUnit.h"
72: #include "ConfigWizardUnit.h"
73: #include "PreviewFormUnit.h"
1.1.1.2 ! root 74: #include "LoginAttemptsFormUnit.h"
1.1 root 75:
76: #include "sbbs_ini.h" // sbbs_read_ini()
77: #include "userdat.h" // lastuser()
78: #include "ntsvcs.h" // NTSVC_NAME_*
79:
80: //---------------------------------------------------------------------------
81: #pragma package(smart_init)
82: #pragma link "trayicon"
83: #pragma link "Trayicon"
84: #pragma resource "*.dfm"
85: TMainForm *MainForm;
86:
87: #define LOG_TIME_FMT " m/d hh:mm:ssa/p"
1.1.1.2 ! root 88: #define STATUSBAR_LAST_PANEL 5
1.1 root 89:
90: /* Service functions are NT-only, must call dynamically :-( */
91: typedef WINADVAPI SC_HANDLE (WINAPI *OpenSCManager_t)(LPCTSTR,LPCTSTR,DWORD);
92: typedef WINADVAPI SC_HANDLE (WINAPI *OpenService_t)(SC_HANDLE,LPCTSTR,DWORD);
93: typedef WINADVAPI BOOL (WINAPI *StartService_t)(SC_HANDLE,DWORD,LPCTSTR*);
94: typedef WINADVAPI BOOL (WINAPI *ControlService_t)(SC_HANDLE,DWORD,LPSERVICE_STATUS);
95: typedef WINADVAPI BOOL (WINAPI *QueryServiceStatus_t)(SC_HANDLE,LPSERVICE_STATUS);
96: typedef WINADVAPI BOOL (WINAPI *QueryServiceConfig_t)(SC_HANDLE,LPQUERY_SERVICE_CONFIG,DWORD,LPDWORD);
97: typedef WINADVAPI BOOL (WINAPI *CloseServiceHandle_t)(SC_HANDLE);
98:
99: OpenSCManager_t openSCManager;
100: OpenService_t openService;
101: StartService_t startService;
102: ControlService_t controlService;
103: QueryServiceStatus_t queryServiceStatus;
104: QueryServiceConfig_t queryServiceConfig;
105: CloseServiceHandle_t closeServiceHandle;
106:
107: SC_HANDLE hSCManager;
108: SC_HANDLE bbs_svc;
109: SC_HANDLE ftp_svc;
110: SC_HANDLE web_svc;
111: SC_HANDLE mail_svc;
112: SC_HANDLE services_svc;
113: SERVICE_STATUS bbs_svc_status;
114: SERVICE_STATUS ftp_svc_status;
115: SERVICE_STATUS web_svc_status;
116: SERVICE_STATUS mail_svc_status;
117: SERVICE_STATUS services_svc_status;
118: QUERY_SERVICE_CONFIG* bbs_svc_config;
119: DWORD bbs_svc_config_size;
120: QUERY_SERVICE_CONFIG* ftp_svc_config;
121: DWORD ftp_svc_config_size;
122: QUERY_SERVICE_CONFIG* web_svc_config;
123: DWORD web_svc_config_size;
124: QUERY_SERVICE_CONFIG* mail_svc_config;
125: DWORD mail_svc_config_size;
126: QUERY_SERVICE_CONFIG* services_svc_config;
127: DWORD services_svc_config_size;
128:
1.1.1.2 ! root 129: const char* LogLevelDesc[] = { "Emergency"
! 130: ,"Alert"
! 131: ,"Critical"
! 132: ,"Error"
! 133: ,"Warning"
! 134: ,"Notice"
! 135: ,"Normal"
! 136: ,"Debug"
! 137: };
! 138: const TColor LogLevelColor[] = {
! 139: clRed
! 140: ,clRed
! 141: ,clRed
! 142: ,clRed
! 143: ,clFuchsia
! 144: ,clBlue
! 145: ,clBlack /* not used */
! 146: ,clGreen
! 147: };
! 148:
! 149: link_list_t bbs_log_list;
! 150: link_list_t event_log_list;
! 151: link_list_t mail_log_list;
! 152: link_list_t ftp_log_list;
! 153: link_list_t web_log_list;
! 154: link_list_t services_log_list;
! 155: link_list_t login_attempt_list;
! 156:
1.1 root 157: DWORD MaxLogLen=20000;
158: int threads=1;
159: time_t initialized=0;
160: static str_list_t recycle_semfiles;
161: static str_list_t shutdown_semfiles;
162: bool terminating=false;
1.1.1.2 ! root 163: ulong errors;
! 164: AnsiString ErrorSoundFile;
! 165:
! 166: static void errormsg(void* p, int level, const char* msg)
! 167: {
! 168: errors++;
! 169:
! 170: if(MainForm->SoundToggle->Checked)
! 171: PlaySound(ErrorSoundFile.c_str(), NULL, SND_ASYNC|SND_FILENAME);
! 172: }
1.1 root 173:
174: static void thread_up(void* p, BOOL up, BOOL setuid)
175: {
176: char str[128];
177: static HANDLE mutex;
178:
179: if(!mutex)
180: mutex=CreateMutex(NULL,false,NULL);
181: WaitForSingleObject(mutex,INFINITE);
182: if(up)
183: threads++;
184: else if(threads>0)
185: threads--;
186: ReleaseMutex(mutex);
187: }
188:
189: int sockets=0;
190:
191: void socket_open(void* p, BOOL open)
192: {
193: char str[128];
194: static HANDLE mutex;
195:
196: if(!mutex)
197: mutex=CreateMutex(NULL,false,NULL);
198: WaitForSingleObject(mutex,INFINITE);
199: if(open)
200: sockets++;
201: else if(sockets>0)
202: sockets--;
203: ReleaseMutex(mutex);
204: }
205:
206: int clients=0;
207: int total_clients=0;
208:
209: static void client_add(void* p, BOOL add)
210: {
211: char str[128];
212:
213: if(add) {
214: clients++;
215: total_clients++;
216: } else if(clients>0)
217: clients--;
218: }
219:
220: static void client_on(void* p, BOOL on, int sock, client_t* client, BOOL update)
221: {
222: char str[128];
223: int i,j;
224: time_t t;
225: static HANDLE mutex;
226: TListItem* Item;
227:
228: if(!mutex)
229: mutex=CreateMutex(NULL,false,NULL);
230: WaitForSingleObject(mutex,INFINITE);
231: WaitForSingleObject(ClientForm->ListMutex,INFINITE);
232:
233: /* Search for exising entry for this socket */
234: for(i=0;i<ClientForm->ListView->Items->Count;i++) {
235: if(ClientForm->ListView->Items->Item[i]->Caption.ToIntDef(0)==sock)
236: break;
237: }
238: if(i>=ClientForm->ListView->Items->Count) {
239: if(update) { /* Can't update a non-existing entry */
240: ReleaseMutex(mutex);
241: ReleaseMutex(ClientForm->ListMutex);
242: return;
243: }
244: i=-1;
245: }
246:
247: if(on) {
248: if(!update)
249: client_add(NULL, TRUE);
250: } else { // Off
251: client_add(NULL, FALSE);
252: if(i>=0)
253: ClientForm->ListView->Items->Delete(i);
254: ReleaseMutex(mutex);
255: ReleaseMutex(ClientForm->ListMutex);
256: return;
257: }
258: if(client!=NULL && client->size==sizeof(client_t)) {
1.1.1.2 ! root 259: t=time(NULL);
1.1 root 260: if(i>=0) {
261: Item=ClientForm->ListView->Items->Item[i];
262: } else {
263: Item=ClientForm->ListView->Items->Add();
1.1.1.2 ! root 264: Item->Data=(void*)t;
1.1 root 265: Item->Caption=sock;
266: }
267: Item->SubItems->Clear();
268: Item->SubItems->Add(client->protocol);
269: Item->SubItems->Add(client->user);
270: Item->SubItems->Add(client->addr);
271: Item->SubItems->Add(client->host);
272: Item->SubItems->Add(client->port);
1.1.1.2 ! root 273: t-=(time_t)Item->Data;
1.1 root 274: sprintf(str,"%d:%02d",t/60,t%60);
275: Item->SubItems->Add(str);
276: }
277: ReleaseMutex(mutex);
278: ReleaseMutex(ClientForm->ListMutex);
279: }
280:
1.1.1.2 ! root 281: static int lputs(void* p, int level, const char *str)
1.1 root 282: {
1.1.1.2 ! root 283: log_msg_t msg;
1.1 root 284:
1.1.1.2 ! root 285: msg.level = level;
! 286: GetLocalTime(&msg.time);
! 287: SAFECOPY(msg.buf, str);
! 288: listPushNodeData((link_list_t*)p, &msg, sizeof(msg));
! 289: return strlen(msg.buf);
! 290: }
1.1 root 291:
1.1.1.2 ! root 292: static void bbs_log_msg(log_msg_t* msg)
! 293: {
! 294: while(MaxLogLen && TelnetForm->Log->Lines->Count >= MaxLogLen)
1.1 root 295: TelnetForm->Log->Lines->Delete(0);
296:
1.1.1.2 ! root 297: AnsiString Line=SystemTimeToDateTime(msg->time).FormatString(LOG_TIME_FMT)+" ";
! 298:
! 299: Line+=AnsiString(msg->buf).Trim();
! 300: TelnetForm->Log->SelLength=0;
! 301: TelnetForm->Log->SelAttributes->Assign(
! 302: MainForm->LogAttributes(msg->level, TelnetForm->Log->Color, TelnetForm->Log->Font));
1.1 root 303: TelnetForm->Log->Lines->Add(Line);
1.1.1.2 ! root 304: SendMessage(TelnetForm->Log->Handle, WM_VSCROLL, SB_BOTTOM, NULL);
1.1 root 305: }
306:
1.1.1.2 ! root 307: static void bbs_status(void* p, const char *str)
1.1 root 308: {
309: static HANDLE mutex;
310:
311: if(!mutex)
312: mutex=CreateMutex(NULL,false,NULL);
313: WaitForSingleObject(mutex,INFINITE);
314:
315: TelnetForm->Status->Caption=AnsiString(str);
316:
317: ReleaseMutex(mutex);
318: }
319:
320: static void bbs_clients(void* p, int clients)
321: {
322: static HANDLE mutex;
323: static save_clients;
324:
325: save_clients=clients;
326:
327: if(!mutex)
328: mutex=CreateMutex(NULL,false,NULL);
329: WaitForSingleObject(mutex,INFINITE);
330:
331: TelnetForm->ProgressBar->Max
332: =(MainForm->bbs_startup.last_node
333: -MainForm->bbs_startup.first_node)+1;
334: TelnetForm->ProgressBar->Position=clients;
335:
336: ReleaseMutex(mutex);
337: }
338:
339: static void bbs_terminated(void* p, int code)
340: {
341: Screen->Cursor=crDefault;
342: MainForm->TelnetStart->Enabled=true;
343: MainForm->TelnetStop->Enabled=false;
1.1.1.2 ! root 344: MainForm->TelnetRecycle->Enabled=false;
! 345: MainForm->TelnetPause->Enabled=false;
! 346: MainForm->TelnetPause->Checked=false;
1.1 root 347: Application->ProcessMessages();
348: }
349: static void bbs_started(void* p)
350: {
351: Screen->Cursor=crDefault;
352: MainForm->TelnetStart->Enabled=false;
353: MainForm->TelnetStop->Enabled=true;
1.1.1.2 ! root 354: MainForm->TelnetRecycle->Enabled=true;
! 355: MainForm->TelnetPause->Enabled=true;
! 356: MainForm->TelnetPause->Checked=false;
1.1 root 357: Application->ProcessMessages();
358: }
359: static void bbs_start(void)
360: {
361: Screen->Cursor=crAppStart;
362: bbs_status(NULL,"Starting");
363:
364: FILE* fp=fopen(MainForm->ini_file,"r");
365: sbbs_read_ini(fp
366: ,&MainForm->global
367: ,NULL ,&MainForm->bbs_startup
368: ,NULL ,NULL
369: ,NULL ,NULL
370: ,NULL ,NULL
371: ,NULL ,NULL
372: );
373: if(fp!=NULL)
374: fclose(fp);
375:
376: _beginthread((void(*)(void*))bbs_thread,0,&MainForm->bbs_startup);
377: Application->ProcessMessages();
378: }
379:
1.1.1.2 ! root 380: static void event_log_msg(log_msg_t* msg)
1.1 root 381: {
1.1.1.2 ! root 382: while(MaxLogLen && EventsForm->Log->Lines->Count >= MaxLogLen)
1.1 root 383: EventsForm->Log->Lines->Delete(0);
384:
1.1.1.2 ! root 385: AnsiString Line=SystemTimeToDateTime(msg->time).FormatString(LOG_TIME_FMT)+" ";
! 386: Line+=AnsiString(msg->buf).Trim();
! 387: EventsForm->Log->SelLength=0;
! 388: EventsForm->Log->SelAttributes->Assign(
! 389: MainForm->LogAttributes(msg->level, EventsForm->Log->Color, EventsForm->Log->Font));
1.1 root 390: EventsForm->Log->Lines->Add(Line);
1.1.1.2 ! root 391: SendMessage(EventsForm->Log->Handle, WM_VSCROLL, SB_BOTTOM, NULL);
1.1 root 392: }
393:
1.1.1.2 ! root 394: static void services_log_msg(log_msg_t* msg)
1.1 root 395: {
1.1.1.2 ! root 396: while(MaxLogLen && ServicesForm->Log->Lines->Count >= MaxLogLen)
1.1 root 397: ServicesForm->Log->Lines->Delete(0);
398:
1.1.1.2 ! root 399: AnsiString Line=SystemTimeToDateTime(msg->time).FormatString(LOG_TIME_FMT)+" ";
! 400: Line+=AnsiString(msg->buf).Trim();
! 401: ServicesForm->Log->SelLength=0;
! 402: ServicesForm->Log->SelAttributes->Assign(
! 403: MainForm->LogAttributes(msg->level, ServicesForm->Log->Color, ServicesForm->Log->Font));
1.1 root 404: ServicesForm->Log->Lines->Add(Line);
1.1.1.2 ! root 405: SendMessage(ServicesForm->Log->Handle, WM_VSCROLL, SB_BOTTOM, NULL);
1.1 root 406: }
407:
1.1.1.2 ! root 408: static void services_status(void* p, const char *str)
1.1 root 409: {
410: static HANDLE mutex;
411:
412: if(!mutex)
413: mutex=CreateMutex(NULL,false,NULL);
414: WaitForSingleObject(mutex,INFINITE);
415:
416: ServicesForm->Status->Caption=AnsiString(str);
417:
418: ReleaseMutex(mutex);
419: }
420:
421: static void services_terminated(void* p, int code)
422: {
423: Screen->Cursor=crDefault;
424: MainForm->ServicesStart->Enabled=true;
425: MainForm->ServicesStop->Enabled=false;
426: MainForm->ServicesRecycle->Enabled=false;
1.1.1.2 ! root 427: MainForm->ServicesPause->Enabled=false;
! 428: MainForm->ServicesPause->Checked=false;
1.1 root 429: Application->ProcessMessages();
430: }
431: static void services_started(void* p)
432: {
433: Screen->Cursor=crDefault;
434: MainForm->ServicesStart->Enabled=false;
435: MainForm->ServicesStop->Enabled=true;
436: MainForm->ServicesRecycle->Enabled=true;
1.1.1.2 ! root 437: MainForm->ServicesPause->Enabled=true;
! 438: MainForm->ServicesPause->Checked=false;
1.1 root 439: Application->ProcessMessages();
440: }
441:
442: static void services_clients(void* p, int clients)
443: {
444: }
445:
1.1.1.2 ! root 446: static void mail_log_msg(log_msg_t* msg)
1.1 root 447: {
448: static FILE* LogStream;
449:
1.1.1.2 ! root 450: if(msg==NULL) {
1.1 root 451: if(LogStream!=NULL)
452: fclose(LogStream);
453: LogStream=NULL;
1.1.1.2 ! root 454: return;
1.1 root 455: }
456:
1.1.1.2 ! root 457: while(MaxLogLen && MailForm->Log->Lines->Count >= MaxLogLen)
1.1 root 458: MailForm->Log->Lines->Delete(0);
459:
1.1.1.2 ! root 460: AnsiString Line=SystemTimeToDateTime(msg->time).FormatString(LOG_TIME_FMT)+" ";
! 461: Line+=AnsiString(msg->buf).Trim();
! 462: MailForm->Log->SelLength=0;
! 463: MailForm->Log->SelAttributes->Assign(
! 464: MainForm->LogAttributes(msg->level, MailForm->Log->Color, MailForm->Log->Font));
1.1 root 465: MailForm->Log->Lines->Add(Line);
1.1.1.2 ! root 466: SendMessage(MailForm->Log->Handle, WM_VSCROLL, SB_BOTTOM, NULL);
1.1 root 467:
468: if(MainForm->MailLogFile && MainForm->MailStop->Enabled) {
469: AnsiString LogFileName
1.1.1.2 ! root 470: =AnsiString(MainForm->cfg.logs_dir)
1.1 root 471: +"LOGS\\MS"
1.1.1.2 ! root 472: +SystemTimeToDateTime(msg->time).FormatString("mmddyy")
1.1 root 473: +".LOG";
474:
475: if(!FileExists(LogFileName)) {
476: if(LogStream!=NULL) {
477: fclose(LogStream);
478: LogStream=NULL;
479: }
480: }
481: if(LogStream==NULL)
482: LogStream=_fsopen(LogFileName.c_str(),"a",SH_DENYNONE);
483:
484: if(LogStream!=NULL) {
1.1.1.2 ! root 485: Line=SystemTimeToDateTime(msg->time).FormatString("hh:mm:ss")+" ";
! 486: Line+=AnsiString(msg->buf).Trim();
1.1 root 487: Line+="\n";
488: fwrite(AnsiString(Line).c_str(),1,Line.Length(),LogStream);
489: }
490: }
491: }
492:
1.1.1.2 ! root 493: static void mail_status(void* p, const char *str)
1.1 root 494: {
495: static HANDLE mutex;
496:
497: if(!mutex)
498: mutex=CreateMutex(NULL,false,NULL);
499: WaitForSingleObject(mutex,INFINITE);
500:
501: MailForm->Status->Caption=AnsiString(str);
502:
503: ReleaseMutex(mutex);
504: }
505:
506: static void mail_clients(void* p, int clients)
507: {
508: static HANDLE mutex;
509:
510: if(!mutex)
511: mutex=CreateMutex(NULL,false,NULL);
512: WaitForSingleObject(mutex,INFINITE);
513:
514: MailForm->ProgressBar->Max=MainForm->mail_startup.max_clients;
515: MailForm->ProgressBar->Position=clients;
516:
517: ReleaseMutex(mutex);
518: }
519:
520: static void mail_terminated(void* p, int code)
521: {
522: Screen->Cursor=crDefault;
523: MainForm->MailStart->Enabled=true;
524: MainForm->MailStop->Enabled=false;
525: MainForm->MailRecycle->Enabled=false;
1.1.1.2 ! root 526: MainForm->MailPause->Enabled=false;
! 527: MainForm->MailPause->Checked=false;
1.1 root 528: Application->ProcessMessages();
529: }
530: static void mail_started(void* p)
531: {
532: Screen->Cursor=crDefault;
533: MainForm->MailStart->Enabled=false;
534: MainForm->MailStop->Enabled=true;
535: MainForm->MailRecycle->Enabled=true;
1.1.1.2 ! root 536: MainForm->MailPause->Enabled=true;
! 537: MainForm->MailPause->Checked=false;
1.1 root 538: Application->ProcessMessages();
539: }
540: static void mail_start(void)
541: {
542: Screen->Cursor=crAppStart;
543: mail_status(NULL, "Starting");
544:
545: FILE* fp=fopen(MainForm->ini_file,"r");
546: sbbs_read_ini(fp
547: ,&MainForm->global
548: ,NULL ,NULL
549: ,NULL ,NULL
550: ,NULL ,NULL
551: ,NULL ,&MainForm->mail_startup
552: ,NULL ,NULL
553: );
554: if(fp!=NULL)
555: fclose(fp);
556:
557: _beginthread((void(*)(void*))mail_server,0,&MainForm->mail_startup);
558: Application->ProcessMessages();
559: }
560:
1.1.1.2 ! root 561: static void ftp_log_msg(log_msg_t* msg)
1.1 root 562: {
563: static FILE* LogStream;
564:
1.1.1.2 ! root 565: if(msg==NULL) {
1.1 root 566: if(LogStream!=NULL)
567: fclose(LogStream);
568: LogStream=NULL;
1.1.1.2 ! root 569: return;
1.1 root 570: }
571:
1.1.1.2 ! root 572: while(MaxLogLen && FtpForm->Log->Lines->Count >= MaxLogLen)
1.1 root 573: FtpForm->Log->Lines->Delete(0);
574:
1.1.1.2 ! root 575: AnsiString Line=SystemTimeToDateTime(msg->time).FormatString(LOG_TIME_FMT)+" ";
! 576: Line+=AnsiString(msg->buf).Trim();
! 577: FtpForm->Log->SelLength=0;
! 578: FtpForm->Log->SelAttributes->Assign(
! 579: MainForm->LogAttributes(msg->level, FtpForm->Log->Color, FtpForm->Log->Font));
1.1 root 580: FtpForm->Log->Lines->Add(Line);
1.1.1.2 ! root 581: SendMessage(FtpForm->Log->Handle, WM_VSCROLL, SB_BOTTOM, NULL);
1.1 root 582:
583: if(MainForm->FtpLogFile && MainForm->FtpStop->Enabled) {
584: AnsiString LogFileName
1.1.1.2 ! root 585: =AnsiString(MainForm->cfg.logs_dir)
1.1 root 586: +"LOGS\\FS"
1.1.1.2 ! root 587: +SystemTimeToDateTime(msg->time).FormatString("mmddyy")
1.1 root 588: +".LOG";
589:
590: if(!FileExists(LogFileName)) {
591: FileClose(FileCreate(LogFileName));
592: if(LogStream!=NULL) {
593: fclose(LogStream);
594: LogStream=NULL;
595: }
596: }
597: if(LogStream==NULL)
598: LogStream=_fsopen(LogFileName.c_str(),"a",SH_DENYNONE);
599:
600: if(LogStream!=NULL) {
1.1.1.2 ! root 601: Line=SystemTimeToDateTime(msg->time).FormatString("hh:mm:ss")+" ";
! 602: Line+=AnsiString(msg->buf).Trim();
1.1 root 603: Line+="\n";
604: fwrite(AnsiString(Line).c_str(),1,Line.Length(),LogStream);
605: }
606: }
607: }
608:
1.1.1.2 ! root 609: static void ftp_status(void* p, const char *str)
1.1 root 610: {
611: static HANDLE mutex;
612:
613: if(!mutex)
614: mutex=CreateMutex(NULL,false,NULL);
615: WaitForSingleObject(mutex,INFINITE);
616:
617: FtpForm->Status->Caption=AnsiString(str);
618:
619: ReleaseMutex(mutex);
620: }
621:
622: static void ftp_clients(void* p, int clients)
623: {
624: static HANDLE mutex;
625:
626: if(!mutex)
627: mutex=CreateMutex(NULL,false,NULL);
628: WaitForSingleObject(mutex,INFINITE);
629:
630: FtpForm->ProgressBar->Max=MainForm->ftp_startup.max_clients;
631: FtpForm->ProgressBar->Position=clients;
632:
633: ReleaseMutex(mutex);
634: }
635:
636: static void ftp_terminated(void* p, int code)
637: {
638: Screen->Cursor=crDefault;
639: MainForm->FtpStart->Enabled=true;
640: MainForm->FtpStop->Enabled=false;
641: MainForm->FtpRecycle->Enabled=false;
1.1.1.2 ! root 642: MainForm->FtpPause->Enabled=false;
! 643: MainForm->FtpPause->Checked=false;
1.1 root 644: Application->ProcessMessages();
645: }
646: static void ftp_started(void* p)
647: {
648: Screen->Cursor=crDefault;
649: MainForm->FtpStart->Enabled=false;
650: MainForm->FtpStop->Enabled=true;
651: MainForm->FtpRecycle->Enabled=true;
1.1.1.2 ! root 652: MainForm->FtpPause->Enabled=true;
! 653: MainForm->FtpPause->Checked=false;
1.1 root 654: Application->ProcessMessages();
655: }
656: static void ftp_start(void)
657: {
658: Screen->Cursor=crAppStart;
659: ftp_status(NULL, "Starting");
660:
661: FILE* fp=fopen(MainForm->ini_file,"r");
662: sbbs_read_ini(fp
663: ,&MainForm->global
664: ,NULL ,NULL
665: ,NULL ,&MainForm->ftp_startup
666: ,NULL ,NULL
667: ,NULL ,NULL
668: ,NULL ,NULL
669: );
670: if(fp!=NULL)
671: fclose(fp);
672:
673: _beginthread((void(*)(void*))ftp_server,0,&MainForm->ftp_startup);
674: Application->ProcessMessages();
675: }
676: //---------------------------------------------------------------------------
1.1.1.2 ! root 677: static void web_log_msg(log_msg_t* msg)
1.1 root 678: {
679: static FILE* LogStream;
680:
1.1.1.2 ! root 681: if(msg==NULL) {
1.1 root 682: if(LogStream!=NULL)
683: fclose(LogStream);
684: LogStream=NULL;
1.1.1.2 ! root 685: return;
1.1 root 686: }
687:
1.1.1.2 ! root 688: while(MaxLogLen && WebForm->Log->Lines->Count >= MaxLogLen)
1.1 root 689: WebForm->Log->Lines->Delete(0);
690:
1.1.1.2 ! root 691: AnsiString Line=SystemTimeToDateTime(msg->time).FormatString(LOG_TIME_FMT)+" ";
! 692: Line+=AnsiString(msg->buf).Trim();
! 693: WebForm->Log->SelLength=0;
! 694: WebForm->Log->SelAttributes->Assign(
! 695: MainForm->LogAttributes(msg->level, WebForm->Log->Color, WebForm->Log->Font));
1.1 root 696: WebForm->Log->Lines->Add(Line);
1.1.1.2 ! root 697: SendMessage(WebForm->Log->Handle, WM_VSCROLL, SB_BOTTOM, NULL);
1.1 root 698: }
699:
1.1.1.2 ! root 700: static void web_status(void* p, const char *str)
1.1 root 701: {
702: static HANDLE mutex;
703:
704: if(!mutex)
705: mutex=CreateMutex(NULL,false,NULL);
706: WaitForSingleObject(mutex,INFINITE);
707:
708: WebForm->Status->Caption=AnsiString(str);
709:
710: ReleaseMutex(mutex);
711: }
712:
713: static void web_clients(void* p, int clients)
714: {
715: static HANDLE mutex;
716:
717: if(!mutex)
718: mutex=CreateMutex(NULL,false,NULL);
719: WaitForSingleObject(mutex,INFINITE);
720:
1.1.1.2 ! root 721: WebForm->ProgressBar->Max=MainForm->web_startup.max_clients;
1.1 root 722: WebForm->ProgressBar->Position=clients;
723:
724: ReleaseMutex(mutex);
725: }
726:
727: static void web_terminated(void* p, int code)
728: {
729: Screen->Cursor=crDefault;
730: MainForm->WebStart->Enabled=true;
731: MainForm->WebStop->Enabled=false;
732: MainForm->WebRecycle->Enabled=false;
1.1.1.2 ! root 733: MainForm->WebPause->Enabled=false; // caused exception
! 734: MainForm->WebPause->Checked=false;
1.1 root 735: Application->ProcessMessages();
736: }
737: static void web_started(void* p)
738: {
739: Screen->Cursor=crDefault;
740: MainForm->WebStart->Enabled=false;
741: MainForm->WebStop->Enabled=true;
742: MainForm->WebRecycle->Enabled=true;
1.1.1.2 ! root 743: MainForm->WebPause->Enabled=true;
! 744: MainForm->WebPause->Checked=false;
1.1 root 745: Application->ProcessMessages();
746: }
747: static void web_start(void)
748: {
749: Screen->Cursor=crAppStart;
750: web_status(NULL, "Starting");
751:
752: FILE* fp=fopen(MainForm->ini_file,"r");
753: sbbs_read_ini(fp
754: ,&MainForm->global
755: ,NULL ,NULL
756: ,NULL ,NULL
757: ,NULL ,&MainForm->web_startup
758: ,NULL ,NULL
759: ,NULL ,NULL
760: );
761: if(fp!=NULL)
762: fclose(fp);
763:
764: _beginthread((void(*)(void*))web_server,0,&MainForm->web_startup);
765: Application->ProcessMessages();
766: }
767: //---------------------------------------------------------------------------
768: /* Server recycle callback (read relevant startup .ini file section) */
769: static void recycle(void* cbdata)
770: {
771: char str[MAX_PATH*2];
772: FILE* fp=NULL;
773: bbs_startup_t* bbs=NULL;
774: ftp_startup_t* ftp=NULL;
775: web_startup_t* web=NULL;
776: mail_startup_t* mail=NULL;
777: services_startup_t* services=NULL;
778:
779: SAFEPRINTF(str,"Reading %s",MainForm->ini_file);
1.1.1.2 ! root 780: if(cbdata==(void*)&bbs_log_list) {
1.1 root 781: bbs=&MainForm->bbs_startup;
1.1.1.2 ! root 782: lputs(cbdata,LOG_INFO,str);
! 783: } else if(cbdata==(void*)&ftp_log_list) {
1.1 root 784: ftp=&MainForm->ftp_startup;
1.1.1.2 ! root 785: lputs(cbdata,LOG_INFO,str);
! 786: } else if(cbdata==(void*)&web_log_list) {
1.1 root 787: web=&MainForm->web_startup;
1.1.1.2 ! root 788: lputs(cbdata,LOG_INFO,str);
! 789: } else if(cbdata==(void*)&mail_log_list) {
1.1 root 790: mail=&MainForm->mail_startup;
1.1.1.2 ! root 791: lputs(cbdata,LOG_INFO,str);
! 792: } else if(cbdata==(void*)&services_log_list) {
1.1 root 793: services=&MainForm->services_startup;
1.1.1.2 ! root 794: lputs(cbdata,LOG_INFO,str);
1.1 root 795: }
796:
797: fp=fopen(MainForm->ini_file,"r");
798: sbbs_read_ini(fp
799: ,&MainForm->global
800: ,NULL ,bbs
801: ,NULL ,ftp
802: ,NULL ,web
803: ,NULL ,mail
804: ,NULL ,services
805: );
806: if(fp!=NULL)
807: fclose(fp);
808: }
809: //---------------------------------------------------------------------------
810: __fastcall TMainForm::TMainForm(TComponent* Owner)
811: : TForm(Owner)
812: {
813: /* Defaults */
1.1.1.2 ! root 814: memset(&global,0,sizeof(global));
1.1 root 815: SAFECOPY(global.ctrl_dir,"c:\\sbbs\\ctrl\\");
816: global.js.max_bytes=JAVASCRIPT_MAX_BYTES;
817: global.js.cx_stack=JAVASCRIPT_CONTEXT_STACK;
818: global.js.branch_limit=JAVASCRIPT_BRANCH_LIMIT;
819: global.js.gc_interval=JAVASCRIPT_GC_INTERVAL;
820: global.js.yield_interval=JAVASCRIPT_YIELD_INTERVAL;
821: global.sem_chk_freq=5; /* seconds */
822:
823: /* These are SBBSCTRL-specific */
824: LoginCommand="telnet://localhost";
825: ConfigCommand="%sscfg.exe %s -l25";
826: MinimizeToSysTray=false;
827: UndockableForms=false;
828: UseFileAssociations=true;
829: Initialized=false;
830:
1.1.1.2 ! root 831: loginAttemptListInit(&login_attempt_list);
! 832:
1.1 root 833: char* p;
834: if((p=getenv("SBBSCTRL"))!=NULL)
835: SAFECOPY(global.ctrl_dir,p);
836: p=lastchar(global.ctrl_dir);
837: if(*p!='/' && *p!='\\')
838: strcat(global.ctrl_dir,"\\");
839:
840: memset(&bbs_startup,0,sizeof(bbs_startup));
841: bbs_startup.size=sizeof(bbs_startup);
1.1.1.2 ! root 842: bbs_startup.cbdata=&bbs_log_list;
! 843: bbs_startup.event_cbdata=&event_log_list;
1.1 root 844: bbs_startup.first_node=1;
845: bbs_startup.last_node=4;
846: bbs_startup.options=BBS_OPT_XTRN_MINIMIZED|BBS_OPT_SYSOP_AVAILABLE;
847: bbs_startup.telnet_port=IPPORT_TELNET;
848: bbs_startup.telnet_interface=INADDR_ANY;
849: bbs_startup.rlogin_port=513;
850: bbs_startup.rlogin_interface=INADDR_ANY;
1.1.1.2 ! root 851: bbs_startup.lputs=lputs;
! 852: bbs_startup.event_lputs=lputs;
! 853: bbs_startup.errormsg=errormsg;
1.1 root 854: bbs_startup.status=bbs_status;
855: bbs_startup.clients=bbs_clients;
856: bbs_startup.started=bbs_started;
857: bbs_startup.recycle=recycle;
858: bbs_startup.terminated=bbs_terminated;
859: bbs_startup.thread_up=thread_up;
860: bbs_startup.client_on=client_on;
861: bbs_startup.socket_open=socket_open;
1.1.1.2 ! root 862: bbs_startup.login_attempt_list=&login_attempt_list;
1.1 root 863:
864: memset(&mail_startup,0,sizeof(mail_startup));
865: mail_startup.size=sizeof(mail_startup);
1.1.1.2 ! root 866: mail_startup.cbdata=&mail_log_list;
1.1 root 867: mail_startup.smtp_port=IPPORT_SMTP;
868: mail_startup.relay_port=IPPORT_SMTP;
869: mail_startup.pop3_port=110;
870: mail_startup.interface_addr=INADDR_ANY;
1.1.1.2 ! root 871: mail_startup.lputs=lputs;
! 872: mail_startup.errormsg=errormsg;
1.1 root 873: mail_startup.status=mail_status;
874: mail_startup.clients=mail_clients;
875: mail_startup.started=mail_started;
876: mail_startup.recycle=recycle;
877: mail_startup.terminated=mail_terminated;
878: mail_startup.options=MAIL_OPT_ALLOW_POP3;
879: mail_startup.thread_up=thread_up;
880: mail_startup.client_on=client_on;
881: mail_startup.socket_open=socket_open;
882: mail_startup.max_delivery_attempts=50;
883: mail_startup.rescan_frequency=3600; /* 60 minutes */
884: mail_startup.lines_per_yield=10;
885: mail_startup.max_clients=10;
886: mail_startup.max_msg_size=10*1024*1024;
1.1.1.2 ! root 887: mail_startup.login_attempt_list=&login_attempt_list;
1.1 root 888:
889: memset(&ftp_startup,0,sizeof(ftp_startup));
890: ftp_startup.size=sizeof(ftp_startup);
1.1.1.2 ! root 891: ftp_startup.cbdata=&ftp_log_list;
1.1 root 892: ftp_startup.port=IPPORT_FTP;
893: ftp_startup.interface_addr=INADDR_ANY;
1.1.1.2 ! root 894: ftp_startup.lputs=lputs;
! 895: ftp_startup.errormsg=errormsg;
1.1 root 896: ftp_startup.status=ftp_status;
897: ftp_startup.clients=ftp_clients;
898: ftp_startup.started=ftp_started;
899: ftp_startup.recycle=recycle;
900: ftp_startup.terminated=ftp_terminated;
901: ftp_startup.thread_up=thread_up;
902: ftp_startup.client_on=client_on;
903: ftp_startup.socket_open=socket_open;
904: ftp_startup.options
905: =FTP_OPT_INDEX_FILE|FTP_OPT_HTML_INDEX_FILE|FTP_OPT_ALLOW_QWK;
906: ftp_startup.max_clients=10;
907: strcpy(ftp_startup.index_file_name,"00index");
908: strcpy(ftp_startup.html_index_file,"00index.html");
909: strcpy(ftp_startup.html_index_script,"ftp-html.js");
1.1.1.2 ! root 910: ftp_startup.login_attempt_list=&login_attempt_list;
1.1 root 911:
912: memset(&web_startup,0,sizeof(web_startup));
913: web_startup.size=sizeof(web_startup);
1.1.1.2 ! root 914: web_startup.cbdata=&web_log_list;
! 915: web_startup.lputs=lputs;
! 916: web_startup.errormsg=errormsg;
1.1 root 917: web_startup.status=web_status;
918: web_startup.clients=web_clients;
919: web_startup.started=web_started;
920: web_startup.recycle=recycle;
921: web_startup.terminated=web_terminated;
922: web_startup.thread_up=thread_up;
923: web_startup.client_on=client_on;
924: web_startup.socket_open=socket_open;
1.1.1.2 ! root 925: web_startup.login_attempt_list=&login_attempt_list;
1.1 root 926:
927: memset(&services_startup,0,sizeof(services_startup));
928: services_startup.size=sizeof(services_startup);
1.1.1.2 ! root 929: services_startup.cbdata=&services_log_list;
1.1 root 930: services_startup.interface_addr=INADDR_ANY;
1.1.1.2 ! root 931: services_startup.lputs=lputs;
! 932: services_startup.errormsg=errormsg;
1.1 root 933: services_startup.status=services_status;
934: services_startup.clients=services_clients;
935: services_startup.started=services_started;
936: services_startup.recycle=recycle;
937: services_startup.terminated=services_terminated;
938: services_startup.thread_up=thread_up;
939: services_startup.client_on=client_on;
940: services_startup.socket_open=socket_open;
1.1.1.2 ! root 941: services_startup.login_attempt_list=&login_attempt_list;
1.1 root 942:
943: bbs_log=INVALID_HANDLE_VALUE;
944: event_log=INVALID_HANDLE_VALUE;
945: ftp_log=INVALID_HANDLE_VALUE;
946: web_log=INVALID_HANDLE_VALUE;
947: mail_log=INVALID_HANDLE_VALUE;
948: services_log=INVALID_HANDLE_VALUE;
949:
950: /* Default local "Spy Terminal" settings */
951: SpyTerminalFont=new TFont;
952: SpyTerminalFont->Name="Terminal";
953: SpyTerminalFont->Size=9;
954: SpyTerminalFont->Pitch=fpFixed;
955: SpyTerminalWidth=434;
956: SpyTerminalHeight=365;
957: SpyTerminalKeyboardActive=true;
958:
959: Application->OnMinimize=FormMinimize;
960:
961: /* Get pointers to NT Service functions */
962: HANDLE hSCMlib = LoadLibrary("ADVAPI32.DLL");
963: if(hSCMlib!=NULL) {
964: openSCManager=(OpenSCManager_t)GetProcAddress(hSCMlib, "OpenSCManagerA");
965: openService=(OpenService_t)GetProcAddress(hSCMlib,"OpenServiceA");
966: startService=(StartService_t)GetProcAddress(hSCMlib,"StartServiceA");
967: controlService=(ControlService_t)GetProcAddress(hSCMlib,"ControlService");
968: queryServiceStatus=(QueryServiceStatus_t)GetProcAddress(hSCMlib,"QueryServiceStatus");
969: queryServiceConfig=(QueryServiceConfig_t)GetProcAddress(hSCMlib,"QueryServiceConfigA");
970: closeServiceHandle=(CloseServiceHandle_t)GetProcAddress(hSCMlib,"CloseServiceHandle");
971: FreeLibrary(hSCMlib);
972: }
973:
974: /* Open Service Manager */
975: if(openSCManager!=NULL)
976: hSCManager = openSCManager(
977: NULL, // machine (NULL == local)
978: NULL, // database (NULL == default)
979: SC_MANAGER_CONNECT // access required
980: );
981:
982: /* Open Synchronet Services */
983: if(hSCManager!=NULL) {
984: bbs_svc = openService(hSCManager, NTSVC_NAME_BBS, GENERIC_READ|GENERIC_EXECUTE);
985: ftp_svc = openService(hSCManager, NTSVC_NAME_FTP, GENERIC_READ|GENERIC_EXECUTE);
986: web_svc = openService(hSCManager, NTSVC_NAME_WEB, GENERIC_READ|GENERIC_EXECUTE);
987: mail_svc = openService(hSCManager, NTSVC_NAME_MAIL, GENERIC_READ|GENERIC_EXECUTE);
988: services_svc = openService(hSCManager, NTSVC_NAME_SERVICES, GENERIC_READ|GENERIC_EXECUTE);
989: }
1.1.1.2 ! root 990:
! 991: {
! 992: int i;
! 993:
! 994: for(i=LOG_EMERG;i<=LOG_DEBUG;i++) {
! 995: LogFont[i] = new TFont;
! 996: LogFont[i]->Color=LogLevelColor[i];
! 997: if(i<=LOG_ERR)
! 998: LogFont[i]->Style = TFontStyles()<< fsBold;
! 999: }
! 1000: }
! 1001:
! 1002: listInit(&bbs_log_list, LINK_LIST_MUTEX);
! 1003: listInit(&event_log_list, LINK_LIST_MUTEX);
! 1004: listInit(&ftp_log_list, LINK_LIST_MUTEX);
! 1005: listInit(&web_log_list, LINK_LIST_MUTEX);
! 1006: listInit(&mail_log_list, LINK_LIST_MUTEX);
! 1007: listInit(&services_log_list, LINK_LIST_MUTEX);
! 1008:
! 1009: TelnetPause->DisableIfNoHandler=false;
! 1010: MailPause->DisableIfNoHandler=false;
! 1011: WebPause->DisableIfNoHandler=false;
! 1012: FtpPause->DisableIfNoHandler=false;
! 1013: ServicesPause->DisableIfNoHandler=false;
1.1 root 1014: }
1015: //---------------------------------------------------------------------------
1016: void __fastcall TMainForm::FileExitMenuItemClick(TObject *Sender)
1017: {
1018: Close();
1019: }
1020: void __fastcall TMainForm::FormCreate(TObject *Sender)
1021: {
1022: Height=400; // Just incase we mess it up in the IDE
1023: Width=700;
1024:
1025: // Verify SBBS.DLL version
1026: long bbs_ver = bbs_ver_num();
1027: if(bbs_ver != VERSION_HEX) {
1028: char str[128];
1029: sprintf(str,"Incorrect SBBS.DLL Version (%lX)",bbs_ver);
1030: Application->MessageBox(str,"ERROR",MB_OK|MB_ICONEXCLAMATION);
1031: Application->Terminate();
1032: }
1033:
1034: // Read Registry keys
1035: TRegistry* Registry=new TRegistry;
1036: if(!Registry->OpenKey(REG_KEY,true)) {
1037: Application->MessageBox("Error opening registry key"
1038: ,REG_KEY,MB_OK|MB_ICONEXCLAMATION);
1039: Application->Terminate();
1040: return;
1041: }
1042: if(Registry->ValueExists("MainFormTop"))
1043: Top=Registry->ReadInteger("MainFormTop");
1044: if(Registry->ValueExists("MainFormLeft"))
1045: Left=Registry->ReadInteger("MainFormLeft");
1046: if(Registry->ValueExists("MainFormHeight"))
1047: Height=Registry->ReadInteger("MainFormHeight");
1048: if(Registry->ValueExists("MainFormWidth"))
1049: Width=Registry->ReadInteger("MainFormWidth");
1050: else
1051: WindowState=wsMaximized; // Default to fullscreen
1052: if(Registry->ValueExists("SpyTerminalWidth"))
1053: SpyTerminalWidth=Registry->ReadInteger("SpyTerminalWidth");
1054: if(Registry->ValueExists("SpyTerminalHeight"))
1055: SpyTerminalHeight=Registry->ReadInteger("SpyTerminalHeight");
1056: if(Registry->ValueExists("SpyTerminalFontName"))
1057: SpyTerminalFont->Name=Registry->ReadString("SpyTerminalFontName");
1058: if(Registry->ValueExists("SpyTerminalFontSize"))
1059: SpyTerminalFont->Size=Registry->ReadInteger("SpyTerminalFontSize");
1060: if(Registry->ValueExists("SpyTerminalKeyboardActive"))
1061: SpyTerminalKeyboardActive
1062: =Registry->ReadBool("SpyTerminalKeyboardActive");
1063:
1064: Registry->CloseKey();
1065: delete Registry;
1066: }
1067: //---------------------------------------------------------------------------
1068: void __fastcall TMainForm::FormShow(TObject *Sender)
1069: {
1070: StartupTimer->Enabled=true;
1071: }
1072: //---------------------------------------------------------------------------
1073:
1074: void __fastcall TMainForm::ViewToolbarMenuItemClick(TObject *Sender)
1075: {
1076: Toolbar->Visible=ViewToolbarMenuItem->Checked;
1077: }
1078: //---------------------------------------------------------------------------
1079: BOOL NTsvcEnabled(SC_HANDLE svc, QUERY_SERVICE_CONFIG* config, DWORD config_size)
1080: {
1081: if(svc==NULL || startService==NULL || queryServiceStatus==NULL || config==NULL)
1082: return(FALSE);
1083:
1084: DWORD ret;
1085: if(!queryServiceConfig(svc,config,config_size,&ret))
1086: return(FALSE);
1087: if(config->dwStartType==SERVICE_DISABLED)
1088: return(FALSE);
1089: return(TRUE);
1090: }
1091: //---------------------------------------------------------------------------
1092: BOOL __fastcall TMainForm::bbsServiceEnabled(void)
1093: {
1094: return NTsvcEnabled(bbs_svc,bbs_svc_config,bbs_svc_config_size);
1095: }
1096: BOOL __fastcall TMainForm::mailServiceEnabled(void)
1097: {
1098: return NTsvcEnabled(mail_svc,mail_svc_config,mail_svc_config_size);
1099: }
1100: BOOL __fastcall TMainForm::ftpServiceEnabled(void)
1101: {
1102: return NTsvcEnabled(ftp_svc,ftp_svc_config,ftp_svc_config_size);
1103: }
1104: BOOL __fastcall TMainForm::webServiceEnabled(void)
1105: {
1106: return NTsvcEnabled(web_svc,web_svc_config,web_svc_config_size);
1107: }
1108: BOOL __fastcall TMainForm::servicesServiceEnabled(void)
1109: {
1110: return NTsvcEnabled(services_svc,services_svc_config,services_svc_config_size);
1111: }
1112: //---------------------------------------------------------------------------
1113: void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
1114: {
1115: UpTimer->Enabled=false; /* Stop updating the status bar */
1116: StatsTimer->Enabled=false;
1117:
1118: if(TrayIcon->Visible) /* minimized to tray? */
1119: TrayIcon->Visible=false; /* restore to avoid crash */
1120:
1121: /* This is necessary to save form sizes/positions */
1122: if(Initialized) /* Don't overwrite registry settings with defaults */
1123: SaveRegistrySettings(Sender);
1124:
1.1.1.2 ! root 1125: StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text="Terminating servers...";
1.1 root 1126: time_t start=time(NULL);
1127: while( (TelnetStop->Enabled && !bbsServiceEnabled())
1128: || (MailStop->Enabled && !mailServiceEnabled())
1129: || (FtpStop->Enabled && !ftpServiceEnabled())
1130: || (WebStop->Enabled && !webServiceEnabled())
1131: || (ServicesStop->Enabled && !servicesServiceEnabled())) {
1132: if(time(NULL)-start>30)
1133: break;
1134: Application->ProcessMessages();
1135: YIELD();
1136: }
1.1.1.2 ! root 1137: StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text="Closing...";
1.1 root 1138: Application->ProcessMessages();
1139:
1140: LogTimer->Enabled=false;
1.1.1.2 ! root 1141:
1.1 root 1142: ServiceStatusTimer->Enabled=false;
1143: NodeForm->Timer->Enabled=false;
1144: ClientForm->Timer->Enabled=false;
1145: }
1146: //---------------------------------------------------------------------------
1147: void __fastcall TMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)
1148: {
1149: CanClose=false;
1150:
1151: if(TelnetStop->Enabled && !bbsServiceEnabled()) {
1152: if(!terminating && TelnetForm->ProgressBar->Position
1.1.1.2 ! root 1153: && Application->MessageBox("Shut down the Terminal Server?"
! 1154: ,"Terminal Server In Use", MB_OKCANCEL)!=IDOK)
1.1 root 1155: return;
1156: TelnetStopExecute(Sender);
1157: }
1158:
1159: if(MailStop->Enabled && !mailServiceEnabled()) {
1160: if(!terminating && MailForm->ProgressBar->Position
1161: && Application->MessageBox("Shut down the Mail Server?"
1162: ,"Mail Server In Use", MB_OKCANCEL)!=IDOK)
1163: return;
1164: MailStopExecute(Sender);
1165: }
1166:
1167: if(FtpStop->Enabled && !ftpServiceEnabled()) {
1168: if(!terminating && FtpForm->ProgressBar->Position
1169: && Application->MessageBox("Shut down the FTP Server?"
1170: ,"FTP Server In Use", MB_OKCANCEL)!=IDOK)
1171: return;
1172: FtpStopExecute(Sender);
1173: }
1174:
1175: if(WebStop->Enabled && !webServiceEnabled()) {
1176: if(!terminating && WebForm->ProgressBar->Position
1177: && Application->MessageBox("Shut down the Web Server?"
1178: ,"Web Server In Use", MB_OKCANCEL)!=IDOK)
1179: return;
1180: WebStopExecute(Sender);
1181: }
1182:
1183: if(ServicesStop->Enabled && !servicesServiceEnabled())
1184: ServicesStopExecute(Sender);
1185:
1186: CanClose=true;
1187: }
1188:
1189: //---------------------------------------------------------------------------
1190: BOOL StartNTsvc(SC_HANDLE svc, SERVICE_STATUS* status, QUERY_SERVICE_CONFIG* config, DWORD config_size)
1191: {
1192: if(svc==NULL || startService==NULL || queryServiceStatus==NULL || config==NULL)
1193: return(FALSE);
1194:
1195: DWORD ret;
1196: if(!queryServiceConfig(svc,config,config_size,&ret))
1197: return(FALSE);
1198: if(config->dwStartType==SERVICE_DISABLED)
1199: return(FALSE);
1200: if(!queryServiceStatus(svc,status))
1201: return(FALSE);
1202: if(status->dwCurrentState!=SERVICE_STOPPED)
1203: return(TRUE);
1204: if(!startService(svc,0,NULL))
1205: Application->MessageBox(AnsiString("ERROR " + IntToStr(GetLastError()) +
1206: " starting " + config->lpDisplayName).c_str()
1207: ,"ERROR"
1208: ,MB_OK|MB_ICONEXCLAMATION);
1209: return(TRUE);
1210: }
1211: //---------------------------------------------------------------------------
1212: void __fastcall TMainForm::TelnetStartExecute(TObject *Sender)
1213: {
1214: if(!StartNTsvc(bbs_svc,&bbs_svc_status,bbs_svc_config,bbs_svc_config_size))
1215: bbs_start();
1216: }
1217: //---------------------------------------------------------------------------
1218: void __fastcall TMainForm::ServicesStartExecute(TObject *Sender)
1219: {
1220: if(StartNTsvc(services_svc,&services_svc_status,services_svc_config,services_svc_config_size))
1221: return;
1222: Screen->Cursor=crAppStart;
1223: services_status(NULL, "Starting");
1224:
1225: FILE* fp=fopen(ini_file,"r");
1226: sbbs_read_ini(fp
1227: ,&MainForm->global
1228: ,NULL ,NULL
1229: ,NULL ,NULL
1230: ,NULL ,NULL
1231: ,NULL ,NULL
1232: ,NULL ,&services_startup
1233: );
1234: if(fp!=NULL)
1235: fclose(fp);
1236:
1237: _beginthread((void(*)(void*))services_thread,0,&services_startup);
1238: Application->ProcessMessages();
1239: }
1240:
1241: //---------------------------------------------------------------------------
1242: BOOL StopNTsvc(SC_HANDLE svc, SERVICE_STATUS* status)
1243: {
1244: if(svc==NULL || controlService==NULL)
1245: return(FALSE);
1246:
1247: return controlService(svc,SERVICE_CONTROL_STOP,status);
1248: }
1249:
1250: //---------------------------------------------------------------------------
1251:
1252: void __fastcall TMainForm::ServicesStopExecute(TObject *Sender)
1253: {
1254: if(StopNTsvc(services_svc,&services_svc_status))
1255: return;
1256: Screen->Cursor=crAppStart;
1257: services_status(NULL, "Terminating");
1258: services_terminate();
1259: Application->ProcessMessages();
1260: }
1261: //---------------------------------------------------------------------------
1262:
1263: void __fastcall TMainForm::TelnetStopExecute(TObject *Sender)
1264: {
1265: if(StopNTsvc(bbs_svc,&bbs_svc_status))
1266: return;
1267: Screen->Cursor=crAppStart;
1268: bbs_status(NULL, "Terminating");
1269: bbs_terminate();
1270: Application->ProcessMessages();
1271: }
1272: //---------------------------------------------------------------------------
1273:
1274: void __fastcall TMainForm::TelnetConfigureExecute(TObject *Sender)
1275: {
1276: static inside;
1277: if(inside) return;
1278: inside=true;
1279:
1280: Application->CreateForm(__classid(TTelnetCfgDlg), &TelnetCfgDlg);
1281: TelnetCfgDlg->ShowModal();
1282: delete TelnetCfgDlg;
1283:
1284: inside=false;
1285: }
1286: //---------------------------------------------------------------------------
1287:
1288:
1289: void __fastcall TMainForm::NodeListStartExecute(TObject *Sender)
1290: {
1291: NodeForm->Timer->Enabled=true;
1292: NodeListStart->Enabled=false;
1293: NodeListStop->Enabled=true;
1294: }
1295: //---------------------------------------------------------------------------
1296:
1297: void __fastcall TMainForm::NodeListStopExecute(TObject *Sender)
1298: {
1299: NodeForm->Timer->Enabled=false;
1300: NodeListStart->Enabled=true;
1301: NodeListStop->Enabled=false;
1302: }
1303: //---------------------------------------------------------------------------
1304:
1305:
1306: void __fastcall TMainForm::MailConfigureExecute(TObject *Sender)
1307: {
1308: static inside;
1309: if(inside) return;
1310: inside=true;
1311:
1312: Application->CreateForm(__classid(TMailCfgDlg), &MailCfgDlg);
1313: MailCfgDlg->ShowModal();
1314: delete MailCfgDlg;
1315:
1316: inside=false;
1317: }
1318: //---------------------------------------------------------------------------
1319:
1320: void __fastcall TMainForm::MailStartExecute(TObject *Sender)
1321: {
1322: if(!StartNTsvc(mail_svc,&mail_svc_status,mail_svc_config,mail_svc_config_size))
1323: mail_start();
1324: }
1325: //---------------------------------------------------------------------------
1326:
1327: void __fastcall TMainForm::MailStopExecute(TObject *Sender)
1328: {
1329: if(StopNTsvc(mail_svc,&mail_svc_status))
1330: return;
1331: Screen->Cursor=crAppStart;
1332: mail_status(NULL, "Terminating");
1333: mail_terminate();
1334: Application->ProcessMessages();
1335: }
1336: //---------------------------------------------------------------------------
1337: void __fastcall TMainForm::ViewTelnetExecute(TObject *Sender)
1338: {
1339: TelnetForm->Visible=ViewTelnet->Checked;
1340: }
1341: //---------------------------------------------------------------------------
1342: void __fastcall TMainForm::ViewEventsExecute(TObject *Sender)
1343: {
1344: EventsForm->Visible=ViewEvents->Checked;
1345: }
1346: //---------------------------------------------------------------------------
1347:
1348: void __fastcall TMainForm::ViewNodesExecute(TObject *Sender)
1349: {
1350: NodeForm->Visible=ViewNodes->Checked;
1351: }
1352: //---------------------------------------------------------------------------
1353:
1354: void __fastcall TMainForm::ViewMailServerExecute(TObject *Sender)
1355: {
1356: MailForm->Visible=ViewMailServer->Checked;
1357: }
1358: //---------------------------------------------------------------------------
1359:
1360: void __fastcall TMainForm::ViewFtpServerExecute(TObject *Sender)
1361: {
1362: FtpForm->Visible=ViewFtpServer->Checked;
1363: }
1364: //---------------------------------------------------------------------------
1365: void __fastcall TMainForm::ViewWebServerExecute(TObject *Sender)
1366: {
1367: WebForm->Visible=ViewWebServer->Checked;
1368: }
1369: //---------------------------------------------------------------------------
1370: void __fastcall TMainForm::ViewServicesExecute(TObject *Sender)
1371: {
1372: ServicesForm->Visible=ViewServices->Checked;
1373: }
1374: //---------------------------------------------------------------------------
1375: void __fastcall TMainForm::ViewStatsExecute(TObject *Sender)
1376: {
1377: StatsForm->Visible=ViewStats->Checked;
1378: }
1379: //---------------------------------------------------------------------------
1380: void __fastcall TMainForm::ViewClientsExecute(TObject *Sender)
1381: {
1382: ClientForm->Visible=ViewClients->Checked;
1383: }
1384: //---------------------------------------------------------------------------
1385: void __fastcall TMainForm::FtpStartExecute(TObject *Sender)
1386: {
1387: if(!StartNTsvc(ftp_svc,&ftp_svc_status,ftp_svc_config,ftp_svc_config_size))
1388: ftp_start();
1389: }
1390: //---------------------------------------------------------------------------
1391:
1392: void __fastcall TMainForm::FtpStopExecute(TObject *Sender)
1393: {
1394: if(StopNTsvc(ftp_svc,&ftp_svc_status))
1395: return;
1396: Screen->Cursor=crAppStart;
1397: ftp_status(NULL, "Terminating");
1398: ftp_terminate();
1399: Application->ProcessMessages();
1400: }
1401: //---------------------------------------------------------------------------
1402:
1403: void __fastcall TMainForm::FtpConfigureExecute(TObject *Sender)
1404: {
1405: static inside;
1406: if(inside) return;
1407: inside=true;
1408:
1409: Application->CreateForm(__classid(TFtpCfgDlg), &FtpCfgDlg);
1410: FtpCfgDlg->ShowModal();
1411: delete FtpCfgDlg;
1412:
1413: inside=false;
1414: }
1415: //---------------------------------------------------------------------------
1416: void __fastcall TMainForm::WebStartExecute(TObject *Sender)
1417: {
1418: if(!StartNTsvc(web_svc,&web_svc_status,web_svc_config,web_svc_config_size))
1419: web_start();
1420: }
1421: //---------------------------------------------------------------------------
1422: void __fastcall TMainForm::WebStopExecute(TObject *Sender)
1423: {
1424: if(StopNTsvc(web_svc,&web_svc_status))
1425: return;
1426: Screen->Cursor=crAppStart;
1427: web_status(NULL, "Terminating");
1428: web_terminate();
1429: Application->ProcessMessages();
1430: }
1431: //---------------------------------------------------------------------------
1432: void __fastcall TMainForm::WebConfigureExecute(TObject *Sender)
1433: {
1434: static inside;
1435: if(inside) return;
1436: inside=true;
1437:
1438: Application->CreateForm(__classid(TWebCfgDlg), &WebCfgDlg);
1439: WebCfgDlg->ShowModal();
1440: delete WebCfgDlg;
1441:
1442: inside=false;
1443: }
1444: //---------------------------------------------------------------------------
1445: void __fastcall TMainForm::BBSConfigureMenuItemClick(TObject *Sender)
1446: {
1447: char str[256];
1448:
1449: sprintf(str,ConfigCommand.c_str()
1450: ,cfg.exec_dir, cfg.ctrl_dir);
1451: STARTUPINFO startup_info={0};
1452: PROCESS_INFORMATION process_info;
1453: startup_info.cb=sizeof(startup_info);
1454: startup_info.lpTitle="Synchronet Configuration Utility";
1455: CreateProcess(
1456: NULL, // pointer to name of executable module
1457: str, // pointer to command line string
1458: NULL, // process security attributes
1459: NULL, // thread security attributes
1460: FALSE, // handle inheritance flag
1461: CREATE_NEW_CONSOLE|CREATE_SEPARATE_WOW_VDM, // creation flags
1462: NULL, // pointer to new environment block
1463: cfg.ctrl_dir, // pointer to current directory name
1464: &startup_info, // pointer to STARTUPINFO
1465: &process_info // pointer to PROCESS_INFORMATION
1466: );
1467: // Resource leak if you don't close these:
1468: CloseHandle(process_info.hThread);
1469: CloseHandle(process_info.hProcess);
1470: }
1471: //---------------------------------------------------------------------------
1472:
1473:
1474:
1475:
1476: void __fastcall TMainForm::NodeCloseButtonClick(TObject *Sender)
1477: {
1478: ViewNodesExecute(Sender);
1479: }
1480: //---------------------------------------------------------------------------
1481:
1482: void __fastcall TMainForm::TelnetCloseButtonClick(TObject *Sender)
1483: {
1484: ViewTelnetExecute(Sender);
1485: }
1486: //---------------------------------------------------------------------------
1487:
1488: void __fastcall TMainForm::MailCloseButtonClick(TObject *Sender)
1489: {
1490: ViewMailServerExecute(Sender);
1491: }
1492: //---------------------------------------------------------------------------
1493:
1494: void __fastcall TMainForm::FtpCloseButtonClick(TObject *Sender)
1495: {
1496: ViewFtpServerExecute(Sender);
1497: }
1498: //---------------------------------------------------------------------------
1499: void __fastcall TMainForm::StatsTimerTick(TObject *Sender)
1500: {
1501: char str[128];
1502: int i;
1503: static stats_t stats;
1504: static users;
1505: static newusers;
1506: static counter;
1507:
1508: if(!StatsForm->Visible)
1509: return;
1510:
1511: getstats(&cfg,0,&stats);
1512:
1513: StatsForm->TotalLogons->Caption=AnsiString(stats.logons);
1514: StatsForm->LogonsToday->Caption=AnsiString(stats.ltoday);
1515: StatsForm->TotalTimeOn->Caption=AnsiString(stats.timeon);
1516: StatsForm->TimeToday->Caption=AnsiString(stats.ttoday);
1517: StatsForm->TotalEMail->Caption=AnsiString(getmail(&cfg,0,0));
1518: StatsForm->EMailToday->Caption=AnsiString(stats.etoday);
1519: StatsForm->TotalFeedback->Caption=AnsiString(getmail(&cfg,1,0));
1520: StatsForm->FeedbackToday->Caption=AnsiString(stats.ftoday);
1521: /* Don't scan a large user database more often than necessary */
1522: if(!counter || users<100 || (counter%(users/100))==0 || stats.nusers!=newusers)
1523: users=total_users(&cfg);
1524: StatsForm->TotalUsers->Caption=AnsiString(users);
1525: StatsForm->NewUsersToday->Caption=AnsiString(newusers=stats.nusers);
1526: StatsForm->PostsToday->Caption=AnsiString(stats.ptoday);
1527: StatsForm->UploadedFiles->Caption=AnsiString(stats.uls);
1528: if(stats.ulb>=1024*1024)
1529: sprintf(str,"%.1fM",stats.ulb/(1024.0*1024.0));
1530: else if(stats.ulb>=1024)
1531: sprintf(str,"%luK",stats.ulb/1024);
1532: else
1533: sprintf(str,"%lu",stats.ulb);
1534: StatsForm->UploadedBytes->Caption=AnsiString(str);
1535: StatsForm->DownloadedFiles->Caption=AnsiString(stats.dls);
1536: if(stats.dlb>=1024*1024)
1537: sprintf(str,"%.1fM",stats.dlb/(1024.0*1024.0));
1538: else if(stats.dlb>=1024)
1539: sprintf(str,"%luK",stats.dlb/1024);
1540: else
1541: sprintf(str,"%lu",stats.dlb);
1542: StatsForm->DownloadedBytes->Caption=AnsiString(str);
1543:
1544: counter++;
1545: }
1546: //---------------------------------------------------------------------------
1547: void __fastcall TMainForm::StatsCloseButtonClick(TObject *Sender)
1548: {
1549: ViewStatsExecute(Sender);
1550: }
1551: //---------------------------------------------------------------------------
1552: enum {
1553: PAGE_UPPERLEFT
1554: ,PAGE_UPPERRIGHT
1555: ,PAGE_LOWERRIGHT
1556: ,PAGE_LOWERLEFT
1557: };
1558: TPageControl* __fastcall TMainForm::PageControl(int num)
1559: {
1560: switch(num)
1561: {
1562: case PAGE_UPPERLEFT:
1563: return(UpperLeftPageControl);
1564: case PAGE_UPPERRIGHT:
1565: return(UpperRightPageControl);
1566: case PAGE_LOWERRIGHT:
1567: return(LowerRightPageControl);
1568: case PAGE_LOWERLEFT:
1569: return(LowerLeftPageControl);
1570: }
1571: return(NULL);
1572: }
1573: int __fastcall TMainForm::PageNum(TPageControl* obj)
1574: {
1575: if(obj==UpperLeftPageControl)
1576: return(PAGE_UPPERLEFT);
1577: if(obj==UpperRightPageControl)
1578: return(PAGE_UPPERRIGHT);
1579: if(obj==LowerRightPageControl)
1580: return(PAGE_LOWERRIGHT);
1581: if(obj==LowerLeftPageControl)
1582: return(PAGE_LOWERLEFT);
1583: return(PAGE_LOWERRIGHT);
1584: }
1585: TColor __fastcall TMainForm::ReadColor(TRegistry* Registry
1586: ,AnsiString name)
1587: {
1588: if(Registry->ValueExists(name + "Color"))
1589: return(StringToColor(Registry->ReadString(name + "Color")));
1590:
1591: return(clWindow); // Default
1592: }
1593: void __fastcall TMainForm::WriteColor(TRegistry* Registry
1594: ,AnsiString name, TColor color)
1595: {
1596: Registry->WriteString(name + "Color", ColorToString(color));
1597: }
1598:
1599: int FontStyleToInt(TFont* Font)
1600: {
1601: int style=0;
1602: for(int i=fsBold;i<=fsStrikeOut;i++)
1603: if(Font->Style.Contains((TFontStyle)i))
1604: style|=(1<<i);
1605: return(style);
1606: }
1607:
1608: void IntToFontStyle(int style, TFont* Font)
1609: {
1610: Font->Style=Font->Style.Clear();
1611: for(int i=fsBold;i<=fsStrikeOut;i++)
1612: if(style&(1<<i))
1613: Font->Style=Font->Style<<(TFontStyle)i;
1614: }
1615:
1616: void __fastcall TMainForm::ReadFont(AnsiString subkey, TFont* Font)
1617: {
1618: // Read Registry keys
1619: TRegistry* Registry=new TRegistry;
1620: AnsiString key = REG_KEY + subkey + "Font";
1621: if(!Registry->OpenKey(key,true)) {
1622: Application->MessageBox("Error opening registry key"
1623: ,key.c_str(),MB_OK|MB_ICONEXCLAMATION);
1624: Application->Terminate();
1625: return;
1626: }
1627: if(Registry->ValueExists("Name"))
1628: Font->Name=Registry->ReadString("Name");
1629: if(Registry->ValueExists("Color"))
1630: Font->Color=StringToColor(Registry->ReadString("Color"));
1631: if(Registry->ValueExists("Height"))
1632: Font->Height=Registry->ReadInteger("Height");
1633: if(Registry->ValueExists("Size"))
1634: Font->Size=Registry->ReadInteger("Size");
1635:
1636: if(Registry->ValueExists("Style"))
1637: IntToFontStyle(Registry->ReadInteger("Style"),Font);
1638:
1639: Registry->CloseKey();
1640: delete Registry;
1641: }
1642: void __fastcall TMainForm::WriteFont(AnsiString subkey, TFont* Font)
1643: {
1644: // Read Registry keys
1645: TRegistry* Registry=new TRegistry;
1646: AnsiString key = REG_KEY + subkey + "Font";
1647: if(!Registry->OpenKey(key,true)) {
1648: Application->MessageBox("Error opening registry key"
1649: ,key.c_str(),MB_OK|MB_ICONEXCLAMATION);
1650: Application->Terminate();
1651: return;
1652: }
1653: Registry->WriteString("Name",Font->Name);
1654: Registry->WriteString("Color",ColorToString(Font->Color));
1655: Registry->WriteInteger("Height",Font->Height);
1656: Registry->WriteInteger("Size",Font->Size);
1657: Registry->WriteInteger("Style",FontStyleToInt(Font));
1658:
1659: Registry->CloseKey();
1660: delete Registry;
1661: }
1662: void __fastcall TMainForm::StartupTimerTick(TObject *Sender)
1663: {
1664: bool TelnetFormFloating=false;
1665: bool EventsFormFloating=false;
1666: bool ServicesFormFloating=false;
1667: bool NodeFormFloating=false;
1668: bool StatsFormFloating=false;
1669: bool ClientFormFloating=false;
1670: bool MailFormFloating=false;
1671: bool FtpFormFloating=false;
1672: bool WebFormFloating=false;
1673: int NodeFormPage=PAGE_UPPERLEFT;
1674: int StatsFormPage=PAGE_UPPERLEFT;
1675: int ClientFormPage=PAGE_UPPERLEFT;
1676: int TelnetFormPage=PAGE_LOWERLEFT;
1677: int EventsFormPage=PAGE_LOWERLEFT;
1678: int MailFormPage=PAGE_UPPERRIGHT;
1679: int FtpFormPage=PAGE_LOWERRIGHT;
1680: int WebFormPage=PAGE_LOWERRIGHT;
1681: int ServicesFormPage=PAGE_LOWERRIGHT;
1682: #if 0 /* not yet working */
1683: bool TelnetFormVisible=true;
1684: bool EventsFormVisible=true;
1685: bool ServicesFormVisible=true;
1686: bool NodeFormVisible=true;
1687: bool StatsFormVisible=true;
1688: bool ClientFormVisible=true;
1689: bool MailFormVisible=true;
1690: bool FtpFormVisible=true;
1691: bool WebFormVisible=true;
1692: #endif
1693:
1694: AnsiString Str;
1695:
1696: delete StartupTimer;
1697:
1698: // Read Registry keys
1699: TRegistry* Registry=new TRegistry;
1700: if(!Registry->OpenKey(REG_KEY,true)) {
1701: Application->MessageBox("Error opening registry key"
1702: ,REG_KEY,MB_OK|MB_ICONEXCLAMATION);
1703: Application->Terminate();
1704: return;
1705: }
1706:
1707: TopPanel->Height=Height/3;
1708: UpperLeftPageControl->Width=Width/2;
1709: LowerLeftPageControl->Width=Width/2;
1710:
1711: if(Registry->ValueExists("TopPanelHeight"))
1712: TopPanel->Height=Registry->ReadInteger("TopPanelHeight");
1713: if(Registry->ValueExists("UpperLeftPageControlWidth"))
1714: UpperLeftPageControl->Width
1715: =Registry->ReadInteger("UpperLeftPageControlWidth");
1716: if(Registry->ValueExists("LowerLeftPageControlWidth"))
1717: LowerLeftPageControl->Width
1718: =Registry->ReadInteger("LowerLeftPageControlWidth");
1719: if(Registry->ValueExists("UndockableForms"))
1720: UndockableForms=Registry->ReadBool("UndockableForms");
1721:
1722: if(UndockableForms) {
1723: if(Registry->ValueExists("TelnetFormFloating"))
1724: TelnetFormFloating=Registry->ReadBool("TelnetFormFloating");
1725: if(Registry->ValueExists("EventsFormFloating"))
1726: EventsFormFloating=Registry->ReadBool("EventsFormFloating");
1727: if(Registry->ValueExists("ServicesFormFloating"))
1728: ServicesFormFloating=Registry->ReadBool("ServicesFormFloating");
1729: if(Registry->ValueExists("NodeFormFloating"))
1730: NodeFormFloating=Registry->ReadBool("NodeFormFloating");
1731: if(Registry->ValueExists("StatsFormFloating"))
1732: StatsFormFloating=Registry->ReadBool("StatsFormFloating");
1733: if(Registry->ValueExists("ClientFormFloating"))
1734: ClientFormFloating=Registry->ReadBool("ClientFormFloating");
1735: if(Registry->ValueExists("MailFormFloating"))
1736: MailFormFloating=Registry->ReadBool("MailFormFloating");
1737: if(Registry->ValueExists("FtpFormFloating"))
1738: FtpFormFloating=Registry->ReadBool("FtpFormFloating");
1739: if(Registry->ValueExists("WebFormFloating"))
1740: WebFormFloating=Registry->ReadBool("WebFormFloating");
1741: }
1742: #if 0
1743: if(Registry->ValueExists("TelnetFormVisible"))
1744: TelnetFormVisible=Registry->ReadBool("TelnetFormVisible");
1745: if(Registry->ValueExists("EventsFormVisible"))
1746: EventsFormVisible=Registry->ReadBool("EventsFormVisible");
1747: if(Registry->ValueExists("ServicesFormVisible"))
1748: ServicesFormVisible=Registry->ReadBool("ServicesFormVisible");
1749: if(Registry->ValueExists("NodeFormVisible"))
1750: NodeFormVisible=Registry->ReadBool("NodeFormVisible");
1751: if(Registry->ValueExists("StatsFormVisible"))
1752: StatsFormVisible=Registry->ReadBool("StatsFormVisible");
1753: if(Registry->ValueExists("ClientFormVisible"))
1754: ClientFormVisible=Registry->ReadBool("ClientFormVisible");
1755: if(Registry->ValueExists("MailFormVisible"))
1756: MailFormVisible=Registry->ReadBool("MailFormVisible");
1757: if(Registry->ValueExists("FtpFormVisible"))
1758: FtpFormVisible=Registry->ReadBool("FtpFormVisible");
1759: if(Registry->ValueExists("WebFormVisible"))
1760: WebFormVisible=Registry->ReadBool("WebFormVisible");
1761: #endif
1762: if(Registry->ValueExists("TelnetFormPage"))
1763: TelnetFormPage=Registry->ReadInteger("TelnetFormPage");
1764: if(Registry->ValueExists("EventsFormPage"))
1765: EventsFormPage=Registry->ReadInteger("EventsFormPage");
1766: if(Registry->ValueExists("ServicesFormPage"))
1767: ServicesFormPage=Registry->ReadInteger("ServicesFormPage");
1768: if(Registry->ValueExists("NodeFormPage"))
1769: NodeFormPage=Registry->ReadInteger("NodeFormPage");
1770: if(Registry->ValueExists("StatsFormPage"))
1771: StatsFormPage=Registry->ReadInteger("StatsFormPage");
1772: if(Registry->ValueExists("ClientFormPage"))
1773: ClientFormPage=Registry->ReadInteger("ClientFormPage");
1774: if(Registry->ValueExists("MailFormPage"))
1775: MailFormPage=Registry->ReadInteger("MailFormPage");
1776: if(Registry->ValueExists("FtpFormPage"))
1777: FtpFormPage=Registry->ReadInteger("FtpFormPage");
1778: if(Registry->ValueExists("WebFormPage"))
1779: WebFormPage=Registry->ReadInteger("WebFormPage");
1780:
1781: TelnetForm->Log->Color=ReadColor(Registry,"TelnetLog");
1782: ReadFont("TelnetLog",TelnetForm->Log->Font);
1783: EventsForm->Log->Color=ReadColor(Registry,"EventsLog");
1784: ReadFont("EventsLog",EventsForm->Log->Font);
1785: ServicesForm->Log->Color=ReadColor(Registry,"ServicesLog");
1786: ReadFont("ServicesLog",ServicesForm->Log->Font);
1787: MailForm->Log->Color=ReadColor(Registry,"MailLog");
1788: ReadFont("MailLog",MailForm->Log->Font);
1789: FtpForm->Log->Color=ReadColor(Registry,"FtpLog");
1790: ReadFont("FtpLog",FtpForm->Log->Font);
1791: WebForm->Log->Color=ReadColor(Registry,"WebLog");
1792: ReadFont("WebLog",WebForm->Log->Font);
1793: NodeForm->ListBox->Color=ReadColor(Registry,"NodeList");
1794: ReadFont("NodeList",NodeForm->ListBox->Font);
1795: ClientForm->ListView->Color=ReadColor(Registry,"ClientList");
1796: ReadFont("ClientList",ClientForm->ListView->Font);
1797:
1.1.1.2 ! root 1798: {
! 1799: int i;
! 1800:
! 1801: for(i=LOG_EMERG; i<=LOG_DEBUG; i++)
! 1802: ReadFont("Log" + AnsiString(LogLevelDesc[i]), LogFont[i]);
! 1803: }
! 1804:
1.1 root 1805: if(Registry->ValueExists("TelnetFormTop"))
1806: TelnetForm->Top=Registry->ReadInteger("TelnetFormTop");
1807: if(Registry->ValueExists("TelnetFormLeft"))
1808: TelnetForm->Left=Registry->ReadInteger("TelnetFormLeft");
1809: if(Registry->ValueExists("TelnetFormWidth"))
1810: TelnetForm->Width=Registry->ReadInteger("TelnetFormWidth");
1811: if(Registry->ValueExists("TelnetFormHeight"))
1812: TelnetForm->Height=Registry->ReadInteger("TelnetFormHeight");
1813:
1814: if(Registry->ValueExists("EventsFormTop"))
1815: EventsForm->Top=Registry->ReadInteger("EventsFormTop");
1816: if(Registry->ValueExists("EventsFormLeft"))
1817: EventsForm->Left=Registry->ReadInteger("EventsFormLeft");
1818: if(Registry->ValueExists("EventsFormWidth"))
1819: EventsForm->Width=Registry->ReadInteger("EventsFormWidth");
1820: if(Registry->ValueExists("EventsFormHeight"))
1821: EventsForm->Height=Registry->ReadInteger("EventsFormHeight");
1822:
1823: if(Registry->ValueExists("ServicesFormTop"))
1824: ServicesForm->Top=Registry->ReadInteger("ServicesFormTop");
1825: if(Registry->ValueExists("ServicesFormLeft"))
1826: ServicesForm->Left=Registry->ReadInteger("ServicesFormLeft");
1827: if(Registry->ValueExists("ServicesFormWidth"))
1828: ServicesForm->Width=Registry->ReadInteger("ServicesFormWidth");
1829: if(Registry->ValueExists("ServicesFormHeight"))
1830: ServicesForm->Height=Registry->ReadInteger("ServicesFormHeight");
1831:
1832: if(Registry->ValueExists("FtpFormTop"))
1833: FtpForm->Top=Registry->ReadInteger("FtpFormTop");
1834: if(Registry->ValueExists("FtpFormLeft"))
1835: FtpForm->Left=Registry->ReadInteger("FtpFormLeft");
1836: if(Registry->ValueExists("FtpFormWidth"))
1837: FtpForm->Width=Registry->ReadInteger("FtpFormWidth");
1838: if(Registry->ValueExists("FtpFormHeight"))
1839: FtpForm->Height=Registry->ReadInteger("FtpFormHeight");
1840:
1841: if(Registry->ValueExists("WebFormTop"))
1842: WebForm->Top=Registry->ReadInteger("WebFormTop");
1843: if(Registry->ValueExists("WebFormLeft"))
1844: WebForm->Left=Registry->ReadInteger("WebFormLeft");
1845: if(Registry->ValueExists("WebFormWidth"))
1846: WebForm->Width=Registry->ReadInteger("WebFormWidth");
1847: if(Registry->ValueExists("WebFormHeight"))
1848: WebForm->Height=Registry->ReadInteger("WebFormHeight");
1849:
1850: if(Registry->ValueExists("MailFormTop"))
1851: MailForm->Top=Registry->ReadInteger("MailFormTop");
1852: if(Registry->ValueExists("MailFormLeft"))
1853: MailForm->Left=Registry->ReadInteger("MailFormLeft");
1854: if(Registry->ValueExists("MailFormWidth"))
1855: MailForm->Width=Registry->ReadInteger("MailFormWidth");
1856: if(Registry->ValueExists("MailFormHeight"))
1857: MailForm->Height=Registry->ReadInteger("MailFormHeight");
1858:
1859: if(Registry->ValueExists("NodeFormTop"))
1860: NodeForm->Top=Registry->ReadInteger("NodeFormTop");
1861: if(Registry->ValueExists("NodeFormLeft"))
1862: NodeForm->Left=Registry->ReadInteger("NodeFormLeft");
1863: if(Registry->ValueExists("NodeFormWidth"))
1864: NodeForm->Width=Registry->ReadInteger("NodeFormWidth");
1865: if(Registry->ValueExists("NodeFormHeight"))
1866: NodeForm->Height=Registry->ReadInteger("NodeFormHeight");
1867:
1868: if(Registry->ValueExists("StatsFormTop"))
1869: StatsForm->Top=Registry->ReadInteger("StatsFormTop");
1870: if(Registry->ValueExists("StatsFormLeft"))
1871: StatsForm->Left=Registry->ReadInteger("StatsFormLeft");
1872: if(Registry->ValueExists("StatsFormWidth"))
1873: StatsForm->Width=Registry->ReadInteger("StatsFormWidth");
1874: if(Registry->ValueExists("StatsFormHeight"))
1875: StatsForm->Height=Registry->ReadInteger("StatsFormHeight");
1876:
1877: if(Registry->ValueExists("ClientFormTop"))
1878: ClientForm->Top=Registry->ReadInteger("ClientFormTop");
1879: if(Registry->ValueExists("ClientFormLeft"))
1880: ClientForm->Left=Registry->ReadInteger("ClientFormLeft");
1881: if(Registry->ValueExists("ClientFormWidth"))
1882: ClientForm->Width=Registry->ReadInteger("ClientFormWidth");
1883: if(Registry->ValueExists("ClientFormHeight"))
1884: ClientForm->Height=Registry->ReadInteger("ClientFormHeight");
1885:
1886: for(int i=0;i<ClientForm->ListView->Columns->Count;i++) {
1887: char str[128];
1888: sprintf(str,"ClientListColumn%dWidth",i);
1889: if(Registry->ValueExists(str))
1890: ClientForm->ListView->Columns->Items[i]->Width
1891: =Registry->ReadInteger(str);
1892: }
1893:
1894: if(Registry->ValueExists("ToolbarVisible"))
1895: Toolbar->Visible=Registry->ReadBool("ToolbarVisible");
1896:
1897: ViewToolbarMenuItem->Checked=Toolbar->Visible;
1898: ViewStatusBarMenuItem->Checked=StatusBar->Visible;
1899:
1900: if(Registry->ValueExists("MaxLogLen"))
1901: MaxLogLen=Registry->ReadInteger("MaxLogLen");
1902:
1903: if(Registry->ValueExists("LoginCommand"))
1904: LoginCommand=Registry->ReadString("LoginCommand");
1905: if(Registry->ValueExists("ConfigCommand"))
1906: ConfigCommand=Registry->ReadString("ConfigCommand");
1907: if(Registry->ValueExists("Password"))
1908: Password=Registry->ReadString("Password");
1909: if(Registry->ValueExists("MinimizeToSysTray"))
1910: MinimizeToSysTray=Registry->ReadBool("MinimizeToSysTray");
1911: if(Registry->ValueExists("UseFileAssociations"))
1912: UseFileAssociations=Registry->ReadBool("UseFileAssociations");
1913: if(Registry->ValueExists("NodeDisplayInterval"))
1914: NodeForm->Timer->Interval=Registry->ReadInteger("NodeDisplayInterval")*1000;
1915: if(Registry->ValueExists("ClientDisplayInterval"))
1916: ClientForm->Timer->Interval=Registry->ReadInteger("ClientDisplayInterval")*1000;
1.1.1.2 ! root 1917: if(Registry->ValueExists("ErrorSoundFile"))
! 1918: ErrorSoundFile=Registry->ReadString("ErrorSoundFile");
1.1 root 1919:
1920: if(Registry->ValueExists("MailLogFile"))
1921: MailLogFile=Registry->ReadInteger("MailLogFile");
1922: else
1923: MailLogFile=true;
1924:
1925: if(Registry->ValueExists("FtpLogFile"))
1926: FtpLogFile=Registry->ReadInteger("FtpLogFile");
1927: else
1928: FtpLogFile=true;
1929:
1930: FILE* fp;
1931: if((!Registry->ValueExists("SysAutoStart")
1932: || (Registry->ValueExists("Imported") && Registry->ReadBool("Imported")))
1933: && ini_file[0]) {
1934: if((fp=fopen(ini_file,"r"))==NULL) {
1935: char err[MAX_PATH*2];
1936: sprintf(err,"Error %d opening initialization file: %s",errno,ini_file);
1937: Application->MessageBox(err,"ERROR",MB_OK|MB_ICONEXCLAMATION);
1938: Application->Terminate();
1939: return;
1940: }
1941: sbbs_read_ini(fp
1942: ,&global
1943: ,&SysAutoStart ,&bbs_startup
1944: ,&FtpAutoStart ,&ftp_startup
1945: ,&WebAutoStart ,&web_startup
1946: ,&MailAutoStart ,&mail_startup
1947: ,&ServicesAutoStart ,&services_startup
1948: );
1.1.1.2 ! root 1949: StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text="Read " + AnsiString(ini_file);
1.1 root 1950: fclose(fp);
1951:
1952: } else { /* Legacy (v3.10-3.11) */
1953:
1954: if(Registry->ValueExists("SysAutoStart"))
1955: SysAutoStart=Registry->ReadInteger("SysAutoStart");
1956: else
1957: SysAutoStart=true;
1958:
1959: if(Registry->ValueExists("MailAutoStart"))
1960: MailAutoStart=Registry->ReadInteger("MailAutoStart");
1961: else
1962: MailAutoStart=true;
1963:
1964: if(Registry->ValueExists("FtpAutoStart"))
1965: FtpAutoStart=Registry->ReadInteger("FtpAutoStart");
1966: else
1967: FtpAutoStart=true;
1968:
1969: if(Registry->ValueExists("WebAutoStart"))
1970: WebAutoStart=Registry->ReadInteger("WebAutoStart");
1971: else
1972: WebAutoStart=true;
1973:
1974: if(Registry->ValueExists("ServicesAutoStart"))
1975: ServicesAutoStart=Registry->ReadInteger("ServicesAutoStart");
1976: else
1977: ServicesAutoStart=true;
1978:
1979: if(Registry->ValueExists("Hostname"))
1980: SAFECOPY(global.host_name,Registry->ReadString("Hostname").c_str());
1981: if(Registry->ValueExists("CtrlDirectory"))
1982: SAFECOPY(global.ctrl_dir,Registry->ReadString("CtrlDirectory").c_str());
1983: if(Registry->ValueExists("TempDirectory"))
1984: SAFECOPY(global.temp_dir,Registry->ReadString("TempDirectory").c_str());
1985:
1986: if(Registry->ValueExists("SemFileCheckFrequency"))
1987: global.sem_chk_freq=Registry->ReadInteger("SemFileCheckFrequency");
1988:
1989: /* JavaScript Operating Parameters */
1990: if(Registry->ValueExists("JS_MaxBytes"))
1991: global.js.max_bytes=Registry->ReadInteger("JS_MaxBytes");
1992: if(global.js.max_bytes==0)
1993: global.js.max_bytes=JAVASCRIPT_MAX_BYTES;
1994: if(Registry->ValueExists("JS_ContextStack"))
1995: global.js.cx_stack=Registry->ReadInteger("JS_ContextStack");
1996: if(global.js.cx_stack==0)
1997: global.js.cx_stack=JAVASCRIPT_CONTEXT_STACK;
1998: if(Registry->ValueExists("JS_BranchLimit"))
1999: global.js.branch_limit=Registry->ReadInteger("JS_BranchLimit");
2000: if(Registry->ValueExists("JS_GcInterval"))
2001: global.js.gc_interval=Registry->ReadInteger("JS_GcInterval");
2002: if(Registry->ValueExists("JS_YieldInterval"))
2003: global.js.yield_interval=Registry->ReadInteger("JS_YieldInterval");
2004:
2005: if(Registry->ValueExists("TelnetInterface"))
2006: bbs_startup.telnet_interface=Registry->ReadInteger("TelnetInterface");
2007: if(Registry->ValueExists("RLoginInterface"))
2008: bbs_startup.rlogin_interface=Registry->ReadInteger("RLoginInterface");
2009:
2010: if(Registry->ValueExists("TelnetPort"))
2011: bbs_startup.telnet_port=Registry->ReadInteger("TelnetPort");
2012: if(Registry->ValueExists("RLoginPort"))
2013: bbs_startup.rlogin_port=Registry->ReadInteger("RLoginPort");
2014:
2015: if(Registry->ValueExists("FirstNode"))
2016: bbs_startup.first_node=Registry->ReadInteger("FirstNode");
2017:
2018: if(Registry->ValueExists("LastNode"))
2019: bbs_startup.last_node=Registry->ReadInteger("LastNode");
2020:
2021: if(Registry->ValueExists("OutbufHighwaterMark"))
2022: bbs_startup.outbuf_highwater_mark=Registry->ReadInteger("OutbufHighwaterMark");
2023: else
2024: bbs_startup.outbuf_highwater_mark=1024;
2025: if(Registry->ValueExists("OutbufDrainTimeout"))
2026: bbs_startup.outbuf_drain_timeout=Registry->ReadInteger("OutbufDrainTimeout");
2027: else
2028: bbs_startup.outbuf_drain_timeout=10;
2029:
2030: if(Registry->ValueExists("AnswerSound"))
2031: SAFECOPY(bbs_startup.answer_sound
2032: ,Registry->ReadString("AnswerSound").c_str());
2033:
2034: if(Registry->ValueExists("HangupSound"))
2035: SAFECOPY(bbs_startup.hangup_sound
2036: ,Registry->ReadString("HangupSound").c_str());
2037:
2038: if(Registry->ValueExists("StartupOptions"))
2039: bbs_startup.options=Registry->ReadInteger("StartupOptions");
2040:
2041: if(Registry->ValueExists("MailMaxClients"))
2042: mail_startup.max_clients=Registry->ReadInteger("MailMaxClients");
2043:
2044: if(Registry->ValueExists("MailMaxInactivity"))
2045: mail_startup.max_inactivity=Registry->ReadInteger("MailMaxInactivity");
2046:
2047: if(Registry->ValueExists("MailInterface"))
2048: mail_startup.interface_addr=Registry->ReadInteger("MailInterface");
2049:
2050: if(Registry->ValueExists("MailMaxDeliveryAttempts"))
2051: mail_startup.max_delivery_attempts
2052: =Registry->ReadInteger("MailMaxDeliveryAttempts");
2053:
2054: if(Registry->ValueExists("MailRescanFrequency"))
2055: mail_startup.rescan_frequency
2056: =Registry->ReadInteger("MailRescanFrequency");
2057:
2058: if(Registry->ValueExists("MailLinesPerYield"))
2059: mail_startup.lines_per_yield
2060: =Registry->ReadInteger("MailLinesPerYield");
2061:
2062: if(Registry->ValueExists("MailMaxRecipients"))
2063: mail_startup.max_recipients
2064: =Registry->ReadInteger("MailMaxRecipients");
2065:
2066: if(Registry->ValueExists("MailMaxMsgSize"))
2067: mail_startup.max_msg_size
2068: =Registry->ReadInteger("MailMaxMsgSize");
2069:
2070: if(Registry->ValueExists("MailSMTPPort"))
2071: mail_startup.smtp_port=Registry->ReadInteger("MailSMTPPort");
2072:
2073: if(Registry->ValueExists("MailPOP3Port"))
2074: mail_startup.pop3_port=Registry->ReadInteger("MailPOP3Port");
2075:
2076: if(Registry->ValueExists("MailRelayServer"))
2077: SAFECOPY(mail_startup.relay_server
2078: ,Registry->ReadString("MailRelayServer").c_str());
2079:
2080: if(Registry->ValueExists("MailRelayPort"))
2081: mail_startup.relay_port=Registry->ReadInteger("MailRelayPort");
2082:
2083: if(Registry->ValueExists("MailDefaultUser"))
2084: SAFECOPY(mail_startup.default_user
2085: ,Registry->ReadString("MailDefaultUser").c_str());
2086:
2087: if(Registry->ValueExists("MailDNSBlacklistSubject"))
2088: SAFECOPY(mail_startup.dnsbl_tag
2089: ,Registry->ReadString("MailDNSBlacklistSubject").c_str());
2090: else
2091: SAFECOPY(mail_startup.dnsbl_tag,"SPAM");
2092:
2093: if(Registry->ValueExists("MailDNSBlacklistHeader"))
2094: SAFECOPY(mail_startup.dnsbl_hdr
2095: ,Registry->ReadString("MailDNSBlacklistHeader").c_str());
2096: else
2097: SAFECOPY(mail_startup.dnsbl_hdr,"X-DNSBL");
2098:
2099: if(Registry->ValueExists("MailDNSServer"))
2100: SAFECOPY(mail_startup.dns_server
2101: ,Registry->ReadString("MailDNSServer").c_str());
2102:
2103: if(Registry->ValueExists("MailInboundSound"))
2104: SAFECOPY(mail_startup.inbound_sound
2105: ,Registry->ReadString("MailInboundSound").c_str());
2106:
2107: if(Registry->ValueExists("MailOutboundSound"))
2108: SAFECOPY(mail_startup.outbound_sound
2109: ,Registry->ReadString("MailOutboundSound").c_str());
2110:
2111: if(Registry->ValueExists("MailPOP3Sound"))
2112: SAFECOPY(mail_startup.pop3_sound
2113: ,Registry->ReadString("MailPOP3Sound").c_str());
2114:
2115: if(Registry->ValueExists("MailOptions"))
2116: mail_startup.options=Registry->ReadInteger("MailOptions");
2117:
2118: if(Registry->ValueExists("FtpMaxClients"))
2119: ftp_startup.max_clients=Registry->ReadInteger("FtpMaxClients");
2120:
2121: if(Registry->ValueExists("FtpMaxInactivity"))
2122: ftp_startup.max_inactivity=Registry->ReadInteger("FtpMaxInactivity");
2123:
2124: if(Registry->ValueExists("FtpQwkTimeout"))
2125: ftp_startup.qwk_timeout=Registry->ReadInteger("FtpQwkTimeout");
2126:
2127: if(Registry->ValueExists("FtpInterface"))
2128: ftp_startup.interface_addr=Registry->ReadInteger("FtpInterface");
2129:
2130: if(Registry->ValueExists("FtpPort"))
2131: ftp_startup.port=Registry->ReadInteger("FtpPort");
2132:
2133: if(Registry->ValueExists("FtpAnswerSound"))
2134: SAFECOPY(ftp_startup.answer_sound
2135: ,Registry->ReadString("FtpAnswerSound").c_str());
2136:
2137: if(Registry->ValueExists("FtpHangupSound"))
2138: SAFECOPY(ftp_startup.hangup_sound
2139: ,Registry->ReadString("FtpHangupSound").c_str());
2140:
2141: if(Registry->ValueExists("FtpHackAttemptSound"))
2142: SAFECOPY(ftp_startup.hack_sound
2143: ,Registry->ReadString("FtpHackAttemptSound").c_str());
2144:
2145: if(Registry->ValueExists("FtpIndexFileName"))
2146: SAFECOPY(ftp_startup.index_file_name
2147: ,Registry->ReadString("FtpIndexFileName").c_str());
2148:
2149: if(Registry->ValueExists("FtpHtmlIndexFile"))
2150: SAFECOPY(ftp_startup.html_index_file
2151: ,Registry->ReadString("FtpHtmlIndexFile").c_str());
2152:
2153: if(Registry->ValueExists("FtpHtmlIndexScript"))
2154: SAFECOPY(ftp_startup.html_index_script
2155: ,Registry->ReadString("FtpHtmlIndexScript").c_str());
2156:
2157: if(Registry->ValueExists("FtpOptions"))
2158: ftp_startup.options=Registry->ReadInteger("FtpOptions");
2159:
2160: if(Registry->ValueExists("ServicesInterface"))
2161: services_startup.interface_addr
2162: =Registry->ReadInteger("ServicesInterface");
2163:
2164: if(Registry->ValueExists("ServicesAnswerSound"))
2165: SAFECOPY(services_startup.answer_sound
2166: ,Registry->ReadString("ServicesAnswerSound").c_str());
2167:
2168: if(Registry->ValueExists("ServicesHangupSound"))
2169: SAFECOPY(services_startup.hangup_sound
2170: ,Registry->ReadString("ServicesHangupSound").c_str());
2171:
2172: if(Registry->ValueExists("ServicesOptions"))
2173: services_startup.options=Registry->ReadInteger("ServicesOptions");
2174:
2175: if(SaveIniSettings(Sender))
2176: Registry->WriteBool("Imported",true); /* Use the .ini file for these settings from now on */
2177: }
2178:
2179: Registry->CloseKey();
2180: delete Registry;
2181:
2182: AnsiString CtrlDirectory = AnsiString(global.ctrl_dir);
2183: if(!FileExists(CtrlDirectory+"MAIN.CNF")) {
2184: Application->CreateForm(__classid(TCtrlPathDialog), &CtrlPathDialog);
2185: if(CtrlPathDialog->ShowModal()!=mrOk) {
2186: Application->Terminate();
2187: return;
2188: }
2189: CtrlDirectory=CtrlPathDialog->Edit->Text;
2190: delete CtrlPathDialog;
2191: }
2192: if(CtrlDirectory.UpperCase().AnsiPos("MAIN.CNF"))
2193: CtrlDirectory.SetLength(CtrlDirectory.Length()-8);
2194: SAFECOPY(global.ctrl_dir,CtrlDirectory.c_str());
2195: memset(&cfg,0,sizeof(cfg));
2196: SAFECOPY(cfg.ctrl_dir,global.ctrl_dir);
2197: cfg.size=sizeof(cfg);
2198: cfg.node_num=bbs_startup.first_node;
2199: char error[256];
2200: SAFECOPY(error,UNKNOWN_LOAD_ERROR);
1.1.1.2 ! root 2201:
! 2202: StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text="Loading configuration...";
1.1 root 2203: if(!load_cfg(&cfg, NULL, TRUE, error)) {
2204: Application->MessageBox(error,"ERROR Loading Configuration"
2205: ,MB_OK|MB_ICONEXCLAMATION);
2206: Application->Terminate();
2207: return;
2208: }
1.1.1.2 ! root 2209: StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text="Configuration loaded";
1.1 root 2210:
2211: recycle_semfiles=semfile_list_init(cfg.ctrl_dir,"recycle","ctrl");
1.1.1.2 ! root 2212: semfile_list_add(&recycle_semfiles,ini_file);
1.1 root 2213: semfile_list_check(&initialized,recycle_semfiles);
2214:
2215: shutdown_semfiles=semfile_list_init(cfg.ctrl_dir,"shutdown","ctrl");
2216: semfile_list_check(&initialized,shutdown_semfiles);
2217:
2218: if(cfg.new_install) {
2219: Application->BringToFront();
2220: for(int i=0;i<10;i++) {
2221: Application->ProcessMessages();
2222: Sleep(300); // Let 'em see the logo for a bit
2223: }
2224: BBSConfigWizardMenuItemClick(Sender);
2225: }
2226:
2227: if(bbs_startup.options&BBS_OPT_MUTE)
2228: SoundToggle->Checked=false;
2229: else
2230: SoundToggle->Checked=true;
2231:
2232: if(bbs_startup.options&BBS_OPT_SYSOP_AVAILABLE)
2233: ChatToggle->Checked=true;
2234: else
2235: ChatToggle->Checked=false;
2236:
2237: if(!NodeFormFloating)
2238: NodeForm->ManualDock(PageControl(NodeFormPage),NULL,alClient);
2239: if(!ClientFormFloating)
2240: ClientForm->ManualDock(PageControl(ClientFormPage),NULL,alClient);
2241: if(!StatsFormFloating)
2242: StatsForm->ManualDock(PageControl(StatsFormPage),NULL,alClient);
2243: if(!MailFormFloating)
2244: MailForm->ManualDock(PageControl(MailFormPage),NULL,alClient);
2245: if(!TelnetFormFloating)
2246: TelnetForm->ManualDock(PageControl(TelnetFormPage),NULL,alClient);
2247: if(!EventsFormFloating)
2248: EventsForm->ManualDock(PageControl(EventsFormPage),NULL,alClient);
2249: if(!ServicesFormFloating)
2250: ServicesForm->ManualDock(PageControl(ServicesFormPage),NULL,alClient);
2251: if(!FtpFormFloating)
2252: FtpForm->ManualDock(PageControl(FtpFormPage),NULL,alClient);
2253: if(!WebFormFloating)
2254: WebForm->ManualDock(PageControl(WebFormPage),NULL,alClient);
2255:
2256: NodeForm->Show();
2257: // ViewNodes->Checked=NodeFormVisible, ViewNodesExecute(Sender);
2258: ClientForm->Show();
2259: // ViewClients->Checked=ClientFormVisible, ViewClientsExecute(Sender);
2260: StatsForm->Show();
2261: // ViewStats->Checked=StatsFormVisible, ViewStatsExecute(Sender);
2262: TelnetForm->Show();
2263: // ViewTelnet->Checked=TelnetFormVisible, ViewTelnetExecute(Sender);
2264: EventsForm->Show();
2265: // ViewEvents->Checked=EventsFormVisible, ViewEventsExecute(Sender);
2266: FtpForm->Show();
2267: // ViewFtpServer->Checked=FtpFormVisible, ViewFtpServerExecute(Sender);
2268: WebForm->Show();
2269: // ViewWebServer->Checked=WebFormVisible;
2270: // WebForm->Visible=ViewWebServer->Checked;
2271: MailForm->Show();
2272: // ViewMailServer->Checked=MailFormVisible,ViewMailServerExecute(Sender);
2273: ServicesForm->Show();
2274: // ViewServices->Checked=ServicesFormVisible,ViewServicesExecute(Sender);
2275:
2276: UpperLeftPageControl->Visible=true;
2277: UpperRightPageControl->Visible=true;
2278: LowerLeftPageControl->Visible=true;
2279: LowerRightPageControl->Visible=true;
2280: HorizontalSplitter->Visible=true;
2281: BottomPanel->Visible=true;
2282: TopPanel->Visible=true;
2283:
2284: // Work-around for CB5 PageControl anomaly
2285: int i;
2286:
2287: for(i=1;i<UpperLeftPageControl->PageCount;i++)
2288: UpperLeftPageControl->ActivePageIndex=i;
2289: UpperLeftPageControl->ActivePageIndex=0;
2290:
2291: for(i=1;i<UpperRightPageControl->PageCount;i++)
2292: UpperRightPageControl->ActivePageIndex=i;
2293: UpperRightPageControl->ActivePageIndex=0;
2294:
2295: for(i=1;i<LowerRightPageControl->PageCount;i++)
2296: LowerRightPageControl->ActivePageIndex=i;
2297: LowerRightPageControl->ActivePageIndex=0;
2298:
2299: for(i=1;i<LowerLeftPageControl->PageCount;i++)
2300: LowerLeftPageControl->ActivePageIndex=i;
2301: LowerLeftPageControl->ActivePageIndex=0;
2302:
1.1.1.2 ! root 2303: /* Open Log Mailslots */
! 2304: LogTimerTick(Sender);
! 2305:
! 2306: /* Query service config lengths */
! 2307: ServiceStatusTimerTick(Sender);
1.1 root 2308:
2309: if(SysAutoStart)
2310: TelnetStartExecute(Sender);
2311: if(MailAutoStart)
2312: MailStartExecute(Sender);
2313: if(FtpAutoStart)
2314: FtpStartExecute(Sender);
2315: if(WebAutoStart)
2316: WebStartExecute(Sender);
2317: if(ServicesAutoStart)
2318: ServicesStartExecute(Sender);
2319:
2320: NodeForm->Timer->Enabled=true;
2321: ClientForm->Timer->Enabled=true;
2322:
1.1.1.2 ! root 2323: SemFileTimer->Interval=global.sem_chk_freq*1000;
1.1 root 2324: SemFileTimer->Enabled=true;
2325:
2326: StatsTimer->Interval=cfg.node_stat_check*1000;
2327: StatsTimer->Enabled=true;
2328: Initialized=true;
2329:
2330: UpTimer->Enabled=true; /* Start updating the status bar */
2331: LogTimer->Enabled=true;
1.1.1.2 ! root 2332:
1.1 root 2333: ServiceStatusTimer->Enabled=true;
2334:
1.1.1.2 ! root 2335: TelnetForm->LogLevelUpDown->Position=bbs_startup.log_level;
! 2336: TelnetForm->LogLevelText->Caption=LogLevelDesc[bbs_startup.log_level];
! 2337: FtpForm->LogLevelUpDown->Position=ftp_startup.log_level;
! 2338: FtpForm->LogLevelText->Caption=LogLevelDesc[ftp_startup.log_level];
! 2339: MailForm->LogLevelUpDown->Position=mail_startup.log_level;
! 2340: MailForm->LogLevelText->Caption=LogLevelDesc[mail_startup.log_level];
! 2341: WebForm->LogLevelUpDown->Position=web_startup.log_level;
! 2342: WebForm->LogLevelText->Caption=LogLevelDesc[web_startup.log_level];
! 2343: ServicesForm->LogLevelUpDown->Position=services_startup.log_level;
! 2344: ServicesForm->LogLevelText->Caption=LogLevelDesc[services_startup.log_level];
! 2345:
1.1 root 2346: if(!Application->Active) /* Starting up minimized? */
2347: FormMinimize(Sender); /* Put icon in systray */
2348: }
2349: //---------------------------------------------------------------------------
2350: void __fastcall TMainForm::SaveRegistrySettings(TObject* Sender)
2351: {
1.1.1.2 ! root 2352: StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text="Saving Registry Settings...";
1.1 root 2353:
2354: // Write Registry keys
2355: TRegistry* Registry=new TRegistry;
2356: if(!Registry->OpenKey(REG_KEY,true)) {
2357: Application->MessageBox("Error creating registry key"
2358: ,REG_KEY,MB_OK|MB_ICONEXCLAMATION);
2359: Application->Terminate();
2360: return;
2361: }
2362: Registry->WriteInteger("MainFormTop",Top);
2363: Registry->WriteInteger("MainFormLeft",Left);
2364: Registry->WriteInteger("MainFormHeight",Height);
2365: Registry->WriteInteger("MainFormWidth",Width);
2366:
2367: Registry->WriteInteger("NodeFormTop",NodeForm->Top);
2368: Registry->WriteInteger("NodeFormLeft",NodeForm->Left);
2369: Registry->WriteInteger("NodeFormHeight",NodeForm->Height);
2370: Registry->WriteInteger("NodeFormWidth",NodeForm->Width);
2371:
2372: Registry->WriteInteger("StatsFormTop",StatsForm->Top);
2373: Registry->WriteInteger("StatsFormLeft",StatsForm->Left);
2374: Registry->WriteInteger("StatsFormHeight",StatsForm->Height);
2375: Registry->WriteInteger("StatsFormWidth",StatsForm->Width);
2376:
2377: Registry->WriteInteger("ClientFormTop",ClientForm->Top);
2378: Registry->WriteInteger("ClientFormLeft",ClientForm->Left);
2379: Registry->WriteInteger("ClientFormHeight",ClientForm->Height);
2380: Registry->WriteInteger("ClientFormWidth",ClientForm->Width);
2381:
2382: for(int i=0;i<ClientForm->ListView->Columns->Count;i++) {
2383: char str[128];
2384: sprintf(str,"ClientListColumn%dWidth",i);
2385: Registry->WriteInteger(str
2386: ,ClientForm->ListView->Columns->Items[i]->Width);
2387: }
2388:
2389: Registry->WriteInteger("TelnetFormTop",TelnetForm->Top);
2390: Registry->WriteInteger("TelnetFormLeft",TelnetForm->Left);
2391: Registry->WriteInteger("TelnetFormHeight",TelnetForm->Height);
2392: Registry->WriteInteger("TelnetFormWidth",TelnetForm->Width);
2393:
2394: Registry->WriteInteger("EventsFormTop",EventsForm->Top);
2395: Registry->WriteInteger("EventsFormLeft",EventsForm->Left);
2396: Registry->WriteInteger("EventsFormHeight",EventsForm->Height);
2397: Registry->WriteInteger("EventsFormWidth",EventsForm->Width);
2398:
2399: Registry->WriteInteger("ServicesFormTop",ServicesForm->Top);
2400: Registry->WriteInteger("ServicesFormLeft",ServicesForm->Left);
2401: Registry->WriteInteger("ServicesFormHeight",ServicesForm->Height);
2402: Registry->WriteInteger("ServicesFormWidth",ServicesForm->Width);
2403:
2404: Registry->WriteInteger("FtpFormTop",FtpForm->Top);
2405: Registry->WriteInteger("FtpFormLeft",FtpForm->Left);
2406: Registry->WriteInteger("FtpFormHeight",FtpForm->Height);
2407: Registry->WriteInteger("FtpFormWidth",FtpForm->Width);
2408:
2409: Registry->WriteInteger("WebFormTop",WebForm->Top);
2410: Registry->WriteInteger("WebFormLeft",WebForm->Left);
2411: Registry->WriteInteger("WebFormHeight",WebForm->Height);
2412: Registry->WriteInteger("WebFormWidth",WebForm->Width);
2413:
2414: Registry->WriteInteger("MailFormTop",MailForm->Top);
2415: Registry->WriteInteger("MailFormLeft",MailForm->Left);
2416: Registry->WriteInteger("MailFormHeight",MailForm->Height);
2417: Registry->WriteInteger("MailFormWidth",MailForm->Width);
2418:
2419: Registry->WriteInteger("TopPanelHeight",TopPanel->Height);
2420: Registry->WriteInteger("UpperLeftPageControlWidth"
2421: ,UpperLeftPageControl->Width);
2422: Registry->WriteInteger("LowerLeftPageControlWidth"
2423: ,LowerLeftPageControl->Width);
2424:
2425: Registry->WriteBool("UndockableForms",UndockableForms);
2426:
2427: Registry->WriteBool("TelnetFormFloating",TelnetForm->Floating);
2428: Registry->WriteBool("EventsFormFloating",EventsForm->Floating);
2429: Registry->WriteBool("ServicesFormFloating",ServicesForm->Floating);
2430: Registry->WriteBool("NodeFormFloating",NodeForm->Floating);
2431: Registry->WriteBool("StatsFormFloating",StatsForm->Floating);
2432: Registry->WriteBool("ClientFormFloating",ClientForm->Floating);
2433: Registry->WriteBool("FtpFormFloating",FtpForm->Floating);
2434: Registry->WriteBool("WebFormFloating",WebForm->Floating);
2435: Registry->WriteBool("MailFormFloating",MailForm->Floating);
2436:
2437: Registry->WriteBool("TelnetFormVisible",TelnetForm->Visible);
2438: Registry->WriteBool("EventsFormVisible",EventsForm->Visible);
2439: Registry->WriteBool("ServicesFormVisible",ServicesForm->Visible);
2440: Registry->WriteBool("NodeFormVisible",NodeForm->Visible);
2441: Registry->WriteBool("StatsFormVisible",StatsForm->Visible);
2442: Registry->WriteBool("ClientFormVisible",ClientForm->Visible);
2443: Registry->WriteBool("FtpFormVisible",FtpForm->Visible);
2444: Registry->WriteBool("WebFormVisible",WebForm->Visible);
2445: Registry->WriteBool("MailFormVisible",MailForm->Visible);
2446:
2447: Registry->WriteInteger("TelnetFormPage"
2448: ,PageNum((TPageControl*)TelnetForm->HostDockSite));
2449: Registry->WriteInteger("EventsFormPage"
2450: ,PageNum((TPageControl*)EventsForm->HostDockSite));
2451: Registry->WriteInteger("ServicesFormPage"
2452: ,PageNum((TPageControl*)ServicesForm->HostDockSite));
2453: Registry->WriteInteger("NodeFormPage"
2454: ,PageNum((TPageControl*)NodeForm->HostDockSite));
2455: Registry->WriteInteger("MailFormPage"
2456: ,PageNum((TPageControl*)MailForm->HostDockSite));
2457: Registry->WriteInteger("FtpFormPage"
2458: ,PageNum((TPageControl*)FtpForm->HostDockSite));
2459: Registry->WriteInteger("WebFormPage"
2460: ,PageNum((TPageControl*)WebForm->HostDockSite));
2461: Registry->WriteInteger("StatsFormPage"
2462: ,PageNum((TPageControl*)StatsForm->HostDockSite));
2463: Registry->WriteInteger("ClientFormPage"
2464: ,PageNum((TPageControl*)ClientForm->HostDockSite));
2465:
2466: WriteColor(Registry,"TelnetLog",TelnetForm->Log->Color);
2467: WriteFont("TelnetLog",TelnetForm->Log->Font);
2468: WriteColor(Registry,"EventsLog",EventsForm->Log->Color);
2469: WriteFont("EventsLog",EventsForm->Log->Font);
2470: WriteColor(Registry,"ServicesLog",ServicesForm->Log->Color);
2471: WriteFont("ServicesLog",ServicesForm->Log->Font);
2472: WriteColor(Registry,"MailLog",MailForm->Log->Color);
2473: WriteFont("MailLog",MailForm->Log->Font);
2474: WriteColor(Registry,"FtpLog",FtpForm->Log->Color);
2475: WriteFont("FtpLog",FtpForm->Log->Font);
2476: WriteColor(Registry,"WebLog",WebForm->Log->Color);
2477: WriteFont("WebLog",WebForm->Log->Font);
2478: WriteColor(Registry,"NodeList",NodeForm->ListBox->Color);
2479: WriteFont("NodeList",NodeForm->ListBox->Font);
2480: WriteColor(Registry,"ClientList",ClientForm->ListView->Color);
2481: WriteFont("ClientList",ClientForm->ListView->Font);
2482:
1.1.1.2 ! root 2483: {
! 2484: int i;
! 2485:
! 2486: for(i=LOG_EMERG;i<=LOG_DEBUG;i++)
! 2487: WriteFont("Log" + AnsiString(LogLevelDesc[i]), LogFont[i]);
! 2488: }
! 2489:
1.1 root 2490: Registry->WriteBool("ToolBarVisible",Toolbar->Visible);
2491: Registry->WriteBool("StatusBarVisible",StatusBar->Visible);
2492:
2493: Registry->WriteInteger("MaxLogLen",MaxLogLen);
2494:
2495: Registry->WriteString("LoginCommand",LoginCommand);
2496: Registry->WriteString("ConfigCommand",ConfigCommand);
2497: Registry->WriteString("Password",Password);
2498: Registry->WriteBool("MinimizeToSysTray",MinimizeToSysTray);
2499: Registry->WriteBool("UseFileAssociations",UseFileAssociations);
2500: Registry->WriteInteger("NodeDisplayInterval",NodeForm->Timer->Interval/1000);
2501: Registry->WriteInteger("ClientDisplayInterval",ClientForm->Timer->Interval/1000);
1.1.1.2 ! root 2502: Registry->WriteString("ErrorSoundFile",ErrorSoundFile);
1.1 root 2503:
2504: Registry->WriteInteger( "SpyTerminalWidth"
2505: ,SpyTerminalWidth);
2506: Registry->WriteInteger( "SpyTerminalHeight"
2507: ,SpyTerminalHeight);
2508: Registry->WriteString( "SpyTerminalFontName"
2509: ,SpyTerminalFont->Name);
2510: Registry->WriteInteger( "SpyTerminalFontSize"
2511: ,SpyTerminalFont->Size);
2512: Registry->WriteBool( "SpyTerminalKeyboardActive"
2513: ,SpyTerminalKeyboardActive);
2514:
2515: Registry->CloseKey();
2516: delete Registry;
2517: }
2518: //---------------------------------------------------------------------------
2519: void __fastcall TMainForm::SaveSettings(TObject* Sender)
2520: {
2521: SaveIniSettings(Sender);
2522: SaveRegistrySettings(Sender);
2523: }
2524: //---------------------------------------------------------------------------
2525: bool __fastcall TMainForm::SaveIniSettings(TObject* Sender)
2526: {
2527: FILE* fp=NULL;
2528: if(ini_file[0]==0)
2529: return(false);
2530:
2531: if((fp=fopen(ini_file,"r+"))==NULL) {
2532: char err[MAX_PATH*2];
2533: SAFEPRINTF2(err,"Error %d opening initialization file: %s",errno,ini_file);
2534: Application->MessageBox(err,"ERROR",MB_OK|MB_ICONEXCLAMATION);
2535: return(false);
2536: }
2537:
1.1.1.2 ! root 2538: StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text="Saving Settings to " + AnsiString(ini_file) + " ...";
1.1 root 2539:
2540: bool success = sbbs_write_ini(fp
2541: ,&cfg
2542: ,&global
2543: ,SysAutoStart ,&bbs_startup
2544: ,FtpAutoStart ,&ftp_startup
2545: ,WebAutoStart ,&web_startup
2546: ,MailAutoStart ,&mail_startup
2547: ,ServicesAutoStart ,&services_startup
2548: );
2549: fclose(fp);
2550:
2551: if(!success) {
2552: char err[MAX_PATH*2];
2553: SAFEPRINTF(err,"Failure writing initialization file: %s",ini_file);
2554: Application->MessageBox(err,"ERROR",MB_OK|MB_ICONEXCLAMATION);
2555: }
2556:
1.1.1.2 ! root 2557: semfile_list_check(&initialized,recycle_semfiles);
1.1 root 2558: return(success);
2559: }
2560:
2561: //---------------------------------------------------------------------------
2562: void __fastcall TMainForm::ImportFormSettings(TMemIniFile* IniFile, const char* section, TForm* Form)
2563: {
2564: Form->Top=IniFile->ReadInteger(section,"Top",Form->Top);
2565: Form->Left=IniFile->ReadInteger(section,"Left",Form->Left);
2566: Form->Width=IniFile->ReadInteger(section,"Width",Form->Width);
2567: Form->Height=IniFile->ReadInteger(section,"Height",Form->Height);
2568: }
2569: //---------------------------------------------------------------------------
2570: void __fastcall TMainForm::ExportFormSettings(TMemIniFile* IniFile, const char* section, TForm* Form)
2571: {
2572: IniFile->WriteInteger(section,"Top",Form->Top);
2573: IniFile->WriteInteger(section,"Left",Form->Left);
2574: IniFile->WriteInteger(section,"Width",Form->Width);
2575: IniFile->WriteInteger(section,"Height",Form->Height);
2576: IniFile->WriteInteger(section,"Page",PageNum((TPageControl*)Form->HostDockSite));
2577: IniFile->WriteBool(section,"Floating",Form->Floating);
2578: }
2579: //---------------------------------------------------------------------------
2580: void __fastcall TMainForm::ImportFont(TMemIniFile* IniFile, const char* section, AnsiString prefix, TFont* Font)
2581: {
2582: Font->Name=IniFile->ReadString(section,prefix + "Name",Font->Name);
2583: Font->Color=StringToColor(IniFile->ReadString(section,prefix + "Color",ColorToString(Font->Color)));
2584: Font->Height=IniFile->ReadInteger(section,prefix + "Height",Font->Height);
2585: Font->Size=IniFile->ReadInteger(section,prefix + "Size", Font->Size);
2586: IntToFontStyle(IniFile->ReadInteger(section,prefix + "Style",FontStyleToInt(Font)),Font);
2587: }
2588: //---------------------------------------------------------------------------
2589: void __fastcall TMainForm::ExportFont(TMemIniFile* IniFile, const char* section, AnsiString prefix, TFont* Font)
2590: {
2591: IniFile->WriteString(section,prefix+"Name",Font->Name);
2592: IniFile->WriteString(section,prefix+"Color",ColorToString(Font->Color));
2593: IniFile->WriteInteger(section,prefix+"Height",Font->Height);
2594: IniFile->WriteInteger(section,prefix+"Size",Font->Size);
2595: IniFile->WriteInteger(section,prefix+"Style",FontStyleToInt(Font));
2596: }
2597: //---------------------------------------------------------------------------
2598: void __fastcall TMainForm::ImportSettings(TObject* Sender)
2599: {
2600: OpenDialog->Filter="Settings files (*.ini)|*.ini|All files|*.*";
2601: OpenDialog->FileName=AnsiString(global.ctrl_dir)+"sbbsctrl.ini";
2602: if(!OpenDialog->Execute())
2603: return;
2604:
1.1.1.2 ! root 2605: StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text="Importing Settings...";
1.1 root 2606:
2607: TMemIniFile* IniFile=new TMemIniFile(OpenDialog->FileName);
2608:
2609: const char* section = "Properties";
2610:
2611: LoginCommand=IniFile->ReadString(section,"LoginCommand",LoginCommand);
2612: ConfigCommand=IniFile->ReadString(section,"ConfigCommand",ConfigCommand);
2613: Password=IniFile->ReadString(section,"Password",Password);
2614: MinimizeToSysTray=IniFile->ReadBool(section,"MinimizeToSysTray",MinimizeToSysTray);
2615: UseFileAssociations=IniFile->ReadBool(section,"UseFileAssociations" ,UseFileAssociations);
2616: UndockableForms=IniFile->ReadBool(section,"UndockableForms",UndockableForms);
2617:
2618: ImportFormSettings(IniFile,section="MainForm",MainForm);
2619: TopPanel->Height=IniFile->ReadInteger(section,"TopPanelHeight",TopPanel->Height);
2620: UpperLeftPageControl->Width=IniFile->ReadInteger(section,"UpperLeftPageControlWidth",UpperLeftPageControl->Width);
2621: LowerLeftPageControl->Width=IniFile->ReadInteger(section,"LowerLeftPageControlWidth",LowerLeftPageControl->Width);
2622: Toolbar->Visible=IniFile->ReadBool(section,"ToolBarVisible",Toolbar->Visible);
2623: StatusBar->Visible=IniFile->ReadBool(section,"StatusBarVisible",StatusBar->Visible);
2624:
2625: ImportFormSettings(IniFile,section="TelnetForm",TelnetForm);
2626: ImportFont(IniFile,section,"LogFont",TelnetForm->Log->Font);
2627: TelnetForm->Log->Color=StringToColor(IniFile->ReadString(section,"LogColor",clWindow));
2628:
2629: ImportFormSettings(IniFile,section="EventsForm",EventsForm);
2630: ImportFont(IniFile,section,"LogFont",EventsForm->Log->Font);
2631: EventsForm->Log->Color=StringToColor(IniFile->ReadString(section,"LogColor",clWindow));
2632:
2633: ImportFormSettings(IniFile,section="ServicesForm",ServicesForm);
2634: ImportFont(IniFile,section,"LogFont",ServicesForm->Log->Font);
2635: ServicesForm->Log->Color=StringToColor(IniFile->ReadString(section,"LogColor",clWindow));
2636:
2637: ImportFormSettings(IniFile,section="FtpForm",FtpForm);
2638: ImportFont(IniFile,section,"LogFont",FtpForm->Log->Font);
2639: FtpLogFile=IniFile->ReadInteger(section,"LogFile",true);
2640: FtpForm->Log->Color=StringToColor(IniFile->ReadString(section,"LogColor",clWindow));
2641:
2642: ImportFormSettings(IniFile,section="WebForm",WebForm);
2643: ImportFont(IniFile,section,"LogFont",WebForm->Log->Font);
2644: WebForm->Log->Color=StringToColor(IniFile->ReadString(section,"LogColor",clWindow));
2645:
2646: ImportFormSettings(IniFile,section="MailForm",MailForm);
2647: ImportFont(IniFile,section,"LogFont",MailForm->Log->Font);
2648: MailLogFile=IniFile->ReadInteger(section,"LogFile",true);
2649: MailForm->Log->Color=StringToColor(IniFile->ReadString(section,"LogColor",clWindow));
2650:
2651: ImportFormSettings(IniFile,section="NodeForm",NodeForm);
2652: ImportFont(IniFile,section,"ListFont",NodeForm->ListBox->Font);
2653: NodeForm->Timer->Interval=IniFile->ReadInteger(section,"DisplayInterval"
2654: ,NodeForm->Timer->Interval/1000)*1000;
2655: NodeForm->ListBox->Color=StringToColor(IniFile->ReadString(section,"ListColor",clWindow));
2656:
2657: ImportFormSettings(IniFile,section="StatsForm",StatsForm);
2658:
2659: ImportFormSettings(IniFile,section="ClientForm",ClientForm);
2660: ImportFont(IniFile,section,"ListFont",ClientForm->ListView->Font);
2661: ClientForm->ListView->Color=StringToColor(IniFile->ReadString(section,"ListColor",clWindow));
2662: ClientForm->Timer->Interval=IniFile->ReadInteger(section,"DisplayInterval"
2663: ,ClientForm->Timer->Interval/1000)*1000;
2664: for(int i=0;i<ClientForm->ListView->Columns->Count;i++) {
2665: char str[128];
2666: sprintf(str,"Column%dWidth",i);
2667: if(IniFile->ValueExists(section,str))
2668: ClientForm->ListView->Columns->Items[i]->Width
2669: =IniFile->ReadInteger(section,str,0);
2670: }
2671:
2672: section = "SpyTerminal";
2673: SpyTerminalWidth=IniFile->ReadInteger(section, "Width", SpyTerminalWidth);
2674: SpyTerminalHeight=IniFile->ReadInteger(section, "Height", SpyTerminalHeight);
2675: SpyTerminalFont->Name=IniFile->ReadString(section, "FontName", SpyTerminalFont->Name);
2676: SpyTerminalFont->Size=IniFile->ReadInteger(section, "FontSize", SpyTerminalFont->Size);
2677: SpyTerminalKeyboardActive=IniFile->ReadBool(section, "KeyboardActive", SpyTerminalKeyboardActive);
2678:
2679: delete IniFile;
2680:
2681: Application->MessageBox(AnsiString("Successfully imported SBBSCTRL settings from "
2682: + OpenDialog->FileName).c_str(),"Successful Import",MB_OK);
2683: }
2684: //---------------------------------------------------------------------------
2685: void __fastcall TMainForm::ExportSettings(TObject* Sender)
2686: {
2687: char str[128];
2688:
2689: SaveDialog->Filter="Settings files (*.ini)|*.ini|All files|*.*";
2690: SaveDialog->FileName=AnsiString(global.ctrl_dir)+"sbbsctrl.ini";
2691: if(!SaveDialog->Execute())
2692: return;
2693:
2694: TMemIniFile* IniFile=new TMemIniFile(SaveDialog->FileName);
2695:
1.1.1.2 ! root 2696: StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text="Exporting Settings...";
1.1 root 2697:
2698: const char* section = "Properties";
2699:
2700: IniFile->WriteString(section,"LoginCommand",LoginCommand);
2701: IniFile->WriteString(section,"ConfigCommand",ConfigCommand);
2702: IniFile->WriteString(section,"Password",Password);
2703: IniFile->WriteBool(section,"MinimizeToSysTray",MinimizeToSysTray);
2704: IniFile->WriteBool(section,"UseFileAssociations",UseFileAssociations);
2705: IniFile->WriteBool(section,"UndockableForms",UndockableForms);
2706:
2707: ExportFormSettings(IniFile,section="MainForm",MainForm);
2708: IniFile->WriteInteger(section,"TopPanelHeight",TopPanel->Height);
2709: IniFile->WriteInteger(section,"UpperLeftPageControlWidth",UpperLeftPageControl->Width);
2710: IniFile->WriteInteger(section,"LowerLeftPageControlWidth",LowerLeftPageControl->Width);
2711: IniFile->WriteBool(section,"ToolBarVisible",Toolbar->Visible);
2712: IniFile->WriteBool(section,"StatusBarVisible",StatusBar->Visible);
2713:
2714: ExportFormSettings(IniFile,section = "NodeForm",NodeForm);
2715: ExportFont(IniFile,section,"ListFont",NodeForm->ListBox->Font);
2716: IniFile->WriteString(section,"ListColor",ColorToString(NodeForm->ListBox->Color));
2717: IniFile->WriteInteger(section,"DisplayInterval",NodeForm->Timer->Interval/1000);
2718:
2719: ExportFormSettings(IniFile,section = "StatsForm",StatsForm);
2720:
2721: ExportFormSettings(IniFile,section = "ClientForm",ClientForm);
2722: ExportFont(IniFile,section,"ListFont",ClientForm->ListView->Font);
2723: IniFile->WriteString(section,"ListColor",ColorToString(ClientForm->ListView->Color));
2724: IniFile->WriteInteger(section,"DisplayInterval",ClientForm->Timer->Interval/1000);
2725: for(int i=0;i<ClientForm->ListView->Columns->Count;i++) {
2726: char str[128];
2727: sprintf(str,"Column%dWidth",i);
2728: IniFile->WriteInteger(section,str
2729: ,ClientForm->ListView->Columns->Items[i]->Width);
2730: }
2731:
2732: ExportFormSettings(IniFile,section = "TelnetForm",TelnetForm);
2733: ExportFont(IniFile,section,"LogFont",TelnetForm->Log->Font);
1.1.1.2 ! root 2734: IniFile->WriteString(section,"LogColor",ColorToString(TelnetForm->Log->Color));
1.1 root 2735:
2736: ExportFormSettings(IniFile,section = "EventsForm",EventsForm);
2737: ExportFont(IniFile,section,"LogFont",EventsForm->Log->Font);
1.1.1.2 ! root 2738: IniFile->WriteString(section,"LogColor",ColorToString(EventsForm->Log->Color));
1.1 root 2739:
2740: ExportFormSettings(IniFile,section = "ServicesForm",ServicesForm);
2741: ExportFont(IniFile,section,"LogFont",ServicesForm->Log->Font);
1.1.1.2 ! root 2742: IniFile->WriteString(section,"LogColor",ColorToString(ServicesForm->Log->Color));
1.1 root 2743:
2744: ExportFormSettings(IniFile,section = "FtpForm",FtpForm);
2745: ExportFont(IniFile,section,"LogFont",FtpForm->Log->Font);
1.1.1.2 ! root 2746: IniFile->WriteString(section,"LogColor",ColorToString(FtpForm->Log->Color));
1.1 root 2747:
2748: ExportFormSettings(IniFile,section = "MailForm",MailForm);
2749: ExportFont(IniFile,section,"LogFont",MailForm->Log->Font);
1.1.1.2 ! root 2750: IniFile->WriteString(section,"LogColor",ColorToString(MailForm->Log->Color));
! 2751:
! 2752: ExportFormSettings(IniFile,section = "WebForm",WebForm);
! 2753: ExportFont(IniFile,section,"LogFont",WebForm->Log->Font);
! 2754: IniFile->WriteString(section,"LogColor",ColorToString(WebForm->Log->Color));
1.1 root 2755:
2756: section = "SpyTerminal";
2757: IniFile->WriteInteger(section, "Width"
2758: ,SpyTerminalWidth);
2759: IniFile->WriteInteger(section, "Height"
2760: ,SpyTerminalHeight);
2761: IniFile->WriteString(section, "FontName"
2762: ,SpyTerminalFont->Name);
2763: IniFile->WriteInteger(section, "FontSize"
2764: ,SpyTerminalFont->Size);
2765: IniFile->WriteBool(section, "KeyboardActive"
2766: ,SpyTerminalKeyboardActive);
2767:
2768: IniFile->UpdateFile();
2769:
2770: delete IniFile;
2771:
2772: Application->MessageBox(AnsiString("Successfully exported SBBSCTRL settings to "
2773: + SaveDialog->FileName).c_str(),"Successful Export",MB_OK);
2774: }
2775: //---------------------------------------------------------------------------
2776:
2777: void __fastcall TMainForm::ViewStatusBarMenuItemClick(TObject *Sender)
2778: {
2779: StatusBar->Visible=!StatusBar->Visible;
2780: ViewStatusBarMenuItem->Checked=StatusBar->Visible;
2781: }
2782: //---------------------------------------------------------------------------
2783: void __fastcall TMainForm::HelpAboutMenuItemClick(TObject *Sender)
2784: {
2785: Application->CreateForm(__classid(TAboutBoxForm), &AboutBoxForm);
2786: AboutBoxForm->ShowModal();
2787: delete AboutBoxForm;
2788: }
2789: //---------------------------------------------------------------------------
2790: BOOL MuteService(SC_HANDLE svc, SERVICE_STATUS* status, BOOL mute)
2791: {
2792: if(svc==NULL || controlService==NULL)
2793: return(FALSE);
2794:
2795: return controlService(svc
2796: ,mute ? SERVICE_CONTROL_MUTE:SERVICE_CONTROL_UNMUTE, status);
2797: }
2798: //---------------------------------------------------------------------------
2799: void __fastcall TMainForm::SoundToggleExecute(TObject *Sender)
2800: {
2801: SoundToggle->Checked=!SoundToggle->Checked;
2802:
2803: if(!SoundToggle->Checked) {
2804: bbs_startup.options|=BBS_OPT_MUTE;
2805: ftp_startup.options|=FTP_OPT_MUTE;
2806: web_startup.options|=FTP_OPT_MUTE;
2807: mail_startup.options|=MAIL_OPT_MUTE;
2808: services_startup.options|=MAIL_OPT_MUTE;
2809: } else {
2810: bbs_startup.options&=~BBS_OPT_MUTE;
2811: ftp_startup.options&=~FTP_OPT_MUTE;
2812: web_startup.options&=~FTP_OPT_MUTE;
2813: mail_startup.options&=~MAIL_OPT_MUTE;
2814: services_startup.options&=~MAIL_OPT_MUTE;
2815: }
2816: MuteService(bbs_svc,&bbs_svc_status,!SoundToggle->Checked);
2817: MuteService(ftp_svc,&ftp_svc_status,!SoundToggle->Checked);
2818: MuteService(web_svc,&web_svc_status,!SoundToggle->Checked);
2819: MuteService(mail_svc,&mail_svc_status,!SoundToggle->Checked);
2820: MuteService(services_svc,&services_svc_status,!SoundToggle->Checked);
2821: }
2822: //---------------------------------------------------------------------------
2823: void __fastcall TMainForm::BBSStatisticsLogMenuItemClick(TObject *Sender)
2824: {
2825: StatsForm->LogButtonClick(Sender);
2826: }
2827: //---------------------------------------------------------------------------
2828:
2829: void __fastcall TMainForm::ForceTimedEventMenuItemClick(TObject *Sender)
2830: {
2831: int i,file;
2832: char str[MAX_PATH+1];
2833:
2834: Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
2835: CodeInputForm->Label->Caption="Event Internal Code";
2836: CodeInputForm->ComboBox->Items->Clear();
2837: for(i=0;i<cfg.total_events;i++)
2838: CodeInputForm->ComboBox->Items->Add(
2839: AnsiString(cfg.event[i]->code).UpperCase());
2840: CodeInputForm->ComboBox->ItemIndex=0;
2841: if(CodeInputForm->ShowModal()==mrOk
2842: && CodeInputForm->ComboBox->Text.Length()) {
2843: for(i=0;i<cfg.total_events;i++) {
2844: if(!stricmp(CodeInputForm->ComboBox->Text.c_str(),cfg.event[i]->code)) {
2845: sprintf(str,"%s%s.now",cfg.data_dir,cfg.event[i]->code);
2846: if((file=_sopen(str,O_CREAT|O_TRUNC|O_WRONLY
2847: ,SH_DENYRW,S_IREAD|S_IWRITE))!=-1)
2848: close(file);
2849: break;
2850: }
2851: }
2852: if(i>=cfg.total_events)
2853: Application->MessageBox(CodeInputForm->ComboBox->Text.c_str()
2854: ,"Event Code Not Found",MB_OK|MB_ICONEXCLAMATION);
2855: }
2856: delete CodeInputForm;
2857: }
2858: //---------------------------------------------------------------------------
2859:
2860: void __fastcall TMainForm::ForceNetworkCalloutMenuItemClick(
2861: TObject *Sender)
2862: {
2863: int i,file;
2864: char str[MAX_PATH+1];
2865:
2866: Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
2867: CodeInputForm->Label->Caption="Hub QWK-ID";
2868: CodeInputForm->ComboBox->Items->Clear();
2869: for(i=0;i<cfg.total_qhubs;i++)
2870: CodeInputForm->ComboBox->Items->Add(
2871: AnsiString(cfg.qhub[i]->id).UpperCase());
2872: CodeInputForm->ComboBox->ItemIndex=0;
2873: if(CodeInputForm->ShowModal()==mrOk
2874: && CodeInputForm->ComboBox->Text.Length()) {
2875: for(i=0;i<cfg.total_qhubs;i++) {
2876: if(!stricmp(CodeInputForm->ComboBox->Text.c_str(),cfg.qhub[i]->id)) {
2877: sprintf(str,"%sqnet/%s.now",cfg.data_dir,cfg.qhub[i]->id);
2878: if((file=_sopen(str,O_CREAT|O_TRUNC|O_WRONLY
2879: ,SH_DENYRW,S_IREAD|S_IWRITE))!=-1)
2880: close(file);
2881: break;
2882: }
2883: }
2884: if(i>=cfg.total_qhubs)
2885: Application->MessageBox(CodeInputForm->ComboBox->Text.c_str()
2886: ,"QWKnet Hub ID Not Found",MB_OK|MB_ICONEXCLAMATION);
2887: }
2888: delete CodeInputForm;
2889: }
2890: //---------------------------------------------------------------------------
2891:
2892: void __fastcall TMainForm::TextMenuItemEditClick(TObject *Sender)
2893: {
2894: char filename[MAX_PATH+1];
2895:
2896: sprintf(filename,"%s%s"
2897: ,MainForm->cfg.text_dir
2898: ,((TMenuItem*)Sender)->Hint.c_str());
2899: EditFile(filename,((TMenuItem*)Sender)->Caption);
2900: }
2901:
2902: //---------------------------------------------------------------------------
2903: void __fastcall TMainForm::CtrlMenuItemEditClick(TObject *Sender)
2904: {
2905: char filename[MAX_PATH+1];
2906:
2907: iniFileName(filename,sizeof(filename)
2908: ,MainForm->cfg.ctrl_dir
2909: ,((TMenuItem*)Sender)->Hint.c_str());
2910: EditFile(filename,((TMenuItem*)Sender)->Caption);
2911: }
2912: void __fastcall TMainForm::DataMenuItemClick(TObject *Sender)
2913: {
2914: char filename[MAX_PATH+1];
2915:
2916: sprintf(filename,"%s%s"
2917: ,MainForm->cfg.data_dir
2918: ,((TMenuItem*)Sender)->Hint.c_str());
2919: EditFile(filename,((TMenuItem*)Sender)->Caption);
2920: }
2921: //---------------------------------------------------------------------------
2922:
2923: //---------------------------------------------------------------------------
2924:
2925: void __fastcall TMainForm::UpTimerTick(TObject *Sender)
2926: {
2927: char str[128];
2928: char days[64];
2929: static time_t start;
2930: ulong up;
2931:
2932: if(!start)
2933: start=time(NULL);
2934: up=time(NULL)-start;
2935:
2936: days[0]=0;
2937: if((up/(24*60*60))>=2) {
2938: sprintf(days,"%u days ",up/(24*60*60));
2939: up%=(24*60*60);
2940: }
2941: sprintf(str,"Up: %s%u:%02u"
2942: ,days
2943: ,up/(60*60)
2944: ,(up/60)%60
2945: );
2946: AnsiString Str=AnsiString(str);
1.1.1.2 ! root 2947: if(MainForm->StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text!=Str)
! 2948: MainForm->StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text=Str;
! 2949:
! 2950: sprintf(str,"Threads: %u",threads);
! 2951: Str=AnsiString(str);
! 2952: if(MainForm->StatusBar->Panels->Items[0]->Text!=Str)
! 2953: MainForm->StatusBar->Panels->Items[0]->Text=Str;
! 2954:
! 2955: sprintf(str,"Sockets: %u",sockets);
! 2956: Str=AnsiString(str);
! 2957: if(MainForm->StatusBar->Panels->Items[1]->Text!=Str)
! 2958: MainForm->StatusBar->Panels->Items[1]->Text=Str;
! 2959:
! 2960: sprintf(str,"Clients: %u",clients);
! 2961: Str=AnsiString(str);
! 2962: if(MainForm->StatusBar->Panels->Items[2]->Text!=Str)
! 2963: MainForm->StatusBar->Panels->Items[2]->Text=Str;
! 2964:
! 2965: sprintf(str,"Served: %u",total_clients);
! 2966: Str=AnsiString(str);
! 2967: if(MainForm->StatusBar->Panels->Items[3]->Text!=Str)
! 2968: MainForm->StatusBar->Panels->Items[3]->Text=Str;
! 2969:
! 2970: sprintf(str,"Errors: %u",errors);
! 2971: Str=AnsiString(str);
1.1 root 2972: if(MainForm->StatusBar->Panels->Items[4]->Text!=Str)
2973: MainForm->StatusBar->Panels->Items[4]->Text=Str;
1.1.1.2 ! root 2974:
1.1 root 2975: #if 0
2976: THeapStatus hp=GetHeapStatus();
2977: sprintf(str,"Mem Used: %lu bytes",hp.TotalAllocated);
2978: Str=AnsiString(str);
2979: if(MainForm->StatusBar->Panels->Items[5]->Text!=Str)
2980: MainForm->StatusBar->Panels->Items[5]->Text=Str;
2981: #endif
2982: if(TrayIcon->Visible) {
2983: /* Animate TrayIcon when in use */
2984: AnsiString NumClients;
2985: try {
2986: if(clients) {
2987: TrayIcon->IconIndex=(TrayIcon->IconIndex==4) ? 59 : 4;
2988: NumClients=" ("+AnsiString(clients)+" client";
2989: if(clients>1)
2990: NumClients+="s";
2991: NumClients+=")";
2992: } else if(TrayIcon->IconIndex!=4)
2993: TrayIcon->IconIndex=4;
2994: TrayIcon->Hint=AnsiString(APP_TITLE)+NumClients;
2995: } catch(...) { /* ignore exceptions here */ };
2996: }
2997: }
2998: //---------------------------------------------------------------------------
2999:
3000:
3001: void __fastcall TMainForm::ChatToggleExecute(TObject *Sender)
3002: {
3003: ChatToggle->Checked=!ChatToggle->Checked;
3004: if(ChatToggle->Checked)
3005: bbs_startup.options|=BBS_OPT_SYSOP_AVAILABLE;
3006: else
3007: bbs_startup.options&=~BBS_OPT_SYSOP_AVAILABLE;
3008:
3009: if(bbs_svc!=NULL && controlService!=NULL)
3010: controlService(bbs_svc
3011: ,ChatToggle->Checked ? SERVICE_CONTROL_SYSOP_AVAILABLE : SERVICE_CONTROL_SYSOP_UNAVAILABLE
3012: ,&bbs_svc_status);
3013: }
3014: //---------------------------------------------------------------------------
3015: void __fastcall TMainForm::UserEditExecute(TObject *Sender)
3016: {
3017: char str[256];
3018:
3019: sprintf(str,"%sUSEREDIT %s",cfg.exec_dir,cfg.data_dir);
3020: WinExec(str,SW_SHOWNORMAL);
3021: }
3022: //---------------------------------------------------------------------------
3023:
3024: void __fastcall TMainForm::BBSPreviewMenuItemClick(TObject *Sender)
3025: {
3026: TOpenDialog* dlg=new TOpenDialog((TComponent*)Sender);
3027:
3028: dlg->Options << ofNoChangeDir;
3029: dlg->Filter = "ANSI/Ctrl-A files (*.asc; *.msg; *.ans)|*.ASC;*.MSG;*.ANS"
3030: "|All files|*.*";
3031: dlg->InitialDir=cfg.text_dir;
3032: if(dlg->Execute()==true) {
3033: Application->CreateForm(__classid(TPreviewForm), &PreviewForm);
3034: PreviewForm->Filename=AnsiString(dlg->FileName);
3035: PreviewForm->ShowModal();
3036: delete PreviewForm;
3037: }
3038: delete dlg;
3039: }
3040: //---------------------------------------------------------------------------
3041: void __fastcall TMainForm::BBSLoginMenuItemClick(TObject *Sender)
3042: {
3043: if(!strnicmp(LoginCommand.c_str(),"start ",6)) /* Doesn't work on NT */
3044: ShellExecute(Handle, "open", LoginCommand.c_str()+6,
3045: NULL,NULL,SW_SHOWDEFAULT);
3046: else if(!strnicmp(LoginCommand.c_str(),"telnet:",7))
3047: ShellExecute(Handle, "open", LoginCommand.c_str(),
3048: NULL,NULL,SW_SHOWDEFAULT);
3049: else
3050: WinExec(LoginCommand.c_str(),SW_SHOWNORMAL);
3051: }
3052: //---------------------------------------------------------------------------
3053: void __fastcall TMainForm::ViewLogClick(TObject *Sender)
3054: {
3055: char str[128];
3056: char filename[MAX_PATH+1];
3057: struct tm* tm;
3058: time_t t;
3059: TModalResult mr;
3060:
3061: if(((TMenuItem*)Sender)->Tag==-1) {
3062: Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
3063: CodeInputForm->Label->Caption="Date";
3064: CodeInputForm->ComboBox->Items->Clear();
3065: CodeInputForm->ComboBox->Text=AnsiString(unixtodstr(&cfg,time(NULL),str));
3066: mr=CodeInputForm->ShowModal();
3067: t=dstrtounix(&cfg,CodeInputForm->ComboBox->Text.c_str());
3068: delete CodeInputForm;
3069: if(mr!=mrOk)
3070: return;
3071: } else {
3072: t=time(NULL);
3073: t-=((TMenuItem*)Sender)->Tag*24*60*60;
3074: }
3075: tm=localtime(&t);
3076: if(tm==NULL)
3077: return;
3078:
3079: /* Close Mail/FTP logs */
1.1.1.2 ! root 3080: mail_log_msg(NULL);
! 3081: ftp_log_msg(NULL);
1.1 root 3082:
1.1.1.2 ! root 3083: if(strchr(((TMenuItem*)Sender)->Hint.c_str(),'.')==NULL)
! 3084: sprintf(filename,"%sLOGS\\%s%02d%02d%02d.LOG"
! 3085: ,MainForm->cfg.logs_dir
! 3086: ,((TMenuItem*)Sender)->Hint.c_str()
! 3087: ,tm->tm_mon+1
! 3088: ,tm->tm_mday
! 3089: ,tm->tm_year%100
! 3090: );
! 3091: else
! 3092: sprintf(filename,"%s\\%s"
! 3093: ,MainForm->cfg.logs_dir
! 3094: ,((TMenuItem*)Sender)->Hint.c_str()
1.1 root 3095: );
3096: ViewFile(filename,((TMenuItem*)Sender)->Caption);
3097: }
3098: //---------------------------------------------------------------------------
3099: void __fastcall TMainForm::UserListExecute(TObject *Sender)
3100: {
3101: UserListForm->Show();
3102: }
3103: //---------------------------------------------------------------------------
3104:
3105: void __fastcall TMainForm::WebPageMenuItemClick(TObject *Sender)
3106: {
3107: ShellExecute(Handle, "open", ((TMenuItem*)Sender)->Hint.c_str(),
3108: NULL,NULL,SW_SHOWDEFAULT);
3109: }
3110: //---------------------------------------------------------------------------
3111: void __fastcall TMainForm::FormMinimize(TObject *Sender)
3112: {
3113: if(MinimizeToSysTray) {
3114: if(Password.Length()) {
3115: TrayIcon->RestoreOn=imNone;
3116: CloseTrayMenuItem->Enabled=false;
3117: ConfigureTrayMenuItem->Enabled=false;
3118: UserEditTrayMenuItem->Enabled=false;
3119: } else {
3120: TrayIcon->RestoreOn=imLeftClickUp;
3121: CloseTrayMenuItem->Enabled=true;
3122: ConfigureTrayMenuItem->Enabled=true;
3123: UserEditTrayMenuItem->Enabled=true;
3124: }
3125: if(!TrayIcon->Visible)
3126: TrayIcon->Visible=true;
3127: TrayIcon->Minimize();
3128: }
3129: }
3130:
3131: void __fastcall TMainForm::TrayIconRestore(TObject *Sender)
3132: {
3133: TrayIcon->Visible=false;
3134: }
3135:
3136: //---------------------------------------------------------------------------
3137:
3138: void __fastcall TMainForm::PropertiesExecute(TObject *Sender)
3139: {
3140: static inside;
3141: if(inside) return;
3142: inside=true;
3143:
3144: Application->CreateForm(__classid(TPropertiesDlg), &PropertiesDlg);
3145: PropertiesDlg->LoginCmdEdit->Text=LoginCommand;
3146: PropertiesDlg->ConfigCmdEdit->Text=ConfigCommand;
3147: PropertiesDlg->HostnameEdit->Text=global.host_name;
3148: PropertiesDlg->CtrlDirEdit->Text=global.ctrl_dir;
3149: PropertiesDlg->TempDirEdit->Text=global.temp_dir;
3150: PropertiesDlg->NodeIntUpDown->Position=NodeForm->Timer->Interval/1000;
3151: PropertiesDlg->ClientIntUpDown->Position=ClientForm->Timer->Interval/1000;
3152: PropertiesDlg->SemFreqUpDown->Position=global.sem_chk_freq;
3153: PropertiesDlg->TrayIconCheckBox->Checked=MinimizeToSysTray;
3154: PropertiesDlg->UndockableCheckBox->Checked=UndockableForms;
3155: PropertiesDlg->FileAssociationsCheckBox->Checked=UseFileAssociations;
3156: PropertiesDlg->PasswordEdit->Text=Password;
3157: PropertiesDlg->JS_MaxBytesEdit->Text=IntToStr(global.js.max_bytes);
3158: PropertiesDlg->JS_ContextStackEdit->Text=IntToStr(global.js.cx_stack);
3159: PropertiesDlg->JS_ThreadStackEdit->Text=IntToStr(global.js.thread_stack);
3160: PropertiesDlg->JS_BranchLimitEdit->Text=IntToStr(global.js.branch_limit);
3161: PropertiesDlg->JS_GcIntervalEdit->Text=IntToStr(global.js.gc_interval);
3162: PropertiesDlg->JS_YieldIntervalEdit->Text=IntToStr(global.js.yield_interval);
1.1.1.2 ! root 3163: PropertiesDlg->JS_LoadPathEdit->Text=global.js.load_path;
! 3164: PropertiesDlg->ErrorSoundEdit->Text=ErrorSoundFile;
1.1 root 3165:
3166: if(MaxLogLen==0)
3167: PropertiesDlg->MaxLogLenEdit->Text="<unlimited>";
3168: else
3169: PropertiesDlg->MaxLogLenEdit->Text=IntToStr(MaxLogLen);
3170: if(PropertiesDlg->ShowModal()==mrOk) {
3171: LoginCommand=PropertiesDlg->LoginCmdEdit->Text;
3172: ConfigCommand=PropertiesDlg->ConfigCmdEdit->Text;
3173: SAFECOPY(global.host_name,PropertiesDlg->HostnameEdit->Text.c_str());
3174: SAFECOPY(global.ctrl_dir,PropertiesDlg->CtrlDirEdit->Text.c_str());
3175: SAFECOPY(global.temp_dir,PropertiesDlg->TempDirEdit->Text.c_str());
3176: global.sem_chk_freq=PropertiesDlg->SemFreqUpDown->Position;
3177: SemFileTimer->Interval=global.sem_chk_freq;
3178:
3179: /* Copy global values to server startup structs */
3180: /* We don't support per-server unique values here (yet) */
3181: SAFECOPY(bbs_startup.host_name,global.host_name);
3182: SAFECOPY(bbs_startup.ctrl_dir,global.ctrl_dir);
3183: SAFECOPY(bbs_startup.temp_dir,global.temp_dir);
3184: bbs_startup.sem_chk_freq=global.sem_chk_freq;
3185:
3186: SAFECOPY(ftp_startup.host_name,global.host_name);
3187: SAFECOPY(ftp_startup.ctrl_dir,global.ctrl_dir);
3188: SAFECOPY(ftp_startup.temp_dir,global.temp_dir);
3189: ftp_startup.sem_chk_freq=global.sem_chk_freq;
3190:
3191: SAFECOPY(web_startup.host_name,global.host_name);
3192: SAFECOPY(web_startup.ctrl_dir,global.ctrl_dir);
3193: SAFECOPY(web_startup.temp_dir,global.temp_dir);
3194: web_startup.sem_chk_freq=global.sem_chk_freq;
3195:
3196: SAFECOPY(mail_startup.host_name,global.host_name);
3197: SAFECOPY(mail_startup.ctrl_dir,global.ctrl_dir);
3198: SAFECOPY(mail_startup.temp_dir,global.temp_dir);
3199: mail_startup.sem_chk_freq=global.sem_chk_freq;
3200:
3201: SAFECOPY(services_startup.host_name,global.host_name);
3202: SAFECOPY(services_startup.ctrl_dir,global.ctrl_dir);
3203: SAFECOPY(services_startup.temp_dir,global.temp_dir);
1.1.1.2 ! root 3204: services_startup.sem_chk_freq=global.sem_chk_freq ;
1.1 root 3205:
3206: Password=PropertiesDlg->PasswordEdit->Text;
3207: NodeForm->Timer->Interval=PropertiesDlg->NodeIntUpDown->Position*1000;
3208: ClientForm->Timer->Interval=PropertiesDlg->ClientIntUpDown->Position*1000;
3209: MinimizeToSysTray=PropertiesDlg->TrayIconCheckBox->Checked;
3210: UndockableForms=PropertiesDlg->UndockableCheckBox->Checked;
3211: UseFileAssociations=PropertiesDlg->FileAssociationsCheckBox->Checked;
1.1.1.2 ! root 3212: ErrorSoundFile=PropertiesDlg->ErrorSoundEdit->Text;
1.1 root 3213:
3214: /* JavaScript operating parameters */
3215: js_startup_t js=global.js; // save for later comparison
3216: global.js.max_bytes
3217: =PropertiesDlg->JS_MaxBytesEdit->Text.ToIntDef(JAVASCRIPT_MAX_BYTES);
3218: global.js.cx_stack
3219: =PropertiesDlg->JS_ContextStackEdit->Text.ToIntDef(JAVASCRIPT_CONTEXT_STACK);
3220: global.js.thread_stack
3221: =PropertiesDlg->JS_ThreadStackEdit->Text.ToIntDef(JAVASCRIPT_THREAD_STACK);
3222: global.js.branch_limit
3223: =PropertiesDlg->JS_BranchLimitEdit->Text.ToIntDef(JAVASCRIPT_BRANCH_LIMIT);
3224: global.js.gc_interval
3225: =PropertiesDlg->JS_GcIntervalEdit->Text.ToIntDef(JAVASCRIPT_GC_INTERVAL);
3226: global.js.yield_interval
3227: =PropertiesDlg->JS_YieldIntervalEdit->Text.ToIntDef(JAVASCRIPT_YIELD_INTERVAL);
1.1.1.2 ! root 3228: SAFECOPY(global.js.load_path, PropertiesDlg->JS_LoadPathEdit->Text.c_str());
1.1 root 3229:
3230: /* Copy global settings, if appropriate (not unique) */
3231: if(memcmp(&bbs_startup.js,&js,sizeof(js))==0) bbs_startup.js=global.js;
3232: if(memcmp(&ftp_startup.js,&js,sizeof(js))==0) ftp_startup.js=global.js;
3233: if(memcmp(&web_startup.js,&js,sizeof(js))==0) web_startup.js=global.js;
3234: if(memcmp(&mail_startup.js,&js,sizeof(js))==0) mail_startup.js=global.js;
3235: if(memcmp(&services_startup.js,&js,sizeof(js))==0) services_startup.js=global.js;
3236:
3237: MaxLogLen
3238: =PropertiesDlg->MaxLogLenEdit->Text.ToIntDef(0);
3239: SaveSettings(Sender);
3240: }
3241: delete PropertiesDlg;
3242:
3243: inside=false;
3244: }
3245: //---------------------------------------------------------------------------
3246:
3247: void __fastcall TMainForm::CloseTrayMenuItemClick(TObject *Sender)
3248: {
3249: Close();
3250: }
3251: //---------------------------------------------------------------------------
3252:
3253: void __fastcall TMainForm::RestoreTrayMenuItemClick(TObject *Sender)
3254: {
3255: #if 0
3256: TrayIcon->Visible=false;
3257: Application->Restore();
3258: #else
3259: static inside;
3260: if(inside)
3261: return;
3262: inside=true;
3263:
3264: if(Password.Length()) {
3265: Application->CreateForm(__classid(TCodeInputForm), &CodeInputForm);
3266: CodeInputForm->Label->Caption="Password";
3267: CodeInputForm->Edit->Visible=true;
3268: CodeInputForm->Edit->PasswordChar='*';
3269: if(CodeInputForm->ShowModal()==mrOk
3270: && CodeInputForm->Edit->Text.AnsiCompareIC(Password)==0)
3271: TrayIcon->Restore();
3272: delete CodeInputForm;
3273: } else
3274: TrayIcon->Restore();
3275:
3276: inside=false;
3277: #endif
3278: }
3279: //---------------------------------------------------------------------------
3280: void __fastcall TMainForm::BBSConfigWizardMenuItemClick(TObject *Sender)
3281: {
3282: TConfigWizard* ConfigWizard;
3283: static inside;
3284: if(inside) return;
3285: inside=true;
3286:
3287: Application->CreateForm(__classid(TConfigWizard), &ConfigWizard);
3288: if(ConfigWizard->ShowModal()==mrOk) {
3289: SaveSettings(Sender);
3290: // ReloadConfigExecute(Sender); /* unnecessary since refresh_cfg() is already called */
3291: }
3292: delete ConfigWizard;
3293:
3294: inside=false;
3295: }
3296: //---------------------------------------------------------------------------
3297:
3298: void __fastcall TMainForm::PageControlUnDock(TObject *Sender,
3299: TControl *Client, TWinControl *NewTarget, bool &Allow)
3300: {
3301: if(NewTarget==NULL) /* Desktop */
3302: Allow=UndockableForms;
3303: }
3304: //---------------------------------------------------------------------------
3305: void __fastcall TMainForm::reload_config(void)
3306: {
3307: char error[256];
3308: SAFECOPY(error,UNKNOWN_LOAD_ERROR);
1.1.1.2 ! root 3309: StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text="Reloading configuration...";
1.1 root 3310: if(!load_cfg(&cfg, NULL, TRUE, error)) {
3311: Application->MessageBox(error,"ERROR Re-loading Configuration"
3312: ,MB_OK|MB_ICONEXCLAMATION);
3313: Application->Terminate();
3314: }
1.1.1.2 ! root 3315: FILE* fp=fopen(MainForm->ini_file,"r");
! 3316: sbbs_read_ini(fp
! 3317: ,&MainForm->global
! 3318: ,NULL ,&MainForm->bbs_startup
! 3319: ,NULL ,NULL
! 3320: ,NULL ,NULL
! 3321: ,NULL ,NULL
! 3322: ,NULL ,NULL
! 3323: );
! 3324: if(fp!=NULL)
! 3325: fclose(fp);
! 3326: StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text="Configuration reloaded";
1.1 root 3327: semfile_list_check(&initialized,recycle_semfiles);
1.1.1.2 ! root 3328:
! 3329: if(bbs_startup.options&BBS_OPT_SYSOP_AVAILABLE)
! 3330: ChatToggle->Checked=true;
! 3331: else
! 3332: ChatToggle->Checked=false;
! 3333:
! 3334: if(bbs_startup.options&BBS_OPT_MUTE)
! 3335: SoundToggle->Checked=false;
! 3336: else
! 3337: SoundToggle->Checked=true;
1.1 root 3338: }
3339: //---------------------------------------------------------------------------
3340:
3341: void __fastcall TMainForm::ReloadConfigExecute(TObject *Sender)
3342: {
3343: FtpRecycleExecute(Sender);
3344: WebRecycleExecute(Sender);
3345: MailRecycleExecute(Sender);
3346: TelnetRecycleExecute(Sender);
3347: ServicesRecycleExecute(Sender);
3348:
3349: reload_config();
3350: #if 0 /* This appears to be redundant */
3351: node_t node;
3352: for(int i=0;i<cfg.sys_nodes;i++) {
3353: int file;
3354: if(NodeForm->getnodedat(i+1,&node,&file))
3355: break;
3356: node.misc|=NODE_RRUN;
3357: if(NodeForm->putnodedat(i+1,&node,file))
3358: break;
3359: }
3360: #endif
3361: }
3362:
3363: //---------------------------------------------------------------------------
3364:
3365:
3366: void __fastcall TMainForm::ServicesConfigureExecute(TObject *Sender)
3367: {
3368: static inside;
3369: if(inside) return;
3370: inside=true;
3371:
3372: Application->CreateForm(__classid(TServicesCfgDlg), &ServicesCfgDlg);
3373: ServicesCfgDlg->ShowModal();
3374: delete ServicesCfgDlg;
3375:
3376: inside=false;
3377: }
3378: //---------------------------------------------------------------------------
3379:
3380: void __fastcall TMainForm::UserTruncateMenuItemClick(TObject *Sender)
3381: {
3382: int usernumber;
3383: int deleted=0;
3384: user_t user;
3385:
3386: Screen->Cursor=crHourGlass;
3387: while((user.number=lastuser(&cfg))!=0) {
3388: if(getuserdat(&cfg,&user)!=0)
3389: break;
3390: if(!(user.misc&DELETED))
3391: break;
3392: if(!del_lastuser(&cfg))
3393: break;
3394: deleted++;
3395: }
3396: Screen->Cursor=crDefault;
3397: char str[128];
3398: sprintf(str,"%u Deleted User Records Removed",deleted);
3399: Application->MessageBox(str,"Users Truncated",MB_OK);
3400: }
3401:
3402: BOOL RecycleService(SC_HANDLE svc, SERVICE_STATUS* status)
3403: {
3404: if(svc==NULL || controlService==NULL)
3405: return(FALSE);
3406:
3407: return controlService(svc, SERVICE_CONTROL_RECYCLE, status);
3408: }
3409:
3410: //---------------------------------------------------------------------------
3411: void __fastcall TMainForm::MailRecycleExecute(TObject *Sender)
3412: {
3413: if(!RecycleService(mail_svc,&mail_svc_status)) {
3414: mail_startup.recycle_now=true;
3415: MailRecycle->Enabled=false;
3416: }
3417: }
3418: //---------------------------------------------------------------------------
3419: void __fastcall TMainForm::FtpRecycleExecute(TObject *Sender)
3420: {
3421: if(!RecycleService(ftp_svc,&ftp_svc_status)) {
3422: ftp_startup.recycle_now=true;
3423: FtpRecycle->Enabled=false;
3424: }
3425: }
3426: //---------------------------------------------------------------------------
3427: void __fastcall TMainForm::WebRecycleExecute(TObject *Sender)
3428: {
3429: if(!RecycleService(web_svc,&web_svc_status)) {
3430: web_startup.recycle_now=true;
3431: WebRecycle->Enabled=false;
3432: }
3433: }
3434: //---------------------------------------------------------------------------
3435: void __fastcall TMainForm::ServicesRecycleExecute(TObject *Sender)
3436: {
3437: if(!RecycleService(services_svc,&services_svc_status)) {
3438: services_startup.recycle_now=true;
3439: ServicesRecycle->Enabled=false;
3440: }
3441: }
3442: //---------------------------------------------------------------------------
3443:
3444: void __fastcall TMainForm::TelnetRecycleExecute(TObject *Sender)
3445: {
3446: if(!RecycleService(bbs_svc,&bbs_svc_status)) {
3447: bbs_startup.recycle_now=true;
3448: TelnetRecycle->Enabled=false;
3449: }
3450: }
3451: //---------------------------------------------------------------------------
3452:
3453: void __fastcall TMainForm::FileEditTextFilesClick(TObject *Sender)
3454: {
3455: TOpenDialog* dlg=new TOpenDialog((TComponent*)Sender);
3456:
3457: dlg->Options << ofNoChangeDir;
3458: dlg->Filter = "Text files (*.txt)|*.TXT"
3459: "|All files|*.*";
3460: dlg->InitialDir=cfg.text_dir;
3461: if(dlg->Execute()==true)
3462: EditFile(dlg->FileName.c_str());
3463: delete dlg;
3464: }
3465: //---------------------------------------------------------------------------
3466:
3467: void __fastcall TMainForm::BBSEditBajaMenuItemClick(TObject *Sender)
3468: {
3469: TOpenDialog* dlg=new TOpenDialog((TComponent*)Sender);
3470:
3471: dlg->Options << ofNoChangeDir;
3472: dlg->Filter = "Baja Source Code (*.src)|*.SRC";
3473: dlg->InitialDir=cfg.exec_dir;
3474: if(dlg->Execute()==true) {
3475: Application->CreateForm(__classid(TTextFileEditForm), &TextFileEditForm);
3476: TextFileEditForm->Filename=AnsiString(dlg->FileName);
3477: TextFileEditForm->Caption="Edit";
3478: if(TextFileEditForm->ShowModal()==mrOk) {
3479: /* Compile Baja Source File (requires Baja v2.33+) */
3480: char cmdline[512];
3481: sprintf(cmdline,"%sbaja -p %s",cfg.exec_dir,dlg->FileName);
3482: WinExec(cmdline,SW_SHOW);
3483: }
3484: delete TextFileEditForm;
3485: }
3486: delete dlg;
3487: }
3488: //---------------------------------------------------------------------------
3489:
3490: void __fastcall TMainForm::FileEditJavaScriptClick(TObject *Sender)
3491: {
3492: TOpenDialog* dlg=new TOpenDialog((TComponent*)Sender);
3493:
3494: dlg->Options << ofNoChangeDir;
3495: dlg->Filter = "JavaScript Files (*.js)|*.JS";
3496: dlg->InitialDir=cfg.exec_dir;
3497: if(dlg->Execute()==true)
3498: EditFile(dlg->FileName.c_str());
3499: delete dlg;
3500: }
3501: //---------------------------------------------------------------------------
3502:
3503: void __fastcall TMainForm::FileEditConfigFilesClick(TObject *Sender)
3504: {
3505: TOpenDialog* dlg=new TOpenDialog((TComponent*)Sender);
3506:
3507: dlg->Options << ofNoChangeDir;
3508: dlg->Filter = "Configuration Files (*.cfg; *.ini; *.conf)|*.cfg;*.ini;*.conf";
3509: dlg->InitialDir=cfg.ctrl_dir;
3510: if(dlg->Execute()==true)
3511: EditFile(dlg->FileName.c_str());
3512: delete dlg;
3513: }
3514:
3515: void __fastcall TMainForm::BBSEditFileClick(TObject *Sender)
3516: {
3517: TOpenDialog* dlg=new TOpenDialog((TComponent*)Sender);
3518:
3519: dlg->Options << ofNoChangeDir;
3520: dlg->Filter = "ANSI/Ctrl-A files (*.asc; *.msg; *.ans)|*.ASC;*.MSG;*.ANS"
3521: "|All files|*.*";
3522: dlg->InitialDir=cfg.text_dir;
3523: if(dlg->Execute()==true) {
3524: Application->CreateForm(__classid(TTextFileEditForm), &TextFileEditForm);
3525: TextFileEditForm->Filename=AnsiString(dlg->FileName);
3526: TextFileEditForm->Caption="Edit";
3527: if(TextFileEditForm->ShowModal()==mrOk) {
3528: Application->CreateForm(__classid(TPreviewForm), &PreviewForm);
3529: PreviewForm->Filename=AnsiString(dlg->FileName);
3530: PreviewForm->ShowModal();
3531: delete PreviewForm;
3532: }
3533: delete TextFileEditForm;
3534: }
3535: delete dlg;
3536: }
3537: //---------------------------------------------------------------------------
1.1.1.2 ! root 3538: bool GetServerLogLine(HANDLE& log, const char* name, log_msg_t* msg)
1.1 root 3539: {
3540: char fname[256];
3541:
3542: if(log==INVALID_HANDLE_VALUE) {
3543: sprintf(fname,"\\\\.\\mailslot\\%s.log",name);
3544: log = CreateMailslot(
3545: fname, // pointer to string for mailslot name
3546: 0, // maximum message size
3547: 0, // milliseconds before read time-out
3548: NULL); // pointer to security structure
3549: if(log==INVALID_HANDLE_VALUE)
3550: return(false);
3551: }
3552: DWORD msgs=0;
3553: if(!GetMailslotInfo(
3554: log, // mailslot handle
3555: NULL, // address of maximum message size
3556: NULL, // address of size of next message
3557: &msgs, // address of number of messages
3558: NULL // address of read time-out
3559: ) || !msgs)
3560: return(false);
3561:
3562: DWORD rd=0;
3563: if(!ReadFile(
3564: log, // handle of file to read
1.1.1.2 ! root 3565: msg, // pointer to buffer that receives data
! 3566: sizeof(*msg), // number of bytes to read
1.1 root 3567: &rd, // pointer to number of bytes read
3568: NULL // pointer to structure for data
3569: ) || !rd)
3570: return(false);
3571:
3572: return(true);
3573: }
3574: //---------------------------------------------------------------------------
3575:
3576: void __fastcall TMainForm::LogTimerTick(TObject *Sender)
3577: {
1.1.1.2 ! root 3578: log_msg_t msg;
! 3579: log_msg_t* pmsg;
1.1 root 3580:
1.1.1.2 ! root 3581: if(!TelnetPause->Checked) {
! 3582: while(GetServerLogLine(bbs_log,NTSVC_NAME_BBS,&msg))
! 3583: bbs_log_msg(&msg);
! 3584:
! 3585: while(GetServerLogLine(event_log,NTSVC_NAME_EVENT,&msg))
! 3586: event_log_msg(&msg);
! 3587:
! 3588: while((pmsg=(log_msg_t*)listShiftNode(&bbs_log_list)) != NULL) {
! 3589: bbs_log_msg(pmsg);
! 3590: free(pmsg);
! 3591: }
1.1 root 3592:
1.1.1.2 ! root 3593: while((pmsg=(log_msg_t*)listShiftNode(&event_log_list)) != NULL) {
! 3594: event_log_msg(pmsg);
! 3595: free(pmsg);
! 3596: }
! 3597: }
1.1 root 3598:
1.1.1.2 ! root 3599: if(!FtpPause->Checked) {
! 3600: while(GetServerLogLine(ftp_log,NTSVC_NAME_FTP,&msg))
! 3601: ftp_log_msg(&msg);
! 3602:
! 3603: while((pmsg=(log_msg_t*)listShiftNode(&ftp_log_list)) != NULL) {
! 3604: ftp_log_msg(pmsg);
! 3605: free(pmsg);
! 3606: }
! 3607: }
! 3608: if(!MailPause->Checked) {
! 3609: while(GetServerLogLine(mail_log,NTSVC_NAME_MAIL,&msg))
! 3610: mail_log_msg(&msg);
! 3611:
! 3612: while((pmsg=(log_msg_t*)listShiftNode(&mail_log_list)) != NULL) {
! 3613: mail_log_msg(pmsg);
! 3614: free(pmsg);
! 3615: }
! 3616: }
! 3617: if(!WebPause->Checked) {
! 3618: while(GetServerLogLine(web_log,NTSVC_NAME_WEB,&msg))
! 3619: web_log_msg(&msg);
! 3620:
! 3621: while((pmsg=(log_msg_t*)listShiftNode(&web_log_list)) != NULL) {
! 3622: web_log_msg(pmsg);
! 3623: free(pmsg);
! 3624: }
! 3625: }
! 3626: if(!ServicesPause->Checked) {
! 3627: while(GetServerLogLine(services_log,NTSVC_NAME_SERVICES,&msg))
! 3628: services_log_msg(&msg);
! 3629:
! 3630: while((pmsg=(log_msg_t*)listShiftNode(&services_log_list)) != NULL) {
! 3631: services_log_msg(pmsg);
! 3632: free(pmsg);
! 3633: }
! 3634: }
1.1 root 3635: }
3636: //---------------------------------------------------------------------------
3637: void CheckServiceStatus(
3638: SC_HANDLE svc
3639: ,SERVICE_STATUS* status
3640: ,QUERY_SERVICE_CONFIG* &config
3641: ,DWORD &config_size
3642: ,TStaticText* text
3643: ,TAction* start
3644: ,TAction* stop
3645: ,TAction* recycle
3646: ,TProgressBar* bar
3647: )
3648: {
3649: if(svc==NULL)
3650: return;
3651:
3652: DWORD ret;
3653:
3654: if(!queryServiceConfig(svc,config,config_size,&ret)) {
3655: if(GetLastError()==ERROR_INSUFFICIENT_BUFFER) {
3656: config_size=ret;
3657: if(config!=NULL)
3658: free(config);
3659: config = (QUERY_SERVICE_CONFIG*)malloc(config_size);
3660: }
3661: return;
3662: }
3663:
3664: if(config->dwStartType==SERVICE_DISABLED)
3665: return;
3666:
3667: if(!queryServiceStatus(svc,status)) {
3668: text->Caption="QueryServiceStatus Error "; // + GetLastError());
3669: return;
3670: }
3671:
3672: bool running=false;
3673:
3674: switch(status->dwCurrentState) {
3675: case SERVICE_STOPPED:
3676: text->Caption="Stopped NT Service";
3677: break;
3678: case SERVICE_STOP_PENDING:
3679: text->Caption="Stopping NT Service";
3680: break;
3681: case SERVICE_RUNNING:
3682: text->Caption="Running NT Service";
3683: running=true;
3684: break;
3685: case SERVICE_START_PENDING:
3686: text->Caption="Starting NT Service";
3687: running=true;
3688: break;
3689: default:
3690: text->Caption="!UNKNOWN: " + status->dwCurrentState;
3691: break;
3692: }
3693:
3694: start->Enabled=!running;
3695: stop->Enabled=running;
3696: recycle->Enabled=running;
3697: }
3698: //---------------------------------------------------------------------------
3699:
3700: void __fastcall TMainForm::ServiceStatusTimerTick(TObject *Sender)
3701: {
3702: if(queryServiceStatus==NULL || queryServiceConfig==NULL
3703: || (bbs_svc==NULL
3704: && ftp_svc==NULL
3705: && web_svc==NULL
3706: && mail_svc==NULL
3707: && services_svc==NULL)) {
3708: ServiceStatusTimer->Enabled=false;
3709: return;
3710: }
3711:
3712: CheckServiceStatus(
3713: bbs_svc
3714: ,&bbs_svc_status
3715: ,bbs_svc_config
3716: ,bbs_svc_config_size
3717: ,TelnetForm->Status
3718: ,TelnetStart
3719: ,TelnetStop
3720: ,TelnetRecycle
3721: ,TelnetForm->ProgressBar
3722: );
3723: CheckServiceStatus(
3724: ftp_svc
3725: ,&ftp_svc_status
3726: ,ftp_svc_config
3727: ,ftp_svc_config_size
3728: ,FtpForm->Status
3729: ,FtpStart
3730: ,FtpStop
3731: ,FtpRecycle
3732: ,FtpForm->ProgressBar
3733: );
3734: CheckServiceStatus(
3735: web_svc
3736: ,&web_svc_status
3737: ,web_svc_config
3738: ,web_svc_config_size
3739: ,WebForm->Status
3740: ,WebStart
3741: ,WebStop
3742: ,WebRecycle
3743: ,WebForm->ProgressBar
3744: );
3745: CheckServiceStatus(
3746: mail_svc
3747: ,&mail_svc_status
3748: ,mail_svc_config
3749: ,mail_svc_config_size
3750: ,MailForm->Status
3751: ,MailStart
3752: ,MailStop
3753: ,MailRecycle
3754: ,MailForm->ProgressBar
3755: );
3756: CheckServiceStatus(
3757: services_svc
3758: ,&services_svc_status
3759: ,services_svc_config
3760: ,services_svc_config_size
3761: ,ServicesForm->Status
3762: ,ServicesStart
3763: ,ServicesStop
3764: ,ServicesRecycle
3765: ,NULL
3766: );
3767:
3768: }
3769: //---------------------------------------------------------------------------
3770: void __fastcall TMainForm::EditFile(AnsiString filename, AnsiString Caption)
3771: {
3772: if(!UseFileAssociations
3773: || (int)ShellExecute(Handle, "edit", filename.c_str(), NULL,NULL,SW_SHOWDEFAULT)<=32) {
3774: Application->CreateForm(__classid(TTextFileEditForm), &TextFileEditForm);
3775: TextFileEditForm->Filename=filename;
3776: TextFileEditForm->Caption=Caption;
3777: TextFileEditForm->ShowModal();
3778: delete TextFileEditForm;
3779: }
3780: }
3781: //---------------------------------------------------------------------------
3782: void __fastcall TMainForm::ViewFile(AnsiString filename, AnsiString Caption)
3783: {
3784: if(!UseFileAssociations
3785: || (int)ShellExecute(Handle, "open", filename.c_str(), NULL,NULL,SW_SHOWDEFAULT)<=32) {
3786: Application->CreateForm(__classid(TTextFileEditForm), &TextFileEditForm);
3787: TextFileEditForm->Filename=filename;
3788: TextFileEditForm->Caption=Caption;
3789: TextFileEditForm->Memo->ReadOnly=true;
3790: TextFileEditForm->ShowModal();
3791: delete TextFileEditForm;
3792: }
3793: }
3794: //---------------------------------------------------------------------------
3795: void __fastcall TMainForm::SemFileTimerTick(TObject *Sender)
3796: {
3797: char* p;
3798:
3799: if((p=semfile_list_check(&initialized,shutdown_semfiles))!=NULL) {
1.1.1.2 ! root 3800: StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text=AnsiString(p) + " signaled";
1.1 root 3801: terminating=true;
3802: Close();
3803: }
3804: else if((p=semfile_list_check(&initialized,recycle_semfiles))!=NULL) {
1.1.1.2 ! root 3805: StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text=AnsiString(p) + " signaled";
1.1 root 3806: reload_config();
3807: }
3808: }
3809: //---------------------------------------------------------------------------
1.1.1.2 ! root 3810: TFont* __fastcall TMainForm::LogAttributes(int log_level, TColor Color, TFont* Font)
! 3811: {
! 3812: if(log_level==LOG_INFO || LogFont[log_level]->Color==Color
! 3813: || log_level > LOG_DEBUG)
! 3814: return Font;
! 3815:
! 3816: return LogFont[log_level];
! 3817: }
! 3818: //---------------------------------------------------------------------------
! 3819: void __fastcall TMainForm::ClearErrorsExecute(TObject *Sender)
! 3820: {
! 3821: errors=0;
! 3822:
! 3823: node_t node;
! 3824: for(int i=0;i<cfg.sys_nodes;i++) {
! 3825: int file;
! 3826: if(NodeForm->getnodedat(i+1,&node,&file))
! 3827: break;
! 3828: node.errors=0;
! 3829: if(NodeForm->putnodedat(i+1,&node,file))
! 3830: break;
! 3831: }
! 3832: }
! 3833: //---------------------------------------------------------------------------
! 3834: void __fastcall TMainForm::ViewErrorLogExecute(TObject *Sender)
! 3835: {
! 3836: char filename[MAX_PATH+1];
! 3837:
! 3838: sprintf(filename,"%sERROR.LOG"
! 3839: ,MainForm->cfg.logs_dir);
! 3840: ViewFile(filename,"Error Log");
! 3841: }
! 3842: //---------------------------------------------------------------------------
! 3843: void __fastcall TMainForm::ViewLoginAttemptsMenuItemClick(TObject *Sender)
! 3844: {
! 3845: LoginAttemptsForm->Show();
! 3846: }
! 3847: //---------------------------------------------------------------------------
1.1 root 3848:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.