forked from sirodcar/commonx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonRequests.pas
More file actions
1411 lines (1227 loc) · 47.2 KB
/
CommonRequests.pas
File metadata and controls
1411 lines (1227 loc) · 47.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit CommonRequests;
interface
uses numbers, RequestInfo, WebResource, WebString, HTTPClient, ErrorResource, systemx, xmltools, graphics, extctrls, jpeg, variants, sysutils, exceptions;
procedure WRQ_ServerTestGraphic(rqInfo: TRequestInfo);
procedure WRQ_Sleep(rqInfo: TRequestInfo);
procedure WRQ_StressException(rqInfo: TRequestInfo);
procedure WRQ_StressDTConn(rqInfo: TRequestInfo);
procedure WRQ_StressCPU(rqInfo: TRequestInfo);
procedure WRQ_StressHeap(rqInfo: TRequestInfo);
procedure WRQ_StressMemory(rqInfo: TRequestInfo);
procedure WRQ_StreamRemoteImage(rQInfo: TRequestInfo);
procedure WRQ_MailingListSubscribe(rqInfo: TRequestInfo);
procedure WRQ_Recurse82(rqInfo: TRequestInfo);
procedure WRQ_JavaCircle(rqInfo: TRequestInfo);
procedure WRQ_Circle(rqInfo: TRequestInfo);
procedure WRQ_BrowserTest(rqInfo: TRequestInfo);
procedure WRQ_ServerStatus(rqInfo: TRequestInfo);
procedure WRQ_FileTest(rqInfo: TRequestInfo);
procedure WRQ_SpeedTest(rqInfo: TRequestInfo);
procedure WRQ_TextEcho(rqInfo: TRequestInfo);
procedure WRQ_StringTest(rqInfo: TRequestInfo);
procedure WRQ_PrimeCalc(rqInfo: TRequestInfo);
procedure WRQ_GET_GetUDS(rqInfo: TRequestInfo);
procedure WRQ_HeapStatus(rqInfo: TRequestInfo);
procedure WRQ_NotFound(rqInfo: TRequestInfo);
procedure WRQ_ParameterEcho(rqInfo: TRequestInfo);
procedure WRQ_DevHalt(rqInfo: TRequestInfo);
//procedure WebServerError(rqInfo: TRequestInfo; sMessage: ansistring;bException: boolean); overload;
//procedure WebServerError(rqInfo: TRequestInfo; sMessage: ansistring);overload;
procedure WebServerError(rqInfo: TRequestInfo; e: exception);
//procedure ShowLastServerError(rqInfo: TRequestInfo; bFramed: boolean; iErrorCode: integer; sFriendlyHeading, sTechDetails: ansistring); overload;
//procedure ShowLastServerError(rqInfo: TRequestInfo; sFriendlyHeading: ansistring); overload;
//procedure ShowLastServerError(rqInfo: TRequestInfo); overload;
procedure WRQ_JavaRedirect(rqInfo: TRequestInfo);
procedure WRQ_UpdateProxy(rqInfo: TRequestInfo);
procedure SendJavaRedirect(rqInfo: TRequestInfo; sUrl: ansistring; breakframes: boolean = true; bWait: boolean = false);overload;
procedure SendJavaRedirect(rqInfo: TRequestInfo; sUrl: ansistring; altMessage: ansistring; breakframes: boolean = true; bWait: boolean = false);overload;
procedure SendAJJavaRedirect(rqInfo: TRequestInfo; sUrl: ansistring; altMessage: ansistring = ''; breakframes: boolean = true; bWait: boolean = false);overload;
procedure CloseWindow(rqInfo: TRequestInfo; ifName: ansistring; sURL: ansistring);
function WRQ_DoTest(Rqinfo: TRequestInfo): boolean;
procedure WRQ_ShowServerConfig(rqInfo: TRequestInfo);
procedure WRQ_ReloadServerConfig(rqInfo: TRequestInfo);
procedure ConfigTableRecord(rqInfo: TRequestInfo; sLeftValue, sRightvalue: ansistring);
procedure ConfigTableRecord2(rqInfo: TRequestInfo; sLeftValue, sRightvalue: ansistring);
procedure ConfigTableRecord3(rqInfo: TRequestInfo; sLeftValue, sRightvalue: ansistring);
procedure ConfigTableRecord5(rqInfo: TRequestInfo; sName, sType, sURL, sStatus: ansistring);
procedure WRQ_ShowVersionInfo(rqInfo: TRequestInfo);
procedure WRQ_GET_SuperSession(rqInfo: TRequestInfo);
procedure WRQ_POST_SuperSession(rqInfo: TRequestInfo);
procedure WRQ_GET_ClearSuperSession(rqInfo: TRequestInfo);
function ExternalResourceStatus(sPath: ansistring): ansistring;
function HttpLinkStatus(sURL: ansistring): ansistring;
function RDTPLinkStatus(sLinkName: ansistring): ansistring;
implementation
uses
WebFunctions, Classes, scktcomp, DataObjectServices, ErrorHandler,
Webconfig, FileCtrl, DataObject, MTDTInterface, VersionInfo, windows,
SimpleAbstractConnection, SimpleMail, better_sockets,
RequestDispatcher;
//------------------------------------------------------------------------------
procedure WRQ_NotFound(rqInfo: TRequestInfo);
//Generates a 404 Not Found error message in HTML.
//This page is displayed if a request passes through the dispatcher without being handled.
begin
rqInfo.Response.ResultCode := 404;
rqInfo.response.contenttype := 'text/html';
//rqInfo.response.content.clear;
with rqinfo.Response.Content do begin
add('<HTML>');
add(WebTitle('404'));
if copy(rqInfo.request.document, 1, 6) ='/help_' then
add('<font size="4" face="Helvetica, Arial">Sorry, help is not available for this topic.<br></font>')
else
add('<H1>The page you are looking for cannot be found (404)</H1>');
add('<BODY>');
add('The document:<B>'+rqInfo.Request.document+ '</B><BR> was not found. Method:"<B>'+rqInfo.request.command+'</B>".<BR><BR>');
add('</BODY>');
add('</HTML>');
end;
end;
//------------------------------------------------------------------------------
procedure WRQ_DevHalt(rqInfo: TRequestInfo);
//Halts the server, active only in debug mode.
begin
exit;
with rqInfo.Response.Content do begin
add('<HTML>');
add(WebTitle('Digital Tundra Web Learner Server 4.0 (ALPHA)'));
add('<H1>Please don''t leave.... we''ll miss you!</H1>');
add('<BODY>');
add('</BODY>');
add('</HTML>');
end;
end;
//------------------------------------------------------------------------------
procedure WRQ_HeapStatus(rqInfo: TRequestInfo);
//w: heap_status.Digital Tundra
//Displays a web page showing the status of the memory heap. Should return
//a bunch of ZEROs if the multi-threaded memory manager is in place.
begin
with rqInfo.Response.Content do begin
add('<HTML>');
add(WebTitle('Mothership web server'));
add(WebHeapStatus);
add('<br>X='+rQInfo.request['x']);
add('</HTML>');
end;
end;
//------------------------------------------------------------------------------
procedure WRQ_ParameterEcho(rqInfo: TRequestInfo);
//For debuging, generates a webpage that simply echos all parameters passed to it. Used to test whether or not parameters are being parsed by the engine propertly or not.
var
t: integer;
begin
rqInfo.NoHit := true;
with rqInfo.response.content do begin
add('<HTML>');
add(WebTitle('Mothership WebServer'));
add('<H2>Mothership</H2><BR>');
add('The following lines should have responded back all parameters passed to the Web Server. Please Ensure that they all make sense.<BR><BR>');
end;
for t:= 0 to rqInfo.Request.ParamCount-1 do begin
rqInfo.Response.Content.add(
'<STRONG>'+
rqInfo.Request.ParamNames[t]+' = </STRONG>'+
rqInfo.Request.Params[rqInfo.Request.ParamNames[t]]+'<BR>')
end;
rqInfo.Response.Content.add('</HTML>');
end;
//------------------------------------------------------------------------------
//procedure WebServerError(rqInfo: TRequestInfo; sMessage: ansistring);
//begin
// WebServerError(rqInfo, sMessage, false);
//end;
//------------------------------------------------------------------------------
procedure WebServerError(rqInfo: TRequestInfo; e: exception);
//Displays the graphical server error page
var
slError: TSTringList;
slBody:TStringList;
sPath: ansistring;
bFatal: boolean;
sOldBody: ansistring;
begin
sOldBody := rqINfo.response.content.text;
sOldBody := stringReplace(sOldBody, '[[[', '[_[', [rfreplaceall]);
rqInfo.response.varpool['oldbody'] := sOldBody;
rqInfo.response.Default('usermessage', '');
rqInfo.response.Default('techmessage', '');
rqInfo.response.Default('errornumber', '-1');
if e is EUserError then begin
rqInfo.response.default('user_message', EUserError(e).UserMessage);
rqInfo.response.default('error_message', '');
bFatal := false;
end else
if e is ENewException then begin
rqInfo.response.default('user_message', EUserError(e).UserMessage);
rqInfo.response.default('error_message', EUserError(e).Message);
bFatal := true
end else begin
rqInfo.response.default('user_message', 'An error has occurred');
rqInfo.response.default('error_message', e.message);
bFatal := true;
end;
if pos('session not found', lowercase(rQInfo.response.varpool['error_message'])) > 0 then begin
rqInfo.response.location := 'out/login.ms';
exit;
end;
if pos(': session', lowercase(rQInfo.response.varpool['error_message'])) > 0 then begin
rqInfo.response.location := 'out/login.ms';
exit;
end;
rqInfo.response.ResultCode := 200;
if bFatal then
rqInfo.response.varpool['fatal'] := 'true'
else
rqInfo.response.varpool['fatal'] := 'false';
// rqInfo.response.content.add(sMessage);
// exit;
//if a sessionID was not provided`then default to 0
if not rqInfo.Request.HasParam('sessionid') then
rqInfo.Response.VarPool['sessionid'] := '0';
//Erase any webpage that was being built
rqInfo.response.Content.clear;
//Get the page from the document -- for display purposes
sPath := ExtractFilePath(rqInfo.Request.Document);
sPath := lowercase(sPath);
slBody := TStringList.Create;
slError := TStringList.create;
try
//load the error template
LoadWebResource(rqInfo, 'error_framed.html');
//setup Dynamic Variables for error template
with rqInfo.Response do begin
VarPool['page_title'] := WEB_APPLICATION_NAME+' - Error';
VarPool['section_title'] := 'Error';
end;
//Throw in the error message
// if bFatal then begin
// slBody.add('<H2>Server Error</H2><BR>');
// slBody.add('There was an internal server error processing your request.<BR>');
// end;
// slBody.add(sMessage+'<BR>');
//LoadWebResourceBody(rqInfo, 'error.html');
//Put the error message into the error template
MergeAtToken(slError, 'body', slBody);
//Put the error template into the response
MergeAtToken(rqInfo.Response.content, 'body', slError);
//Reforce processing of dynamic variables
rqInfo.Response.ProcessDynamicVariables;
//Setup default error code
rqInfo.Response.ResultCode := 500;
finally
slBody.Free;
slError.free;
end;
end;
//------------------------------------------------------------------------------
//procedure ShowLastServerError(rqInfo: TRequestInfo); overload;
//begin
// if uppercase(rqInfo.request.command) = 'GET' then
// ShowLastServerError(rqInfo, 'Unable to Display Page')
// else
// ShowLastServerError(rqInfo, 'There was a problem submitting your information');
//
//end;
//------------------------------------------------------------------------------
//procedure ShowLastServerError(rqInfo: TRequestInfo; bFramed: boolean; iErrorCode: integer; sFriendlyHeading, sTechDetails: ansistring);
//var
// sMessage: ansistring;
// sResourceMessage: ansistring;
// sDel: ansistring;
// sLastError: ansistring;
//begin
// try
// rqInfo.response.varpool['error_message'] := '';
// sResourceMessage := '';
// sLastError := GetLastServerErrorMessage;
//
// //get a stock message from the error resource
// if iErrorCode<2000 then
// sResourceMessage := ErrorRes.ErrorMessages[iErrorCode];
//
//
// if sResourceMessage <> '' then
// sDel := '<BR>';
// if (sResourceMessage <> sFriendlyHeading) and (sFriendlyHeading <> '') then
// sFriendlyHeading := sFriendlyHeading+sDel+sResourceMessage;
// if (sFriendlyHeading = '') and (iErrorCode<>0) then
// sFriendlyHeading := sResourceMessage;
//
// //if the error code is betweeen 1000 and 1500 display the server error message
// //as the friendly heading
//
// if (iErrorcode >1000) and (iErrorCode<=1500) then
// sFriendlyHeading := sLastError;
//
// rqInfo.response.varpool['usermessage'] := sFriendlyHeading;
// rqInfo.response.varpool['techmessage'] := sTechDetails;
// rqInfo.response.varpool['errorcode'] := inttostr(iErrorCode);
// rqInfo.response.varpool['page_title'] := '';
// rqInfo.response.varpool['section_title'] := '';
// rqInfo.response.varpool['page_message'] := '';
//
// //default response to `body`
// rqInfo.response.content.text := '`body`';
//
// if (not bFramed) and(2=1) then begin
// rqInfo.response.varpool['error_true'] := '0000';
// LoadWebResource(rqInfo, rqInfo.response.content, 'main_template_passive.html');
// LoadwebResourceBody(rqInfo, 'new_error.ps2');
// end else begin
// try
// LoadWebResource(rqInfo, rqInfo.response.content, 'error_framed.html');
// except
// rqInfo.response.content.text := '[[[error_message]]]';
// end;
// end;
//
//
// //special error processing
//// case iErrorCode of
//(* 933: LoadWebResourceBody(rqInfo, 'error_busy.html');
// 932: LoadWebResourceBody(rqInfo, 'error_busy.html');
// 925: LoadWebResourceBody(rqInfo, 'error_account.html');
// 924: rqInfo.response.location := 'change_account.ms';
// 916: LoadWebResourceBody(rqInfo, 'already_running_courseware.html');
// 107: begin
// LoadMainShell(rqinfo, rqInfo.response.content, 0, '', 'Already Logged In', 'Already Logged In');
// LoadWebResourceBody(rqInfo, 'already_logged_in.html');
// end;
// 114: LoadWebResourceBody(rqInfo, 'license_limit_exceeded.html');
// 115: LoadWebResourceBody(rqInfo, 'service_not_activated.html');
// 117: LoadWebResourceBody(rqInfo, 'session_expired.html');
// 118: LoadWebResourceBody(rqInfo, 'feature_unavailable_nointernet.html');*)
//// else
// //generic errors
// LoadWebResourceBody(rqInfo, 'generic_error.html');
//// LoadwebResource('generic_error.html', rqInfo.response.content);
//// end;
//
// rqInfo.response.varpool['error_message'] := sLastError;
//
// // rqInfo.Response.content.Add(rqInfo.Response.VarPoolStatus);
//
// rqInfo.Response.ResultCode := 500;
//
// rqInfo.response.contenttype := 'text/html';
// //rQInfo.response.NeedsProcessing := false;
// rqInfo.Response.ProcessDynamicVariables;
// except
// on e: Exception do begin
// rqInfo.response.content.text := 'Error displaying error page: '+e.Message;
// end;
// end;
//end;
//
procedure WRQ_JavaRedirect(rqInfo: TRequestInfo);
//a: Jason Nelson
//w: Java_redirect.Digital Tundra
//Sends a redirect to the browser, using javascript. Useful for forwarding the user
//to a page in cases where you don't want the user to be able to click BACK to go back.
begin
//if the result was falsified (which occurs on launch), force the session state
//back to 1.
rqInfo.request.Default('altmessage', 'You are being redirected to another page.');
rqINfo.SetupDefaultVarPool;
//get/default the breakframes parameter
if not rqInfo.response.hasvar('breakframes') then
rqInfo.response.varpool['breakframes'] := 'true';
rqInfo.response.varpool['breakframes'] := lowercase(rqInfo.response.varpool['breakframes']);
with rqInfo.Response.content do begin
add('<HTML>');
add('<HEAD>');
add('<TITLE>Redirect</TITLE>');
//redirecting
add('<SCRIPT Language="Javascript" DEFER>');
add('<!--');
//include this java if breakframes is TRUE
add('function Goto() {');
add(' window.location = "'+MorphURL(rqinfo.Request['return']+'"'));
add('};');
add('function onPageLoad(){');
if rqInfo.response.varpool['breakframes'] = 'true' then begin
add('if (window != top) top.location.href = "'+MorphURL(rqinfo.Request['return']+'"'));
add('else window.location = "'+MorphURL(rqinfo.Request['return']+'"'));
end else begin
if rqInfo.request.hasparam('wait') then begin
add(' setTimeout(''Goto();'', '+inttostr(Random(8000)+5000)+');')
end else begin
add(' window.location = "'+MorphURL(rqinfo.Request['return']+'"'));
end;
end;
add('}');
add('//-->');
add('</SCRIPT>');
// add('<meta content="blendTrans(duration=0.5)" http-equiv="Page-Enter">');
// add('<meta content="blendTrans(God...duration=0.5)" http-equiv="Page-Exit">');
add('</Head>');
add('<body bgcolor="#FFFFFF" onLoad="onPageLoad()">');
add('<table width="400" border="0" cellspacing="0" cellpadding="0" align="center">');
add(' <tr>');
add(' <td><center>');
add('<p><b><font face="Helvetica, Arial" size="4"><BR><BR><BR>Please Wait...<br> </font></b>');
add('<font size="2" face="arial, helvetica">[[[altmessage]]]</font><BR>');
add('<font size="2" face="arial, helvetica"><a href="[[[return]]]">Click here</a> if you do not see the next page in 10 seconds.</font><BR>');
add(' <BR><img src="images/working.gif" width="447" height="25"></p>');
add('</center></td></tr></table>');
add('</body>');
add('</html>');
// add('</HTML>');
end;
end;
procedure WRQ_AJJavaRedirect(rqInfo: TRequestInfo);
//a: Jason Nelson
//w: Java_redirect.Digital Tundra
//Sends a redirect to the browser, using javascript. Useful for forwarding the user
//to a page in cases where you don't want the user to be able to click BACK to go back.
begin
//if the result was falsified (which occurs on launch), force the session state
//back to 1.
rqInfo.request.Default('altmessage', 'You are being redirected to another page.');
rqINfo.SetupDefaultVarPool;
//get/default the breakframes parameter
if not rqInfo.response.hasvar('breakframes') then
rqInfo.response.varpool['breakframes'] := 'true';
rqInfo.response.varpool['breakframes'] := lowercase(rqInfo.response.varpool['breakframes']);
with rqInfo.Response.content do begin
//redirecting
add('<SCRIPT Language="Javascript" DEFER>');
add('<!--');
//include this java if breakframes is TRUE
add('function Goto() {');
add(' window.location = "'+MorphURL(rqinfo.Request['return']+'"'));
add('};');
add('function onPageLoad(){');
if rqInfo.response.varpool['breakframes'] = 'true' then begin
add('if (window != top) top.location.href = "'+MorphURL(rqinfo.Request['return']+'"'));
add('else window.location = "'+MorphURL(rqinfo.Request['return']+'"'));
end else begin
if rqInfo.request.hasparam('wait') then begin
add(' setTimeout(''Goto();'', '+inttostr(Random(8000)+5000)+');')
end else begin
add(' window.location = "'+MorphURL(rqinfo.Request['return']+'"'));
end;
end;
add('}');
add('//-->');
add('</SCRIPT>');
add('<table width="400" border="0" cellspacing="0" cellpadding="0" align="center">');
add(' <tr>');
add(' <td><center>');
add('<p><b><font face="Helvetica, Arial" size="4"><BR><BR><BR>Please Wait...<br> </font></b>');
add('<font size="2" face="arial, helvetica">[[[altmessage]]]</font><BR>');
add('<font size="2" face="arial, helvetica"><a href="[[[return]]]">Click here</a> if you do not see the next page in 10 seconds.</font><BR>');
add(' <BR><img src="images/working.gif" width="447" height="25"></p>');
add('</center></td></tr></table>');
add('<SCRIPT language="Javascript" DEFER>');
add('<!--');
add(' onPageLoad();');
add('');
add('//-->');
add('</SCRIPT>');
// add('</HTML>');
end;
end;
//------------------------------------------------------------------------------
procedure SendJavaRedirect(rqInfo: TRequestInfo; sUrl: ansistring; breakframes: boolean = true; bWait: boolean = false);
begin
SendJavaRedirect(rqInfo, sUrl, '', breakframes, bWait);
end;
procedure SendAJJavaRedirect(rqInfo: TRequestInfo; sUrl: ansistring; altMessage: ansistring = ''; breakframes: boolean = true; bWait: boolean = false);overload;
begin
rqInfo.response.content.clear;
rqInfo.Request.AddParam('return', sUrl, pcContent);
if breakframes then
rqInfo.Request.AddParam('breakframes', 'true', pcContent)
else
rqInfo.Request.AddParam('breakframes', 'false', pcContent);
if bWait then
rqInfo.Request.AddParam('wait', '4000', pcContent);
if altmessage = '' then
altMessage := 'You are being redirected to another web page';
rqInfo.Request.AddParam('altmessage', altMessage, pcContent);
rqInfo.Request.AddParam('url', sURL, pcContent);
rqInfo.SetupDefaultVarpool;
LoadWebResource(rqInfo, 'aj_java_redirect.html')
// WRQ_JavaRedirect(rqInfo);
end;
procedure SendJavaRedirect(rqInfo: TRequestInfo; sUrl: ansistring; altMessage: ansistring; breakframes: boolean = true; bWait: boolean = false);
//a: Jason Nelson
//Sends a redirect to the browser, using javascript. Useful for forwarding the user
//to a page in cases where you don't want the user to be able to click BACK to go back.
//p: BreakFrames: Indicates that when redirecting, the browser should redirect the parent frame.
//p: bWait: Indicates that the page should wait 4 seconds before redirecting.
begin
rqInfo.response.content.clear;
rqInfo.Request.AddParam('return', sUrl, pcContent);
if breakframes then
rqInfo.Request.AddParam('breakframes', 'true', pcContent)
else
rqInfo.Request.AddParam('breakframes', 'false', pcContent);
if bWait then
rqInfo.Request.AddParam('wait', '4000', pcContent);
if altmessage = '' then
altMessage := 'You are being redirected to another web page';
rqInfo.Request.AddParam('altmessage', altMessage, pcContent);
rqInfo.Request.AddParam('url', sURL, pcContent);
rqInfo.SetupDefaultVarpool;
LoadWebResource(rqInfo, 'java_redirect.html')
// WRQ_JavaRedirect(rqInfo);
end;
//------------------------------------------------------------------------------
procedure WRQ_ServerTestGraphic(rqInfo: TRequestInfo);
function TestHTTPLInk(sDest: ansistring): boolean;
var
http: THTTPClient;
begin
http := THTTPClient.create;
try
result := http.get(adjustwebpath(WebServerconfig.conn[sDest].URL)+WebServerconfig.conn[sDest].TestURL,'');
finally
http.free;
end;
end;
var
img: TImage;
jpg: TJpegImage;
sDest: ansistring;
bGood: boolean;
bUnknown: boolean;
begin
bGood := false;
bUnknown := true;
img := Timage.create(nil);
try
img.width := 640;
img.height := 20;
img.canvas.fillrect(Rect(0,0,img.width, img.height));
img.canvas.lock;
jpg := TJpegImage.create;
try
try
sDest := rqINfo.request['Dest'];
if WebServerconfig.conn[sDest].NoTest then
bUnknown := true
else
if WebServerConfig.conn[sDest].Middleware then begin
// bGood := DOSVPool.ServersByName[WebServerConfig.conn[sDest].Name].Server.Alive;
bGood := false;
bUnknown := false;
end else begin
bGood := TestHTTPLInk(sDest);
bUnknown := false;
end;
if bUnknown then begin
jpg.LoadFromFile(slash(WebServerConfig.ExternalResourcepath)+'images\normal.jpg');
// img.canvas.draw(0,0,jpg);
// img.canvas.textOut(18,2, 'Unknown/Untested');
end else
if bGood then begin
jpg.LoadFromFile(slash(WebServerConfig.ExternalResourcepath)+'images\smiley.jpg');
// img.canvas.draw(0,0,jpg);
img.canvas.textOut(18,2, 'OK!');
end else begin
jpg.LoadFromFile(slash(WebServerConfig.ExternalResourcepath)+'images\frowny.jpg');
// img.canvas.draw(0,0,jpg);
// img.canvas.textOut(18,2, 'Down');
end;
except
on E: exception do begin
jpg.LoadFromFile(slash(WebServerConfig.ExternalResourcepath)+'images\frowny.jpg');
// img.canvas.draw(0,0,jpg);
// img.canvas.textOut(18,2, 'Exception:'+E.Message);
end;
end;
// StreamImageAsJpeg(rqINfo, img);
finally
img.canvas.unlock;
jpg.free;
end;
finally
img.free;
end;
end;
procedure WRQ_ShowServerConfig(rqInfo: TRequestInfo);
//w: show_server_config.Digital Tundra
//a: Jason Nelson
//Shows the configuration of the Tier. Tests all connections to all external tiers.
const
STATUS = '<BR><B><font size="2">Status: </font></B>';
var
t: integer;
dest : TNetConnection;
begin
try
with rqInfo.response.content do begin
add('<HTML><BODY>');
add('<TABLE WIDTH="100%" BORDER="0">');
add('<TR><TD COLSPAN=2 BGCOLOR="F7C7C7">');
add('<B>Web Server Configuration Information</B><BR>');
add('</TD></TR>');
//Main Info
ConfigTableRecord(rqInfo, 'configFile', WebServerConfig.ConfigFile+' (<a href="reload_server_config.Digital Tundra">reload</a>)');
//EchoPageParameters
if WebServerConfig.EchoPageParameters then
ConfigTableRecord(rqInfo, 'EchoPageParameters', 'On')
else
ConfigTableRecord(rqInfo, 'EchoPageParameters', 'Off');
//ResourcePath
rqInfo.response.SendChunk;
ConfigTableRecord(rqInfo, 'ExternalResourcePath', WebServerConfig.ExternalResourcePath+STATUS+ExternalResourceStatus(WebServerConfig.ExternalResourcePath));
rqInfo.response.SendChunk;
ConfigTableRecord(rqInfo, 'FarmRouter', WebServerConfig.FarmRouter+STATUS+HttpLinkStatus(WebServerConfig.FarmRouter));
add('</Table>');
rqInfo.response.SendChunk;
//Destination Information
add('<B>Destinations ('+inttostr(WebServerConfig.ConnectionCount)+')</B><BR>');
add('<TABLE WIDTH="100%" BORDER="0" BGCOLOR="#BBBBBB">');
for t := 0 to WebServerConfig.ConnectionCount-1 do begin
dest :=WebServerConfig.DestByIndex[t];
if dest.MiddleWare then begin
ConfigTableRecord5(rqINfo, dest.Name, 'RDTP', dest.Host+':'+dest.Endpoint, '<img src="server_test_graphic.jpg?dest='+EncodeWEbString(dest.Name)+'">');
end
else begin
if dest.Citrix then begin
ConfigTableRecord5(rqINfo, dest.Name, 'CITRIX', dest.Host+':'+dest.Endpoint, '<img src="server_test_graphic.jpg?dest='+EncodeWEbString(dest.Name)+'">');
end
else begin
ConfigTableRecord5(rqINfo, dest.Name, 'HTTP', dest.URL, '<img src="server_test_graphic.jpg?dest='+EncodeWEbString(dest.Name)+'">');
end;
end;
rqInfo.response.SendChunk;
end;
add('</table>');
add('</BODY></HTML>');
end;
rqInfo.response.SendFooter;
except
rqInfo.response.content.add('Exception: '+Exception(ExceptObject).Message);
end;
end;
//------------------------------------------------------------------------------
procedure WRQ_ServerStatus(rqInfo: TRequestInfo);
//a: Jason Nelson
//w: server_status.Digital Tundra
//Shows the status of all threads in the web server. Includes page names and instantiated Data objects if
//extrainfo=true is passed as a parameter to the page.
var
t: integer;
dest : TNetConnection;
http: THTTPClient;
result : boolean;
begin
result := true;
rqInfo.response.NoDebug := true;
rqInfo.response.contenttype := 'text/plain';
try
http := nil;
try
http := THTTPClient.create;
with rqInfo.response.content do begin
FOR t := 0 to WebServerConfig.ConnectionCount-1 DO BEGIN
dest :=WebServerConfig.DestByIndex[t];
try
if dest.Middleware then begin
result := true;
end
else begin
IF dest.Citrix THEN BEGIN
//cannot test
END
ELSE BEGIN
if not http.Get(adjustwebpath(dest.url)+'load.Digital Tundra', '') then begin
add(Dest.name+' down');
result := false;
end;
END;
end;
except
add(Dest.name+' down');
result := false;
end;
END;//for
if result then
add('OK');
end;//with
finally
http.free;
end;
except
rqInfo.response.resultcode := 500;
rqInfo.response.Content.clear;
rqInfo.response.content.add('Exception: '+Exception(ExceptObject).Message);
end;
end;
//------------------------------------------------------------------------------
procedure ConfigTableRecord(rqInfo: TRequestInfo; sLeftValue, sRightvalue: ansistring);
//a: Jason Nelson
//Helper function for show_server_config.Digital Tundra
begin
with rqInfo.response.content do begin
add('<TR><TD WIDTH="200" BGCOLOR="#F7F7F7">');
Add(sLeftValue);
add('</TD>');
add('<TD WIDTH="99%" BGCOLOR="#F7F7F7"><font face="Helvetica, Arial" size=2">');
if sRightValue='' then
add('<font color="#FF0000">undefined</font>');
Add(sRightValue);
add('</font></TD></TR>');
end;
end;
//------------------------------------------------------------------------------
procedure ConfigTableRecord2(rqInfo: TRequestInfo; sLeftValue, sRightvalue: ansistring);
//a: Jason Nelson
//Helper function for show_server_config.Digital Tundra
begin
with rqInfo.response.content do begin
add('<TR><TD WIDTH="20%" BGCOLOR="#c7c7F7">');
Add(sLeftValue);
add('</TD>');
add('<TD WIDTH="80%" BGCOLOR="#c7c7F7">');
if sRightValue='' then
add('<font color="#FF0000">undefined</font>');
Add(sRightValue);
add('</TD></TR>');
end;
end;
procedure ConfigTableRecord5(rqInfo: TRequestInfo; sName, sType, sURL, sStatus: ansistring);
//a: Jason Nelson
//Helper function for show_server_config.Digital Tundra
begin
with rqInfo.response.content do begin
add('<TR><TD WIDTH="10%" BGCOLOR="#FFFFFF">');
Add(sName);
add('</TD>');
add('<TD WIDTH="40" BGCOLOR="#FFFFFF">');
Add(sType);
add('</TD>');
add('<TD WIDTH="50%" BGCOLOR="#FFFFFF">');
Add(sURL);
add('</TD>');
add('<TD WIDTH="1" BGCOLOR="#FFFFFF">');
Add(sStatus);
add('</TD></TR>');
end;
end;
//------------------------------------------------------------------------------
procedure ConfigTableRecord3(rqInfo: TRequestInfo; sLeftValue, sRightvalue: ansistring);
//a: Jason Nelson
//Helper function for show_server_config.Digital Tundra
begin
with rqInfo.response.content do begin
add('<TR><TD WIDTH="35%" BGCOLOR="#F7F7F7">');
Add(sLeftValue);
add('</TD>');
add('<TD BGCOLOR="#F7F7F7"><font face="Helvetica, Arial" size=2">');
if sRightValue='' then
add('<font color="#FF0000">undefined</font>');
Add(sRightValue);
add('</font></TD></TR>');
end;
end;
//------------------------------------------------------------------------------
procedure WRQ_ReloadServerConfig(rqInfo: TRequestInfo);
//a: Jason Nelson
//w: reload_server_config.Digital Tundra
//This page is accessed via a link on the show_server_config.Digital Tundra page. It currently
//does not work because of Windows INI caching.
begin
WebServerConfig.LoadConfig;
rqInfo.Response.location := 'show_server_config.Digital Tundra';
end;
//------------------------------------------------------------------------------
procedure WRQ_GET_GetUDS(rqInfo: TRequestInfo);
//a: Jason Nelson
//w: Get_UDS.Digital Tundra
//Returns a plain text response with two lines. The first is the internal URL to the User Data Server. The second is the external URL.
var
sTemp: ansistring;
begin
try
rqInfo.response.contentType := 'text/plain';
// sTemp := WebServerConfig.Dest['UserDataServer'].URL;
sTemp := adjustwebpath(WebServerConfig.FarmRouter)+'proxy.UserDataServer.';
rqInfo.response.content.add(sTemp);
rqInfo.response.content.add(sTemp);
except
rqInfo.response.resultcode := 203;
end;
end;
//------------------------------------------------------------------------------
procedure WRQ_GET_SuperSession(rqInfo: TRequestInfo);
//w: super_session.Digital Tundra
//a: Jason Nelson
//Helper page for load testing. Requires special setup of accounts. Do not use. Obsolete.
begin
with rqInfo.response.content do begin
add('<form method="POST" action="super_session.Digital Tundra">');
add('Enter your super session id here: <input type="text" name="supersession" value="0">');
add('<input type="submit">');
add('</form>');
end;
end;
//------------------------------------------------------------------------------
procedure WRQ_POST_SuperSession(rqInfo: TRequestInfo);
//w: super_session.Digital Tundra
//a: Jason Nelson
//Helper page for load testing. Requires special setup of accounts. Do not use. Obsolete.
begin
(* rqInfo.response.CookieName := 'supersession';
rqInfo.response.CookieValue := inttohash(strtoint(rqInfo.request['supersession']), rqInfo.request.clientIP);
with rqInfo.response.content do begin
add('<HTML><BODY><CENTER>');
add('<B><H1>Super session has been set!</H1>');
add('<BR>Note: please make sure you return to the <a href="utility.Digital Tundra">utility page</a> and clear the super session.<BR>');
add('<BR><a href="admin_home.Digital Tundra?sessionid='+inttohash(0, rqInfo.request.clientIP)+'">Continue to the admin home page</a>');
add('<BR>-or-<BR><a href="learner_home.Digital Tundra?sessionid='+inttohash(0, rqInfo.request.clientIP)+'">Continue to the learner home page</a>');
add('</B></CENTER></BODY></HTML>');
end;
*)
end;
//------------------------------------------------------------------------------
procedure WRQ_GET_ClearSuperSession(rqInfo: TRequestInfo);
begin
rqInfo.response.AddCookie('supersession', '');
with rqInfo.response.content do begin
add('<HTML><BODY>');
add('<B>Super session has been cleared</B><BR>');
add('<a href="javascript:history.back(1)">Back</a>');
add('</BODY></HTML>');
end;
end;
//------------------------------------------------------------------------------
function ExternalResourceStatus(sPath: ansistring): ansistring;
//a: Jason Nelson
//Checks the existance of a path, and returns an HTML ansistring response. Helper function for
//show_server_status.Digital Tundra.
begin
if DirectoryExists(sPath) then
result := '<font color="#007F00" size="2">OK!</font>'
else
result := '<font color="#7F0000" size="2">Incorrect!</font>';
end;
//------------------------------------------------------------------------------
function HttpLinkStatus(sURL: ansistring): ansistring;
//a: Jason Nelson
//Checks the existance of a URL, and returns an HTML ansistring response. Helper function for
//show_server_status.Digital Tundra.
var
http: THTTPClient;
begin
http := THTTPClient.create;
try
try
if NOT http.Get(AdjustWebPath(sURL)+'load.Digital Tundra', '') then begin
result := '<font color="#7F0000" size="2">No Response!</font>';
exit;
end;
if http.ResultCode = '200' then
result := '<font color="#007f00" size="2">200 OK!</font>'
else
result := '<font color="#7F7F00" size="2">'+http.ResultCode+' ???</font>';
except
result := '<font color="#AF0000" size="2">Exception:'+Exception(ExceptObject).Message+'</font>';
end;
finally
http.free;
end;
end;
//------------------------------------------------------------------------------
function RDTPLinkStatus(sLinkName: ansistring): ansistring;
//a: Jason Nelson
//Checks the existance of a Data-Tier, and returns an HTML ansistring response. Helper function for
//show_server_status.Digital Tundra.
var
DOSV: TDataObjectServices;
begin
try
DOSV := DOSVPool.ServersByName[sLinkName];
if not (DOSV = nil) then begin
result := '<font color="#7F0000" size="2">Data Object Services not initialized</font>'
end;
except
result := '<font color="#AF0000" size="2">'+Exception(ExceptObject).Message+'</font>';
end;
end;
procedure WRQ_PrimeCalc(rqInfo: TRequestInfo);
//w: Prime_calc.Digital Tundra
//This function was created to contrast the scalability of the memory manager in the Middle tier. It simply calculates primenumbers, a CPU-intensive, but not heap intensive task.
var
t, u: integer;
bIsPrime: boolean;
begin
for t:=600000 to 600100 do begin
bIsPrime := true;
for u:=2 to t div 2 do begin
if (t mod u) = 0 then begin
bIsPrime := false;
end;
end;
if bIsPrime then
rqInfo.response.content.add(inttostr(t));
end;
end;
procedure WRQ_StringTest(rqInfo: TRequestInfo);
//w: Prime_calc.Digital Tundra
//This function was created to stress the memory manager in the middle-tier, it puts
//stress on memory allocation by concatinating a bunch of ansistrings. We can then monitor performance and scalability.
var
t: integer;
s1, s2: ansistring;
t1, t2: cardinal;
build: ansistring;
begin
t1 := GetTickCount;
for t:= 0 to 5000000 do begin
s1 := 'hi';
s2 := s1+'!';
s1 := s1[1];
build := build + s1;
end;
t2 := GetTickCount;
rqInfo.response.content.add('done '+floattostr(500000/((t2-t1)/1000))+' ops per second.');
end;
procedure WRQ_UpdateProxy(rqInfo: TRequestInfo);
//a: Jason Nelson
//w: Update_proxy.Digital Tundra