Jump to content

Problem with automating login on HP Pro Curve Switch web portal


Recommended Posts

Hi guys,

I am trying to automate login to an HP Pro Curve switch web portal. Unfortunately these switches have no remote command line interface... I even spoke with HP Pro Curve support line and they don't have a solution for these switches. No telnet/ssh/CLI interface (other than console cable which beats the point). There are hundreds of switches... and only web portal access.

For now I just need to manage to autologin... later I want to alter configuration parameters.

 

I came across AutoIT and I've been able to write a script that automates login to the router which is great, but I can't seem to isolate the correct elements on the switch portal page with AutoIT and need help.

For a juniper it was easy to login:

#NoTrayIcon
#include <ie.au3>
if $CmdLine[1] = "Router" Then
$Address = "http://" & $CmdLine[2] & ":8080/"
$pwd=$CmdLine[3]
 
$oIE = _IECreate ($Address)
$oForm = _IEFormGetObjByName ($oIE, "login")
 
for $stuff in $oForm
if $stuff.name = "admin_id" then _IEFormElementSetValue ($stuff, "admin")
if $stuff.name = "admin_pw" then _IEFormElementSetValue ($stuff, $pwd)
If $stuff.value == " Login " Then $stuff.click
Next
exit
EndIf

However I can't get $oForm = _IEFormGetObjByName ($oIE, "login") to work on the HP Switch, the elements are not being found...

#NoTrayIcon
#include <ie.au3>
$Address = "http://10.255.96.2"
$pwd="mypass"
 
$oIE = _IECreate ($Address)
_IELoadWait($oIE)
$oForm = _IEFormGetObjByName ($oIE, "maindata")
 
for $stuff in $oForm
if $stuff.name = "password" and $stuff.type = "password" then _IEFormElementSetValue ($stuff, $pwd)
If $stuff.value == "Login" and $stuff.type = "submit" Then $stuff.click
Next
 
exit

It doesn't input it at all only errors.

--> IE.au3 T3.0-1 Warning from function _IEFormGetObjByName, $_IESTATUS_NoMatch
"H:loginToSwitch.au3" (10) : ==> Variable must be of type "Object".:
for $stuff in $oForm
for $stuff in $oForm^ ERROR
>Exit code: 1    Time: 2
 
Here is the page code:
 
ameset framespacing="0" border="0" frameborder="0" rows="80,*">
 
    <frameset framespacing="0" border="0" frameborder="0" cols="*,22"></frameset>
    <frame src="login.html" noresize="" name="loginFrame" scrolling="auto">
        #document
            <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
            <html>
                <head></head>
                <body onload="loadConfiguration();">
                    <script type="text/javascript" language="javascript"></script>
                    <form onsubmit="return login();" name="tF" method="post" action="login.html">
                        <table class="container" style="height: 650px">
                            <tbody>
                                <tr>
                                    <td class="container">
                                        <div class="container">
                                            <div class="loginbox">
                                                <!--
 
                                                 Login box HTML code here... 
 
                                                -->
                                                <table class="login">
                                                    <tbody>
                                                        <tr></tr>
                                                        <tr>
                                                            <td class="hdr style2" valign="top"></td>
                                                            <td class="maindata">
                                                                <input id="password" type="password" onkeypress="capsCheck(event);" size="20" name="password" maxlength="16"></input>
                                                                <script type="text/javascript" language="javascript"></script>
                                                                <input class="button" type="submit" style="position: relative; top: 2;" value="Login"></input>
                                                                <br></br>
                                                                <span id="passwd" class="default" style="display: none;"></span>
                                                            </td>
                                                        </tr>
                                                        <tr></tr>
                                                        <tr></tr>
                                                    </tbody>
                                                </table>
                                                <span id="wrong" class="warning" style="display: none;"></span>
                                                <br></br>
                                                <span id="capsmsg" class="warning" style="display: none;"></span>
                                                <br></br>
 
 
                                                It is recommended that you use a minimum of
 
                                                <br></br>
 
                                                Microsoft® Internet Explorer 5.5 to view the Inter…
 
                                                <br></br>
                                                <br></br>
                                                <!--
 
                                                 Login box HTML end... 
 
                                                -->
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <script type="text/javascript" language="javascript"></script>
                    </form>
                </body>
            </html>
    </frame>
 
