Jump to content
Sign in to follow this  

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
$oIE = _IECreateEmbedded()
$oSink = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents")
If @error Then
    MsgBox(0x10, Default, "DWebBrowserEvents Hook Error: 0x" & Hex(@error, 8) & "  (" & @error & ")")
#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
#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)
$oForm = _IEFormGetCollection($oIE, ($FormNum - 1)) ; convert to zero array
_IEFormSubmit($oForm, 0) ; no_wait
    ;~ Sleep(5)
Until GUIGetMsg() = -3 ; $GUI_EVENT_CLOSE
#EndRegion  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

   AuthStr=<Base64-encoded Username:Password String>

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]

Share this post

Link to post
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
Sign in to follow this