Help is needed with Set Widget Value action

This works only if you set apart different site each window. It will not work if you define the same site in two separate windows

I have 2 Custom Entity Screens. Each has a single HTML Widget on it. Both screens/widgets take me to the same site but with different URL parameters.

http://localhost/?screen=REQUEST
http://localhost/?screen=ORDER

I have 2 automation commands on my Ticket screen: 1 for each Entity Screen

EDIT: you are correct though
 they are not in their own session - if I change a session variable on 1 screen, it follows to the other screen. Not sure I like that behavior, though I realize sessions are stored server-side.

P.S. I looked at Roboform - it is indeed a browser addon/extension so it can perform emulation like keystrokes.

1 Like

@QMcKay,
The only solution I can think of would be to implement application viewer widget
If it were possible it could provide a solution to many issues like this.
For example display time clock software, email software, Google Chrome,etc

@emre,
It probably sounds weird And sorry if this sounds stupid,but I do not know if something like this could ever be possible :blush:

I wouldn’t be surprised if @emre could add an option to have the HTML Viewer Widgets in their own sessions, but even by default, I now realize that something like Firefox is using the same session across multiple tabs if they are the same site. Though maybe that’s my PHP settings or my code making it behave that way.

EDIT: nope, it’s Firefox doing it
 it shares sessions across tabs - lots of talk about it on the 'net.
EDIT2: apparently, they all handle it this way: IE, Chrome, Safari, etc. There are ways around it though, with options or switches etc.
EDIT3: provisions can also be made server-side; though in most cases I assume this rarely happens

I do not have Firefox installed and IE also sharing sessions between tabs.

So your saying you want the ability for Samba to open other applications and display them through a screen in Samba? Adding that ability would open up a lot of other potential issues. Someone could unknowingly compromise the security of their system if they used this and did not understand the risk.

There are other ways to go about what your wanting. Most of them would involve you contacting your webmaster and working out a solution to fit their security model and your needs. Maybe they can give you another way to access your content that can be accessed via an API kind of like how I can make Command Buttons perform functions in TimeTrex.

The bottom line is
 unless your hosting it locally on your own server or have shared server access where you can allow such a thing you are going to find it VERY VERY hard to convince them to allow this kind of log in. It is too large of a security risk.

PS there is something you can do now that would make it work. It is not easy and might require some crafty and somewhat crazy chaining of batch files
 but you can use autohotkey and program a script to basically type it in and press enter for you
 but even that has risks.

What is autohotkey And how to use it? :blush:

http://www.autohotkey.com/ Its a macro script automation scripting language for windows. It can be used to emulate keyboard presses.

dear @kendash,
According to your explanation it seems a possible solution but I do not know how to use it.
With this tool I can for example write a script to come in to the site and fill Username and Password?
If yes then how?

Something like this should work?

<HTML>
<HEAD>
<TITLE>mishloha Login</TITLE>
<script>
    function loginForm() {
        document.myform.action = "http://reports.mishloha.co.il/";
        document.myform.submit();
    }
</script>
</HEAD>
<BODY onLoad="loginForm()">
    <FORM NAME="myform" METHOD="POST">
        <INPUT TYPE="hidden" NAME="rest_id" VALUE="3940"> 
        <INPUT TYPE="hidden" NAME="password" VALUE="111111">
    </FORM>
</BODY>
</HTML>

No, that won’t work.

Looking through AHK, you should be able to accomplish autologin, but you need to become familiar with the AHK syntax, and since the Widget is embedded in SambaPOS, you will likely need a BAT or something else to go along with it. The BAT could fire the AHK file, or if there is a file association, you might be able to run the AHK using Start Process directly, immediately after your Widget loads.

They talk about using COM within the IE DOM. There’s more to it, but assuming you call your object wb (meaning WebBrowser) as is shown in their Tutorials, you would write a script that does:

wb.Document.All.username.Value := "username"
or 
wb.Document.All.rest_id.Value := "userid"
then
wb.Document.All.password.Value := "password"
then
b.Document.All.login-button.Click()

You’ll want to read this:
http://www.autohotkey.com/board/topic/64563-basic-ahk-v11-com-tutorial-for-webpages/

EDIT: now that I think about it, I’m not even sure that will work, since the form isn’t visible in the source of the page. Instead it’s pulled from a .js file. Still worth a try, since the elements should be present even if not visible in source.

I think the first hurdle is getting the handle to the Widget, which is based on IE. Since the Widget is embedded in SambaPOS, I don’t know if you’ll be able to access it at all.

This creates a an IE Window:

wb := ComObjCreate("InternetExplorer.Application") ; create object wb
wb.Visible := True ; make it visible
wb.Navigate("http://www.google.com") ; go to the website - CHANGE THIS

This identifies an IE Window that is already open (try this one first). Note that you will need the IEGet function for this method - it is the last function in the last code block:

