Jump to content

HTTP Authorization


Recommended Posts

I'm trying to build a fully automated router restarter to handle the entire process of logging into my router, loading the page with the restart form on it, submitting the form and displaying the appropriate pages from the router.

So far, I have built a GUI that performs all but the login correctly. What happens is the script will load the correct page that contains the restart form, but at the point of submitting the form -- to trigger the router to restart -- I get an IE error page that basically says it could not find the site. The strange thing is that it works perfectly if I have previously logged in successfully and saved the credentials in IE's password manager. It's like the script uses the authorization I send with the request for the page with the form on it, but then uses empty authorization to submit the form.

Here's a snippet from my full script. I use the ActiveX IEObject.Navigate() to send the HTTP authorization header because I couldn't find an appropriate function in AutoIt3 or the IE UDF... (Did I over-look one?) The variables $RouterURL, $AuthStr and $FormNum are retrieved from an INI file, shown below.

#Region  >>>  IE
#include <IE.au3>
$__IEAU3Debug = True
_IEErrorHandlerRegister()
$oIE = _IECreateEmbedded()
$oSink = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents")
If @error Then
    MsgBox(0x10, Default, "DWebBrowserEvents Hook Error: 0x" & Hex(@error, 8) & "  (" & @error & ")")
    Exit
EndIf
#EndRegion  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#Region  >>>  GUI
;~ #include <GUIConstants.au3>
; 0x80CE0000 = PopUp+Caption+MinimizeBox+SizeBox+SysMenu
; 0x14CF0000 = Overlapped+Visible+ClipSiblings
$InetGUI = GUICreate(StringTrimRight(@ScriptName, 4), 810, 240, Default, Default, 0x14CF0000)
$InetObject = GUICtrlCreateObj($oIE, 1, 1, 800, 218)
$InetStatus = GUICtrlCreateLabel("Status", 1, 221, 698, 18, 0x100B) ; (Sunken+Simple)
$InetProgress = GUICtrlCreateProgress(700, 221, 100, 18, 0x0) ; (Smooth)=0x1
GUISetState()
#EndRegion  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#Region  >>>  Core
; SYNTAX: object.Navigate(url As String,[Flags As Variant,][TargetFrameName As Variant,][PostData As Variant,][Headers As Variant])
$oIE.navigate($RouterURL, "", "", "", "Authorization: Basic " & $AuthStr & @CRLF & @CRLF)
_IELoadWait($oIE)
$oForm = _IEFormGetCollection($oIE, ($FormNum - 1)) ; convert to zero array
_IEFormSubmit($oForm, 0) ; no_wait
Do
    ;~ Sleep(5)
Until GUIGetMsg() = -3 ; $GUI_EVENT_CLOSE
Exit
#EndRegion  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

RouterURL=http://172.31.110.1/tshtml/tools/misc.html
   AuthStr=<Base64-encoded Username:Password String>
   FormNum=2

What I want is for this GUI to trigger the router to restart when launched from any user account, regardless of whether or not the account has previously logged into the router web configuration or saved the credentials in the password manager. In other words, I want the Guest account to be able to restart the router by simply running this script.

[right][img]style_emoticons/autoit/robot.gif[/img]One of TenSecondary Adjunct of Unimatrix Z03[/right]

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...