Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

One text file is present:

system1,10.111.23.45,OFF,powered-off

system2,10.111.23.46,ON,used

system3,10.111.23.47,OFF,idle

One CGI file is written which reads the above text file and prints on the GUI. If for system1 OFF is present in text file on GUI one button should be shown as "POWER ON" for this system and if ON is present one button is shown as "POWER OFF".

Below is the cgi file:

#!/usr/bin/perl use strict; #use CGI qw/:standard/; #use CGI qw( :html *p); use CGI qw(:cgi-lib :standard); &ReadParse(*input); use CGI qw( :html *p); use CGI::Pretty; print header, start_html('Utilization'); my $cgi_obj = new CGI(); my $power_on = $cgi_obj->param('power_on'); my $power_off = $cgi_obj->param('power_off'); if($power_off){ Change::change_file("INFO", "$power_off", "POWER_STATUS", "OFF"); } if($power_on){ Change::change_file("INFO", "$power_on", "POWER_STATUS", "ON"); } my $h = "<h3><font color=\"#0B0B61\"><center><b>System Management Page +</b></center></font color> </h3>"; $h .= "<table border=\"1\">\n<tr>\n";</p> $h .= "<td WIDTH=50 bgcolor=\"#0101DF\"><font color=\"#FFFFFF\ +"><strong><center>Serial No.</center></strong></td>\n"; $h .= "<td WIDTH=200 bgcolor=\"#0101DF\"><font color=\"#FFFFFF +\"><strong><center>NAME</center></strong></td>\n"; $h .= "<td WIDTH=200 bgcolor=\"#0101DF\"><font color=\"#FFFFFF +\"><strong><center>IP</center></strong></td>\n"; $h .= "<td WIDTH=200 bgcolor=\"#0101DF\"><font color=\"#FFFFFF +\"><strong><center>State_ON_OFF</center></strong></td>\n"; $h .= "<td WIDTH=200 bgcolor=\"#0101DF\"><font color=\"#FFFFFF +\"><strong><center>Used state</center></strong></td>\n"; $h .= "</tr>"; <p>open(my $FH,"INFO") or die ("$!");</p> <p> my $ref={};</p> <p>my $i = 1;</p> <p> while(<$FH>){</p> <p>my ($NAME,$IP,$POWER_OFF_ON,$USED_STATE)=split(/,/);</p> $h .= "<tr>"; $h .= "<td WIDTH=50 bgcolor=\"#BCF5A9\"><center>$i.</center></ +td>"; $h .= "<td WIDTH=150 bgcolor=\"#BCF5A9\"><center>$NAME</center +></td>"; $h .= "<td WIDTH=150 bgcolor=\"#BCF5A9\"><center>$IP</center>< +/td>"; if ( $POWER_OFF_ON eq "OFF"){ $h .= "<form name=\"ON\" method=\"get\" action=\"tool. +cgi\"><br>"; $h .= "<td WIDTH=250 bgcolor=\"#BCF5A9\"><center>$POWE +R_OFF_ON<br>"; $h .= "<input type=\"hidden\" name=\"power_off\" value= +\"$NAME\">"; $h .= "<center><input type=\"submit\" value=\"SWITCH ON +\"></center</td>"; $h .= "</form>"; } else { $h .= "<form name=\"OFF\" method=\"get\" action=\"tool. +cgi\"><br>"; $h .= "<td WIDTH=250 bgcolor=\"#BCF5A9\"><center>$POWER +_OFF_ON<br>"; $h .= "<input type=\"hidden\" name=\"power_ +off\" value=\"$NAME\">"; $h .= "<center><input type=\"submit\" value=\"SWITCH OF +F\"></center</td>"; $h .= "</form>"; } $h .= "<td WIDTH=150 bgcolor=\"#BCF5A9\"><center>$USED_STATE</ +center></td>"; $h .= "</tr>"; $i++; } print "$h"; print $cgi_obj->end_html(); exit;

I want that if "POWER ON" button is pressed. It changes the INFO file and corresponding to that system it replaces OFF ny ON and the display the same cgi file with update data. Now as written in line 15 and line 18. one subroutine called change_file is called if "POWER ON" or "POWER OFF" buttons are pressed which changes the value as asked.

Subroutine from the Change.pl

my ($name, $selected_system, $value_to_change, $new_val) = @_; my $ref; my ($NAME,$IP,$POWER_OFF_ON,$USED_STATE); rename $name, "$name~" or die "Cannot rename: $!"; open FH1, "<$name~" or die "Cannot open: $!"; open FH2, ">$name" or die "Cannot create: $!"; while (<FH1>) { ($NAME,$IP,$POWER_OFF_ON,$USED_STATE)=split(/;/); $ref->{$NAME}{FILER_IP}=$FILER_IP; $ref->{$NAME}{FILER_RLM_IP}=$FILER_RLM_IP; $ref->{$NAME}{POWER_OFF_ON}=$POWER_OFF_ON; $ref->{$NAME}{OWNER}=$OWNER; $ref->{$NAME}{DETAILS}=$DETAILS; $ref->{$NAME}{RESERVED_BY}=$RESERVED_BY; print "$NAME",";","$ref->{$NAME}{FILER_IP}",";","$ref->{$NAM +E}{FILER_RLM_IP}",";","$ref->{$NAME}{POWER_OFF_ON}",";","$ref->{$NAME +}{OWNER}",";","$ref->{$FILER_NAME}{DETAILS}",";","$ref->{$FILER_NAME} +{RESERVED_BY}"; print "$NAME",";","$ref->{$NAME}{FILER_IP}",";","$ref->{$NAME +}{FILER_RLM_IP}",";","$ref->{$NAME}{POWER_OFF_ON}",";","$ref->{$NAME} +{OWNER}",";","$ref->{$FILER_NAME}{DETAILS}",";","$ref->{$FILER_NAME}{ +RESERVED_BY}"; if (!($NAME eq "$selected_system")){ print FH2 $_; } elsif ($value_to_change eq "POWER_STATUS"){ print FH2 "$NAME",",","$ref->{$NAME}{IP}",",","$new_val","," +,"$ref->{$NAME}{USED_STATE}","\n"; } }

In reply to Re^2: To call a .pl file when a button is pressed on a GUI created using Perl CGI by pratibha.blr
in thread To call a .pl file when a button is pressed on a GUI created using Perl CGI by pratibha.blr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (16)
    As of 2018-06-22 17:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?



      Results (124 votes). Check out past polls.

      Notices?