wb := IEGet("Google") ;Tab/window name - CHANGE THIS

This identifies an open IE window in a different way (try this one if above doesn’t work):

For wb in ComObjCreate("Shell.Application").Windows ; for each open window
If InStr(wb.FullName, "iexplore.exe") ; check if it's an ie window
break ; keep that window's handle
; this assumes an ie window is available. it won't work if not

You should use one of the above to grab the window (Widget). You would pre-pend the correct method above with the following:

IELoad(wb) ; function that waits for page to load
wb.Document.All.username.Value := "username" ; CHANGE THIS 
; or use rest_id instead
wb.Document.All.rest_id.Value := "yourID" ; CHANGE THIS 
wb.Document.All.password.Value := "password" ; CHANGE THIS
; I believe this is the name of the Submit button on your webpage
wb.Document.All.login-button.Click()


; support functions - used by above

IELoad(wb)    ;You need to send the IE handle to the function unless you define it as global.
{
    If !wb    ;If wb is not a valid pointer then quit
        Return False
    Loop    ;Otherwise sleep for .1 seconds untill the page starts loading
        Sleep,100
    Until (wb.busy)
    Loop    ;Once it starts loading wait until completes
        Sleep,100
    Until (!wb.busy)
    Loop    ;optional check to wait for the page to completely load
        Sleep,100
    Until (wb.Document.Readystate = "Complete")
Return True
}


IEGet(Name="")        ;Retrieve pointer to existing IE window/tab
{
    IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
        Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
        : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
    For wb in ComObjCreate( "Shell.Application" ).Windows
        If ( wb.LocationName = Name ) && InStr( wb.FullName, "iexplore.exe" )
            Return wb
} ;written by Jethrow

I would first try to simply run the AHK script while the Widget is loaded to see if it works at all. If you have success with that you could throw an Automation Command on the screen and create a Rule to have it execute a Start Process action which calls the AHK script. Or have the Start Process action execute as the final action in the Rule that opens the Entity Screen.

1 Like

@QMcKay has mentioned several things to try. AHK is simple yet complex. It can emulate almost anything but its not always straight forward how to set it up. I am pretty sure you would need some batch files to get it moving though. You can execute .bat from Start Process action as well.

EDIT: Woop sorry @QMcKay I did not realize you had already mentioned using the .bat files.

@QMcKay,
Can you help me prepare the files and post them so that I can try, I really do not know what I should do with it, it’s a bit unfair that you invest so much time in it and I can not understand at all how to deal with it.
By the way,
I thought that If we had the option to choose the Browser on the html viewer widget settings We could set each html viewer to a different browser Then They will not have the same session
I can set one window in IE and use another window in chrome for example.

You can simply just manually run the AHK script and if it works then we can work on creating some .bat files and call it all with Start Process action. Simply copy the script you want to run and paste it into a txt file save it as name.ahk

You simply double click the.ahk file you made to execute it.

I can not figure out what to do. You can Please make me a script file to the site will run even without a user name and Password are correct. I can update later if it works.

I tested it and it looks like it will not work. It is looking specifically for a window title. There will be no window title for IE since it is running it through samba as a HTML viewer. You can maybe try a few other things, but it looks like your best bet would be contact your webmaster and discuss possibility of an API that you can interact with and use Samba to start a .bat file that would use that API. Or maybe they can help you with a solution that would work.

For example: TimeTrex has an API that I get Samba to interact with using .bat files and PHP scripts. Start Process action fires my .bat files which starts the php scripts etc. I can tell it to log a specific user in, perform specific tasks and log that user out with just php and the API. This may or may not be supported by your webmaster you could certainly find out though.

1 Like

@Jesse is correct. It won’t be that simple, but using COM it should still be possible. We need to the get the Form Objects inside the IE Object, inside the SambaPOS Object. I am not well-versed enough to fully understand how this is done. @emre can probably help in this regard. This is a screen shot while hovering over the HTML Widget embedded in an Entity Screen


Using information somewhere here we should be able to get the Handle to Internet Explorer_Server1 and the rest should theoretically work. I just can’t figure out the syntax yet


http://ahkscript.org/docs/commands/WinGet.htm

1 Like

I ran this script


; Example #2: This will visit all windows on the entire system and display info about each of them:
WinGet, id, list,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
    WinActivate, ahk_id %this_id%
    WinGetClass, this_class, ahk_id %this_id%
    WinGetTitle, this_title, ahk_id %this_id%
    MsgBox, 4, , Visiting All Windows`n%a_index% of %id%`nahk_id %this_id%`nahk_class %this_class%`n%this_title%`n`nContinue?
    IfMsgBox, NO, break
}

and got this


1 Like

So it looks like it should be possible. I wonder how you would tell it to find the _Hidden window. surely just adding _Hidden wouldn’t work
would it?