</frameset>
<noframes></noframes>

 

However if I right click on the page and view page source of http://10.255.96.2/index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<meta name=Copyright content="Copyright (c) 2005 HP Networks, Inc. All Rights Reserved.">
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<meta http-equiv="Pragma" content="no-cache">
<title>HP Networks Web Interface</title>
<script src="/mainjs.js" language=javascript type="text/javascript"></script>
<script language="javascript" type="text/javascript">
//<!--
checkFrame();    // Ensure we are not within a frame
implementLoginFrames('login.html');
document.write('<noframes>');
//-->
</script>
</head>

<body BGCOLOR="#DAE3EB">
<center>
<font color="#008BD1" face="Arial, Helvetica, sans-serif"><B>Please ensure that your browser supports Frames and Javascript, and that they are both enabled.</b></font>
</center>
<script language="javascript" type="text/javascript">
//<!--
document.write('<\/noframes>');
//-->
</script>
</body>
</html>

And the main.js contains these:

function GUIpopup(winObj, page, title, scroll, hlp)
{
    // winObj is a global variable object stored in top.html: wizTop or helpTop
    var width = screen.width;
    var height = screen.height;
    popup = eval(winObj);

    // Note: !popup.location is an Opera fix
    if ( !popup || popup.closed || !popup.location )
    {
        if ( hlp != "yes" ) hlp = 300;
        else hlp = 500;
        
        if ( scroll != "yes" && scroll != "no" ) scroll = "yes";    //default
        
        winOptions = "width=566,height="+hlp+",toolbar=no,status=no,scrollbars="+scroll+",resizable=yes,menubar=no";
        popup = window.open("", "", winOptions);
        popup.moveTo((screen.width-566)/2,(screen.height-300)/2);
    }

    popup.focus();
    popup.location = page;
    popup.document.title = title;
    eval(winObj + ' = popup');
}

function gURL(pageURL)
{
    location=pageURL;
}

function wURL(pageURL)
{
    myWindow = window.open();
    myWindow.location.href = pageURL;
}

function checkFrame()
{
    var pl = parent.location.href;
    var start = pl.lastIndexOf('/')+1;
    var end = pl.length;
    var subStr = pl.substring(start, end);

    if ( subStr != "index.html" ) { top.location = "/index.html"; }
}

function implementLoginFrames(pageURL)
{
    document.write('<frameset rows="80,*" frameborder="0" border="0" framespacing="0"> ');
    document.write('<frameset cols="*,22" frameborder="0" border="0" framespacing="0"> ');
    document.write('<frame scrolling="no" name="topFrame" noresize src="top_logout.html" >');
    document.write('<frame scrolling="no" name="dataFrame" noresize src="poll_blank.html">');   
    document.write('</frameset>');
    document.write('<frame scrolling="auto" name="loginFrame" noresize src="'+pageURL+'" >');
    document.write('</frameset>');
}

/* capsCheck()
 * Description:
 *  CAPS LOCK check for password entry.
 *  A warning message is displayed if CAPS LOCK is left on.
 *  The warning message is a hidden block with the ID of 'capsmsg'.
 *
 * Usage: onKeyPress="capsCheck(event);"
 */
function capsCheck( e ) {
    var asciiKey=0;
    var shiftState=false;

    if( !e ) { e = window.event; } 
    
    if( !e ) { 
        document.getElementById('capsmsg').style.display = "none";
        return; 
    }

    asciiKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
    
    shiftState = e.shiftKey || ( e.modifiers && ( e.modifiers & 4 ) );

    // Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
    if ( ( asciiKey >= 65 && asciiKey <= 90 ) && !shiftState ) {
        document.getElementById('capsmsg').style.display = "";

    // Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
    } else if ( ( asciiKey >= 97 && asciiKey <= 122 ) && shiftState ) {
        document.getElementById('capsmsg').style.display = "";
    } else {
        document.getElementById('capsmsg').style.display = "none";
    }
}
Edited by ahmedar
Link to comment
Share on other sites

  • Moderators

