I wrote a very simple cgi to change an IP address of a linux server.

First, user will get LOGIN.PL

LOGIN.PL will call EDIT_IP.PL

if user click 'Save', EDIT_IP.PL will call SAVE_CONFIG.PL

SAVE_CONFIG.PL will do these :
  - modifying ip address configuration (/etc/sysconfig/...)
  - calling external program (written in C) to restart network card (ifup/ifdown)
  - Displaying message "configuration saved"
  - REDIRECTING back to LOGIN.PL 

The situation is, all steps are working fine ... except the last 2 steps (displaying 
message and
redirecting). Sometimes it works, sometimes NOT ... I dont know why.

Here is the last code of SAVE_CONFIG.PL :

  if ($a ne $b) {
     Write_ifcfg ("eth0", $NewIPAddress);
     $ip_addr = $NewIPAddress;
  }

  Ok "Configuration saved.";

  system("/var/www/cgi-bin/changeip");


Can I "flush" cgi operation? 
Because after calling "changeip", the IP address of the web server will be changed ... 
and the
user browser "SOMETIMES" did not get the output of "Ok" function.


Here is the Ok function :

  sub Ok {
     my ($msg) = @_;
     print $cgi->start_html(-head=>meta({-http_equiv => 'Refresh',
                                         -content => '10; url=http://'.$ip_addr.'/'}));
     print "<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>";
     print "<TABLE border='0' width=500 align=center bgcolor=#C7D7F3>";
     print "<TR><TH align=center bgcolor=#1E4691><font color=#FFFFFF> &nbsp </font>";
     print "<TR><TH>&nbsp";
     print "<TR><TH align=center>$msg";
     print "<TR><TH>&nbsp";
     print $cgi->end_html;
  }


In the user browser, it will 'stuck' (in progress) ... but if you "view source", it 
will contain
the content of that Ok web page. Then we need to press browser STOP button, the 
message will be
displayed, and the rest is normal ... the redirection (Refresh) is executed.

I was wondering if I can 'flush' the cgi operation, so in SAVE_CONFIG.PL will be like 
this :

  if ($a ne $b) {
     Write_ifcfg ("eth0", $NewIPAddress);
     $ip_addr = $NewIPAddress;
  }

  Ok "Configuration saved.";

  flush_cgi_operation;   
  # so, cgi output is written in the user browser

  system("/var/www/cgi-bin/changeip");


I hope you understand what I meant :) I am not very good in english.

Regards,
me.

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to