addons:hobbitnotes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revisionBoth sides next revision
addons:hobbitnotes [2017/12/05 05:51] – [notes header for 4.3] wikiadminaddons:hobbitnotes [2017/12/05 05:53] – [notes_footer for 4.3] wikiadmin
Line 178: Line 178:
 <hidden onHidden="Show Code ⇲" onVisible="Hide Code ⇱"> <hidden onHidden="Show Code ⇲" onVisible="Hide Code ⇱">
 <code html> <code html>
-<BR><BR>+  <BR><BR>
  
-<TABLE SUMMARY="Bottomline" WIDTH="100%"> +  <TABLE SUMMARY="Bottomline" WIDTH="100%"> 
-<TR> +    <TR> 
-  <TD> <HR WIDTH="100%"> </TD> +      <TD> <HR WIDTH="100%"> </TD> 
-</TR> +    </TR> 
-<TR> +    <TR> 
-        <TD ALIGN=RIGHT><FONT FACE="Arial, Helvetica" SIZE="-2" COLOR="silver"><B><A HREF="http://xymon.sourceforge.net/" style="text-decoration: none">Xymon &XYMONDREL</A></B></FONT></TD> +      <TD ALIGN=RIGHT><FONT FACE="Arial, Helvetica" SIZE="-2" COLOR="silver"><B><A HREF="http://xymon.sourceforge.net/" style="text-decoration: none">Xymon &XYMONDREL</A></B></FONT></TD> 
-</TR> +    </TR> 
-</TABLE>+  </TABLE>
  
 </BODY> </BODY>
Line 469: Line 469:
 use CGI ":standard"; use CGI ":standard";
 use HTML::FromText; use HTML::FromText;
- 
  
 # Your $XYMONHOME # Your $XYMONHOME
Line 475: Line 474:
 my $xymon_cmd = "$xymon_home/bin/xymon"; my $xymon_cmd = "$xymon_home/bin/xymon";
 # xymon config file # xymon config file
-my $xymoncfg="$xymon_home/etc/xymonserver.cfg"; +my $xymoncfg = "$xymon_home/etc/xymonserver.cfg";
-# The web path to gifs. +
-#my $xymon_web  = "/xymon/"; +
-# xymon_gifs appears to be unused +
-#my $xymon_gifs = "$xymon_home/www/gifs/"; # The main web path for xymon display.+
  
 # The actual www notes dir on the server # The actual www notes dir on the server
Line 487: Line 482:
 my $xymon_header = "$xymon_home/web/notes_header"; # Change this if needed. my $xymon_header = "$xymon_home/web/notes_header"; # Change this if needed.
 my $xymon_footer = "$xymon_home/web/notes_footer"; # Change this if needed. my $xymon_footer = "$xymon_home/web/notes_footer"; # Change this if needed.
 +
 #Standard hosts.cfg file #Standard hosts.cfg file
 my $xymon_hosts = "$xymon_home/hosts.cfg"; my $xymon_hosts = "$xymon_home/hosts.cfg";
-my $xymon_showhosts = "$xymon_home/bin/xymoncfg";+my $xymon_menu = "$xymon_home/etc/xymonmenu.cfg";
  
 # No changes needed below. # No changes needed below.
Line 504: Line 500:
 # Set up the environment variables and dynamic variables from xymonserver.cfg # Set up the environment variables and dynamic variables from xymonserver.cfg
 foreach (`$xymon_home/bin/xymoncmd env | /usr/bin/grep XYMON`) { foreach (`$xymon_home/bin/xymoncmd env | /usr/bin/grep XYMON`) {
-    chomp; +  chomp; 
-    next if $_ =~ /^directory/; +  next if $_ =~ /^directory/; 
-    my ($var,$val) = /^\s*(.*?)\s*=\s*(.*)/; +  my ($var,$val) = /^\s*(.*?)\s*=\s*(.*)/; 
-    $ENV{$var}  = $val;+  $ENV{$var} = $val;
 } }
