Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: ASP to Perl

  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    41
    Thanks
    4
    Thanked 0 Times in 0 Posts

    ASP to Perl

    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.

    Code:
    <%
    '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
    %>

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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.
    Last edited by oracleguy; 11-05-2009 at 05:47 PM.
    OracleGuy

  • #3
    New Coder
    Join Date
    Oct 2009
    Posts
    41
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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.

    Code:
     '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
    %>

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,877
    Thanks
    2
    Thanked 164 Times in 159 Posts
    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...b/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...ib/DBD/LDAP.pm

    Net::LDAP - Lightweight Directory Access Protocol
    http://search.cpan.org/~gbarr/perl-l...b/Net/LDAP.pod


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •