Jump to content

Web-based AutoIt! - New with AuCGI!


theguy0000
 Share

Recommended Posts

Well, I haven't quite gotten bored with this yet, although I'm getting there.

For myself, I decided to split the "CGI" functions that interface with the Web Server from the "HTML" functions that just format text and put tags around it. I tried to standardize the names and parameters some.

Here's the complete CGI functions I'm currently using:

_cgiStartApp() - Sets up the variables, pretty much has to be first CGI command

_cgiBufferMode( [bMode]=true ) - Switches between buffered mode where each Write waits for a _cgiCommitBuffer command or non-buffered where each goes instantly. Can be executed before _cgiStartApp. Page defaults to non-buffered.

_cgiClearBuffer() - In buffered mode, clears everything waiting to be written.

_cgiCommitBuffer() - In buffered mode, writes everything waiting to be written.

_cgiEndApp() - Commits the buffer and prevents further writing of the page.

_cgiWrite( sText ) - Place text on the web page.

_cgiRedirect( sURL ) - Sends a page redirect. In buffered mode, must be executed before the first commit buffer. In non-buffered mode, must be executed before first _cgiWrite().

_cgiReadGet( sVariable )

_cgiReadPost( sVariable )

_cgiReadCookie( sVariable ) - Read Get, Post or Cookie with the name of sVariable. Can be executed before _cgiStartApp.

_cgiWriteCookie( sVariable, sValue ) - Writes Cookie. Must be executed before firse _cgiCommitBuffer in buffered mode, or before first _cgiWrite in non-buffered mode.

_cgiURLEncode( sText )

_cgiURLDecode( sText ) (De)codes text for embedding in URLs.

Hope someone finds some use in them. Hope no one finds any remaining typos in them.

Global $__WebPageInitializationString[4]
; [0]=Redirect
; [1]=Content-Type
; [2]=Cookies
; [3]=Page text
Global $__WebPageInitializationFlags=0
Global $__WebPageFlagsDataSent = 1
Global $__WebPageFlagsBuffered = 2
Global $__WebPageFlagsRedirected = 4
Global $__WebPageFlagsAppStarted = 8


Func _cgiStartApp ( )
    If BitAND( $__WebPageInitializationFlags, $__WebPageFlagsDataSent ) Then
        SetError( 1 )
        Return
    ElseIf BitAnd( $__WebPageInitializationFlags, $__WebPageFlagsAppStarted ) Then
        SetError( 3 )
        Return
    EndIf
    
    $__WebPageInitializationString[0] = ""
    $__WebPageInitializationString[1] = "Content-Type: text/html" & Chr(13) & Chr(10)
    $__WebPageInitializationString[2] = ""
    $__WebPageInitializationString[3] = ""
    
    $__WebPageInitializationFlags = BitOR( $__WebPageInitializationFlags, $__WebPageFlagsAppStarted )

EndFunc

Func _cgiBufferMode ( $bBuffer=true )
    If $bBuffer Then
        $__WebPageInitializationFlags = BitOR( $__WebPageInitializationFlags, $__WebPageFlagsBuffered )
    Else
        $__WebPageInitializationFlags = BitAND( $__WebPageInitializationFlags, BitNot( $__WebPageFlagsBuffered ) )
    EndIf
EndFunc

Func _cgiClearBuffer( )
    $__WebPageInitializationString[3] = ""
EndFunc

Func _cgiCommitBuffer( )
    Local $i, $iStart=0
    
    If Not BitAND( $__WebPageInitializationFlags, $__WebPageFlagsAppStarted ) Then
        SetError( 3 )
        Return
    EndIf
    If BitAND( $__WebPageInitializationFlags, $__WebPageFlagsDataSent ) Then
        $iStart = 3
    EndIf
    $__WebPageInitializationString[2] &= @CRLF
    If BitAND( $__WebPageInitializationFlags, $__WebPageFlagsRedirected ) Then
        $__WebPageInitializationString[3] = ""
    EndIf
    For $i=$iStart to 3
        ConsoleWrite( $__WebPageInitializationString[ $i ] )
        $__WebPageInitializationString[ $i ]=""
    Next
    $__WebPageInitializationFlags = BitOR( $__WebPageInitializationFlags, $__WebPageFlagsDataSent )
EndFunc

Func _cgiEndApp( )
    If Not BitAND( $__WebPageInitializationFlags, $__WebPageFlagsAppStarted ) Then
        SetError( 3 )
        Return
    EndIf
    _cgiCommitBuffer( )
    $__WebPageInitializationFlags = BitAND( $__WebPageInitializationFlags, BitNOT( $__WebPageFlagsAppStarted ) )    
EndFunc

Func _cgiRedirect( $sURL )
    If Not BitAND( $__WebPageInitializationFlags, $__WebPageFlagsAppStarted ) Then
        SetError( 3 )
        Return
    EndIf
    If BitAND( $__WebPageInitializationFlags, $__WebPageFlagsDataSent ) Then
        SetError( 1 )
        Return
    Else
        $__WebPageInitializationString[0] = "Location: " & $sURL & @CRLF
        $__WebPageInitializationFlags = BitOR( $__WebPageInitializationFlags, $__WebPageFlagsRedirected )
    EndIf
EndFunc

Func _cgiWrite($sText, $bNewLine=1)
    If Not BitAND( $__WebPageInitializationFlags, $__WebPageFlagsAppStarted ) Then
        SetError( 3 )
        Return
    EndIf
    $__WebPageInitializationString[3] &= $sText
    If $bNewLine Then
        $__WebPageInitializationString[3] &= @CRLF
    EndIf
    If Not BitAND( $__WebPageInitializationFlags, $__WebPageFlagsBuffered ) Then
        _cgiCommitBuffer( )
    EndIf
EndFunc

Func _cgiReadPost( $sVar)
    Local $vars, $var_array
    
    If ConsoleRead( 0,true ) > 0 Then
        $varstring = ConsoleRead( EnvGet("CONTENT_LENGTH"), true)
    Else
        $varstring=EnvGet( "POST_STRING" )
    EndIf

    If Not StringInStr($varstring, $sVar&"=") Then Return ""

    $vars = StringSplit ($varstring, "&")
    For $i=1 To $vars[0]
        $var_array = StringSplit ($vars[$i], "=")
        If $var_array[0] < 2 Then Return "error"
        If $var_array[1] = $sVar Then Return _cgiURLDecode( $var_array[2] )
    Next
    Return ""
    
EndFunc

Func _cgiReadGet( $sVar )
    Local $vars, $var_array

    $varstring = EnvGet("QUERY_STRING")
    If Not StringInStr($varstring, $sVar&"=") Then Return ""

    $vars = StringSplit ($varstring, "&")
    For $i=1 To $vars[0]
        $var_array = StringSplit ($vars[$i], "=")
        If $var_array[0] < 2 Then Return "error"
        If $var_array[1] = $sVar Then Return _cgiURLDecode( $var_array[2] )
    Next
    Return ""
EndFunc

Func _cgiReadCookie($sVar)
    Local $vars, $var_array
    
    $varstring = EnvGet("HTTP_COOKIE")
    If Not StringInStr($varstring, $sVar&"=") Then Return ""

    $vars = StringSplit ($varstring, "; ", 1)
    For $i=1 To $vars[0]
        $var_array = StringSplit ($vars[$i], "=")
        If $var_array[0] < 2 Then Return "error"
        If $var_array[1] = $sVar Then Return _cgiURLDecode( $var_array[2] )
    Next
    Return ""
EndFunc

Func _cgiSetCookie( $sCookie, $sValue )
    If Not BitAND( $__WebPageInitializationFlags, $__WebPageFlagsAppStarted ) Then
        SetError( 3 )
        Return
    EndIf
    If BitAND( $__WebPageInitializationFlags, $__WebPageFlagsDataSent ) Then
        SetError( 1 )
        Return
    Else
        $__WebPageInitializationString[2] &= "Set-Cookie: " & $sCookie & "=" & _cgiURLEncode( $sValue ) & @CRLF
    EndIf
EndFunc

