Scripting Engine ...

Use this forum if you want to discuss a problem or ask a question related to a hMailServer beta release.
Post Reply
User avatar
SorenR
Senior user
Senior user
Posts: 6268
Joined: 2006-08-21 15:38
Location: Denmark

Scripting Engine ...

Post by SorenR » 2024-02-09 18:39

I'm working on adding luascript to version 5.6.9.

It sort of works and yet it does not. I get some errors that I can't explain.

Anyways, I created this code (Eventhandlers.xx) to test the scripting engine:

VBScript:

Code: Select all

Sub OnClientConnect( oClient )
    Call Test
End Sub

Sub Test
    Set objShell = CreateObject("WScript.Shell")
    Set colSystemEnvVars = objShell.Environment("Process")

    '    hMailServer
    'EventLog.Write( "System = " & colSystemEnvVars("PROCESSOR_ARCHITECTURE") )

    '    CScript
    WScript.Echo( "System = " & colSystemEnvVars("PROCESSOR_ARCHITECTURE") )
End Sub

Call Test
JavaScript:

Code: Select all

function OnClientConnect(oClient) {
    Test();
}
 
function Test() {
    var objShell;
    var colSystemEnvVars;

    //    CScript
    var out = WScript.StdOut;
    
    objShell = new ActiveXObject("WScript.Shell");
    colSystemEnvVars = objShell.Environment("Process");

    //    hMailServer
    //EventLog.Write( "System = " + colSystemEnvVars("PROCESSOR_ARCHITECTURE") );

    //    CScript
    out.WriteLine( "System = " + colSystemEnvVars("PROCESSOR_ARCHITECTURE") );
}

Test();
LuaScript:

Code: Select all

function OnClientConnect(oClient)
    Test()
end
 
function Test()
    objShell = luacom.CreateObject("WScript.Shell")
    colSystemEnvVars = objShell:Environment("Process")
    
    --    hMailServer
    -- EventLog.Write( "System = " .. colSystemEnvVars("PROCESSOR_ARCHITECTURE") )
    
    --    CScript
    print( "System = " .. colSystemEnvVars("PROCESSOR_ARCHITECTURE") )
end

Test()
When I call the above code vith CScript Eventhandlers.vbs, .js or .lua I get "System = AMD64"
When I call the above code from inside hMailServer I get "System = x86" - well except for LuaScript.

Computer is "AMD64" Windows 10 Home x64 on Intel Core i7-6500U.

This is my theory; VBScript and JavaScript is present in the registry both as x86 and x64 keys, LuaScript is only present as x64.

The exact spot LuaScript fails is when the scripting engine verifies that a certain trigger (eg. OnClientConnect) exists in the LuaScript engine - the actual code IS present in the source code of the LuaScript engine.
https://github.com/hmailserver/hmailser ... ite.h#L279

I have both x86 and x64 versions of luascript.dll originally built by Natural Style Co. Ltd. https://na-s.jp/LuaScript/.
I also have a version of hMailServer 5.6.9 modified to use LuaScript.

So... Er... Help ?
SørenR.

Old data analysts don’t die – they just get broken down by age and sex.

palinka
Senior user
Senior user
Posts: 4417
Joined: 2017-09-12 17:57

Re: Scripting Engine ...

Post by palinka » 2024-02-09 19:41

No help... Just an "atta boy!" 👍

User avatar
SorenR
Senior user
Senior user
Posts: 6268
Joined: 2006-08-21 15:38
Location: Denmark

Re: Scripting Engine ...

Post by SorenR » 2024-02-10 04:12

Perhaps I should add that this code runs in a command prompt when called by CScript...

Code: Select all

    oApp = luacom.CreateObject("hMailServer.Application")
    oApp:Authenticate("Administrator", "Cosmic.Secret.Level.Password")

    WScript:Echo( "oApp.Settings.SSLCertificates.Count = " .. oApp.Settings.SSLCertificates.Count )

    for i=0,oApp.Settings.SSLCertificates.Count-1,1
    do
        WScript:Echo( "i = " .. i )
        WScript:Echo( "Certificate ID " .. oApp.Settings.SSLCertificates(i).ID)
        WScript:Echo( "Certificate Name " .. oApp.Settings.SSLCertificates(i).Name)
        WScript:Echo( "Certificate File " .. oApp.Settings.SSLCertificates(i).CertificateFile)
        WScript:Echo( "Certificate Key " .. oApp.Settings.SSLCertificates(i).PrivateKeyFile)
    end

    WScript:Echo( "oApp.Settings.TCPIPPorts.Count = " .. oApp.Settings.TCPIPPorts.Count )

    for i=0,oApp.Settings.TCPIPPorts.Count-1,1
    do
        WScript:Echo( "i = " .. i )
        WScript:Echo( "TCPIP Port ID " .. oApp.Settings.TCPIPPorts(i).ID)
        WScript:Echo( "TCPIP Port Address " .. oApp.Settings.TCPIPPorts(i).Address)
        WScript:Echo( "TCPIP Port Protocol " .. oApp.Settings.TCPIPPorts(i).Protocol)
        WScript:Echo( "TCPIP Port Port " .. oApp.Settings.TCPIPPorts(i).PortNumber)
        WScript:Echo( "TCPIP Port Enable " .. tostring(oApp.Settings.TCPIPPorts(i).UseSSL))
        WScript:Echo( "TCPIP Port Certificate ID " .. oApp.Settings.TCPIPPorts(i).SSLCertificateID)
    end
