lighttpd - how to make html button trigger a script?

Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions
Author Message
MuzzleVelocity
DD-WRT User


Joined: 23 Apr 2010
Posts: 125

PostPosted: Sun Mar 10, 2019 14:43    Post subject: lighttpd - how to make html button trigger a script? Reply with quote
So i have lighttpd on my router hosting a very simple webpage. Whats the easiest/best way to have a button on the page that triggers a script execution on the router?

Right now I have a simple html button ( using form method="get" and button type="submit" ...etc.) with an action that loads a different html file. On that other html file I have an SSI command <!--#exec cmd="/opt/my_script.sh" --> that immediately runs my_script.sh. (I have lighttpd configured to load the mod_ssi module).

This is working perfectly fine. the only annoyance is that it needs to switch html files to execute the script.

Is there a simpler way to have a button directly execute a script?

Thanks for any insights! and yes I know SSI is a relic of the 1990's, but it seems to work fine for me Smile. Although if there is a better way to do it thats just as easy I am all ears
Sponsor
grable
DD-WRT Novice


Joined: 28 Aug 2022
Posts: 1

PostPosted: Sun Aug 28, 2022 15:04    Post subject: Re: lighttpd - how to make html button trigger a script? Reply with quote
MuzzleVelocity wrote:
Is there a simpler way to have a button directly execute a script?


Php is a very easy and lightweight way to do it.

assuming you have entware, use opkg to install the PHP module.

in your html file you would add something like this:
Code:

       <?php
      if(array_key_exists('button1', $_POST)) {
            button1();
        }
        function button1() {
        shell_exec("/opt/your_script.sh");
      }
       ?>



search google for "php shell_exec examples"
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum