...

View Full Version : ASP to Perl



pppebble88
11-05-2009, 03:56 PM
Hello,

We just got word that we have to use only PERL on the project we are working on. Currently, we have it pretty much working with ASP. I was wondering if someone could help us convert the code from asp to perl. Thanks a lot and the code is below.



<%
'Look for logoff request
StatusIn = request.querystring("Status")

If StatusIn = "Logoff" Then
Session.abandon
msg = "User Logged Off."
End If

SessName = Session("Name")

If SessName <> "" then
response.redirect("staff.html")
End If


strServerName = ""
strName = Request("username")
strPassword = Request("password")
ActionIN = request("Action")

If ActionIn = "Logon" then

If strName = "" OR strPassword = "" then
msg = "You must include both a User Name and a Password."
End If

If strName <> "" AND strPassword <> "" then

'Establish an object connection and set up the query to find the DN
set oConn = CreateObject("ADODB.Connection")

set oCommand = CreateObject("ADODB.Command")
set oRS = CreateObject("ADODB.Recordset")
oConn.Provider = "ADsDSOObject"
oConn.Open "Ads Provider"
set oCommand.ActiveConnection = oConn 'set the active connection

strQuery= "<LDAP://" & strServername & ">;(&(cn=" & strName & "*));Adspath,cn;subtree"

oCommand.CommandText = strQuery
set oRS = oCommand.Execute 'Execute the query

'Dissect the object to find the DN (Adspath)

Do While Not oRS.EOF
mydn = oRS.Fields(0)
ReturnValue2 = oRS.Fields(0)
Exit Do

oRS.MoveNext
Loop

'Dissect the variable to get the string we want
querydn = InStrRev(mydn, "/")
querydn = Mid(mydn, querydn + 1)

'Now that we have our DN we requery to check for authentication

On Error Resume Next

strDSN = ""
Set dso = GetObject("LDAP:")
Set comp = dso.OpenDSObject(strDSN,querydn,strPassword,0)

If Err.Number = 0 Then
'Check to see if the user is in the ACL in the database%>
<!--#include file="dbconn.asp"-->
<% SQL_query = "SELECT * FROM hbusers where User = '" & strName & "'"
Set RS = MyConn.Execute(SQL_query)

If not rs.eof then
'Get User Role
RoleIn = RS("Role")
'create session variables.
Session("Name") = strName
Session("Role") = RoleIn

response.redirect "http://www.google.com"
End If
If rs.eof then
msg = "You are not authorized to access this application."
End If
ElseIf Err.Number <> 0 Then
msg = "You have entered the incorrect Novell password. Please go back and enter the correct password."
End If
End If
End If
%>

oracleguy
11-05-2009, 05:45 PM
We aren't going to do all the work for you, show us what you have so far (as in the new perl script). If there are specific parts of the script that you are unsure how to do in perl, we can help you there. And answer specific perl questions of course.

If you want someone to just rewrite the script for you and you aren't interested in learning perl, post it in the paid projects forum (http://www.codingforums.com/forumdisplay.php?f=47).

pppebble88
11-05-2009, 10:57 PM
Oracleguy,

I am not looking for anyone to just "do the work for me"...I am trying to figure out if someone could help lead me in the right direction to converting this code...

1. Is it even possible to do what this code does in perl?
2. If so, are there any references to do such a thing?

In a second question, I am trying to verify if an entered username (that was entered in the login box) is in a mySQL table that i have created. The sql table has a list of user names and their "roles". Their role stipulates what they can "see" on the page. That is what the below code snippet does. Any resources/help that could be provided to develop an SQL query that is interfaced with DBI to check the elements in a SQL database and see what they are would be appreciated. Thanks a lot.



'Now that we have our DN we requery to check for authentication

On Error Resume Next

strDSN = "LDAP://directory.usna.edu"
Set dso = GetObject("LDAP:")
Set comp = dso.OpenDSObject(strDSN,querydn,strPassword,0)

If Err.Number = 0 Then
'Check to see if the user is in the ACL in the database%>
<!--#include file="dbconn.asp"-->
<% SQL_query = "SELECT * FROM hbusers where User = '" & strName & "'"
Set RS = MyConn.Execute(SQL_query)

If not rs.eof then
'Get User Role
RoleIn = RS("Role")
'create session variables.
Session("Name") = strName
Session("Role") = RoleIn

response.redirect "http://www.google.com"
End If
If rs.eof then
msg = "You are not authorized to access this application."
End If
ElseIf Err.Number <> 0 Then
msg = "You have entered the incorrect Novell password. Please go back and enter the correct password."
End If
End If
End If
%>

FishMonger
11-06-2009, 12:08 AM
I don't know anything about ASP, but here are some links to Perl modules that you'll need.

CGI - Handle Common Gateway Interface requests and responses
http://search.cpan.org/~lds/CGI.pm-3.48/lib/CGI.pm

DBI - Database independent interface for Perl
http://search.cpan.org/~timb/DBI-1.609/DBI.pm

DBD::mysql - MySQL driver for the Perl5 Database Interface (DBI)
http://search.cpan.org/~capttofu/DBD-mysql-4.013/lib/DBD/mysql.pm

You stated that you need to query a mysql table, but your code references LDAP.

DBD::LDAP - Perl extension for DBI, providing an SQL/Perl DBI interface to Ldap databases.
http://search.cpan.org/~turnerjw/DBD-LDAP-0.10/lib/DBD/LDAP.pm

Net::LDAP - Lightweight Directory Access Protocol
http://search.cpan.org/~gbarr/perl-ldap-0.39/lib/Net/LDAP.pod



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum