Jump to content

AutoProxy


erifash
 Share

Recommended Posts

[old version]

I have created a program named AutoProxy that will, when run, accept traffic to your network ip address (@IPADDRESS1) on port 80 (you may change the port in the code). If you open a web browser and go to http://put.your.networkip.here:port the program will send the web browser (through tcp) an html page named 'local.htm'. Anyone on the local network may view the page. The special thing about this html document is that AutoProxy will dynamically replace variables in the html (beginning and ending with '%') with variables specified in the file 'variables.ini'. You may edit the variables.ini to add your own variables/macros. The best thing about this program is that it is so versatile. Going to my network ip even works on my psp! :P

[/old version]

AutoProxy has been recently updated. Now the default file is index.htm. It has custom commands and webserver functionality (untested). Some minor bugs were fixed. See post #12 for details.

Everything required is in the zip attached.

Questions/comments are greatly appreciated! :lmao:

EDIT: Added %port% to variables.ini.

EDIT: Added %get% variable and example html form.

EDIT: Rebuilt with many new features! See post #12 for details.

EDIT: Made a simple version. This will just display a page to anyone who connects. See post #16.

AutoProxy.zip

Edited by erifash
Link to comment
Share on other sites

  • Replies 46
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Thanks! I wanted to make this as useful as possible because I can see it being used for many different things. All I need to do now is somehow get input from the web page back to the script (AutoItX anyone? hmmm...).

Edited by erifash
Link to comment
Share on other sites

let me think...

the script sends the request as a GET request:

http://10.0.0.1:80/?q=100

q=100 is the data

And the server returns the data as a html or xml page.

Can't talk more today, gotta go!

Link to comment
Share on other sites

Hmm, this looks promising. Too bad nobody has made an FTP server that can actually work through my firewall. Tried many, failure occured. My router doesn't like FTP servers, even though i configured the port forwarding to allow incoming and outgoing UDP and TCP connections for FTP servers using the correct port and everything.

This will only work on LAN right?

It would be neat if it worked for WAN as well. As in:

http://<your ISP assigned WAN IP>/index.html

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

This will only work on LAN right?

True.

It would be neat if it worked for WAN as well. As in:

http://<your ISP assigned WAN IP>/index.html

That would be cool. I really wanted it to work over the internet but for $IP I can't use the computer's public ip. It would be nice to have your computer be a webserver using AutoIt.

@nfwu:

Would this html work? I haven't tested it as of yet. I am trying to figure out what exactly it would send the script.

<center>
<form action="http://%ip%:80/?q=textarea" method="get" name="AutoExecute">
<textarea name="textarea" cols="40" rows="5" wrap="virtual"></textarea><br>
<input name="execute" type="submit" value="Execute AutoIt Code on Server">
</form>
</center>
Link to comment
Share on other sites

Ahhh! The computer that i'm on right now won't let me test anything... :P I guess I will have to wait until tomorrow.

Link to comment
Share on other sites

Ok, this is how it will work:

<center>
<form action="http://10.0.0.1:80/" method="get" name="AutoExecute">
<textarea name="data1" cols="40" rows="5" wrap="virtual"></textarea><br>
<textarea name="data2" cols="40" rows="5" wrap="virtual"></textarea><br>
<input type="submit" value="Execute AutoIt Code on Server">
</form>
</center>

then the url that the web browser would request for is:

http://10.0.0.1:80/?data1=whateva&data2=someinput

where whateva and someinput are what the user inputed.

spaces in the data will be send as %20 like:

http://10.0.0.1:80/?data1=spaces%20rock!&data2=How%20do%20you%20do?

with the input being "spaces rock!" and "How do you do?"

so, to recap, format:

http://<url>?<name_of_input>=<data>&<name_of_input2>=<data>

Edited by nfwu
Link to comment
Share on other sites

Thank you. For a second there I thought I would need to brush up on my javascript knowledge! :P All that's left to do for now is figure out what information the script is recieving ($recv) when the user presses 'execute'. I can't test it at the moment so all I can do now is add the variable %port% to variables.ini. It is updated in the first post.

Link to comment
Share on other sites

I added the %get% variable to variables.ini plus gave an example on how to use it in the html. Now AutoProxy can store information from the browser/user into a variable for later use! Keep in mind that AutoProxy is just an example of what AutoIt can accomplish and think up new ways to use this code. :P

Edited by erifash
Link to comment
Share on other sites

  • 3 weeks later...

Okay, I have rebuilt AutoProxy with lots of new features:

1. Custom commands: It will now execute mini-scripts defined in autoproxy.ini with included functions in functions.au3.

