-
Notifications
You must be signed in to change notification settings - Fork 0
/
vbscript.asp
2538 lines (2266 loc) · 79.4 KB
/
vbscript.asp
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
<%
Const adInteger = 3
Const adVarChar = 200
Function Base64Encode(sText)
Dim oXML, oNode
Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
Set oNode = oXML.CreateElement("base64")
oNode.dataType = "bin.base64"
oNode.nodeTypedValue =Stream_StringToBinary(sText)
Base64Encode = oNode.text
Set oNode = Nothing
Set oXML = Nothing
End Function
Function Base64Decode(ByVal vCode)
Dim oXML, oNode
Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
Set oNode = oXML.CreateElement("base64")
oNode.dataType = "bin.base64"
oNode.text = vCode
Base64Decode = Stream_BinaryToString(oNode.nodeTypedValue)
Set oNode = Nothing
Set oXML = Nothing
End Function
'Stream_StringToBinary Function
'2003 Antonin Foller, http://www.motobit.com
'Text - string parameter To convert To binary data
Function Stream_StringToBinary(Text)
Const adTypeText = 2
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream 'As New Stream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save text/string data.
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
BinaryStream.CharSet = "us-ascii"
'Open the stream And write text/string data To the object
BinaryStream.Open
BinaryStream.WriteText Text
'Change stream type To binary
BinaryStream.Position = 0
BinaryStream.Type = adTypeBinary
'Ignore first two bytes - sign of
BinaryStream.Position = 0
'Open the stream And get binary data from the object
Stream_StringToBinary = BinaryStream.Read
Set BinaryStream = Nothing
End Function
'Stream_BinaryToString Function
'2003 Antonin Foller, http://www.motobit.com
'Binary - VT_UI1 | VT_ARRAY data To convert To a string
Function Stream_BinaryToString(Binary)
Const adTypeText = 2
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream 'As New Stream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save binary data.
BinaryStream.Type = adTypeBinary
'Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.Write Binary
'Change stream type To text/string
BinaryStream.Position = 0
BinaryStream.Type = adTypeText
'Specify charset For the output text (unicode) data.
BinaryStream.CharSet = "us-ascii"
'Open the stream And get text/string data from the object
Stream_BinaryToString = BinaryStream.ReadText
Set BinaryStream = Nothing
End Function
Function Hash(HashType, Target)
On Error Resume Next
Dim PlainText
If IsArray(Target) = True Then PlainText = Target(0) Else PlainText = Target End If
With CreateObject("ADODB.Stream")
.Open
.CharSet = "Windows-1252"
.WriteText PlainText
.Position = 0
.CharSet = "UTF-8"
PlainText = .ReadText
.Close
End With
If Err.number<>0 Then
PlainText = REPLACE(encodeURL(PlainText),"%","")
Hash HashType, PlainText
Else
Set UTF8Encoding = CreateObject("System.Text.UTF8Encoding")
Dim PlainTextToBytes, BytesToHashedBytes, HashedBytesToHex
PlainTextToBytes = UTF8Encoding.GetBytes_4(PlainText)
Select Case HashType
Case "md5": Set Cryptography = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider") '< 64 (collisions found)
Case "ripemd160": Set Cryptography = CreateObject("System.Security.Cryptography.RIPEMD160Managed")
Case "sha1": Set Cryptography = CreateObject("System.Security.Cryptography.SHA1Managed") '< 80 (collision found)
Case "sha256": Set Cryptography = CreateObject("System.Security.Cryptography.SHA256Managed")
Case "sha384": Set Cryptography = CreateObject("System.Security.Cryptography.SHA384Managed")
Case "sha512": Set Cryptography = CreateObject("System.Security.Cryptography.SHA512Managed")
Case "md5HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACMD5")
Case "ripemd160HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACRIPEMD160")
Case "sha1HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA1")
Case "sha256HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA256")
Case "sha384HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA384")
Case "sha512HMAC": Set Cryptography = CreateObject("System.Security.Cryptography.HMACSHA512")
End Select
Cryptography.Initialize()
If IsArray(Target) = True Then Cryptography.Key = UTF8Encoding.GetBytes_4(Target(1))
BytesToHashedBytes = Cryptography.ComputeHash_2((PlainTextToBytes))
For x = 1 To LenB(BytesToHashedBytes)
HashedBytesToHex = HashedBytesToHex & Right("0" & Hex(AscB(MidB(BytesToHashedBytes, x, 1))), 2)
Next
If Err.Number <> 0 Then Response.Write(Err.Description) Else Hash = LCase(HashedBytesToHex)
On Error GoTo 0
End if
End Function
Sub CreateFolder(ByVal FullPath)
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(FullPath) Then
CreateFolder fso.GetParentFolderName(FullPath)
fso.CreateFolder FullPath
End If
End Sub
Function transformXML(xmlfile, xslfile)
Dim xDoc, xslDoc
Set xDoc = Server.CreateObject("Microsoft.XMLDOM")
xDoc.async="false"
IF TypeName(xmlfile)="DOMDocument" THEN
Set xDoc = xmlfile
ELSEIF TypeName(xmlfile)="IXMLDOMElement" THEN
xDoc.loadXML(xmlfile.xml)
ELSE
'Load XML file
xDoc.async = false
xDoc.load(xmlfile)
END IF
'Load XSL file
set xslDoc = Server.CreateObject("Microsoft.XMLDOM")
xslDoc.async = false
xslDoc.load(xslfile)
'Transform file
transformXML = xmlDoc.transformNode(xslDoc)
End function
function asyncCall(strUrl)
Set xmlHttp = Server.Createobject("MSXML2.ServerXMLHTTP")
xmlHttp.Open "GET", strUrl, False
xmlHttp.setRequestHeader "User-Agent", "asp httprequest"
xmlHttp.setRequestHeader "content-type", "application/x-www-form-urlencoded"
xmlHttp.Send
'response.write xmlHttp.responseText
'xmlHttp.abort()
set xmlHttp = Nothing
end function
FUNCTION checkConnection(oCn)
IF LCASE(SESSION("secret_engine")) = "google" THEN
DIM google_response
google_response = apiCall("https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=" & session("secret_token"))
Set xml_google_response = JSONToXML(google_response)
IF NOT(xml_google_response.documentElement IS NOTHING) THEN
Dim nError: Set nError = xml_google_response.documentElement.selectSingleNode("error|error_description")
Dim nEmail: Set nEmail = xml_google_response.documentElement.selectSingleNode("email")
IF NOT(nError IS NOTHING) THEN
Session.Contents.RemoveAll
Session.Abandon
ELSEIF NOT(nEmail IS NOTHING) THEN
IF NOT(nEmail.text = session("user_login")) THEN
Session.Contents.RemoveAll
Session.Abandon
END IF
END IF
END IF
IF session("user_login") = "" THEN
Session("AccessGranted") = FALSE
session("status") = "unauthorized"
Response.ContentType = "application/json"
Response.CharSet = "ISO-8859-1"
Response.Status = "401 Unauthorized" %>
{
"message": "Conexión no autorizada"
}
<% response.end
END IF
ELSE
DIM StrCnn: StrCnn = "driver={SQL Server};server="&SESSION("secret_server_id")&";uid="&SESSION("secret_database_user")&";pwd="&SESSION("secret_database_password")&";database="&SESSION("secret_database_name")
If oCn.State = 0 THEN
ON ERROR RESUME NEXT
oCn.Open StrCnn
End if
IF NOT(Err.Number=0 AND (TRIM(SESSION("secret_server_id"))<>"" AND TRIM(SESSION("secret_database_user"))<>"" AND TRIM(SESSION("secret_database_password"))<>"" AND TRIM(SESSION("secret_database_name"))<>"")) THEN
Session("AccessGranted") = FALSE
Session("status") = "unauthorized"
DIM error_description
IF (Err.number<>0) THEN
error_description = Err.Description
ELSEIF oCn.errors.count<>0 THEN
error_description = "Can't connect"
END IF
ErrorDesc=SqlRegEx.Replace(error_description, "")
'response.write Err.Number&": "&Err.Description
IF INSTR(ErrorDesc,"SQL Server does not exist or access denied")>0 OR INSTR(ErrorDesc,"Communication link failure")>0 OR INSTR(ErrorDesc,"ConnectionWrite")>0 THEN
AsyncCall "http://localhost:8080/startSQL"
'AsyncCall Left(currentLocation, instrRev(currentLocation, "/"))&"reconnect.asp"
Err.Clear
Sleep(3)
If oCn.State = 0 Then
'response.write "Here 1 "&oCn.State&"<br/>"
ON ERROR RESUME NEXT
oCn.Open StrCnn
IF Err.Number<>0 THEN
'response.write "Here 2 "&oCn.State
Response.ContentType = "application/json"
Response.CharSet = "ISO-8859-1"
ErrorDesc=SqlRegEx.Replace(Err.Description, "")
'response.Write ErrorDesc
IF INSTR(ErrorDesc,"SQL Server does not exist or access denied")>0 OR INSTR(ErrorDesc,"Communication link failure")>0 THEN
Response.Status = "503 Service Unavailable" '"408 Request Timeout"
%>
{
"success": false,
"message": "No se pudo establecer una conexión con la base de datos <%= sDatabaseName %>: <%= RegEx_JS_Escape.Replace(SqlRegEx.Replace(Err.Description, ""), "\$&") %>"
}
<% response.end
END IF
END IF
End If
END IF
END IF
END IF
END FUNCTION
Function RandomNumber(intHighestNumber)
Randomize
RandomNumber = Int(Rnd * intHighestNumber) + 1
End Function
Function testMatch(sOriginal, sPatrn)
Dim regEx, Match, Matches, strReturn
Set regEx = New RegExp
regEx.Pattern = sPatrn
regEx.IgnoreCase = True ' Distinguir mayúsculas de minúsculas.
regEx.Multiline = True ' Distinguir mayúsculas de minúsculas.
regEx.Global = True
testMatch = regEx.Test(sOriginal)
End Function
Function getMatch(sOriginal, sPatrn)
Dim regEx, Match, Matches, strReturn
Set regEx = New RegExp
regEx.Pattern = sPatrn
regEx.IgnoreCase = True ' Distinguir mayúsculas de minúsculas.
regEx.Multiline = True ' Distinguir mayúsculas de minúsculas.
regEx.Global = True
Set Matches = regEx.Execute(sOriginal)
Set getMatch = Matches
End Function
Function replaceMatch(sOriginal, sPatrn, sReplacementText)
Dim regEx, Match, Matches, strReturn
Set regEx = New RegExp
regEx.Pattern = sPatrn
regEx.IgnoreCase = True ' Distinguir mayúsculas de minúsculas.
regEx.Multiline = True ' Distinguir mayúsculas de minúsculas.
regEx.Global = True
IF IsNullOrEmpty(sOriginal) THEN
replaceMatch = ""
ELSE
replaceMatch = regEx.Replace(sOriginal, sReplacementText)
END IF
End Function
Function replaceEvaluatingMatch(sOriginal, sPatrn, sReplacementText)
Dim regEx, Match, Matches, strReturn
Set regEx = New RegExp
regEx.Pattern = sPatrn
regEx.IgnoreCase = True ' Distinguir mayúsculas de minúsculas.
regEx.Multiline = True ' Distinguir mayúsculas de minúsculas.
regEx.Global = True
IF IsNullOrEmpty(sOriginal) THEN
replaceEvaluatingMatch = ""
ELSE
replaceEvaluatingMatch = regEx.Replace(sOriginal, sReplacementText) 'Evaluate(regEx.Replace(sOriginal, sReplacementText))
END IF
End Function
Function applyTemplate(sOriginal, sPatrn, sTemplate)
Dim regEx, Match, Matches, strReturn
Set regEx = New RegExp
regEx.Pattern = sPatrn
regEx.IgnoreCase = True ' Distinguir mayúsculas de minúsculas.
regEx.Multiline = True ' Distinguir mayúsculas de minúsculas.
regEx.Global = True
strReturn=regEx.Replace(sOriginal, sTemplate)
strReturn=REPLACE(strReturn, "ñ", "ni")
strReturn=REPLACE(strReturn, "Ñ", "NI")
applyTemplate=EVAL(strReturn)
End Function
Function getDisplayName(strTemp)
Dim patrn
patrn="\{(.*)\}*"
Dim regEx, Match, Matches
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True ' Distinguir mayúsculas de minúsculas.
regEx.Multiline = True ' Distinguir mayúsculas de minúsculas.
regEx.Global = True
strTemp=regEx.Replace(strTemp, "")
getDisplayName=strTemp
End Function
Function getParameters(ByVal sParameters)
Set getParameters = getMatch(sParameters, "(?:@)([\w\.\(\)""]*)=([^@]*)(?!(\s*@))")
' Set getParameters = getMatch(sParameters, "(?:@)([\w\.\(\)""]*)=([\w\d\s,=\(\)\[\]""'\.\*\+\/\-\\&\?\!<>]*)(?!(\s*@))")
End Function
Function getMetadataString(sOriginal, sColumnName)
Dim patrn, regEx, Match, Submatch, sMetadataString
patrn=","&sColumnName&"@{(.*?)}@"
' strMatchPattern="«\w*(\([^«]|[\w\(\)\,\s\-]*\))*»"
' Debugger Me, "<strong>"&sColumnName&"("&getMatch(","&sOriginal, patrn).Count&"): </strong> ("&sOriginal&"): "
' response.write sOriginal &"<br>"
For Each Match in getMatch(","&sOriginal, patrn)
FOR EACH Submatch IN Match.Submatches
getMetadataString=TRIM(Submatch)
NEXT
Next
End Function
Function getMetadata(sOriginal, sColumnName, sPropertyName)
' sOriginal=getMetadataString(sOriginal, sColumnName)
Dim strMatchPattern, i, Match, sValue
' response.write sOriginal & "<br>"
'IF sPropertyName="ControlParameters" THEN Debugger Me, sOriginal
strMatchPattern=";@"&sPropertyName&"\:(.*?);@"
'IF sPropertyName="ControlParameters" THEN Debugger Me, strMatchPattern
' strMatchPattern="«\w*(\([^«]|[\w\(\)\,\s\-]*\))*»"
DIM SubMatch
i=0
For Each Match in getMatch(";"&sOriginal&"@", strMatchPattern)
'For Each SubMatch IN Match.SubMatches
sValue=TRIM(Match.SubMatches(0))
'NEXT
' i=i+1
' sValue=LEFT(Match.value, LEN(Match.value)-1)
' sValue=RTRIM(replace(sValue, ";"&sPropertyName&":", ""))
Next
' Debugger Me, sPropertyName&"> "&sValue
' response.write "<br><br>"
IF sValue="NULL" THEN sValue=NULL
getMetadata=sValue
End Function
Function Evaluate(ByVal sInput)
Evaluate=fncEvaluate(sInput)
End Function
Function fncEvaluate(ByVal sInput)
DIM vReturnValue
' IF IsObject(vInput) THEN
' EXECUTE("Set Evaluate=sInput")
' ELSE
ON ERROR RESUME NEXT
EXECUTE("vReturnValue="&CString(sInput).RemoveEntities())
IF Err.Number<>0 THEN
response.write "Ocurrió el siguiente error en funcion <strong>fncEvaluate</strong>:"&Err.Description&vbcrlf&"<br> Al evaluar "&sInput&".<br>"
Debugger Me, ("vReturnValue="&CString(sInput).RemoveEntities().Replace("(["&chr(13)&""&chr(9)&""&chr(10)&""&vbcr&""&vbcrlf&""&vbtab&"])", "<strong>-especial-</strong>"))
response.end
Err.Clear
END IF
ON ERROR GOTO 0
' END IF
fncEvaluate=vReturnValue
End Function
function evalTemplate(byVal fldformat, ByRef oDictionary, ByVal aDataRow)
Dim patrn, fldvalue
patrn="\{(\w*)\}*"
Dim regEx, Match, Matches
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True ' Distinguir mayúsculas de minúsculas.
regEx.Multiline = True ' Distinguir mayúsculas de minúsculas.
regEx.Global = True
'' response.write fldformat &"-->"
' fldvalue=regEx.Replace(fldformat, "getDataRowValue(RowNumber, oDictionary(""fieldsDictionary"")(""$1""))")
fldvalue=regEx.Replace(fldformat, "getDataRowValue(aDataRow, oDictionary.item(""$1"").ParentCell.ColumnNumber)")
'' fldvalue=replace(fldformat, "{0}", fldvalue) '"datarow(oDictionary(""fieldsDictionary"")(""PrecioViv""))-123")
evalTemplate=EVAL(fldvalue)
End Function
function EvaluateTemplate(byVal fldformat, ByRef oDictionary, ByVal iRecord)
Dim patrn, fldvalue
patrn="\{(\w*)\}*"
Dim regEx, Match, Matches
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True ' Distinguir mayúsculas de minúsculas.
regEx.Multiline = True ' Distinguir mayúsculas de minúsculas.
regEx.Global = True
' Dim a, i
' a=oDictionary.Keys
' for i=0 to oDictionary.Count-1
' Response.Write("a: "&a(i))
' Response.Write("<br />")
' next
' set a=nothing
fldvalue=regEx.Replace(fldformat, "oDictionary.item(""$1"")")'oDictionary.item(""$1"").Value")
' response.write fldvalue&"<br>"
EvaluateTemplate=EVAL(fldvalue)
End Function
Function TranslateTemplate(ByVal sTemplate)
TranslateTemplate=CString(sTemplate).Remove(vbcrlf).Replace("\""", """""").Replace("\$_GET\[""(.*?)""\]", "request.querystring(""$1"")").Replace("([^\\])\[(?!\$)(\w*)\](?!=\!)", "$1oFields(""$2"")").RemoveEntities().Replace("((?=.?)(?!\\)\[(?!\$)(?:\w*)(?!\\)\])(\!)", "$1") '\[(?!\$)(\w*)\]
End Function
function EvaluateFieldsTemplate(ByVal sTemplate, ByRef oFields)
ON ERROR RESUME NEXT:
IF sTemplate<>"" THEN
Assign EvaluateFieldsTemplate, EVAL(sTemplate)
'EXECUTE("SET EvaluateFieldsTemplate."&sPropertyName&"=Evaluate(sTemplate)")
'IF Err.Number<>0 THEN
' Err.Clear
' EXECUTE("EvaluateFieldsTemplate."&sPropertyName&"=sTemplate")
'END IF
ELSE
EvaluateFieldsTemplate=sTemplate
END IF
[&Catch] TRUE, Me, "EvaluateFieldsTemplate", ""&sTemplate&" <strong>=></strong><br> ": ON ERROR GOTO 0
End Function
function ContextualEvaluation(ByVal sTemplate, ByRef oContext)
ON ERROR RESUME NEXT:
IF sTemplate<>"" THEN
Assign EvaluateFieldsTemplate, Evaluate(sTemplate)
EXECUTE("SET EvaluateFieldsTemplate."&sPropertyName&"=Evaluate(sTemplate)")
IF Err.Number<>0 THEN
Err.Clear
EXECUTE("oElement."&sPropertyName&"=vInput")
END IF
ELSE
EvaluateFieldsTemplate=sTemplate
END IF
[&Catch] TRUE, Me, "EvaluateFieldsTemplate", ""&sTemplate&" <strong>=></strong><br> ": ON ERROR GOTO 0
End Function
function EvaluateRowTemplate(byVal sTemplate, ByRef oFields)
Dim fldvalue
fldvalue=TranslateTemplate(sTemplate)
' fldvalue=regEx.Replace(sTemplate, "oFields(""$1"")")'oDictionary.item(""$1"").Value")
' response.write fldvalue&"<br>"
ON ERROR RESUME NEXT:
DIM oResult
Assign oResult, EVAL(fldvalue)
[&Catch] TRUE, Me, "EvaluateRowTemplate", ""&sTemplate&" <strong>=></strong><br> "&fldvalue: ON ERROR GOTO 0
IF IsObject(oResult) THEN
Set EvaluateRowTemplate=oResult
ELSE
EvaluateRowTemplate=oResult
END IF
End Function
Function TextDataBind(byRef sText, ByRef oFields)
'"& (""&RTRIM( Candidato )&"") &"
'RESPONSE.WRITE eval("""Texto: ""&Evaluate(""RTRIM( ""& """""""&Candidato&""""""" &"" )"")&"" Fin Texto""")
'"&RTRIM(""«Candidato»""))&"
'RESPONSE.WRITE EVAL("""Texto: ""&RTRIM(Candidato)&"" Fin Texto""")
'RESPONSE.WRITE EVAL("""Texto: ""&Evaluate("""&REPLACE("""&RTRIM(""""&Candidato&"""")&""", """", """""""")&""")&"" Fin Texto""")
'RESPONSE.WRITE Evaluate("""Nombre: ""& (""&( Candidato )&"") &""""" )
'RESPONSE.END
' Set TextDataBind = CString(sText).Replace("""", """""").Append("""").Prepend("""").Replace("(?:<|<)%(.*?)%(?:>|>)", """&Evaluate(""($1)"") &""" ).Replace("(?:«|«)(.*?)(?:»|»)", """&(""$1"")&""").Evaluate()
'"""& (""Evaluate( $1 ) "") &"""
IF NOT oFields IS NOTHING THEN
Set TextDataBind = CString(sText).DoubleQuote() _
.Replace("""(?:«|«)(.*?)(?=[\s]*(?:»|»))", """") _
.Replace("\[(.*?)\](?=[\)\s]*(?=»|»))", "oFields(""$1"").GetCode()") _
.Replace("\{(.*?)\}(?=[\)\s]*(»|»))", "oFields(""$1"")") _
.Replace("#(.*?)#(?=»|»)", "session(""$1"")") _
.Replace("(?:«|«)(.*?)(?:»|»)", """&( $1 )&""") _
.Evaluate()
ELSE
Set TextDataBind = CString(sText).DoubleQuote() _
.Replace("(?:«|«)(.*?)(?:»|»)", """&( $1 )&""") _
.Evaluate()
END IF
End Function
Function TextEvaluate(byRef sText)
Set TextEvaluate = CString(sText).Replace("""", """""").Append("""").Prepend("""").Replace("(?:«|«)(.*?)(?:»|»)", """&($1)&""").Evaluate()
End Function
Function getDataRowValue(ByVal aDataRow, ByVal FieldColumnNumber)
Dim thisrow, returnValue
IF FieldColumnNumber="" THEN
returnValue=""
ELSE
' thisrow=arrayData(RowNumber)
' response.write "RowNumber: "&RowNumber&", FieldColumnNumber: "&FieldColumnNumber&" ("&thisrow&")<br>"
' aDataRow=split(thisrow, "#c#")
returnValue=aDataRow(FieldColumnNumber)
END IF
IF Err.Number<>0 THEN
response.write "Error en getDataRowValue("&RowNumber&", "&FieldColumnNumber&") <br>"
'Err.Clear
END IF
getDataRowValue=returnValue
End Function
Function calculateRowSpan(ByVal RowNumber, ByVal spanRowsBy)
' response.write "Buscando a partir de n: "&RowNumber&"<br>"
returnValue=0
IF spanRowsBy="" THEN
calculateRowSpan=1
EXIT FUNCTION
ELSE
FOR therow=RowNumber TO ubound(arrayData)-1
thisrow=arrayData(therow)
datarow=split(thisrow, "#c#")
IF NOT(therow=RowNumber) THEN
thisRowValReference=evalTemplate(spanRowsBy, therow)
' response.write "r: "&therow&", n: "&RowNumber&", "&UBOUND(arrayData)&"("&thisRowValReference&" vs "&lastRowValReference&"): "&returnValue&"<br>"
IF NOT(lastRowValReference=thisRowValReference) THEN
' response.write "Valor encontrado: "&returnValue
calculateRowSpan=returnValue
EXIT FUNCTION
END IF
END IF
lastRowValReference=evalTemplate(spanRowsBy, therow)
returnValue=returnValue+1
NEXT
calculateRowSpan=returnValue
END IF
End Function
FUNCTION ErrorDisplay(parmSource, parmConn, objDictionary)
' If objDictionary.item("debug")=true THEN
' response.write "<hr>ErrorDisplay called<br>"
' response.flush
' END IF
ErrorDisplay=0
DIM errvbs, errdesc
errvbs=err.number
errdesc=err.description
objDictionary.item("errorsource")=parmSource
' IF objDictionary.item("debug")=true THEN
' response.write "errvbs=" & errvbs & "<br>"
' response.write "errdesc=" & errdesc & "<br>"
' response.write "parmsource=" & parmSource & "<br>"
' response.flush
' END IF
DIM errordetails, customerror
customerror=false
If errvbs<>0 THEN
SELECT CASE errvbs
CASE -2147467259
objDictionary.item("errordesc")="Bad DSN"
objDictionary.item("errornum")=2
errordetails=objDictionary.item("conn")
ErrorDisplay=2
objDictionary.item("errorname")="error_dsn_bad"
CASE -2147217843
objDictionary.item("errordesc")="Bad DSN Login Info"
objDictionary.item("errornum")=3
errordetails=objDictionary.item("conn")
ErrorDisplay=3
objDictionary.item("errorname")="error_dsn_bad_login"
CASE -2147217865
objDictionary.item("errordesc")="Invalid Object Name"
objDictionary.item("errornum")=4
errordetails="probably query has wrong table name - SQL= " & objDictionary.item("sql")
ErrorDisplay=4
objDictionary.item("errorname")="error_query_badname"
CASE -2147217900
objDictionary.item("errordesc")="Bad Query Syntax"
objDictionary.item("errornum")=5
errordetails=errdesc & " - SQL= " & objDictionary.item("sql")
ErrorDisplay=5
objDictionary.item("errorname")="error_query_badsyntax"
CASE ELSE
objDictionary.item("errordesc")="VBscript Error #=<b>" & errvbs & "</b>, desc=<b>" & errdesc & "</b>"
errordetails="n/a"
ErrorDisplay=1
objDictionary.item("errorname")="error_unexpected"
END SELECT
END IF
' IF objDictionary.item("debug")=true THEN
' response.write "objDictionary.item(""errordesc"")=" & objDictionary.item("errordesc") & "<br>"
' response.write "objDictionary.item(""errornum"")=" & objDictionary.item("errornum") & "<br>"
' response.write "errordetails=" & errordetails & "<br>"
' response.write "errorDisplay=" & errordisplay & "<br>"
' response.write "objDictionary.item(""errordesc"")=" & objDictionary.item("errordesc") & "<br>"
' END IF
Dim errorname
errorname=objDictionary.item("errorname")
IF objDictionary.item(errorname)="" THEN
' nothing to do
ELSE
customerror=true
objDictionary.item("errordesc")=objDictionary.item(errorname)
END IF
IF customerror=TRUE THEN
objDictionary.item("errordesc")= replace(objDictionary.item("errordesc"), "{details}", errordetails)
ELSE
IF objDictionary.item("errorsdetailed")=TRUE THEN
objDictionary.item("errordesc")=objDictionary.item("errordesc") & " details=<b>" & errordetails & "</b>"
END IF
END IF
DIM howmanyerrors, dberrnum, dberrdesc, dberrdetails, counter
howmanyerrors=parmConn.errors.count
' IF objDictionary.item("debug")=true THEN
' response.write "howmanyerrors =" & howmanyerrors & "<br>"
' response.flush
' END IF
dberrdetails="<b>(details: "
IF howmanyerrors>0 THEN
FOR counter= 0 TO 0'howmanyerrors
dberrnum=parmconn.errors(counter).number
dberrdesc=parmconn.errors(counter).description
dberrdetails=dberrdetails & " #=" & dberrnum & ", desc=" & dberrdesc & "; "
NEXT
objDictionary.item("adoerrornum")=1
objDictionary.item("adoerrordesc")="DB Error " & dberrdetails
END IF
'objDictionary.item("errornum")=ErrorDisplay
' If objDictionary.item("debug")=true THEN
' response.write "objDictionary(""adoerrornum"")=" & objDictionary("adoerrornum") & "<br>"
' response.write "objDictionary(""adoerrordesc"")=" & objDictionary("adoerrordisc") & "<br>"
' response.write "Leaving ErrorDisplay Function<br>"
' response.write "objDictionary(""errornum"")=" & objDictionary("errornum") & "<br>"
' response.flush
' END IF
END FUNCTION
Function ToTitleFromPascal(ByVal s)
Dim s0, s1, s2, s3, s4, sf, Regex
Set Regex = New RegExp
Regex.Global = True
Regex.IgnoreCase = False
regEx.Multiline = True ' Distinguir mayúsculas de minúsculas.
' remove name space
Regex.Pattern = "(.*\.)(.*)"
s0 = Regex.Replace(s, "$2")
' add space before Capital letter
Regex.Pattern = "[A-Z]"
s1 = Regex.Replace(s0, " $&")
' replace '_' with space
Regex.Pattern = "[_]"
s2 = Regex.Replace(s1, " ")
' replace double space with single space
Regex.Pattern = " "
s3 = Regex.Replace(s2, " ")
' remove and double capitals with inserted space
Regex.Pattern = "([A-Z])\s([A-Z])"
' response.write s&": "&Regex.Test(s3) &"<br>"
DO WHILE Regex.Test(s3)
s3 = Regex.Replace(s3, "$1$2")
LOOP
S4=s3
' response.write s&": "&Regex.Test(s3) &"<br>" &"<br>"
Regex.Pattern = "^\s"
sf = Regex.Replace(s4, "")
' force first character to upper case
ToTitleFromPascal=ToTitleCase(sf)
End Function
Function ToTitleCase(ByVal text)
' RegEx.Replace(RegEx.Replace(@str, "[a-z](?=[A-Z])", "$& ", 0), "(?<=[A-Z])[A-Z](?=[a-z])", " $&", 0)
Dim sb, i
For i = 0 To LEN(text) - 1
If i > 0 Then
If MID(text, i, 1) = " " OR MID(text, i, 1) = vbTab OR MID(text, i, 1) = "/" Then
sb=sb&(UCASE(MID(text, i+1, 1)))
Else
sb=sb&(LCASE(MID(text, i+1, 1)))
End If
Else
sb=sb&UCASE(MID(text, i+1, 1))
End If
Next
ToTitleCase=sb
End Function
Function FormatearNombre(strTemp)
strTemp=replace(UCASE(strTemp), "Á", "A")
strTemp=replace(UCASE(strTemp), "A", "[AÁ]")
strTemp=replace(UCASE(strTemp), "É", "E")
strTemp=replace(UCASE(strTemp), "E", "[EÉ]")
strTemp=replace(UCASE(strTemp), "Í", "I")
strTemp=replace(UCASE(strTemp), "I", "[IÍ]")
strTemp=replace(UCASE(strTemp), "Ó", "O")
strTemp=replace(UCASE(strTemp), "O", "[OÓ]")
strTemp=replace(UCASE(strTemp), "Ú", "U")
strTemp=replace(UCASE(strTemp), "U", "[UÚ]")
FormatearNombre=strTemp
End Function
'Function FormatValue(ByVal vValue, ByVal sFormat, ByVal iDecimalPositions)
' IF IsNullOrEmpty(vValue) THEN FormatValue="": Exit Function END IF
' IF IsNullOrEmpty(sFormat) THEN FormatValue=vValue: Exit Function END IF
' SELECT CASE UCASE(sFormat)
' CASE "MONEY"
' IF IsNullOrEmpty(iDecimalPositions) THEN iDecimalPositions=2
' FormatValue=FormatCurrency(vValue, iDecimalPositions)
' CASE "PERCENT"
' IF IsNullOrEmpty(iDecimalPositions) THEN iDecimalPositions=2
' FormatValue=FormatPercent(vValue/100, iDecimalPositions)
' CASE "DATE"
' FormatValue=FormatDateTime(vValue, 2)
' CASE "DATETIME"
' FormatValue=FormatDateTime(vValue, 2)&" "&FormatDateTime(vValue, 3)
' CASE "NUMERIC"
' IF IsNullOrEmpty(iDecimalPositions) THEN iDecimalPositions=0
' FormatValue=FormatNumber(vValue, iDecimalPositions)
' CASE ELSE
'' IF IsNumeric(vValue) THEN
'' IF IsNullOrEmpty(iDecimalPositions) THEN iDecimalPositions=0
'' FormatValue=FormatNumber(vValue, iDecimalPositions)
'' ELSE
' FormatValue=vValue
'' END IF
' END SELECT
'End Function
Function URLDecode2(sConvert)
Dim aSplit
Dim sOutput
Dim I
IF sConvert="" THEN
URLDecode2 = ""
Exit Function
End If
If IsNull(sConvert) Then
URLDecode2 = ""
Exit Function
End If
' convert all pluses to spaces
sOutput = REPLACE(sConvert, "+", " ")
sOutput = REPLACE(sOutput, "%A0", " ")
sOutput = REPLACE(sOutput, "%2C", ",")
' next convert %hexdigits to the character
aSplit = Split(sOutput, "%")
If IsArray(aSplit) Then
sOutput = aSplit(0)
For I = 0 to UBound(aSplit) - 1
'response.write "--"&Left(aSplit(i + 1), 2)&Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2) &"--"
'response.end
IF testMatch(Left(aSplit(i + 1), 2),"[0-9A-F]{2}") THEN
sOutput = sOutput & _
Chr("&H" & Left(aSplit(i + 1), 2)) &_
Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
ELSE
sOutput = sOutput & "%" & aSplit(i + 1)
END IF
Next
End If
URLDecode2 = sOutput
End Function
Function RegExTest(str, patrn)
Dim regEx
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Pattern = patrn
RegExTest = regEx.Test(str)
End Function
Function URLDecode(sStr)
'UrlDecode = URLDecode2(sStr): Exit Function
DIM str, code, a0
str=""
code=sStr&""
code=Replace(code,"+"," ")
While len(code)>0
If InStr(code,"%")>0 Then
str = str & Mid(code,1,InStr(code,"%")-1)
code = Mid(code,InStr(code,"%"))
a0 = UCase(Mid(code,2,1))
If a0="U" And RegExTest(code,"^%u[0-9A-F]{4}") Then
str = str & ChrW((Int("&H" & Mid(code,3,4))))
code = Mid(code,7)
ElseIf a0="E" And RegExTest(code,"^(%[0-9A-F]{2}){3}") Then
str = str & ChrW((Int("&H" & Mid(code,2,2)) And 15) * 4096 + (Int("&H" & Mid(code,5,2)) And 63) * 64 + (Int("&H" & Mid(code,8,2)) And 63))
code = Mid(code,10)
ElseIf a0>="C" And a0<="D" And RegExTest(code,"^(%[0-9A-F]{2}){2}") Then
str = str & ChrW((Int("&H" & Mid(code,2,2)) And 3) * 64 + (Int("&H" & Mid(code,5,2)) And 63))
code = Mid(code,7)
ElseIf (a0<="B" Or a0="F") And RegExTest(code,"^%[0-9A-F]{2}") Then
str = str & Chr(Int("&H" & Mid(code,2,2)))
code = Mid(code,4)
Else
str = str & "%"
code = Mid(code,2)
End If
Else
str = str & code
code = ""
End If
Wend
URLDecode = str
End Function
Function FormatValue(sParamValue)
bParameterString=NOT(sParamValue="" OR sParamValue="NULL" OR sParamValue="DEFAULT" OR ISNUMERIC(sParamValue) OR testMatch(sParamValue, "^['@]"))
IF bParameterString THEN sParamValue="'"&REPLACE(sParamValue,"'","''")&"'" END IF
IF sParamValue="" THEN sParamValue="NULL" END IF
FormatValue = sParamValue
End Function
Function encodeURL(sConvert)
Dim strTemp
strTemp=server.urlEncode(sConvert)
strTemp=replace(strTemp, "%2C", ",")
strTemp=replace(strTemp, "%28", "(")
strTemp=replace(strTemp, "%29", ")")
strTemp=replace(strTemp, "%2A", "*")
strTemp=replace(strTemp, "%3D", "=")
strTemp=replace(strTemp, "%2E", ".")
strTemp=replace(strTemp, "%2F", "/")
strTemp=replace(strTemp, "%3C", "<")
strTemp=replace(strTemp, "%3E", ">")
strTemp=replace(strTemp, "%5F", "_")
encodeURL=strTemp
End Function
Function HTMLEncode(sText)
HTMLEncode=Server.HTMLEncode(sText)
End Function
Function HTMLDecode(sText)
Dim i
sText = Replace(sText, """, Chr(34))
sText = Replace(sText, "<" , Chr(60))
sText = Replace(sText, ">" , Chr(62))
sText = Replace(sText, "&" , Chr(38))
' sText = Replace(sText, " ", Chr(32))
sText = Replace(sText, "
", Chr(13))
For i = 1 to 255
sText = Replace(sText, "&#" & i & ";", Chr(i))
Next
HTMLDecode = sText
End Function
'ESTAS FUNCIONES DEBEN ESTAR IGUALES QUE EN EL SQL SERVER
Function anioReal(byVal Fecha)
semana=semanaReal(Fecha)
IF YEAR(Fecha-DATEPART("w", Fecha, 2, 1)+1)<>YEAR(Fecha+7-DATEPART("w", Fecha, 2, 1)) THEN
IF semana=1 THEN
anioReal=YEAR(Fecha+7-DATEPART("w", Fecha, 2, 1))
ELSE
anioReal=YEAR(Fecha-DATEPART("w", Fecha, 2, 1)+1)
END IF
ELSE
anioReal=YEAR(Fecha)
END IF
End Function
Function semanaReal(byVal Fecha)
Dim iSemanaCalculada
Fecha=CDATE(Fecha)
IF DatePart("ww", Fecha, 2, 1)=54 OR DATEPART("w", CDATE("1/1/"&YEAR(Fecha)), 2, 1)<4 THEN
iSemanaCalculada=DATEPART("ww", Fecha+7-DATEPART("w", Fecha, 2, 1), 2, 1)
ELSEIF DATEPART("w", CDATE("1/1/"&YEAR(Fecha)), 2, 1)>4 THEN
IF DATEPART("ww", Fecha, 2, 1)=1 AND DATEPART("w", Fecha, 2, 1)>4 THEN
iSemanaCalculada=semanaReal(Fecha-DATEPART("w", Fecha, 2, 1)+1)
ELSE
iSemanaCalculada=DATEPART("ww", Fecha-DATEPART("w", Fecha, 2, 1), 2, 1)
END IF
ELSEIF DATEPART("w", CDATE("1/1/"&YEAR(Fecha)), 2, 1)=4 OR DATEPART("w", CDATE("31/12/"&YEAR(Fecha)), 2, 1)=4 THEN
iSemanaCalculada=DatePart("ww", Fecha, 2, 1)
ELSE
iSemanaCalculada=-1
END IF
semanaReal=iSemanaCalculada
End Function
Function Numero_Letras(byVal cant)
IF TRIM(cant)="" THEN
Numero_Letras=""
ELSE
Numero_Letras=Pesos(CDBL(cant))
END IF
End Function
Function leeArchivo(byVal fileName)
Const ParaLeer = 1
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
'ON ERROR RESUME NEXT
Set f = fso.OpenTextFile(fileName, ParaLeer)
IF Err.Number<>0 THEN
response.write "Error al abrir archivo "&fileName&". Error:"&REPLACE(Err.Description,"'","\'")
response.end
''Err.Clear
END IF
leeArchivo = f.ReadAll
'ON ERROR GOTO 0
End Function
Sub BindFile (byRef strFile, byVal oRecordSet)
Dim strMatchPattern, i
strMatchPattern="«\w*(\([^«]|[\w\(\)\,\s\-]*\))*»"
End Sub
Function interpretaContratos (byRef sContrato)
Dim strMatchPattern, i
Dim Matches, Match
' sContrato=HTMLDecode(sContrato)
strMatchPattern="(?:«|«)(.*?)(?:»|»)"
Set Matches = getMatch(sContrato, strMatchPattern)
i=0
For Each Match in Matches
i=i+1
' strReturnStr = i&".- Match found at position "
' strReturnStr = strReturnStr & Match.FirstIndex & ". Match Value is '"
' strReturnStr = strReturnStr & replace(replace(Match.value, "«", ""), "»", "") & "'="&EVAL(replace(replace(Match.value, "«", ""), "»", ""))&"."
if session("IdUsuario")=1 THEN
'ON ERROR RESUME NEXT
END IF
sContrato=replace(sContrato, Match.value, EVAL(Match.Submatches(0)))
' sContrato=replace(sContrato, Match.value, "<label style=""text-decoration:'underline';""> "&EVAL(replace(replace(Match.value, "«", ""), "»", ""))&" </label>")
' Response.Write(strReturnStr &"<BR>")
Next
interpretaContratos=sContrato
End Function
Const MinNum = 0
Const MaxNum = 4294967295.99
Function Pesos(Number)
DIM strPesos
DIM CompletarDecimales
If (Number >= MinNum) And (Number <= MaxNum) Then
Pesos = conLetra(Fix(Number))
If CSNG(Round((Number - Fix(Number)) * 100)) < 10 Then
CompletarDecimales="0"
Else