ahmedar.

Can I now mark #2864 as resolved? Was my suggestion correct? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

ahmedar.

Can I now mark #2864 as resolved? Was my suggestion correct? ;)

M23

 

Just sent you a MP :D

 

You need to read about frames and look at the functions 

_IEFrameGetObjByName and 
_IEFrameGetCollection

 

Any examples? Sorry I am new to AutoIT and inexperienced, but loving it so far. I am only experienced in VBscript, VBA and VB.NET  :) Still got lots to learn!

Edited by ahmedar
Link to comment
Share on other sites

I tried, 0,1,2,3 on the frame (saw one example mentioning picking frame number)

$oIE = _IECreate ($Address)
_IELoadWait($oIE)
$o_frame = _IEFrameGetCollection($oIE, 1)
$oForm = _IEFormGetObjByName ($o_frame, "loginbox")
 
for $stuff in $oForm
if $stuff.name = "password" and $stuff.type = "password" then _IEFormElementSetValue ($stuff, $pwd)
If $stuff.value == "Login" and $stuff.type = "submit" Then $stuff.click
Next
 
exit

I also tried $o_frame = _IEFrameGetCollection($oIE, "loginFrame") as I see that mentioned in the code.

Edited by ahmedar
Link to comment
Share on other sites

Hi,

I'm not sure if this will help,

But I been using it for my "Web" Login stuff

also, depending on the page,  I changed some of the code, 

ie,

If $oUser.Type = 'text' Then        to      If $oUser.Type = 'Email' Then    or     If $oUser.Type = 'Email' or $oUser.Type = 'text' Then

and

        If $oButton.Type = 'submit' Then    to      If $oButton.Type = 'Sign In' Then

Nigel

Edited by Noddle
Link to comment
Share on other sites

Hi,

I'm not sure if this will help,

But I been using it for my "Web" Login stuff

also, depending on the page,  I changed some of the code, 

ie,

If $oUser.Type = 'text' Then        to      If $oUser.Type = 'Email' Then    or     If $oUser.Type = 'Email' or $oUser.Type = 'text' Then

and

        If $oButton.Type = 'submit' Then    to      If $oButton.Type = 'Sign In' Then

Nigel

 

I got the first code working with logging into my router no problem, opens page, waits to load, enters user/pass, logs in, boom.. but for the switches, it appears to be framed and generated or something along those lines.. no matter what I did I could not quite get it work... That's why I pasted the HTML and javascript code in hopes of someone understanding it better than I did.

Edited by ahmedar
Link to comment
Share on other sites

Haha.. I just tried spy.au3... it crashes when I try CTRL+W on the login box in IE :(

 

//TODO codetemplates.txt not available An error occurred when reading the file."C:Program Files (x86)AutoIt3UIAsimplespy.au3" (104) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$oTW.getparentelement($oparentHandle[$i-1],$oparentHandle[$i])
$oTW.getparentelement($oparentHandle[$i-1],^ ERROR
 
Also if I try CTRL+R (to record) it crashes right away too...
Edited by ahmedar
Link to comment
Share on other sites

change this in simplespy (I assume you have a deep tree more then 10 (grand)parents so change it to 50 and 49

 local $oParentHandle[10] ; Max 10 (grand)parents

;~  at least 1
 $i=0
 $oTW.getparentelement($oUIElement,$oparentHandle[$i])
 $oParentHandle[$i]=objcreateinterface($oparentHandle[$i],$sIID_IUIAutomationElement, $dtagIUIAutomationElement)
 If IsObj($oParentHandle[$i]) = 0 Then
  msgbox(1,"No parent", "UI Automation failed",10)
 Else
  while ($i <=9) and (IsObj($oParentHandle[$i])=true)
   $i=$i+1
   $oTW.getparentelement($oparentHandle[$i-1],$oparentHandle[$i])
   $oParentHandle[$i]=objcreateinterface($oparentHandle[$i],$sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  wend
  $parentCount=$i-1
;~   consolewrite($parentCount & " parents found" & @crlf)
 EndIf

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...