home *** CD-ROM | disk | FTP | other *** search
- unit WABD_Admin;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- WABD_Objects,WABD_Utils;
-
- type
- TWABDAdmin = class(TDataModule)
- frmAdmin: TWABD_Form;
- WABD_Raw1: TWABD_HTMLSection;
- tblSessions: TWABD_Table;
- WABDAdminSession: TWABD_Session;
- fsGenerel: TWABD_FormSection;
- WABD_Button1: TWABD_Button;
- WABD_Label1: TWABD_Label;
- lSessionCnt: TWABD_Label;
- fsSessions: TWABD_FormSection;
- WABD_Button2: TWABD_Button;
- WABD_Label16: TWABD_Label;
- cbStats: TWABD_ComboBox;
- tblStats: TWABD_Table;
- fsStats: TWABD_FormSection;
- WABD_Raw2: TWABD_HTMLSection;
- fsStatHeader: TWABD_FormSection;
- WABD_Label2: TWABD_Label;
- lBufferSize: TWABD_Label;
- WABD_Label4: TWABD_Label;
- lSize: TWABD_Label;
- WABD_Label6: TWABD_Label;
- lAverage: TWABD_Label;
- WABD_Label8: TWABD_Label;
- lSum: TWABD_Label;
- WABD_Label10: TWABD_Label;
- lPointCount: TWABD_Label;
- WABD_Label12: TWABD_Label;
- lMin: TWABD_Label;
- WABD_Label14: TWABD_Label;
- lMax: TWABD_Label;
- WABD_Label3: TWABD_Label;
- lSite: TWABD_Label;
- fsSetup: TWABD_FormSection;
- WABD_Label5: TWABD_Label;
- WABD_Label7: TWABD_Label;
- eAdminUser: TWABD_Edit;
- eAdminPassword: TWABD_Edit;
- eAdminPasswordRetype: TWABD_Edit;
- WABD_Label9: TWABD_Label;
- btnSetAdminUser: TWABD_Button;
- lPasswordStatus: TWABD_Label;
- chbGarbageCollection: TWABD_CheckBox;
- eGarbageInterval: TWABD_Edit;
- WABD_Label11: TWABD_Label;
- chbGatherStatistics: TWABD_CheckBox;
- WABD_Label13: TWABD_Label;
- eAdminText: TWABD_Edit;
- btnSetGarbage: TWABD_Button;
- lGarbageStatus: TWABD_Label;
- WABD_Label15: TWABD_Label;
- eTimeout: TWABD_Edit;
- btnSetAdminText: TWABD_Button;
- WABD_Label17: TWABD_Label;
- lSessionID: TWABD_Label;
- WABD_Label18: TWABD_Label;
- eMaxSessions: TWABD_Edit;
- btnMax: TWABD_Button;
- WABD_Label19: TWABD_Label;
- WABD_Label20: TWABD_Label;
- WABD_Label21: TWABD_Label;
- WABD_Label22: TWABD_Label;
- btnSaveStats: TWABD_Button;
- btnLoadStats: TWABD_Button;
- btnClearStat: TWABD_Button;
- btnClearAllStats: TWABD_Button;
- frmLoggedOff: TWABD_Form;
- rawLogout: TWABD_HTMLSection;
- WABD_Label23: TWABD_Label;
- eRouteWhen: TWABD_Edit;
- WABD_Label24: TWABD_Label;
- eRouteHow: TWABD_Edit;
- WABD_Label25: TWABD_Label;
- mRouteSites: TWABD_Memo;
- WABD_Label26: TWABD_Label;
- WABD_Label27: TWABD_Label;
- WABD_Label28: TWABD_Label;
- btnSetRoute: TWABD_Button;
- WABD_Label29: TWABD_Label;
- eMaxIdenticalUser: TWABD_Edit;
- WABD_Label30: TWABD_Label;
- WABD_Label31: TWABD_Label;
- eInfo: TWABD_Edit;
- btnSendTextSessions: TWABD_Button;
- WABD_Label32: TWABD_Label;
- chbNetworkStats: TWABD_CheckBox;
- procedure WABDAdminSessionFirstLogon(RemoteHost: String);
- procedure WABD_Button1UserClick(Sender: TObject);
- procedure tblSessionsUserClick(Sender: TObject; RowIndex: Integer);
- procedure WABD_Button2UserClick(Sender: TObject);
- procedure cbStatsUserChange(Sender: TObject);
- procedure btnSetAdminUserUserClick(Sender: TObject);
- procedure btnSetGarbageUserClick(Sender: TObject);
- procedure btnSetAdminTextUserClick(Sender: TObject);
- procedure btnTerminateDLLUserClick(Sender: TObject);
- procedure btnMaxUserClick(Sender: TObject);
- procedure btnSaveStatsUserClick(Sender: TObject);
- procedure btnLoadStatsUserClick(Sender: TObject);
- procedure btnClearStatUserClick(Sender: TObject);
- procedure btnClearAllStatsUserClick(Sender: TObject);
- procedure btnSetRouteUserClick(Sender: TObject);
- procedure btnSendTextSessionsUserClick(Sender: TObject);
- procedure tblSessionsRenderCell(Sender: TWABD_Table; Row, Col: Integer;
- var Text: String; var HAlign: TWABD_HorzAlignment;
- var VAlign: TWABD_VertAlignment; var Color, BGColor: TColor;
- var Size: Integer; var Bold, Italic, Underline, Fixed,
- Strike: Boolean; var Width, Height: Integer;
- var AllowWordWrap: Boolean);
- procedure tblStatsRenderCell(Sender: TWABD_Table; Row, Col: Integer;
- var Text: String; var HAlign: TWABD_HorzAlignment;
- var VAlign: TWABD_VertAlignment; var Color, BGColor: TColor;
- var Size: Integer; var Bold, Italic, Underline, Fixed,
- Strike: Boolean; var Width, Height: Integer;
- var AllowWordWrap: Boolean);
- private
- { Private declarations }
- FAppSetupForm:TWABD_Form;
-
- public
- { Public declarations }
- constructor Create(AOwner:TComponent); override;
- constructor CreateWithAppSetupForm(AOwner:TComponent; AppSetupForm:TWABD_Form);
- procedure KillAllSessions;
- procedure KillSession(SesID:integer);
- procedure BuildSessionList;
- procedure BuildStats(grpname:string);
- procedure BuildSetup;
- procedure Update;
- end;
-
- var
- WABDAdmin: TWABDAdmin;
-
- implementation
-
- const
- IDENT_SESSION='wabdstatses';
- IDENT_SETUP='wabdstatsetup';
- IDENT_APPSETUP='wabdappsetup';
-
- {$R *.DFM}
-
- constructor TWABDAdmin.Create(AOwner:TComponent);
- begin
- FAppSetupForm:=nil;
- inherited;
- end;
-
- constructor TWABDAdmin.CreateWithAppSetupForm(AOwner:TComponent; AppSetupForm:TWABD_Form);
- begin
- FAppSetupForm:=AppSetupForm;
- inherited Create(AOwner);
- end;
-
- procedure TWABDAdmin.Update;
- var
- i:integer;
- oi:integer;
- lst:TList;
- begin
- // Build list of stats.
- oi:=cbStats.SelIndex;
- with frmAdmin.Session.SessionMgr do
- begin
- cbStats.Lines.clear;
- cbStats.Lines.Add(IDENT_SESSION+'=Sessions');
- cbStats.Lines.Add(IDENT_SETUP+'=General setup');
- if FAppSetupForm<>nil then cbStats.Lines.Add(IDENT_APPSETUP+'=Application setup');
- if Stats<>nil then
- begin
- lst:=Stats.LockList;
- try
- for i:=0 to lst.count-1 do
- cbStats.Lines.Add(TWABD_SesStatGroup(lst.Items[i]).Name);
- finally
- Stats.UnlockList;
- end;
- end;
- end;
- cbStats.SelIndex:=oi;
- if cbStats.SelIndex<0 then cbStats.SelIndex:=0;
-
- // Check choise.
- if cbStats.Text=IDENT_SESSION then
- begin
- BuildSessionList;
- tblSessions.Visible:=true;
- tblStats.Visible:=false;
- fsSetup.Visible:=false;
- end else if cbStats.Text=IDENT_SETUP then
- begin
- BuildSetup;
- fsSetup.Visible:=true;
- tblSessions.Visible:=false;
- tblStats.Visible:=false;
- end else if cbStats.Text=IDENT_APPSETUP then
- begin
- FAppSetupForm.show;
- end else if cbStats.Text<>'' then
- begin
- BuildStats(cbStats.Text);
- tblStats.visible:=true;
- tblSessions.visible:=false;
- fsSetup.Visible:=false;
- end;
-
- with frmAdmin.Session.SessionMgr do
- begin
- lSite.caption:=SiteName;
- end;
- lSessionID.caption:=inttostr(WABDAdminSession.sessionID);
- end;
-
- procedure TWABDAdmin.KillAllSessions;
- var
- i:integer;
- lst:TList;
- ses:TWABD_Session;
- begin
- with frmAdmin.Session.SessionMgr do
- begin
- lst:=SessionList.LockList;
- try
- for i:=lst.Count-1 downto 0 do
- begin
- ses:=TWABD_Session(lst.Items[i]);
- if ses.SessionID<>WABDAdminSession.SessionID then
- begin
- ses.LogOff;
- CheckLogOff(ses);
- end;
- end;
- finally
- SessionList.UnlockList;
- end;
- end;
- end;
-
- procedure TWABDAdmin.KillSession(SesID:integer);
- var
- i:integer;
- lst:TList;
- ses:TWABD_Session;
- begin
- with frmAdmin.Session.SessionMgr do
- begin
- lst:=SessionList.LockList;
- try
- for i:=0 to lst.Count-1 do
- begin
- ses:=TWABD_Session(lst.Items[i]);
- if ses.SessionID=SesID then
- begin
- ses.LogOff;
- if SesID<>WABDAdminSession.sessionID then CheckLogOff(ses);
- break;
- end;
- end;
- finally
- SessionList.UnlockList;
- end;
- end;
- end;
-
- procedure TWABDAdmin.BuildSetup;
- begin
- with frmAdmin.Session.SessionMgr do
- begin
- eAdminUser.text:=Admin.AdminUser;
- eAdminPassword.text:=Admin.AdminPassword;
- eAdminPasswordRetype.Text:='';
- chbGarbageCollection.Checked:=GarbageCollection;
- eGarbageInterval.Text:=inttostr(CheckTimeOutInterval);
- chbGatherStatistics.Checked:=GatherStatistics;
- chbNetworkStats.Checked:=NetworkStatistics;
- eTimeOut.Text:=inttostr(DefaultSessionTimeout);
- eAdminText.Text:=WebAdministrator;
- eMaxSessions.Text:=inttostr(MaxConcurrentSessions);
- eMaxIdenticalUser.Text:=inttostr(MaxIdenticalUser);
- eRouteWhen.Text:=inttostr(ord(RouteWhen));
- eRouteHow.Text:=inttostr(ord(RouteHow));
- mRouteSites.Lines.Assign(RouteSites);
- end;
- end;
-
- procedure TWABDAdmin.BuildStats(grpname:string);
- var
- i,j:integer;
- grp:TWABD_SesStatGroup;
- avg:double;
- header:string;
- lst,grplst:TList;
- const
- Weekdays:array [1..7] of string = ( 'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
- MonthNames:array [1..12] of string = ( 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec' );
- begin
-
- with frmAdmin.Session.SessionMgr,tblStats do
- begin
- i:=Stats.IndexOf(grpname);
-
- lst:=Stats.LockList;
- try
- grp:=TWABD_SesStatGroup(lst.Items[i]);
-
- // Decide header.
- case grp.GroupType of
- wabdstatgroupTurnAround: header:='msecs.';
- wabdstatgroupcount: header:='Count';
- wabdstatgroupvalue: header:='Value';
- end;
-
- // Setup table.
- grplst:=grp.LockList;
- try
- Cells.SafeSetSize(4,1+24+1+31+1+12+1+7+1+grplst.count);
- j:=0;
-
- // Build hourly list.
- Cells[0,j]:='*Hour';
- Cells[1,j]:='*Count';
- Cells[2,j]:='*Sum';
- Cells[3,j]:='*Avg.';
- inc(j);
- for i:=0 to 23 do
- begin
- Cells[0,j]:=inttostr(i);
- Cells[1,j]:=inttostr(grp.HourlyCount[i]);
- Cells[2,j]:=format('%.2f',[grp.HourlyValues[i]]);
- if grp.HourlyCount[i]>0 then
- Cells[3,j]:=format('%.2f',[grp.HourlyValues[i] / grp.HourlyCount[i]])
- else
- Cells[3,j]:='N/A';
- inc(j);
- end;
-
- // Build hourly list.
- Cells[0,j]:='*Day';
- Cells[1,j]:='*Count';
- Cells[2,j]:='*Sum';
- Cells[3,j]:='*Avg.';
- inc(j);
- for i:=1 to 31 do
- begin
- Cells[0,j]:=inttostr(i);
- Cells[1,j]:=inttostr(grp.DailyCount[i]);
- Cells[2,j]:=format('%.2f',[grp.DailyValues[i]]);
- if grp.DailyCount[i]>0 then
- Cells[3,j]:=format('%.2f',[grp.DailyValues[i] / grp.DailyCount[i]])
- else
- Cells[3,j]:='N/A';
- inc(j);
- end;
-
- // Build monthly list.
- Cells[0,j]:='*Month';
- Cells[1,j]:='*Count';
- Cells[2,j]:='*Sum';
- Cells[3,j]:='*Avg.';
- inc(j);
- for i:=1 to 12 do
- begin
- Cells[0,j]:=MonthNames[i];
- Cells[1,j]:=inttostr(grp.MonthlyCount[i]);
- Cells[2,j]:=format('%.2f',[grp.MonthlyValues[i]]);
- if grp.MonthlyCount[i]>0 then
- Cells[3,j]:=format('%.2f',[grp.MonthlyValues[i] / grp.MonthlyCount[i]])
- else
- Cells[3,j]:='N/A';
- inc(j);
- end;
-
- // Build day list.
- Cells[0,j]:='*Weekday';
- Cells[1,j]:='*Count';
- Cells[2,j]:='*Sum';
- Cells[3,j]:='*Avg.';
- inc(j);
- for i:=1 to 7 do
- begin
- Cells[0,j]:=WeekDays[i];
- Cells[1,j]:=inttostr(grp.DayCount[i]);
- Cells[2,j]:=format('%.2f',[grp.DayValues[i]]);
- if grp.DayCount[i]>0 then
- Cells[3,j]:=format('%.2f',[grp.DayValues[i] / grp.DayCount[i]])
- else
- Cells[3,j]:='N/A';
- inc(j);
- end;
-
- // Build list.
- Cells[0,j]:='*Timestamp';
- Cells[1,j]:='*User';
- Cells[2,j]:='*Info';
- Cells[3,j]:='*'+header;
- inc(j);
- for i:=grplst.Count-1 downto 0 do
- with PWABD_SesStatRec(grplst.Items[i])^do
- begin
- Cells[0,j]:=DateTimeToStr(Stamp);
- Cells[1,j]:=User;
- Cells[2,j]:=Info;
- Cells[3,j]:=floattostr(trunc(Value));
- inc(j);
- end;
-
- // Build substat list.
-
- // Show group values.
- lBufferSize.caption:=inttostr(grp.BufferSize);
- lSize.caption:=inttostr(grplst.Count);
- lPointCount.caption:=inttostr(grp.TotalCount);
- if grp.TotalCount>0 then
- avg:=grp.Sum / grp.TotalCount
- else
- avg:=0;
- lAverage.caption:=format('%.2f',[avg]);;
- lMin.caption:=format('%.2f',[grp.Min]);
- lMax.caption:=format('%.2f',[grp.Max]);
- lSum.caption:=format('%.2f',[grp.Sum]);
- finally
- grp.UnlockList;
- end;
- finally
- Stats.UnlockList;
- end;
- end;
- end;
-
- procedure TWABDAdmin.BuildSessionList;
- var
- i:integer;
- lst:TList;
- begin
- with frmAdmin.Session.SessionMgr,tblSessions do
- begin
- eInfo.Text:=Info;
- lst:=SessionList.LockList;
- try
- lSessionCnt.caption:=inttostr(lst.count);
-
- Cells.SafeSetSize(6,lst.count+1);
- Cells[0,0]:='SessionID';
- Cells[1,0]:='User';
- Cells[2,0]:='Browser';
- Cells[3,0]:='Logged on';
- Cells[4,0]:='Last access';
- Cells[5,0]:='Timeout (secs.)';
-
- for i:=0 to lst.Count-1 do
- with TWABD_Session(lst.Items[i]) do
- begin
- Cells[0,i+1]:=IntToStr(SessionID);
- Cells[1,i+1]:=UserName;
- Cells[2,i+1]:=WABD_Browser[Request.Browser]+' '+FloatToStr(Request.BrowserVersion);
- Cells[3,i+1]:=DateTimeToStr(CreateTime);
- Cells[4,i+1]:=DateTimeToStr(LastAccess);
- Cells[5,i+1]:=inttostr(TimeOutLength-trunc(24*60*60*(now-LastAccess)));
- end;
- finally
- SessionList.UnlockList;
- end;
- end;
- end;
-
- procedure TWABDAdmin.WABDAdminSessionFirstLogon(RemoteHost: String);
- begin
- Update;
- end;
-
- procedure TWABDAdmin.WABD_Button1UserClick(Sender: TObject);
- begin
- Update;
- end;
-
- procedure TWABDAdmin.tblSessionsUserClick(Sender: TObject;
- RowIndex: Integer);
- var
- SesID:integer;
- begin
- SesID:=StrToInt(tblSessions.Cells[0,RowIndex]);
- KillSession(SesID);
- if SesID=WABDAdminSession.sessionID then
- begin
- rawLogout.HTML.Text:=frmAdmin.Session.SessionMgr.Admin.LogoutHTML;
- frmLoggedOff.Show;
- end
- else Update;
- end;
-
- procedure TWABDAdmin.WABD_Button2UserClick(Sender: TObject);
- begin
- KillAllSessions;
- Update;
- end;
-
- // Show stats.
- procedure TWABDAdmin.cbStatsUserChange(Sender: TObject);
- begin
- Update;
- end;
-
- // Setup admin username/password.
- procedure TWABDAdmin.btnSetAdminUserUserClick(Sender: TObject);
- begin
- with frmAdmin.Session.SessionMgr do
- begin
- if (length(eAdminUser.Text)>0) and (eAdminPassword.Text = eAdminPasswordRetype.Text) then
- begin
- Admin.AdminUser:=Trim(eAdminUser.Text);
- Admin.AdminPassword:=Trim(eAdminPassword.Text);
- eAdminPasswordRetype.Text:='';
- lPasswordStatus.caption:='New username and password is set.';
- end
- else
- lPasswordStatus.caption:='Username not given or password retyped incorrectly.';
- end;
- Update;
- end;
-
- // Setup garbage collection/stat collection.
- procedure TWABDAdmin.btnSetGarbageUserClick(Sender: TObject);
- var
- i,t:integer;
- begin
- with frmAdmin.Session.SessionMgr do
- begin
- try
- i:=strtoint(eGarbageInterval.Text);
- if (i<10) or (i>9999) then raise Exception.Create('Invalid value.');
- t:=strtoint(eTimeOut.Text);
- if (t<-1) then raise Exception.Create('Invalid value');
- except
- lGarbageStatus.caption:='Invalid interval entered.';
- exit;
- end;
-
- CheckTimeOutInterval:=i;
- GarbageCollection:=chbGarbageCollection.Checked;
- GatherStatistics:=chbGatherStatistics.Checked;
- NetworkStatistics:=chbNetworkStats.Checked;
- DefaultSessionTimeout:=t;
- lGarbageStatus.caption:='Garbage/stat.collection setup is set.';
- end;
- Update;
- end;
-
- procedure TWABDAdmin.btnSetAdminTextUserClick(Sender: TObject);
- begin
- with frmAdmin.Session.SessionMgr do
- WebAdministrator:=trim(eAdminText.Text);
- Update;
- end;
-
- procedure TWABDAdmin.btnTerminateDLLUserClick(Sender: TObject);
- begin
- KillAllSessions;
- KillSession(WABDAdminSession.SessionID);
-
- end;
-
- procedure TWABDAdmin.btnMaxUserClick(Sender: TObject);
- begin
- with frmAdmin.Session.SessionMgr do
- try
- MaxConcurrentSessions:=strtoint(eMaxSessions.Text);
- MaxIdenticalUser:=strtoint(eMaxIdenticalUser.Text);
- except
- end;
- Update;
- end;
-
- procedure TWABDAdmin.btnSaveStatsUserClick(Sender: TObject);
- begin
- with frmAdmin.Session do
- if SessionMgr.Stats<>nil then SessionMgr.Stats.Save(Request.DllName);
- end;
-
- procedure TWABDAdmin.btnLoadStatsUserClick(Sender: TObject);
- begin
- with frmAdmin.Session do
- if SessionMgr.Stats<>nil then SessionMgr.Stats.Load(Request.DllName);
- Update;
- end;
-
- procedure TWABDAdmin.btnClearStatUserClick(Sender: TObject);
- var
- grp:TWABD_SesStatGroup;
- lst:TList;
- i:integer;
- begin
- with frmAdmin.Session.SessionMgr do
- begin
- if Stats=nil then exit;
-
- i:=Stats.IndexOf(cbStats.Text);
- lst:=Stats.LockList;
- try
- grp:=TWABD_SesStatGroup(lst.Items[i]);
- if grp=nil then exit;
- grp.Zero;
- finally
- Stats.UnlockList;
- end;
- end;
- Update;
- end;
-
- procedure TWABDAdmin.btnClearAllStatsUserClick(Sender: TObject);
- begin
- with frmAdmin.Session.SessionMgr do
- if Stats<>nil then Stats.Zero;
- Update;
- end;
-
- procedure TWABDAdmin.btnSetRouteUserClick(Sender: TObject);
- begin
- with frmAdmin.Session.SessionMgr do
- try
- RouteWhen:=TWABD_RouteWhen(strtoint(eRouteWhen.Text));
- RouteHow:=TWABD_RouteHow(strtoint(eRouteHow.Text));
- RouteSites.Assign(mRouteSites.Lines);
- except
- eRouteWhen.Text:=inttostr(ord(RouteWhen));
- eRouteHow.Text:=inttostr(ord(RouteHow));
- mRouteSites.Lines.Assign(RouteSites);
- end;
- end;
-
- procedure TWABDAdmin.btnSendTextSessionsUserClick(Sender: TObject);
- var
- lst:TList;
- s:string;
- i:integer;
- begin
- s:=Trim(eInfo.Text);
- with frmAdmin.Session.SessionMgr do
- begin
- Info:=s;
- lst:=SessionList.LockList;
- try
- for i:=0 to lst.count-1 do
- with TWABD_Session(lst.Items[i]) do
- Info:=s;
- finally
- SessionList.UnlockList;
- end;
- end;
- end;
-
- procedure TWABDAdmin.tblSessionsRenderCell(Sender: TWABD_Table; Row,
- Col: Integer; var Text: String; var HAlign: TWABD_HorzAlignment;
- var VAlign: TWABD_VertAlignment; var Color, BGColor: TColor;
- var Size: Integer; var Bold, Italic, Underline, Fixed, Strike: Boolean;
- var Width, Height: Integer; var AllowWordWrap: Boolean);
- begin
- if (Col=0) or (Row=0) then BGColor:=clSilver;
- end;
-
- procedure TWABDAdmin.tblStatsRenderCell(Sender: TWABD_Table; Row,
- Col: Integer; var Text: String; var HAlign: TWABD_HorzAlignment;
- var VAlign: TWABD_VertAlignment; var Color, BGColor: TColor;
- var Size: Integer; var Bold, Italic, Underline, Fixed, Strike: Boolean;
- var Width, Height: Integer; var AllowWordWrap: Boolean);
- begin
- if (length(Text)>0) and (Text[1]='*') then
- begin
- BGColor:=clSilver;
- Text:=copy(Text,2,length(Text));
- end;
- end;
-
- end.
-