LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to run a server-side Javascript in Apache (https://www.linuxquestions.org/questions/programming-9/how-to-run-a-server-side-javascript-in-apache-204641/)

Linh 07-13-2004 04:53 PM

How to run a server-side Javascript in Apache
 
I am running an Apache web server under Linux.
The Java script below suppose to write a file
named servertype.conf to a web server under
the directory /var/apache/.

The Java script responded properly but it did not create a file.
This Java script is embedded within a Python script, and the
Pyhton script does run.
There is an error. Error 'File is undefined'

The code var mysummary = new File("/var/apache/servertype.conf")
is a server-side script.
How do I get this server-side script to work in Apache ?
This code is also shown on line number 10 below.

===========================

Alternatively, I could use a Server Side Include (SSI) feature to
write to a file in a web server with the statement as showned
on line number 9 below.

The code AddHandler server-parsed .conf
would then be added to the file /etc/httpd/conf/httpd.conf

So far I could not get either of the two methods to work.
I am running Apache version 1.3.26
===========================
Code:

1) <SCRIPT LANGUAGE="Javascript">
2) <!--

//Javascript added by Linh on 7-13-2004 for switching between
//master iserver and secondary iserver

3) function select_button (form)
4)  {
5)  if (form.defms[1].checked)
6)    if (confirm ("You are changing from a master iserver
                            to a secondary iserver. Is this what you want ?
                            To complete this process, you must
                            1) Enter Iserver IP address.
                            2) Enter the Iserver Registration Password.
                            3) and finally click the button
                                'Apply Changes to System'") )
7)      {
8)        alert ("Clicked Yes");

9)        <!--#exec echo "ServerType=Secondary" > /var/apache/servertype.conf -->

10)    var mysummary = new File("/var/apache/servertype.conf");
        mysummary.open("w");
        mysummary.write('ServerType=Secondary');
        mysummary.flush();
        mysummary.close();

      }
    else
      {
        form.defms[1].checked = false
        form.defms[0].checked = true
        alert ("Clicked No");
      }
 }
//-->
</SCRIPT>

 <input type=radio name="defms" value="ms" onClick="select_button (this.form)" %s></td>
<input type=radio name="defms" value="ss" onClick="select_button (this.form)" %s></td>


Proud 07-14-2004 03:30 PM

Ok, I'm not 100% sure of how you're using Javascript, but if you want the user to see that confirm dialog, it must be being run client side in a browser. Consequentally that code you've pasted must be in the html sent to the browser, and the SSI code will have already been parsed by the server before sending the html to the user.

I think your problem is that the JS in this case is executed client side, after the page html is generated and sent. Maybe you need to be passing the dialog result to another page, and/or using a server side language like php to process the form's result (maybe just perl/a cgi script). I've never had to code a site with dynamic pages such as these, so I could be completely wrong, but this is just my suggestion. :)

Linh 07-15-2004 09:36 AM

reply
 
Thank you Proud for your help.


All times are GMT -5. The time now is 12:14 AM.