Jump to content

Web-based AutoIt! - New with AuCGI!


theguy0000
 Share

Recommended Posts

Drumroll please.............

:)HERE IT IS AT LAST :P

After much testing I may safely say this is a less complicated and safer way to have all the functionality we need.

parser.au3

#include <File.au3>
#include "webinclude.au3"
_StartWebApp()
$_script = '#include "' & @ScriptDir & '\webinclude.au3"' & @CRLF
$_tmp_fl = ""
If $cmdline[0] = 0 Then
    die("Au3 support disabled. Please check server parameters.")
Else
    If $cmdline[1] = @ScriptName Then die("Script cannot run itself.")
    $_au3_file_content = FileRead(@WorkingDir & "\" & $cmdline[1], FileGetSize(@WorkingDir & "\" & $cmdline[1]))
    
    ;begin validation
    $_au3_begin = StringInStr($_au3_file_content, "<?au3")
    $_au3_end = StringInStr($_au3_file_content, "?>")
    If $_au3_end < $_au3_begin Then
        die("Improperly ended or incorrectly formatted tags in script.")
    EndIf
    $_spl1 = StringSplit($_au3_file_content, "<?au3", 1)
    $_spl2 = StringSplit($_au3_file_content, "?>", 1)
    If $_spl1[0] <> $_spl2[0] Then
        die("Too many or too few au3 tags (tags are not symmetrical).")
    EndIf
    
    ;begin parsing
    $_au3_file_content = StringReplace($_au3_file_content, "<?au3", "|")
    $_au3_file_content = StringReplace($_au3_file_content, "?>", "|")
    $_parselines = StringSplit($_au3_file_content, "|")
    For $_var_i = 1 To $_parselines[0]
        If mod($_var_i, 2) = 0 Then ;even
            $_script &= StringStripWS($_parselines[$_var_i], 3) & @CRLF ;au3 scripting
        Else ;odd
            $_script &= 'echo("' & StringReplace(StringReplace($_parselines[$_var_i], '"', '""'), @CRLF, '" & @CRLF & "') & '")' & @CRLF ;html
        EndIf
    Next
    $_tmp_fl = _TempFile()
    FileWrite($_tmp_fl, $_script)
    $_write_lines = ""
    $pid = Run(@AutoItExe & ' /ErrorStdOut "' & $_tmp_fl & '"', @ScriptDir, @SW_HIDE, 2)
    Do
        $_write_lines &= StdOutRead($pid)
    Until @error
    ConsoleWrite($_write_lines)
EndIf

Func OnAutoItExit()
    If FileExists($_tmp_fl) Then
        FileDelete($_tmp_fl)
    EndIf
EndFunc

and a test webpage to see that it does indeed work correctly:

index.au3

<html>
<head>
<title>AutoIt <?au3 echo(@AutoItVersion) ?> Test Webpage located at <?au3 echo(@WorkingDir) ?></title>
</head>
<body>
Testing this page<br>
<?au3
echo("test1<br>")
?>
Something else stupid<br>
<?au3
echo($_REMOTE_ADDR)
?>

<?au3
Func alert($msg)
    echo("<script>alert('" & $msg & "')</script>")
EndFunc
alert("funny stuff")
?>
</body>
</html>
Edited by this-is-me
Who else would I be?
Link to comment
Share on other sites

  • Moderators

If you are parsing line by line, this might work:

$String = "Variable 1 is <?au3 echo(var1) ?>. Variable 2 is <?au3 echo(var2) ?>."
MsgBox(0, '', _ParseVars($String))

Func _ParseVars($sString)
    Local $sCombine
    $aVarNum = _SRE_BetweenEX($sString, 'Variable ', ' is <')
    $aVarGet = _SRE_BetweenEX($sString, 'au3 ', ' \?>')
    If IsArray($aVarNum) And IsArray($aVarGet) Then
        For $iCC = 0 To UBound($aVarNum) - 1
            If Not $iCC Then
                $sCombine &= 'echo("Variable ' & $aVarNum[$iCC] & ' is ")' _
                    & @CRLF & $aVarGet[$iCC] & @CRLF
            Else
                $sCombine &= 'echo(". Variable ' & $aVarNum[$iCC] & ' is ")' _
                    & @CRLF & $aVarGet[$iCC] & @CRLF
            EndIf
        Next
        $sCombine &= 'echo(".")'
        Return $sCombine
    EndIf
    Return SetError(1, 0, 0)
EndFunc

Func _SRE_BetweenEX($s_String, $s_Start, $s_End, $iCase = 'i')
    If $iCase <> 'i' Then $iCase = ''
    $a_Array = StringRegExp ($s_String, '(?' & $iCase & _
            ':' & $s_Start & ')(.*?)(?' & $iCase & _
            ':' & $s_End & ')', 3)
    If @extended & IsArray($a_Array) Then Return $a_Array
    Return SetError(1, 0, 0)
EndFunc   ;==>_SRE_BetweenEX
For the question I had before I fell asleep this morning.

http://www.autoitscript.com/forum/index.ph...st&p=241179

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thanks for the code, but I am simply at a loss to understand it. I attempted to get the gist of what was going on, but I don't understand StringRegExp all that well. Would you mind explaining the logic to me and how your code works.? If not, that's ok. I understand you may have other work to do.

Who else would I be?
Link to comment
Share on other sites

  • Moderators

Thanks for the code, but I am simply at a loss to understand it. I attempted to get the gist of what was going on, but I don't understand StringRegExp all that well. Would you mind explaining the logic to me and how your code works.? If not, that's ok. I understand you may have other work to do.

It's just parsing through looking for strings I told it to search for and the end string to search for, then returning the end result back. I told it to look for Variable[space] and [space]is[space] (or something ike that), and it returns the Variable number to me, then I wanted the echo(var#) so I told it to search for the strings that are constant that echo(var#) sits between.

The function I wrote is like StringBetween, but it's StringRegExpBetween (thus _SRE_Between) simply returing the inbetween results from constants I tell it to look for.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Something useful that AutoIt could really do other than spit out HTML written from scripts is interface with a database such as SQLite. (Now being used alot by PHP users over MySQL and PostgreSQL, also officially released with Apache now as well)

HTML could talk to the AutoIt script, and request information from a datasource. Make it a server language, not a new HTML :)

Maybe the above is what is trying to be done, I am not quite sure.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

@Smoke, now that I look at it with that understanding, it makes much more sense.

@JS, yes, that is exactly what we are doing, and what you can do with this. With this script, it is like php with Au3 instead. You can use "regular html" outside of <?au3 ?> tags, and autoit 3 inside them on the server side.

Who else would I be?
Link to comment
Share on other sites

@Smoke, now that I look at it with that understanding, it makes much more sense.

@JS, yes, that is exactly what we are doing, and what you can do with this. With this script, it is like php with Au3 instead. You can use "regular html" outside of <?au3 ?> tags, and autoit 3 inside them on the server side.

I thought that was the case as I finished reading the thread, but I thought I should post anyways :)

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

I updated the script to take into account if the parser is compiled. You can now have a truly portable version of Au3 scripting. This is useful if you have an example webpage and server you keep on a USB stick. You can include parser.exe and have full Au3 server-side access.

The only changes are to webinclude.au3, where I removed #include <IE.au3> altogether and removed the _Mail function.

parser.au3

#include <File.au3>
#include "webinclude.au3"
_StartWebApp()
If @Compiled Then
    FileInstall("webinclude.au3", @TempDir & "\webinclude.au3", 1)
EndIf
If @Compiled Then
    $_script = '#include "webinclude.au3"' & @CRLF
Else
    $_script = '#include "' & @ScriptDir & '\webinclude.au3"' & @CRLF
EndIf
$_tmp_fl = ""
If $cmdline[0] = 0 Then
    die("Au3 support disabled. Please check server parameters.")
Else
    If $cmdline[1] = @ScriptName Then die("Script cannot run itself.")
    $_au3_file_content = FileRead(@WorkingDir & "\" & $cmdline[1], FileGetSize(@WorkingDir & "\" & $cmdline[1]))
    
    ;begin validation
    $_au3_begin = StringInStr($_au3_file_content, "<?au3")
    $_au3_end = StringInStr($_au3_file_content, "?>")
    If $_au3_end < $_au3_begin Then
        die("Improperly ended or incorrectly formatted tags in script.")
    EndIf
    $_spl1 = StringSplit($_au3_file_content, "<?au3", 1)
    $_spl2 = StringSplit($_au3_file_content, "?>", 1)
    If $_spl1[0] <> $_spl2[0] Then
        die("Too many or too few au3 tags (tags are not symmetrical).")
    EndIf
    
    ;begin parsing
    $_au3_file_content = StringReplace($_au3_file_content, "<?au3", "|")
    $_au3_file_content = StringReplace($_au3_file_content, "?>", "|")
    $_parselines = StringSplit($_au3_file_content, "|")
    For $_var_i = 1 To $_parselines[0]
        If mod($_var_i, 2) = 0 Then ;even
            $_script &= StringStripWS($_parselines[$_var_i], 3) & @CRLF ;au3 scripting
        Else ;odd
            $_script &= 'echo("' & StringReplace(StringReplace($_parselines[$_var_i], '"', '""'), @CRLF, '" & @CRLF & "') & '")' & @CRLF ;html
        EndIf
    Next
    $_tmp_fl = _TempFile()
    FileWrite($_tmp_fl, $_script)
    $_write_lines = ""
    $pid = Run(@AutoItExe & ' /ErrorStdOut /AutoIt3ExecuteScript "' & $_tmp_fl & '"', @ScriptDir, @SW_HIDE, 2)
    Do
        $_write_lines &= StdOutRead($pid)
    Until @error
    ConsoleWrite($_write_lines)
EndIf

Func OnAutoItExit()
    If FileExists($_tmp_fl) Then
        FileDelete($_tmp_fl)
    EndIf
    If @Compiled Then
        If FileExists(@TempDir & "\webinclude.au3") Then
            If Not FileIsOpen(@TempDir & "\webinclude.au3") Then
                FileDelete(@TempDir & "\webinclude.au3")
            EndIf
        EndIf
    EndIf
EndFunc

Func FileIsOpen($file)
   Local $a = _RealFileOpen($file)
   If $a == "FFFFFFFF" Then Return 1
   _RealFileClose($a)
   Return 0
EndFunc

Func _RealFileOpen( $szFile )
   Local $GENERIC_READ = 0x80000000 
   Local $OPEN_EXISTING = 3 
   Local $FILE_ATTRIBUTE_NORMAL = 0x00000080
   Local $RFO_h
   $RFO_h = DllCall("kernel32.dll", "hwnd", "CreateFile", "str", $szFile, "long", $GENERIC_READ, "long", 0, "ptr", 0, "long", $OPEN_EXISTING, "long", $FILE_ATTRIBUTE_NORMAL, "long", 0)
   Return $RFO_h[0]
EndFunc

Func _RealFileClose( $hFile )
   Local $RFC_r
   $RFC_r = DllCall( "kernel32.dll", "int", "CloseHandle", "hwnd", $hFile )
   Return $RFC_r[0]
EndFunc
Who else would I be?
Link to comment
Share on other sites

LOL!

If you don't want your tray icons constantly flashing as users visit your site, don't forget to add #NoTrayIcon to the top of the parser script.

EDIT: I was just thinking that it may be advisable to use a copy of _INetSmtpMail as the mailer on the server...

I also see an issue with the portable version of parser if the au3 webpage wants to call an #include line for anything in the (autoit) includes directory. Should we script for this? Full Au3 Support at all times from parser.au3 or only what support we have now?

Edited by this-is-me
Who else would I be?
Link to comment
Share on other sites

@This:

Ok, you've rekindled my love for this project! I'm using my own version of your cgi handler which does the same thing as yours AFAIK... I just love writing my own stuff :) Plus my pages use my webCGI include file instead of the webinclude your using and I had to rewrite for that!

But, seriously - awesome! I never would have thought to do it how you did. I briefly pondered how to make a handler and was no where close to what you came up with.

Now I just have to incorporate your most recent changes for the compiled version LOL. Stop changing it!

Link to comment
Share on other sites

LOL I believe that any changes needed to be added (if any at all) will be in relation to adding #include support to those scripts run from compiled versions of parser.au3 and changes to webinclude.au3 to make it more portable in itself.

Who else would I be?
Link to comment
Share on other sites

theguy0000 or anyone else, could you provide a short example of how to use session variables?

I played with it a bit but did not quite understand how to correctly use them (session vars).

Thanks for your work on this project!

Edit: What I had in mind:

A script that would allow someeone to enter a username and password and then remeber that they are logged in for the entire session.

Is that doable?

Edited by lte5000
Link to comment
Share on other sites

Wow, it's been a while since I was last on here. I have to say, this is awsome. I'll have to read more about this when I have the time.

You could use this for a faster StringFindOccurances(). I'm not sure who to credit for it, tho (I just remember seeing it somewhere). Searching for "Return UBound" seems to get a good list of ppl (if you really want to give credit to someone).

Func __StringFindOccurances($sStr1, $sStr2)
    Return UBound(StringSplit($sStr1, $sStr2, 1)) - 2
EndFunc
Link to comment
Share on other sites

theguy0000 or anyone else, could you provide a short example of how to use session variables?

I played with it a bit but did not quite understand how to correctly use them (session vars).

Thanks for your work on this project!

Edit: What I had in mind:

A script that would allow someeone to enter a username and password and then remeber that they are logged in for the entire session.

Is that doable?

You could store stuff in an INI file or database or what have you.

#)

Link to comment
Share on other sites

With the new StringRegExp* functions this may be able to go even faster in parsing the data.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Well, This is good, Now I can make a "remote control" to turn remote admin on and off ^^

I go to the page, (from someone elses pc) and click start, and itll run it on this pc :lmao:, And stop stops it. Funkeh eh? Ima make a fully fledged webbased remote control, lol.

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
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...