Classic asp posting login form no longer working - vbscript

Working on a classic asp website I've notice a behavior that is causing a lot of trouble to some users. Somehow after a posting a Login Form some password are no longer going thru, getting error (104) reset connection by peer trying to access the main.asp .
Here is the weird thing that you guys can help me figure out:
After many hours trying to find a clue, we got it all back working just by changing the HTML name atribute from name="pwdSenha" to name="pwdTestSenha" then a day after it started all over again, so weve changed the name one more time, now its all working fine again but i guess just until tomorrow.
Is there an explanation for what's happening?
Here is the simplified code:
<form class="modal-content animate" id="frmLogin" name="frmLogin" method="post" action="../functions/aut_user.asp">
<div class="container">
<label><b>Login</b></label>
<input type="text" placeholder="Entre com Login" name="txtLogin" maxlength="45" required>
<label><b>Senha</b></label>
<input type="password" placeholder="Entre com a Senha" name="pwdSenha" maxlength="15">
<button id="bntLoginEntrar" type="submit">Entrar</button>
</div>
</form>
The Autentication class
<%
if funConectaBD() and Session("USER_ID") = "" then
Dim strLogin, strSenha
strLogin = fAspas(Request.Form("txtLogin"))
strSenha = "IS NULL"
if Trim(Request.Form("pwdSenha")) <> "" then
strSenha = "= '" & Cript(Request.Form("pwdSenha")) & "'"
end if
if strLogin <> "" then
'on error resume next
Dim adoRSLogin
Set adoRSLogin = Server.CreateObject("ADODB.Recordset")
adoRSLogin.ActiveConnection = bdConn
Dim strSQL
if Session("USER_CHANGE_PASS") <> "S" then
strSQL = "SELECT * " &_
"FROM users us" &_
"WHERE us.login = '" & strLogin & "' AND us.senha " & strSenha & " AND us.ativo = 'S';"
else
strSQL = "SELECT " &_
"FROM usuario us " &_
"WHERE us.login = '" & strLogin & "' AND us.ativo = 'S';"
end if
'Response.Write(strSQL & "<br/>")
'Response.End()
adoRSLogin.Open(strSQL)
if not adoRSLogin.EOF then
Session("USER_ID") = adoRSLogin("numero")
Session("FUNC_ID") = adoRSLogin("funcionario")
Session("USER_NAME") = adoRSLogin("nome")
Session("FUNC_NAME") = ""
Session("USER_LOGIN") = adoRSLogin("login")
Session("USER_EMAIL") = adoRSLogin("email")
Session("USER_PHONE") = adoRSLogin("telefone")
if adoRSLogin("adm") = "S" then
Session("USER_ADM") = TRUE
else
Session("USER_ADM") = FALSE
end if
Session("UNIT_ID") = adoRSLogin("unidade_numero")
Session("UNIT_NAME") = adoRSLogin("unidade_nome")
strSQL = "CALL inclui_conexao(" & Session("UNIT_ID") & "," & Session("USER_ID") & ",NOW(),NULL);"
'Response.Write(strSQL & "<br/>")
'Response.End
bdConn.execute(strSQL)
'on error goto 0
end if
strSQL = empty
set adoRSLogin = nothing
end if
end if
%>

Related

access checkbox populated in treeview

I am populating a treelist in the run-time. I want to add a checkbox to every leaf of the treelist. I am using the function below to populate the treeview and it works fine. but I am not able to access the checkbox
here is my code
Private Function GetChilds(ParentID As Integer) As String
Dim ChildsStr As String = ""
SQL = "Select Category_Name,Category_ID from Categories where Category_IsDeleted=0 and Category_ParentID=" & ParentID & " order by Category_Order"
Dim drx As SqlDataReader
drx = PF.ExecuteReader(SQL)
If drx.HasRows Then
ChildsStr += "<ul style='display: block'>" & vbNewLine
Do While drx.Read
Dim Ishavechd As Boolean = IsHaveChild(drx("Category_ID"))
If Ishavechd Then
ChildsStr += "<li class=""file-tree-folder open"">" & vbNewLine
Else
ChildsStr += "<li>" & vbNewLine
End If
ChildsStr += drx("Category_Name") & " "
If Not Ishavechd Then ChildsStr += " <input id='" & drx("Category_ID") & "' type='checkbox' />"
ChildsStr += GetChilds(drx("Category_ID"))
ChildsStr += "</li>" & vbNewLine
Loop
ChildsStr += "</ul>" & vbNewLine
End If
drx.Close()
Return ChildsStr
End Function
it populates good. and I am using this code to retrieve the checkbox value
Dim chk As HtmlControls.HtmlInputCheckBox = CType(Panel1.FindControl("8"), HtmlControls.HtmlInputCheckBox)
Response.Write(chk.Checked)
There is a checkbox with this id "8" I am sure of that.
I am adding the treeview to panel
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
I am getting this error
Object reference not set to an instance of an object.
Please help.
I found a solution. I have added name attribute to the checkbox
<input name='" & drx("Category_ID") & "' id='" & drx("Category_ID") & "' type='checkbox' />
in the button click I used
Reques.form(checkbox name)