- 
-# not used 
-#$ENV{'XYMONBODYHEADER'}='file:/home/xymon/server/etc/xymonmenu.cfg'; 
  
 sub print_notesdata { sub print_notesdata {
-    open (NOTESDATA, "<$xymon_notesdata/${host}") or &print_error("I can't read from $xymon_notesdata/$host!"); +  open (NOTESDATA, "<$xymon_notesdata/${host}") or &print_error("I can't read from $xymon_notesdata/$host!"); 
-    while (<NOTESDATA>) { +  while (<NOTESDATA>) { 
-        print; +    print; 
-    +  
-    close NOTESDATA;+  close NOTESDATA;
 } }
  
 sub write_notesdata { sub write_notesdata {
-    open (NOTESDATA, ">$xymon_notesdata/$host") or &print_error("I can't write to $xymon_notesdata/$host!"); +  open (NOTESDATA, ">$xymon_notesdata/$host") or &print_error("I can't write to $xymon_notesdata/$host!"); 
-    print NOTESDATA $note; +  print NOTESDATA $note; 
-    close NOTESDATA;+  close NOTESDATA;
 } }
  
 sub make_note { sub make_note {
-    my ($color) = @_; +  my ($color) = @_; 
-    my $note = "$xymon_notes/${host}.html";+  my $note = "$xymon_notes/${host}.html";
  
-    open (NOTE, ">$note") or &print_error("I can't open $note for writing!"); +  open (NOTE, ">$note") or &print_error("I can't open $note for writing!"); 
-    select NOTE; +  select NOTE; 
-    &print_header($color); +  &print_header($color); 
-    &print_notesdata; +  &print_notesdata; 
-    &print_footer($color); +  &print_footer($color); 
-    select STDOUT; +  select STDOUT; 
-    close NOTE;+  close NOTE;
 } }
  
 sub save_note { sub save_note {
-    &write_notesdata; +  &write_notesdata; 
-    &make_note('blue'); +  &make_note('blue'); 
-    &get_note; +  &get_note; 
-    print '<center><b><font color="white">Note saved.</font></b></center><p>'; +  print '<center><b><font color="white">Note saved.</font></b></center><p>'; 
-    &print_note;+  &print_note;
 } }
  
 sub edit_note { sub edit_note {
-    if ($cmd =~ /add html/) { +  if ($cmd =~ /add html/) { 
-        my $t2h = HTML::FromText->new({ +    my $t2h = HTML::FromText->new({ 
-                  blockcode  => 1, +              blockcode  => 1, 
-                  lines      => 1, +              lines      => 1, 
-                  tables     => 1, +              tables     => 1, 
-                  bullets    => 1, +              bullets    => 1, 
-                  numbers    => 1, +              numbers    => 1, 
-                  urls       => 1, +              urls       => 1, 
-                  email      => 1, +              email      => 1, 
-                  bold       => 1, +              bold       => 1, 
-                  underline  => 1, +              underline  => 1, 
-                  }); +              }); 
-        $note = $t2h->parse( $note ); +    $note = $t2h->parse( $note ); 
-        #$note =~ s/\n/<br>/sgi;+    #$note =~ s/\n/<br>/sgi;
-    }+  }
  
-    if ($cmd =~ /strip html/) { +  if ($cmd =~ /strip html/) { 
-        $note =~ s/<.*?>//sgi; +    $note =~ s/<.*?>//sgi; 
-    }+  }
  
-    print <<HTML;+  print <<HTML;
 <CENTER> <CENTER>
   <TABLE BORDER="1" CELLPADDING="3">   <TABLE BORDER="1" CELLPADDING="3">
Line 581: Line 574:
           <TEXTAREA ROWS="35" COLS="80" NAME="note" STYLE="background-color:#000033;color:dddddd">           <TEXTAREA ROWS="35" COLS="80" NAME="note" STYLE="background-color:#000033;color:dddddd">
 HTML HTML
-    if ($note) { +  if ($note) { 
-        print $note; +    print $note; 
-    } elsif ($lines[0]) { +  } elsif ($lines[0]) { 
-        print @lines; +    print @lines; 
-    } else { +  } else { 
-        print '<!-- Remember to use proper HTML formatting here. -->';+    print '<!-- Remember to use proper HTML formatting here. -->';
-        print <<HTML;+    print <<HTML;
           </TEXTAREA><br>           </TEXTAREA><br>
           <input name="cmd" value="preview" type="submit"> <input name="cmd" value="add html tags" type="submit"> <input name="cmd" value="strip html tags" type="submit"> <input name="cmd" value="cancel" type="submit">           <input name="cmd" value="preview" type="submit"> <input name="cmd" value="add html tags" type="submit"> <input name="cmd" value="strip html tags" type="submit"> <input name="cmd" value="cancel" type="submit">
Line 599: Line 592:
  
 sub print_note { sub print_note {
 +  print <<HTML;
 +<CENTER>
 +  <TABLE WIDTH="75%" BORDER="1" CELLPADDING="3">
 +    <CAPTION>
 +      <CENTER><H2>$host [$hosts{$host}]</H2></CENTER>
 +    </CAPTION>
 +    <TR>
 +      <TD>
 +HTML
 +  if ($lines[0]) {
 +    print @lines;
     print <<HTML;     print <<HTML;
-<CENTER><TABLE WIDTH="75%BORDER="1CELLPADDING="3"><CAPTION><CENTER><H2>$host [$hosts{$host}]</H2></CENTER></CAPTION><TR><TD>+      </TD> 
 +    </TR> 
 +    <TR> 
 +      <TD ALIGN="CENTER"> 
 +        <form method="POST"
 +          <input type="hiddenname="host" value="$host">
 HTML HTML
-    if ($lines[0]) { +  } elsif ($cmd =~ /preview/) { 
-        print @lines; +    print <<HTML; 
-        print <<HTML; +        $note 
-</TD></TR><TR><TD ALIGN="CENTER"><form method="POST"><input type="hidden" name="host" value="$host">+      </TD> 
 +    </TR> 
 +    <TR> 
 +      <TD ALIGN="CENTER"> 
 +        <form method="POST"> 
 +          <input type="hidden" name="host" value="$host"> <input name="cmd" value="save" type="submit">
 HTML HTML
-    elsif ($cmd =~ /preview/+  else 
-        print <<HTML; +    print <<HTML; 
-$note</TD></TR><TR><TD ALIGN="CENTER"><form method="POST"><input type="hidden" name="host" value="$host"> <input name="cmd" value="save" type="submit">+      The are no notes for $host [$hosts{$host}]. 
 +    </TD> 
 +  </TR> 
 +  <TR> 
 +    <TD ALIGN="CENTER"> 
 +      <form method="POST"> 
 +        <input type="hidden" name="host" value="$host">
 HTML HTML
-    else { +  
-        print <<HTML; +    print <<HTML; 
-The are no notes for $host [$hosts{$host}].</TD></TR> <TR><TD ALIGN="CENTER"><form method="POST"><input type="hidden" name="host" value="$host"> +          <input type="hidden" name="note" value='$note'> <input name="cmd" value="edit" type="submit"> <input name="cmd" value="list" type="submit"> 
-HTML +        </form> 
-    +      </TD> 
-        print <<HTML; +    </TR> 
-<input type="hidden" name="note" value='$note'> <input name="cmd" value="edit" type="submit"> <input name="cmd" value="list" type="submit"></form></TD></TR></TABLE></CENTER>+  </TABLE> 
 +</CENTER>
 HTML HTML
 } }
 # #
 sub print_error { sub print_error {
-    my $error = shift; +  my $error = shift; 
-    print "<center><b><font color=\"red\">$error</font></b></center><p>";+  print "<center><b><font color=\"red\">$error</font></b></center><p>";
 } }
  
 sub get_note { sub get_note {
-    if ( -s "$xymon_notesdata/$host") { +  if ( -s "$xymon_notesdata/$host") { 
-        open (NOTE, "<$xymon_notesdata/$host") or &print_error("I can't open $xymon_notesdata/$host for reading!"); +    open (NOTE, "<$xymon_notesdata/$host") or &print_error("I can't open $xymon_notesdata/$host for reading!"); 
-        while (my $note = <NOTE>) { +    while (my $note = <NOTE>) { 
-            push @lines, $note+      push @lines, $note;
-        } +
-        close NOTE;+
     }     }
 +    close NOTE;
 +  }
 } }
  
 sub print_menu { sub print_menu {
-    print '<CENTER><TABLE BORDER="1" CELLPADDING="3"><CAPTION><H2><CENTER>Xymon Notes</CENTER></H2><b></b></CAPTION>'; +  print '<CENTER><TABLE BORDER="1" CELLPADDING="3"><CAPTION><H2><CENTER>Xymon Notes</CENTER></H2><b></b></CAPTION>'; 
-    for my $host(sort keys %hosts) { +  for my $host(sort keys %hosts) { 
-        print <<HTML;+    print <<HTML;
 <TR><TD>$host</TD><TD>$hosts{$host}</TD> <TR><TD>$host</TD><TD>$hosts{$host}</TD>
 <TD><form method="POST"><input type="hidden" name="host" value="$host"> <input name="cmd" value="view" type="submit"> <input name="cmd" value="edit" type="submit"></form></TD></TR> <TD><form method="POST"><input type="hidden" name="host" value="$host"> <input name="cmd" value="view" type="submit"> <input name="cmd" value="edit" type="submit"></form></TD></TR>
 HTML HTML
-    +  
-    print '</TABLE></CENTER>';+  print '</TABLE></CENTER>';
 } }
  
 sub get_hosts { sub get_hosts {
-    open (HOSTS, "-|", $xymon_cmd, '127.0.0.1', 'hostinfo') or &print_error("I can't open $xymon_hosts!"); +  open (HOSTS, "-|", $xymon_cmd, '127.0.0.1', 'hostinfo') or &print_error("I can't open $xymon_hosts!"); 
-    while (<HOSTS>) { +  while (<HOSTS>) { 
-        my ($hostname, $hostip, @dummy) = split('\|'); +    my ($hostname, $hostip, @dummy) = split('\|'); 
-        $hosts{$hostname} = $hostip; +    $hosts{$hostname} = $hostip; 
-    +  
-    close HOSTS;+  close HOSTS;
 } }
  
 sub print_header { sub print_header {
-    my $color = shift; +  my $color = shift; 
-    print "Content-type: text/html; charset=iso-8859-1\n\n"; +  print "Content-type: text/html; charset=iso-8859-1\n\n"; 
-    open (HEAD, "<$xymon_header") or &print_error("I can't open $xymon_header for reading!"); +  open (HEAD, "<$xymon_header") or &print_error("I can't open $xymon_header for reading!"); 
-    while (<HEAD>) { +  while (<HEAD>) { 
-        # It's a bit hard to edit with a refresh ;) +    # It's a bit hard to edit with a refresh ;) 
-        if (/META/i && /HTTP-EQUIV/i && /REFRESH/i && /CONTENT/i) { s/<(.*?)>/<!-- Refresh removed -->/g; } +    if (/META/i && /HTTP-EQUIV/i && /REFRESH/i && /CONTENT/i) { s/<(.*?)>/<!-- Refresh removed -->/g; } 
-        s/&XYMONLOGO/$ENV{'XYMONLOGO'}/g; +    s/&XYMONLOGO/$ENV{'XYMONLOGO'}/g; 
-        s/&XYMONBACKGROUND/$color/g; +    s/&XYMONBACKGROUND/$color/g; 
-        s/&XYMONBODYCSS/$ENV{'XYMONBODYCSS'}/g; +    s/&XYMONBODYCSS/$ENV{'XYMONBODYCSS'}/g; 
-        s/&XYMONBODYMENUCSS/$ENV{'XYMONBODYMENUCSS'}/g; +    s/&XYMONBODYMENUCSS/$ENV{'XYMONBODYMENUCSS'}/g; 
-        s/&XYMONMENUSKIN/$ENV{'XYMONMENUSKIN'}/g; +    s/&XYMONMENUSKIN/$ENV{'XYMONMENUSKIN'}/g; 
-        s/&XYMONPAGEPATH/$ENV{'XYMONPAGEPATH'}/g; +    s/&XYMONPAGEPATH/$ENV{'XYMONPAGEPATH'}/g; 
-        s/&XYMONSKIN/$ENV{'XYMONSKIN'}/g; +    s/&XYMONSKIN/$ENV{'XYMONSKIN'}/g; 
-        s/&XYMONDATE/$ENV{'XYMONDATE'}/g;+    s/&XYMONDATE/$ENV{'XYMONDATE'}/g; 
 + 
 +    if (/&XYMONBODYHEADER/) { 
 +      s/&XYMONBODYHEADER//g; 
 +      open (MENU, "<$xymon_menu") or &print_error("I can't open $xymon_menu for reading!"); 
 +      while (<MENU>) { 
 +        s/\$XYMONSERVERWWWURL/$ENV{'XYMONSERVERWWWURL'}/g; 
 +        s/\$XYMONSERVERCGIURL/$ENV{'XYMONSERVERCGIURL'}/g; 
 +        s/\$XYMONSERVERSECURECGIURL/$ENV{'XYMONSERVERSECURECGIURL'}/g;
         print;         print;
 +      }
 +      close MENU;
     }     }
-    close HEAD;+    print; 
 +  } 
 +  close HEAD;
 } }
  
 sub print_footer { sub print_footer {
-    open (FOOT, "<$xymon_footer") or &print_error("I can't open $xymon_footer for reading!"); +  open (FOOT, "<$xymon_footer") or &print_error("I can't open $xymon_footer for reading!"); 
-    while (<FOOT>) { +  while (<FOOT>) { 
-        s/&XYMONMENUSKIN/$ENV{'XYMONMENUSKIN'}/g; +    s/&XYMONMENUSKIN/$ENV{'XYMONMENUSKIN'}/g; 
-        s/&XYMONDREL/$version/g; +    s/&XYMONDREL/$version/g; 
-        print; +    print; 
-    +  
-    close FOOT;+  close FOOT;
 } }
  
Line 693: Line 726:
 &print_header($color); # I like blue ;) &print_header($color); # I like blue ;)
 if ($cmd =~ /edit|html/) { if ($cmd =~ /edit|html/) {
-    &get_note; +  &get_note; 
-    &edit_note;+  &edit_note;
 } elsif ($cmd eq 'view') { } elsif ($cmd eq 'view') {
-    &get_note; +  &get_note; 
-    &print_note;+  &print_note;
 } elsif ($cmd eq 'preview') { } elsif ($cmd eq 'preview') {
-    &print_note;+  &print_note;
 } elsif ($cmd eq 'preview as html') { } elsif ($cmd eq 'preview as html') {
-    &print_note;+  &print_note;
 } elsif ($cmd eq 'save') { } elsif ($cmd eq 'save') {
-    &save_note;+  &save_note;
 } else { } else {
-    &print_menu;+  &print_menu;
 } }
  
Line 712: Line 745:
 $| = $oldbar; $| = $oldbar;
 select ($cfh); select ($cfh);
 +
 </code> </code>
 </hidden> </hidden>
  • addons/hobbitnotes.txt
  • Last modified: 2017/12/05 05:54
  • by wikiadmin