SørenR.

Old data analysts don’t die – they just get broken down by age and sex.

User avatar
SorenR
Senior user
Senior user
Posts: 6268
Joined: 2006-08-21 15:38
Location: Denmark

Re: Scripting Engine ...

Post by SorenR » 2024-02-10 13:36

SorenR wrote:
2024-02-09 18:39
This is my theory; VBScript and JavaScript is present in the registry both as x86 and x64 keys, LuaScript is only present as x64.

The exact spot LuaScript fails is when the scripting engine verifies that a certain trigger (eg. OnClientConnect) exists in the LuaScript engine - the actual code IS present in the source code of the LuaScript engine.
https://github.com/hmailserver/hmailser ... ite.h#L279

I have both x86 and x64 versions of luascript.dll originally built by Natural Style Co. Ltd. https://na-s.jp/LuaScript/.
I also have a version of hMailServer 5.6.9 modified to use LuaScript.

So... Er... Help ?
OK, got both x86 and x64 script engines registered - seems my registry was FU'd from a previous Lua install.

C:\Windows\System32\CScript Script.lua outputs "System = AMD64"

C:\Windows\SysWOW64\CScript Script.lua outputs "System = x86"

hMailServer script engine still fails :roll:

Code: Select all

function Test()
    objShell = luacom.CreateObject("WScript.Shell")
    colSystemEnvVars = objShell:Environment("Process")
    WScript:Echo( "System = " .. colSystemEnvVars("PROCESSOR_ARCHITECTURE") )
end

Test()
SørenR.

Old data analysts don’t die – they just get broken down by age and sex.

User avatar
SorenR
Senior user
Senior user
Posts: 6268
Joined: 2006-08-21 15:38
Location: Denmark

Re: Scripting Engine ...

Post by SorenR » 2024-02-10 18:27

Hmm... This project is probably doomed!

In the luascript script engine all of these:

Code: Select all

IDispatch->GetTypeInfo
IDispatch->GetIDsOfNames
IActiveScript->Close
IActiveScript->InterruptScriptThread
IActiveScriptError->GetSourceLineText
return "E_NOTIMPL"

and they are all referenced in ScriptSite.h. :roll:

I think I'll be hacking some of the code to bypass "stuff" and see what I can make it do then ... Perhaps I can learn something :mrgreen:
SørenR.

Old data analysts don’t die – they just get broken down by age and sex.

User avatar
SorenR
Senior user
Senior user
Posts: 6268
Joined: 2006-08-21 15:38
Location: Denmark

Re: Scripting Engine ...

Post by SorenR » 2024-02-11 22:22

Just poking about....

Yeah... Python 3.11.6 Active scripting run from "cscript script.pys" :mrgreen:
I've only spend one day with Python and I hate it deeply already :roll:

Code: Select all

import sys, win32com.client as win32
oApp = win32.Dispatch("hMailServer.Application")
oApp.Authenticate("Administrator", #COSMICSECRET)

print( "oApp.Settings.SSLCertificates.Count = " + str(oApp.Settings.SSLCertificates.Count) )

for i in range(0, oApp.Settings.SSLCertificates.Count):
	print( "i = " + str(i) )
	print( "Certificate ID   " + str(oApp.Settings.SSLCertificates(i).ID) )
	print( "Certificate Name " + str(oApp.Settings.SSLCertificates(i).Name) )
	print( "Certificate File " + str(oApp.Settings.SSLCertificates(i).CertificateFile) )
	print( "Certificate Key  " + str(oApp.Settings.SSLCertificates(i).PrivateKeyFile) )

print( "oApp.Settings.TCPIPPorts.Count = " + str(oApp.Settings.TCPIPPorts.Count) )

for i in range(0, oApp.Settings.TCPIPPorts.Count):
	print( "i = " + str(i) )
	print( "TCPIP Port ID             " + str(oApp.Settings.TCPIPPorts(i).ID) )
	print( "TCPIP Port Address        " + str(oApp.Settings.TCPIPPorts(i).Address) )
	print( "TCPIP Port Protocol       " + str(oApp.Settings.TCPIPPorts(i).Protocol) )
	print( "TCPIP Port Port           " + str(oApp.Settings.TCPIPPorts(i).PortNumber) )
	print( "TCPIP Port Enable         " + str(oApp.Settings.TCPIPPorts(i).UseSSL) )
	print( "TCPIP Port Certificate ID " + str(oApp.Settings.TCPIPPorts(i).SSLCertificateID) )

Code: Select all

[change the paths to your install path]
install latest python 3
get pywin32
  >pip install pywin32
start search 'environment variables', add PYTHONPATH and PYTHONHOME set both to 'D:\Program\Python3'
also edit PATH to remove duplicates (or other versions of python)
register as active script engine
  >python d:\Program\Python3>python Lib\site-packages\win32comext\axscript\client\pyscript.py
Note: I went ahead and found pyscript.py in explorer and ran it... 8)

Server testing to morrow after I modify hMailServer to run Python ... Maybe ... If it works :mrgreen:
SørenR.

Old data analysts don’t die – they just get broken down by age and sex.

Post Reply