LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   html buttons to launch server-side scripts (https://www.linuxquestions.org/questions/linux-newbie-8/html-buttons-to-launch-server-side-scripts-4175545594/)

Talita 06-17-2015 03:41 AM

html buttons to launch server-side scripts
 
Hello forum members,
I'm trying to create an internal website as an interface to my (Ubuntu) server to run a number of scripts (server-side). I'm a newbie when it comes to creating websites, but what web language can I best use / study for accomplish my goal. I've already started with PHP but haven't found a way to launch server side shell / python scripts by clicking on a picture / button.

Thanks for your reply

Talita

zhjim 06-17-2015 04:05 AM

Check out the system function of php or the exec funtion.

Somethings you might run into are the permissions. Normaly a webserver is run under a specific user that might not have acces to all binaries or path you like. You might solve this with a sudo line or the apropiate su module of apache (cant recall exact name right now).

If you show us what you have got so far we are able to help you out much better.

Talita 06-17-2015 04:35 AM

Hello zhjim,

For now I've just got a basis HTML page, but I'm trying to gather the knowledge how to link the scripts (phyton) to the pictures.

Code:

<html>
        <head>
                <title>title</title>
                <link rel="stylesheet" href="BASIC.css" type="text/css">
                <style></style>
        </head>
        <body>
                <table align="center" border="0">
                                <td><br></td>
                                <td><img src="green_arrow_up.png"></td>
                                <td><br></td>
                        </tr>
                        <tr>
                                <td><img src="green_arrow_left.png"></td>
                                <td><img src="green_dot.png"></td>
                                <td><img src="green_arrow_right.png"></td>
                        </tr>
                        <tr>
                                <td><br></td>
                                <td><img src="green_arrow_down.png"></td>
                                <td><br></td>
                        </tr>
                </table>
        </body>
</html>

BASIC.css is still empty

zhjim 06-17-2015 05:41 AM

You could use the on_click function of javascript. Either call a function that handles the rest or just directly call another page

Quote:

<img onclick="window.open('http://www.w3.org', '_blank')">
Or put an a tag around the img tag that loads the right page.

Why not first try to run your scripts directly? Namely create a webpage that once opened runs the script you want to. This way you don't have to fight at two fronts. After that do the img click thing. And once both parts work individualy you tie them together.

Keith Hedger 06-17-2015 06:05 AM

1 Attachment(s)
Here's what I do to put a button under each pic in a table
Code:

<html>
        <div align="center"
                <head>
                        <title>Pyramids 3</title>
                </head>
                <body bgcolor=#ccb947>
                        <h1>Pyramids 3</h1>
        </div>
        <div align="center">
                <form action="/cgi-bin/uploadimage?folder=/Photos/Pictures/PhonePics/" method="post"
                        enctype="multipart/form-data">
                        <input type="file" name="file" id="file">
                        <input type="submit" name="submit" value="Upload File">
                </form>
        </div>
        <div <head="" align="center">
                <table cellspacing=2>
<tr valign=bottom>

                        <td>
                                <center>
                                <a href="picture037.jpg"><img src="tmb/picture037.jpg" alt="click to enlarge"></a>
                                <font size="-4"><form action="/cgi-bin/edit?name=/Photos/Pictures/PhonePics//picture037.jpg" method="post" style="padding: 0; margin: 0">
        <input type="submit" value="Edit">
</form></font>
                        <td>
                                <center>
                                <a href="picture038.jpg"><img src="tmb/picture038.jpg" alt="click to enlarge"></a>
                                <font size="-4"><form action="/cgi-bin/edit?name=/Photos/Pictures/PhonePics//picture038.jpg" method="post" style="padding: 0; margin: 0">
        <input type="submit" value="Edit">
</form></font>
                        <td>
                                <center>
                                <a href="picture039.jpg"><img src="tmb/picture039.jpg" alt="click to enlarge"></a>
                                <font size="-4"><form action="/cgi-bin/edit?name=/Photos/Pictures/PhonePics//picture039.jpg" method="post" style="padding: 0; margin: 0">
        <input type="submit" value="Edit">
</form></font>
...

and so on, this gives:
Attachment 18726

all the scripts are in "cgi-bin" in the root of the server and the config part of /etc/apache2/sites-available/default is
Code:

NameVirtualHost *:80
<VirtualHost *:80>
ServerName keithhedger.darktech.org

DocumentRoot /media/Homenet/Homenet
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /media/Homenet/Homenet/cgi-bin/
<Directory "/media/Homenet/Homenet/cgi-bin/">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order deny,allow
        deny from all
        Allow from 192.168.1.0/255.255.255.0
</Directory>

<Directory /media/Homenet/Homenet/user-scripts/>
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        AllowOverride None
        Order allow,deny
        allow from all
</Directory>

AddHandler cgi-script .sh

</VirtualHost>

Most of the scripts are in BASH
Hope that this gives you a start.
P.S.
The 'Allow from ... ' bit is so that the scripts are only executable form the LAN and not the internet, remove that bit if you want anyone to execute your scripts.

Talita 06-18-2015 01:00 PM

Hello Keith,

As far as I can understand your code your using a 'post' method.
So I will try to read up on that topic.
Any good suggestions to start from?

And thank-you al for your your replays!

Talita

Keith Hedger 06-18-2015 01:54 PM

Yes this is bash script for the 'uploadimage' button:
Code:

#!/bin/bash -e

#©keithhedger Mon 23 Sep 15:50:51 BST 2013 kdhedger68713@gmail.com

waitPage ()
{
        echo "Content-type: text/html"
        echo ""
        echo "<html><head>"
        echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=$HTTP_REFERER\">"
        echo "</head>"
        echo "<body>"
        echo "<b>$1</b>"
        echo "</body></html>"
        exec >&-
}

f=$(echo $QUERY_STRING|/usr/bin/awk -F '&' '{print $1}')
FOLDER="${f/folder=/}"
waitPage "Uploading file to ${FOLDER}..."

if [ "$REQUEST_METHOD" = "POST" ];then
        TMPOUT=/tmp/fwupdate
        cat >$TMPOUT
        n=$(awk "NR==2" $TMPOUT|awk -F "=" '{print $3}')
        NAME=${n//\"/}
        NAME=${NAME:0:${#NAME}-1}

        if [ X"$NAME" = "X" ];then
                rm "$TMPOUT" $TMPOUT.1||true
                exit 0
        fi
# Get the line count
        LINES=$(wc -l $TMPOUT | cut -d ' ' -f 1)

# Remove the first four lines
        tail -$((LINES - 4)) $TMPOUT >$TMPOUT.1

# Remove the last line
        head -$((LINES - 9)) $TMPOUT.1 >$TMPOUT.jpg
        truncate --size=-2 $TMPOUT.jpg
fi

mv $TMPOUT.jpg "/media/Media${FOLDER}/${NAME}"
/media/Media/WebSite/cgi-bin/autothumb -r "/media/Media" -n "/media/Media${FOLDER}"
rm "$TEMPOUT" $TMPOUT.1

exit 0

It should give you a start on how to do some stuff, it is complicated and takes time, permissions are important, start simple and build from there, good luck.


All times are GMT -5. The time now is 11:11 PM.