Page 1 of 1

A stack on the web which accepts parameters

Posted: Sun Jun 21, 2020 7:56 pm
by AlbertAA
I have another beginner question, related to using LC to create stacks which run on the web (which I have never done until now).

I checked out the LiveCode Lesson on creating a standalone stacks which can be accessed from the Web, but also realized that in order to be able to try it I need to acquire an additional license (on top of my Indy 9 6). Therefore, before proceeding I would like to have your assessment of how difficult it is to create a stack with the following features:

I should be able to call the stack (eg from a browser) with a URL similar to:

"https://www. mydomainname .com /myLCStacks/myFirstStack myParam1 myParam2"

where myFirstStack would be the name of the stack, and myParam1 and myParam2 would be 2 parameters (both strings). Can I do this - a stack to which I can pass parameters?

What the stack would do is:
1. Create a file with name myParam1 containing only the string passed in myParam2 (this I can do)
2. Put the file on my ftp server (this I can do too)

Thank you for your advice and any hints on where I can find further guidance or examples

Re: A stack on the web which accepts parameters

Posted: Sun Jun 21, 2020 10:27 pm
by ClipArtGuy
This sounds like a job for livecode server.

Now, if you wanted an actual stack running in a browser window, you'd probably use the HTML5 deployment, which you can check out for free in the community edition.

Re: A stack on the web which accepts parameters

Posted: Mon Jun 22, 2020 7:28 am
by AlbertAA
You are perfectly right. I was just hoping not to have to dive into server issues, but this is effectively a task that should be done from there (no UI needed). I will go through your links and hope to find out there if what I need to do can be done easily with a LC server.

Still interested in finding out if a stack can be called via a URL with parameters passing, and will install the Community edition to try out the HTML5 part, which I hope has evolved well in the meantime (I still remember the first announcements, many many many years ago ..., but porting the whole environment on the Web is obviously not a trivial issue).

Re: A stack on the web which accepts parameters

Posted: Mon Jun 22, 2020 11:32 am
by SparkOut
If no UI is required and your task is really just to take two parameters and "handle" them, then I would not even look at the HTML5 option for this.
The GUI takes a good while to load, and there are many limitations in implementation for things that you would find an irrelevance and not appropriate to your scenario. By all means, investigate LiveCode HTML5 for curiosity and other reasons!
You might find that (as often advocated by Richard) a client-side stack that launches a stack delivered from your server url with a "go stack..." command can do what you want. It sounds very much like LiveCode Server is the right tool for this job though.

Re: A stack on the web which accepts parameters

Posted: Tue Jun 30, 2020 3:09 am
by AlbertAA
Following your advice I adventured into setting up an Apache server and learning to work with the LC Server. It is definitely a good solution to be able to do exactly what I wanted originally : To call what is now a LC script (rather than a stack) the way I needed - from a URL with parameters.
Everything run smoothly except for the FTP part of my script, for which I still cannot find a solution.

In my original stack I was using the libURLftpUploadFile command and ftp was running well. But in my server script I started getting errors:

1. First it required me to include the "Internet" library. After some searching I solved this by adding the statement (start using "rev lib Urrl . livecodescript") and adding the file "rev lib Urrl . livecodescript". NOTE that I added spaces and an additional r otherwise I cannot post)

2. Then I started getting an error related to Callbacks, so I removed it, and my script is now:
libURLftpUploadFile zipCreatedFull, tDestination.
Still, the script stops where it usually does the ftp upload, and the error message mentions again callbacks (which I do not use anymore) and I do not know how to proceed because the error seems to be in the library. Here it is:

stack "C:/ *** /htdocs/LCServer/rev lib urrl .livecodescript"
row 622, col 1: hostnameToAddress: callbacks are not allowed on server
row 622, col 1: get: error in expression
row 622, col 1: if-then: error in statement
row 614, col 1: Handler: error in statement (ulGetFormat)
row 3435, col 1: Handler: can't find handler (ulGetFormat)
row 3435, col 1: switch: error in statement
row 3415, col 1: Handler: error in statement (libUrlFtpUploadFile)
file "C:/ *** /htdocs/LCServer/APELauncher2 .lc"
row 145, col 1: Handler: can't find handler (libURLftpUploadFile)
row 145, col 1: if-then: error in statement
row 145, col 1: if-then: error in statement
row 145, col 1: if-then: error in statement

Does it mean that the LC Server does not allow to use ftp, or perhaps in a different way, or am I doing something wrong? Can you help me interpreting this error message?

I have also looked into alternatives, and given that I am operating from Windows there is the possibility to upload my zip file to my ftp address using get shell(Command) - with the Command being ("powershell .exe ...") . This works well with single-line commands, but the ftp command is a bit more complex (than xcopy or so) and requires itself a script. So, in case I go down this way I will still need to find and adapt a script, and test if it works. Do you recommend this alternative approach? Do you have examples of using powershell with scripts from the LC Server?


Re: A stack on the web which accepts parameters

Posted: Tue Jun 30, 2020 4:53 am
by ghettocottage
Is your ftp server and your web server (runing livecode server) the same creature? If so, it might be unnecessary to use ftp, instead just creating the file in the location on the server where you want it.

If they are two different servers, an approach could be to write a bash script and run the bash script from the livecode script like so:

Code: Select all

put shell("./path/to/bash/script "&tFile ) into tScript
and your bash script could be something like:

Code: Select all


quote USER $USER
put $FILE
exit 0
If nothing else, your bash script will help you to troubleshoot if your server can upload via FTP

Re: A stack on the web which accepts parameters + ftp upload from LC script on LC Server

Posted: Tue Jun 30, 2020 9:29 pm
by AlbertAA
The LC Server and the FTP server are on different machines, unfortunately (as I did not succeed in installing Apache and LC Server correctly on the sme machine, which runs ISS).

Your script was inspiring. Thank you. After trying for some time to adapt it to go through shell commands, I decided to switch to call powershell, and now have a simple but well-functioning script in a bat file which i can call using shell and powersh*ell*.exe (the * are added for posting reasons). Would love to share it, but I would have to add * or similar characters to every second word to be able to post it (although it actually doesn't contain anything "dangerous" :-(

I also succeeded in changing the target directory on the ftp server, and the last point which bothers me a bit is that the username and password are "exposed" in the bat file. Curious people might therefore find them out pretty easily. Is there a good solution for that too?

Thank you again for the support and hints. That's really a great forum!

Re: A stack on the web which accepts parameters

Posted: Tue Jun 30, 2020 9:55 pm
by SparkOut
Where are you storing the batch file? If it is below the document root, then it's probably as secure as it's going to be - otherwise you already have a security breach.
You could additionally save the credentials (even salted and encrypted) in a text file outside the doc root. You can then read that in as part of the script that calls the batch file, and passes those credentials as parameters.
This also has the advantage of being able to change the saved credentials easily at need.