2. Webserver functionality! If you configure port forwarding correctly, AutoProxy will act as a webserver. (sorry untested, stupid port forwarding...)

3. Other pages/files: If any files are requested by the client, AutoProxy will send it to them.

4. Error pages: AutoProxy will put up the appropriate error page when it encounters an error.

5. Various improvements and bug fixes.

If you have any problems, bug reports, comments, or questions post them here!

The new zip is in the first post. :lmao:

Link to comment
Share on other sites

  • 2 weeks later...

wow, I really like this. I would like to see if i can get this into my script if you wouldn't mind. i am confused on how it works completely, is there some way it can be more simple. and for some reason the script uses my router assigned ip instead of my internet ip. please help. Thank you very much

Check out ConsultingJoe.com
Link to comment
Share on other sites

Question from an autoit newbie here...

Why do I get an error when I try to run the script?

Line 76 (file c:\.......\AutoProxy.au3)

Case "goto"

Error : "Case" statement with no matching "Select" statement

Thanks.. :-)

Edited by xman
Link to comment
Share on other sites

Sorry I've been away for a while... :lmao:

@zerocool: I will put up a simple version of this script soon. To fix your problem just use 127.0.0.1.

@xman: You need the latest beta version of AutoIt.

Edited by erifash
Link to comment
Share on other sites

Here it is, plain and simple:

Global $session = 1
Global $listen
Global $sock
TCPStartup()

HotKeySet('{ESC}', 'OnAutoItExit')

Global Const $IP = @IPAddress1
Global Const $PORT = 54321
Global Const $HEADER = 'HTTP/1.0 200 OK' & @CRLF & 'Content-Type: text/html' & @CRLF & @CRLF
Global $file = @ScriptDir & '\index.htm'
Global $html
Global $recv

If FileExists($file) Then
    $html = FileRead($file)
Else
    $html = '<b>This is a test.<b>'
EndIf

$listen = TCPListen($IP, $PORT, 100)
If $listen = -1 Then mError('Unable to connect.')

Run(@ComSpec & ' /c start http://' & $IP & ':' & $PORT, @ScriptDir, @SW_HIDE)

While 1
    $sock = TCPAccept($listen)
    If $sock >= 0 Then
        $recv = _SockRecv($sock)
        $send = _SockSend($sock, $header & $html)
        TCPCloseSocket($sock)
    Else
        Sleep(10)
    EndIf
Wend

Func mError($sText, $iFatal = 0, $sTitle = 'Error', $iOpt = 0)
    Local $ret = MsgBox(48 + 4096 + 262144 + $iOpt, $sTitle, $sText)
    If $iFatal Then Exit
    Return $ret
EndFunc

Func _SockRecv($iSocket, $iBytes = 2048)
    Local $sData = ''
    While $sData = ''
        $sData = TCPRecv($iSocket, $iBytes)
    Wend
    Return $sData
EndFunc

Func _SockSend($iSocket, $sData)
    Return TCPSend($iSocket, $sData)
EndFunc

Func OnAutoItExit()
    TCPCloseSocket($sock)
    TCPCloseSocket($listen)
    TCPShutdown()
    Exit
EndFunc
Link to comment
Share on other sites

  • 4 weeks later...

Here is my combined script:

#include <Array.au3>
Global $session = 1
Global $listen
Global $sock
TCPStartup()

Global Const $IP = @IPAddress1
Global Const $PORT = 80
Global $header
Global $html
Global $recv
Global $write
Global $lista[255]
ResetNormal()
$listen = TCPListen($IP, $PORT, 100)
If $listen = -1 Then mError('Unable to connect.')

Func ResetNormal()
    ResetHeader()
    LoadHTML(@ScriptDir & "\index.htm")
EndFunc  ;==>ResetNormal

Func ResetHeader($sType = "text/html", $sNum = "200")
    $header = 'HTTP/1.0 ' & $sNum & ' OK' & @CRLF & 'Content-Type: ' & $sType & @CRLF & @CRLF
EndFunc  ;==>ResetHeader

While 1
    $sock = TCPAccept($listen)
    If $sock >= 0 Then
        $recv = _SockRecv($sock)
        If StringLeft($recv, 11) <> "GET / HTTP/" Then _GET($recv)
        $send = _SockSend($sock, $header & $html)
        TCPCloseSocket($sock)
        ResetNormal()
        $session += 1
        DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    Else
        Sleep(10)
    EndIf
WEnd

Func URLUnformat($sURL)
    Local $sNew = ''
    $sURL = StringSplit(StringReplace($sURL, "+", " "), "")
    For $i = 1 To $sURL[0]
        If $sURL[$i] = "%" Then
            $sNew &= Chr('0x' & $sURL[$i + 1] & $sURL[$i + 2])
            $i += 2
        Else
            $sNew &= $sURL[$i]
        EndIf
    Next
    Return $sNew