How can I reference a dynamically created ID in HTA (vbscript)?

See slimmed down code. I'm essentially creating a list of items (printers) along with a dynamically created unique radio button ID, and then I'd like to be able reference said Radio ID in order to toggle the Checked between True/False in Sub SetDefaultPrinter. Why? Because using Add Devices / Search is too hard for some of our users, hence, a cute little GUI. Why dynamic? Because I have multiple separate networks and I'd prefer the script to adjust itself as needed.
<html>
<head>
<title>My HTML application</title>
<HTA:APPLICATION
APPLICATIONNAME="My HTML application"
ID="MyHTMLapplication"
VERSION="1.0"/>
</head>
<script language="VBScript">
Public jj, strPrinters, strModels, strLocations
Sub Window_OnLoad
strPrinters = Array("Printer1", "Printer2")
strModels = Array("HP Color LaserJet 4525", "HP Color LaserJet 4525")
strLocations = Array("Room 1", "Room 2")
jj = UBound(strPrinters)
Call OnClickGo()
End Sub
Sub OnClickGo()
DataArea1.InnerHTML = ""
For i = 0 To jj
DataArea1.InnerHTML = DataArea1.InnerHTML & "<BR><font style=color:green;font-weight=bold;>" &_
"<input type=""" & "radio""" & " name=""" &_
strPrinters(i) & "Radio""" & " id=""" & "Radio" & i & """" &_
" title=""" & "Clicking here will set " & strPrinters(i) & " as default printer.""" &_
" onclick=""" & "SetDefaultPrinter(" & i & ")""" & " onmouseover=""" & "Pointer""" &_
" onmouseout=""" & "DefaultCursor""" & "></input>" &_
"<span id=""" & strPrinters(i) & "Span""" &_
" title=""" & "Click here delete printer mapping for " & strPrinters(i) & """" &_
" onmouseover=""" & "Pointer""" & " onmouseout=""" & "DefaultCursor""" &_
" onclick=""" & "OnClickDelete(" & i & ")""" &_
">" & strPrinters(i) & ", " & strModels(i) & ", Location: " & strLocations(i) & "</span></font>"
Next
End Sub
'========================================
'= Set Default Printer ==================
'========================================
Sub SetDefaultPrinter(ii)
DataArea2.InnerHTML = strPrinters(ii) & " would have been set as default if this was fully functional."
'
' Radio0 and Radio1 are dynamically created IDs, *really* want to somehow
' dynamically reference the dynamically created IDs.
' i.e. something like
' If ii <> 0 Then (Radio & ii).checked = False
'
If ii <> 0 Then Radio0.checked = False
If ii <> 1 Then Radio1.checked = False
End Sub
'========================================
'= Delete Printer Mapping ===============
'========================================
Sub OnClickDelete(ii)
DataArea2.InnerHTML = strPrinters(ii) & " would have been deleted if this was fully functional."
'Set wshnetwork = CreateObject("WScript.Network")
'wshnetwork.RemovePrinterConnection "\\SERVER\" & strPrinters(PrinterToDelete)
End Sub
'========================================
'= MOUSE Pointers =======================
'========================================
Sub Pointer
document.body.style.cursor = "hand"
End Sub
Sub DefaultCursor
document.body.style.cursor = "default"
End Sub
</script>
<body bgcolor="white">
<span id="DataArea1"></span>
<BR><BR><BR>
<span id="DataArea2"></span>
</body>
</html>
user2345916, I have modified your code where the variables pass like you wanted. I left your comments intact, so you can pick up where you left off. Hope this helps!
Basically, the answer to your problem lies within the button's "ID", "VALUE" and "ONCLICK" values.
The ONCLICK='SetDefaultPrinter(" & i & ")' will pass the looped number to the SubRoutine.
The SetDefaultPrinter(Radioii) sets a variable from the "ONCLICK" field of the button that sends you to that SubRoutine (In this case, it's a 0 or 1).
The "FileName = document.getElementById("Radio" & Radioii).value" gets the "VALUE" field of the button that matches the "ID" field that is set between the "()", which in your case is also the variable that was pulled from the ONCLICK.
From here, you can use (FileName) variable to do whatever you want (Match IF/THEN, etc)
<script language=vbscript>
Sub Window_OnLoad
window.resizeTo 500,300
strPrinters = Array("Printer 1", "Printer 2")
strModels = Array("HP Color LaserJet 4525", "HP Color LaserJet 4525")
strLocations = Array("Room 1", "Room 2")
jj = UBound(strPrinters)
For i = 0 To jj
strHTML1 = "<span id='Delete" & i & "' value='" & strPrinters(i) & "'title='Click here delete printer mapping for " & strPrinters(i) & "' onmouseover='Pointer' onmouseout='DefaultCursor' onclick='OnClickDelete(" & i & ")'> " & strPrinters(i) & " - " & strModels(i) & ", Location: " & strLocations(i) & "</span>"
strHTML2 = strHTML2 & "<input type='radio' name='radio' value='" & strPrinters(i) & "' id='Radio" & i & "' title='Clicking here will set " & strPrinters(i) & " as default printer.' onclick='SetDefaultPrinter(" & i & ")' onmouseover='Pointer' onmouseout='DefaultCursor'>" &_
"" & strHTML1 & "</input><br>"
DataArea1.InnerHTML = strHTML2
Next
End Sub
'========================================
'= Set Default Printer ==================
'========================================
Sub SetDefaultPrinter(Radioii)
FileName = document.getElementById("Radio" & Radioii).value
DataArea3.InnerHTML = Filename & " would have been set as default if this was fully functional."
'
' Radio0 and Radio1 are dynamically created IDs, *really* want to somehow
' dynamically reference the dynamically created IDs.
' i.e. something like
' If ii <> 0 Then (Radio & ii).checked = False
'
If Radioii = 0 Then Radio0 = False
If Radioii = 1 Then Radio1 = False
End Sub
'========================================
'= Delete Printer Mapping ===============
'========================================
Sub OnClickDelete(Deleteii)
RemoveName = document.getElementById("Delete" & Deleteii).value
DataArea3.InnerHTML = RemoveName & " would have been deleted if this was fully functional."
'Set wshnetwork = CreateObject("WScript.Network")
'wshnetwork.RemovePrinterConnection "\\SERVER\" & strPrinters(PrinterToDelete)
End Sub
'========================================
'= MOUSE Pointers =======================
'========================================
Sub Pointer
document.body.style.cursor = "hand"
End Sub
Sub DefaultCursor
document.body.style.cursor = "default"
End Sub
</script>

Filter out NULL fields returned in a objCom.CommandText

Using the script below, I am able to list users in an OU as expected however the output lists everything including users that are missing data in the custom ipphone field. I need help to modify the code to NOT list a user with a missing extension number in the ipphone field. "This indicates a user has left the company and should not show up on the phone list"
<%# Language=VBScript %>
<% response.Buffer = True %>
<html><head>
<title></title>
</head>
<body>
<h1>Directory</h1>
<%
' Define the AD OU that contains our users
usersOU = "LDAP://OU=IT,OU=Hollister,OU=Houston,OU=NFSmith,DC=nfsmith,DC=info"
' Make AD connection and run query
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.provider ="ADsDSOObject"
objCon.Properties("User ID") = "domain\user"
objCon.Properties("Password") = "password"
objCon.Properties("Encrypt Password") = TRUE
objCon.open "Active Directory Provider"
Set objCom = CreateObject("ADODB.Command")
Set objCom.ActiveConnection = objCon
objCom.CommandText ="select givenName,sn,telephonenumber,ipphone FROM '"+ usersOU +"' where ipphone='*' ORDER by givenName"
Set objRS = objCom.Execute
' Loop over returned recordset and output HTML
Response.Write "<table>" + vbCrLf
Do While Not objRS.EOF Or objRS.BOF
Response.Write " <tr>"
Response.Write "<td>" + objRS("givenName") + "</td>"
Response.Write "<td>" + objRS("sn") + "</td>"
Response.Write "<td>" + objRS("telephonenumber") + "</td>"
Response.Write "<td>" + objRS("IPphone") + "</td>"
Response.Write "</tr>" + vbCrLf
objRS.MoveNext
Response.Flush
Loop
Response.Write "</table>"
' Clean up
objRS.Close
objCon.Close
Set objRS = Nothing
Set objCon = Nothing
Set objCom = Nothing
%>
</body>
</html>
Check if the value is Null before writing the output:
Do Until objRS.EOF
If Not IsNull(objRS("ipPhone")) Then
Response.Write " <tr><td>" + objRS("givenName")
Response.Write "</td><td>" + objRS("sn")
Response.Write "</td><td>" + objRS("telephoneNumber")
Response.Write "</td><td>" + objRS("ipPhone")
Response.Write "</td></tr>" & vbCrLf
Response.Flush
End If
objRS.MoveNext
Loop
If you don't want the NULL records at all, why don't you tell your SQL query to exclude them?
So where you have
objCom.CommandText ="select givenName,sn,telephonenumber,ipphone FROM '"+ _
usersOU +"' where ipphone='*' ORDER by givenName"
add a condition:
objCom.CommandText = "SELECT givenName, sn, telephonenumber, ipphone FROM '" & _
usersOU & "' WHERE ipphone = '*' AND ipphone IS NOT NULL ORDER BY givenName"
(I'm not sure what the purpose of ipphone = '*' is, but I don't work with Active Directory much.)
The other approach, i.e. testing for IsNull(objRS("ipPhone")) in your code, is useful if you want to do something else if the field is null — maybe add an "inactive" class, that sort of thing.

VB6 To send a Form Post

Here is the code I am using:
Dim httpReq As New WinHttp.WinHttpRequest
Dim strLineOut As String
Dim strReturn As String
Dim strStatus As String
lblResponse1.Caption = ""
DoEvents
strLineOut = "<form name=""form1"" method=""post"" enctype=""multipart/form-data"">" & vbCrLf
strLineOut = strLineOut & " <input name=""hdntype"" type=""hidden"" id=""hnd1"" value=""1"">" & vbCrLf
strLineOut = strLineOut & " <input name=""hnd1"" type=""hidden"" id=""hnd1"" value=""Value1"">" & vbCrLf
strLineOut = strLineOut & " <input name=""hdn2"" type=""hidden"" id=""hdn2"" value=""Value2"">" & vbCrLf
strLineOut = strLineOut & " <input type=""submit"" name=""Submit"" value=""Submit"">" & vbCrLf
strLineOut = strLineOut & "</form>" & vbCrLf
httpReq.Open "POST", "http://www.XXXX.com/XMLProjects/vb6test/form_post.asp", False
httpReq.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
'text/xml
'application/x-www-form-urlencoded
'httpReq.StatusText
'httpReq.Status
'httpReq.SetRequestHeader "Content-Length", Len(strLineOut)
httpReq.Send (strLineOut)
strStatus = httpReq.StatusText
strReturn = httpReq.ResponseText
Debug.Print strReturn & vbCrLf & strStatus
lblResponse1.Caption = strReturn & vbCrLf & strStatus
Set httpReq = Nothing
The asp that catches the form cannot seem to recognize the form. It sees a form with one item.
The catch code in the asp is:
Response.Write Request.Form("hdntype")
Response.Write "the form object is " & Request.Form.Item(1) & vbCrLf
The response from the asp is:
the form object is "form1"method="post"enctype="multipart/form-data">
<inputname="hdntype"type="hidden"id="hnd1"value="1">
<inputname="hnd1"type="hidden"id="hnd1"value="Nick">
<inputname="hdn2"type="hidden"id="hdn2"value="Arnone">
<inputtype="submit"name="Submit"value="Submit"></form>
It does not see the item hdntype, or any other item within the form. It sees 1 item, the entire form.
If I do a Request.TotalBytes, I can see everythinhg in the asp.
If I add a querystring objects, I can see each object.
I cannot see form objects.
In VB6, if you send the data like this:
strIDJob = "34"
strAuthString = "supertest"
DataToPost = ""
DataToPost = DataToPost & "IDJob=" & strIDJob & "&"
DataToPost = DataToPost & "AUTH=" & strAuthString & "&"
(im sending it to an ASP page, using the CreateObject("Msxml2.XMLHTTP.6.0") component)
(sending with POST with only this header included: "application/x-www-form-urlencoded")
Then, you can retrieve each item using the code bellow (in ASP), one by one:
IDJob = Request.Form.Item(1) 'here is the core point of this post. This is the line that matters
AUTH = Request.Form.Item(2) 'here is the core point of this post. This is the line that matters
response.write "IDJob = " & IDJob & "<BR>"
response.write "AUTH = " & AUTH & "<BR>"
Response.End
this code in asp produces the following return/output:
IDJob = 34AUTH = supertest

HTA(vbs) - To do list - delete or modify array items

I'm trying to create an HTA To Do List saving locally to a text file. Every time you press submit button generates a new entry that display inside hta body and it's being saved inside the text file. I want to develop this furthermore :
delete an entry and update body/text file
modify an entry and update body/text file
put new entry on top
Any suggestions?
<html>
<head>
<HTA:APPLICATION SINGLEINSTANCE="yes" APPLICATIONNAME="To Do List">
</head>
<SCRIPT Language="VBScript">
Sub Window_OnLoad
ReadBlog
End Sub
Sub SaveData
strDel1="<"
strDel2=">"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\Test.txt") Then
Set objFile = objFSO.OpenTextFile("C:\Test.txt", 8)
strLine = strDel1 & Time & vbTab & Date & vbTab & Title.Value & vbTab & Message.Value & strDel2
objFile.WriteLine strLine
objFile.Close
Else
Set objFile = objFSO.CreateTextFile("C:\Test.txt")
strLine = strDel1 & Time & vbTab & Date & vbTab & Title.Value & vbTab & Message.Value & strDel2
objFile.WriteLine strLine
objFile.Close
End If
ReadBlog
ClearText
End Sub
Sub ReadBlog
Const ForReading = 1, ForWriting = 2
dim sampletext, objRegExp, SearchPattern, ReplacePattern, matches
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Test.txt", ForReading)
Do Until objFile.AtEndOfStream
sampletext = objFile.ReadAll
SearchPattern = "<"
SearchPattern = SearchPattern & "(.*?)([\s\S]*?)"
SearchPattern = SearchPattern & ">"
Set objRegExp = New RegExp
objRegExp.Pattern = searchpattern ' apply the search pattern
objRegExp.Global = True ' match all instances if the serach pattern
objRegExp.IgnoreCase = True ' ignore case
Set matches = objRegExp.execute(sampletext)
If matches.Count > 0 Then ' there was at least one match to the search pattern
i=0
For Each match in matches
arrEntry = Split(Split(match.Value, "<")(1), ">")(0)
arrFields = Split(arrEntry, vbTab)
strTime = arrFields(0)
strDate = arrFields(1)
strTitle = arrFields(2)
strMessage = arrFields(3)
strHTML = strHTML & "<p>" & strTime & "</p>"
strHTML = strHTML & "<p>" & strDate & "</p>"
strHTML = strHTML & "<p>" & strTitle & "</p>"
strHTML = strHTML & "<p>" & strMessage & "</p>"
strHTML = strHTML & "<input type='button' name='Delete' value='Delete' >"& i &"<p>"
i=i+1
Next
Else ' there were no matches found
MsgBox objRegExp.Pattern & "was not found in the string"
End If
Loop
DataArea.InnerHTML = strHTML
Set objRegExp = Nothing
Set objFSO = Nothing
End Sub
Sub ClearText
Title.Value = ""
Message.Value = ""
End Sub
</SCRIPT>
<body>
<input type="text" name="Title" size="101"><p>
<textarea rows="10" cols="76" type="text" name="Message" size="25"></textarea><p>
<input type="button" value="Submit" onClick="SaveData">
<p><div id="DataArea"></div></p>
</body>
</html>
Are you particularly tied to using text files? If you used a database (such as access) you could do this quite easily (you don't have to have access installed to use an access database with an HTA either). And it would open up some other possibilities.
Incidentally, I also notice you're doing this:
strHTML = strHTML & "<p>" & strTime & "</p>"
strHTML = strHTML & "<p>" & strDate & "</p>"
strHTML = strHTML & "<p>" & strTitle & "</p>"
strHTML = strHTML & "<p>" & strMessage & "</p>"
Not a big thing, but concatenating the strings like that isn't great for performance. You'd be better off writing it all to the variable at the same time, otherwise it has to keep writing the variable to memory over and over again.
If you want to read a file with HTA you can easily do it in javaScript. Since the context changes IE allws you to directly read file on the computer or the network to wich the computer is linked to. In order to do so, you need to access the File System Object (FSO)
Full Documentation on FSO
If you are still looking to access a database you need to use the ADODB.Connection. That will allow you to connect to database localy or remotely. Altought there is not much documentation on the subject we did it at my work place. With a little imagination you can figure out how to fix it.
Documentation on the ADODB.Connnect
In this documentation the example are in VB but you can write them in JS as well.

Resources