What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Solved Shell scripts from WebUI

Rename the file to end with .js. Refer to it as /ext/results.js

Or you can use .htm.
 
Last edited:
Rename the file to end with .js. Refer to it as /ext/results.js

Or you can use .htm.
That fixed it but led me to my next hurdle.

When I try to include showloading() and document.form.submit, to allow for the script to run / complete when the service-event is triggered, the returned results.js isn't displayed in the textarea. But if I remove show loading() and document.form.submit the results do show. Note - I'm not actually running the triggered service at this point, I have a results.js populated with the output of one my script already.

Below is the onclick function that gets called when the Run button is hit.
- What do I need to do to get the results to display after a delay period?
- I the showloading() + document.form.submit() combination the proper way to allow for a delay?
- Any suggestions or pointers much appreciated


Code:
function runScript(){
        /* Retrieve value from input fields, and store in object */
        custom_settings.scriptsui_script = "/jffs/addons/scriptsui/mysript.sh";

        /* Store object as a string in the amng_custom hidden input field */
        document.getElementById('amng_custom').value = JSON.stringify(custom_settings);

        /* Apply */
        showLoading()
        document.form.submit();
        get_results_data();

}
 
Any suggestions or pointers much appreciated
There are a few examples of "submitting" a request to trigger the service-event without getting into the whole "Please wait..." overlay.

See if you can make sense of the cake_status_check hidden form and submit_refresh_status() function in CakeQoS-Merlin.

You essentially pass the action for service-event to run via the action_script ASP variable and then trigger the ajax check with a suitable timeout based on how long you think it will take for the response to be ready in /www/ext/.

The main page doesn't get blocked or refreshed until the result is available. If you need to use the custom_settings to transfer your script name, I don't recall if you need to submit the main form in order for httpd to process that variable or not.

Otherwise, when your page refreshes after submit, you need something in the initial() function to load that file under /ext/ into your text field. Maybe you should post the full code somewhere for review. Or study how the System Log page loads the initial syslog files and then refreshes every 3 seconds. It uses special commands for fetching the syslog data, but the initial load through ajax calls is still there.
 
There are a few examples of "submitting" a request to trigger the service-event without getting into the whole "Please wait..." overlay.

See if you can make sense of the cake_status_check hidden form and submit_refresh_status() function in CakeQoS-Merlin.

You essentially pass the action for service-event to run via the action_script ASP variable and then trigger the ajax check with a suitable timeout based on how long you think it will take for the response to be ready in /www/ext/.

The main page doesn't get blocked or refreshed until the result is available. If you need to use the custom_settings to transfer your script name, I don't recall if you need to submit the main form in order for httpd to process that variable or not.

Otherwise, when your page refreshes after submit, you need something in the initial() function to load that file under /ext/ into your text field. Maybe you should post the full code somewhere for review. Or study how the System Log page loads the initial syslog files and then refreshes every 3 seconds. It uses special commands for fetching the syslog data, but the initial load through ajax calls is still there.
Thank you @dave14305 for all the pointers, feedback, and references. I finally have a working prototype based on the Third Party API.

As time permits and if there’s interest, I’ll provide a write of the prototype.
 
I like the idea of a script launching directory, similar to like /init.d . any script we have written in the SSH terminal and add a launcher in this directory can be enabled/disabled as a service to launch at service-start, or can be an individual file we trigger from the webui. Or even better, there can be individual hooks that can be setup to ensure the script launches on a specific event as long as the script is enabled during a particular service or event call.
 
@dave14305, @thelonelycoder, @SomeWhereOverTheRainBow or anyone

Following the Third Party Addon API example, particularly the Web Usage section, how do you update the Textarea of a form AFTER "document.form.submit()" completes?

My goal is to be able to update the textarea of the form with the results of the script (script writes to text file) that gets run after the custom_settings.txt file is updated and the associated launcher runs a given script that was selected in the form (I have a button with an onclick runscpript). My javascript for reading the script results file works and populates the text area successfully if I DON'T execute the document.form.submit().

If I understand the form submit correctly, it will destroy the current page. So I'm trying to figure out how to delay (I tried setTimeout) the call to me update results function with no luck.

Below is screenshot of the Custom Page and attached is the associated asp
1744465818038.png
 

Attachments

I would submit a different form than the main form so it doesn’t need to reload the whole page. If you are loading your script list via js, presumably you have some way to identify them uniquely.

So the action_script on this additional form could be start_scriptsuiname1 and you can have a service-event script check look for that event, and pass name1 to your script to run it:
Code:
if echo "$2" | /bin/grep -q "^scriptsui"; then
   sh /jffs/addons/scriptsui/scriptsui.sh "${2#scriptsui}" &
fi
Another example is the ver_check form in FlexQoS. It submits and fetches results without reloading the page.
 
Last edited:
I would submit a different form than the main form so it doesn’t need to reload the whole page. If you are loading your script list via js, presumably you have some way to identify them uniquely.

So the action_script on this additional form could be start_scriptsuiname1 and you can have a service-event script check look for that event, and pass name1 to your script to run it:
Code:
if echo "$2" | /bin/grep -q "^scriptsui"; then
   sh /jffs/addons/scriptsui/scriptsui.sh "${2#scriptsui}" &
fi
Another example is the ver_check form in FlexQoS. It submits and fetches results without reloading the page.
Thank you @dave14305, I now have a working solution based on all your input and direction - this is solved!!!

@dave14305, with your permission, I may attempt to create a script for maintaining “scriptsui”, borrowing much of what I see / learned from your FlexQoS script. Would that be OK?
 
Last edited:

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top