EndFunc  ;==>URLUnformat

Func _GET($sData)
    
    $sData1 = StringSplit($sData, @CRLF, 1)
    $sData = StringSplit($sData, @CRLF, 1)
    
    If @error Or Not IsArray($sData) Then
        ResetHeader('text/html', '500')
        LoadHTML(@ScriptDir & "\404.htm")
        Return
    EndIf
    
    $sData = StringTrimRight(StringTrimLeft($sData[1], 5), 9)
    
    If $sData == "?" Or $sData == "?=" Then
        ResetHeader('text/html', '500')
        LoadHTML(@ScriptDir & "\500.htm")
        Return
    EndIf
    
    $ime1 = StringSplit($sData1[1], " ", 1)
    $ime2 = StringSplit($ime1[2], "=", 1)
    
    If $ime2[1] == "/?command" And $ime2[2] > "" Then
        Select
            Case $ime2[2] = "exit"
                Exit
            Case $ime2[2] = "result"
                WriteHTML('Result:<br>' & ArrayDisplayHTML($sData1))
            Case Else
                _ArrayAdd($lista, $ime2[2])
                WriteHTML('Result at write:<br>' & ArrayDisplayHTML($lista))
        EndSelect
        ResetHeader()
        Return
    EndIf
    
    Local $sGetFile = @ScriptDir & "\" & StringReplace(URLUnformat($sData), "/", "\")
    If FileExists($sGetFile) And Not StringInStr(FileGetAttrib($sGetFile), "D") Then
        Local $sExt = StringSplit($sGetFile, ".")
        ResetHeader(IniRead(@ScriptDir & "\nastavitve.ini", "Extentions", $sExt[$sExt[0]], "*/*"))
        LoadFILE($sGetFile)
        Return
    Else
        ResetHeader('text/html', '404')
        LoadHTML(@ScriptDir & "\404.htm")
        Return
    EndIf
    
    If $sData == "" Then
        ResetNormal()
        Return
    Else
        ResetHeader('text/html', '404')
        LoadHTML(@ScriptDir & "\404.htm")
        Return
    EndIf
    
EndFunc  ;==>_GET

Func LoadHTML($sFile)
    $html = FileRead($sFile)
EndFunc  ;==>LoadHTML

Func WriteHTML($write)
    $html = $write
EndFunc  ;==>WriteHTML

Func LoadFILE($sFile)
    $html = FileRead($sFile)
EndFunc  ;==>LoadFILE


Func mError($sText, $iFatal = 0, $sTitle = 'Error', $iOpt = 0)
    Local $ret = MsgBox(48 + 4096 + 262144 + $iOpt, $sTitle, $sText)
    If $iFatal Then Exit
    Return $ret
EndFunc  ;==>mError

Func _SockRecv($iSocket, $iBytes = 2048)
    Local $sData = ''
    While $sData = ''
        $sData = TCPRecv($iSocket, $iBytes)
    WEnd
    Return $sData
EndFunc  ;==>_SockRecv

Func _SockSend($iSocket, $sData)
    Return TCPSend($iSocket, $sData)
EndFunc  ;==>_SockSend

Func ArrayDisplayHTML(Const ByRef $avArray)
    Local $iCounter = 0, $sMsg = ""
    
    If (Not IsArray($avArray)) Then
        SetError(1)
        Return 0
    EndIf
    
    For $iCounter = 0 To UBound($avArray) - 1
        $sMsg = $sMsg & StringStripCR($avArray[$iCounter]) & "<and>"
    Next
    
    SetError(0)
    Return $sMsg
EndFunc  ;==>ArrayDisplayHTML

Func OnAutoItExit()
    TCPCloseSocket($sock)
    TCPCloseSocket($listen)
    TCPShutdown()
    Exit
EndFunc  ;==>OnAutoItExit

Ponosen prebivalec Slovenije!My blog http://blog.babnopolje.net/

Link to comment
Share on other sites

  • 1 month later...

It is good but when it opens a page it does it in an exisiting window.

If IniRead(@ScriptDir & "\autoproxy.ini", "Server", "startbrowser", "0") == "1" Then Run(@ComSpec & " /c start explorer http://" & $IP & ":" & $PORT, @ScriptDir, @SW_HIDE)

will solve the problem (line 22) (just added explorer)

Link to comment
Share on other sites

  • 3 months later...

can you make this an actual proxy that you can use like The Proxomitron? or similer? Im looking for some code that can be used as a transperent proxy that sits on your computer and hooks requests for sertin webpages.

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