Func _cgiURLEncode( $sText )
    Local $sReturn=""
    
    For $i=1 to StringLen( $sText )
        Switch StringMid( $sText, $i, 1 )
        Case '0' to '9', 'A' to 'Z', 'a' to 'z'
            $sReturn &= StringMid( $sText, $i, 1 )
        Case ' '
            $sReturn &= "+"
        Case Else
            $sReturn &= "%" & Hex( Asc( StringMid( $sText, $i, 1 ) ), 2 )
        EndSwitch
    Next
    
    Return $sReturn
EndFunc

Func _cgiURLDecode( $sText )
    Local $sReturn
    
    For $i=1 to StringLen( $sText )
        Switch StringMid( $sText, $i, 1 )
        Case '+'
            $sReturn &= " "
        Case '%'
            $sReturn &= Chr( Dec( StringMid( $sText, $i + 1, 2 ) ) )
            $i += 2
        Case Else
            $sReturn &= StringMid( $sText, $i, 1 )
        EndSwitch
    Next
    
    Return $sReturn
EndFunc
Link to comment
Share on other sites

  • 3 weeks later...

i know this thread is kinda dead, but...i added die ( )

and made it so that you don't have to put a title for _StartWebApp ( ). If you don't enter a title, it doesn't start the html for you. but it still needs to be at the top of the app or you will get a "500 Internal System Error".

edit: and just added documentation in the first post for both of these.

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

_StartWebApp ("I am a cool web page...")
echo ("Hello world and all who inhabit it!<br />")
_WebCounter ("Yay! you are visitor number % to this web page!")

edit: and be sure to follow the instructions in the first post to get your server up and running. after you have your server installed, scripts go in C:\Program Files\Abyss\htdocs\filename.au3 and then can be accessed from http://127.0.0.1/filename.au3

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

hey what if instead of leaving parameters blank like i say in the first post, what if I put \ErrorStdOut. I think that would make it write errors to the browser's screen right? like php does.

edit: yes this does exactly what I want.

For people who already have it set up...

1. Go to your Abyss Web Server Console (usually http://127.0.0.1:9999/ )

2. Click the Configure button next to the Default Host row in the Hosts table

3. Click Scripting Parameters

4. In the row that contains your AutoIt interpreter in the Interpreters table, click the pencil. It's the row that has the path to your AutoIt beta exe.

5. In Arguments, put "/ErrorStdOut" without the quotes.

6. Click OK.

7. Click OK again.

8. Click the Restart button at the top.

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

Added session capability. I know I promised cookies but that would be way too hard to work with, so just use session vars instead. updated code and lots of info on the new functions in the first post.

  • _Cookie ( )
  • _StartWebApp_Session ( )
  • _GenerateSId ( )
  • _GetSID ( )
  • _Session_set ( )
  • _Session ( )
:)

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

theguy0000 - this is really cool man, I suck at making webpages, and have 0 knowledge when it comes to HTML. Maybe I can learn a little bit about webpages with this. Thanks

EDIT: Hey theguy0000, is there any possible away with Abyss to rename the webpage to something rather than my IP address? Like www.thisisdanswebpage.com or something with words like that? Like I said, I have no knowledge what so ever about webpages, so if this is a really dumb question just say "NO!". If there isn't maybe we could "hack" a way with autoit to make it let you, lol. Just wondering.

Edited by dandymcgee

- Dan [Website]

Link to comment
Share on other sites

theguy0000 - this is really cool man, I suck at making webpages, and have 0 knowledge when it comes to HTML. Maybe I can learn a little bit about webpages with this. Thanks

EDIT: Hey theguy0000, is there any possible away with Abyss to rename the webpage to something rather than my IP address? Like www.thisisdanswebpage.com or something with words like that? Like I said, I have no knowledge what so ever about webpages, so if this is a really dumb question just say "NO!". If there isn't maybe we could "hack" a way with autoit to make it let you, lol. Just wondering.

its not that stupid of a question, actually.

It's very possible.

you need:

1. a domain. You get get one for only only about $10 per year. try the coupon code gdh0727 to drastically reduce this, not sure if it works though.

2. a dns server, for windows. maybe ZoneEdit? untested.

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

has somebody something like an address book with this new cgi udf or other web based autoit udf?.......

or maybe other database scripts?

I congratulate :):P super great UDFs

thanks :D

Edited by BasicOs
Autoit.es - Foro Autoit en Español Word visitors Image Clustrmap image: - Football Spanish team - Spanish team: Casillas, Iniesta, Villa, Xavi, Puyol, Campdevilla, etc..Programando en Autoit+Html - Coding Autoit-Html - Arranca programas desde Internet - Preprocesador de Autoit a http
Link to comment
Share on other sites

has somebody something like an address book with this new cgi udf or other web based autoit udf?.......

or maybe other database scripts?

I congratulate :):D super great UDFs

thanks :D

thanks :P

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

I'm having troubles with Abyss. I got a small webpage set up with just three lines and a title of text, but it isn't allowing anyone but me and my sister (we're on a router) veiw it. My IP address is 192.168.2.100, and when I type it in I get the webpage the way I'm supposed to, but when other people (I'm talking to friends on Yahoo!) try it, it doesn't work. Do I have to reconfig my router to allow something? Please help.

- Dan [Website]

Link to comment
Share on other sites

I'm having troubles with Abyss. I got a small webpage set up with just three lines and a title of text, but it isn't allowing anyone but me and my sister (we're on a router) veiw it. My IP address is 192.168.2.100, and when I type it in I get the webpage the way I'm supposed to, but when other people (I'm talking to friends on Yahoo!) try it, it doesn't work. Do I have to reconfig my router to allow something? Please help.

Yes. I need your router manufacturer. Lynksis, D-Link, etc...and model number.

edit:but i have to go sorry. will help tomorrow!

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

the 192.XXX number is your internal router IP address, for your friend to look at your page, you will need to provide them with your external IP, which is your IP address on the internet, which will be completely different from the one you posted. You can also use a application from no-ip.org, which can allow for a named address to the computer it is running on, i.e. YOURNAMEHERE.no-ip.org (there are many others than no-ip.org that you can use).

And you will have to allow ports that are incoming on port 80 (or whatever port you are hosting web pages on) to be forwarded to YOUR computer (or whichever one is actually hosting them)

Hope this will clarify things a little more for you.

Laterzzz,

Onoitsu2

Things I have made:[font="Trebuchet Ms"]_CheckTimeBlock UDF(LT)MOH Call Ignore List (MOH = Modem On Hold)[/font]

Link to comment
Share on other sites

Hi theguy0000

Honestly I think I'm a lot more positive about your invention than the majority of users here (it seems at least!). Think you're totally on the right path by allowing the same programming language (i.e. AutoIt) to span multiple domains - the old school attitude of: "hell if you're going to write a local application at least use straight Assembler" or "the only language for the dynamic web development is PHP/RUBY/etc./etc." is -SO- outdated. Of course there's going to be some idiosyncrasies at the very start of a project like this. But, ultimately you're providing AutoIt scripters with the freedom to move beyond the realm of local app development and towards the interweb without them having to dedicate uncessesary braincycles to learn yet-another-programming-language that take up valuable time that could have been used to do something useful instead! So, what I'm really getting at here is: Thank you a LOT for your work on this project! It GREAT! :)

Link to comment
Share on other sites

Hi theguy0000

Honestly I think I'm a lot more positive about your invention than the majority of users here (it seems at least!). Think you're totally on the right path by allowing the same programming language (i.e. AutoIt) to span multiple domains - the old school attitude of: "hell if you're going to write a local application at least use straight Assembler" or "the only language for the dynamic web development is PHP/RUBY/etc./etc." is -SO- outdated. Of course there's going to be some idiosyncrasies at the very start of a project like this. But, ultimately you're providing AutoIt scripters with the freedom to move beyond the realm of local app development and towards the interweb without them having to dedicate uncessesary braincycles to learn yet-another-programming-language that take up valuable time that could have been used to do something useful instead! So, what I'm really getting at here is: Thank you a LOT for your work on this project! It GREAT! :P

well thank you very much :)

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

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