Ticket #3: munin-cgi-graph_fastcgi.diff
| File munin-cgi-graph_fastcgi.diff, 4.6 kB (added by blueyed, 4 years ago) |
|---|
-
/usr/lib/cgi-bin/munin-cgi-graph
old new 40 40 use IO::Handle; 41 41 use Date::Manip; 42 42 use POSIX qw(strftime); 43 use CGI::Fast; 43 44 44 45 my $GRAPHER = "/usr/share/munin/munin-graph"; 45 46 my $conffile = "/etc/munin/munin.conf"; … … 66 67 67 68 my $config = &munin_readconfig ($conffile); 68 69 69 my $path = $ENV{PATH_INFO} || "";70 $path =~ s/^\///;71 ($dom, $host, $serv) = split /\//, $path;72 ($serv, $scale) = split /-/, $serv, 2;73 $scale =~ s/\.png$//;74 70 75 &verify_parameters ($dom, $host, $serv, $scale); 71 # BEGIN FAST-CGI LOOP: 72 while (new CGI::Fast) 73 { 74 my $path = $ENV{PATH_INFO} || ""; 75 $path =~ s/^\///; 76 ($dom, $host, $serv) = split /\//, $path; 77 ($serv, $scale) = split /-/, $serv, 2; 78 $scale =~ s/\.png$// if defined $scale; 76 79 77 my $filename = get_picture_filename ($config, $dom, $host, $serv, $scale); 80 if (! &verify_parameters ($dom, $host, $serv, $scale)) 81 { 82 print "Status: 500\n"; 83 print "Content-Type: text/html\n"; 84 print "\n"; 85 print "Invalid parameters!"; 86 next; 87 } 78 88 79 my $time = time;89 my $filename = get_picture_filename ($config, $dom, $host, $serv, $scale); 80 90 81 if (-f $filename) 82 { 83 my @sstats = stat ($filename); 84 my $slast_modified = strftime ("%a, %d %b %Y %H:%M:%S %Z", localtime ($sstats[9])); 91 my $time = time; 85 92 86 if (defined $ENV{HTTP_IF_MODIFIED_SINCE} and 87 !&modified ($ENV{HTTP_IF_MODIFIED_SINCE}, $sstats[9]-1)) 93 if (-f $filename) 88 94 { 89 print "Status: 304\n"; 90 print "Content-Type: image/png\n"; 91 print "Expires: ", strftime ("%a, %d %b %Y %H:%M:%S GMT", gmtime(time+($period{$scale}-($time%$period{$scale})))), "\n"; 92 print "Last-Modified: $slast_modified\n"; 93 print "\n"; 94 exit 0; 95 my @sstats = stat ($filename); 96 my $slast_modified = strftime ("%a, %d %b %Y %H:%M:%S %Z", localtime ($sstats[9])); 97 98 if (defined $ENV{HTTP_IF_MODIFIED_SINCE} and 99 !&modified ($ENV{HTTP_IF_MODIFIED_SINCE}, $sstats[9]-1)) 100 { 101 print "Status: 304\n"; 102 print "Content-Type: image/png\n"; 103 print "Expires: ", strftime ("%a, %d %b %Y %H:%M:%S GMT", gmtime(time+($period{$scale}-($time%$period{$scale})))), "\n"; 104 print "Last-Modified: $slast_modified\n"; 105 print "\n"; 106 next; 107 } 95 108 } 96 }97 109 98 if (! &graph_usable ($filename, $time)) 99 { 100 my $ret = (&draw_graph ($host, $serv, $TIMES{$scale}) || "Unknown error"); 101 if (! -f $filename) 110 if (! &graph_usable ($filename, $time)) 102 111 { 103 ::logger ("Warning: Could not draw graph \"$host-$serv-$scale.png\": $ret"); 104 print "Status: 500\n"; 105 print "Content-Type: image/png\n"; 106 print "\n"; 107 exit 0; 112 my $ret = (&draw_graph ($host, $serv, $TIMES{$scale}) || "Unknown error"); 113 if (! -f $filename) 114 { 115 ::logger ("Warning: Could not draw graph \"$host-$serv-$scale.png\": $ret"); 116 print "Status: 500\n"; 117 print "Content-Type: image/png\n"; 118 print "\n"; 119 next; 120 } 108 121 } 109 }110 122 111 my @stats = stat ($filename);112 my $last_modified = strftime ("%a, %d %b %Y %H:%M:%S %Z", localtime ($stats[9]));123 my @stats = stat ($filename); 124 my $last_modified = strftime ("%a, %d %b %Y %H:%M:%S %Z", localtime ($stats[9])); 113 125 114 print "Content-Type: image/png\n";115 print "Expires: ", strftime ("%a, %d %b %Y %H:%M:%S GMT", gmtime(time+($period{$scale}-($time%$period{$scale})))), "\n";116 print "Last-Modified: $last_modified\n";117 print "\n";126 print "Content-Type: image/png\n"; 127 print "Expires: ", strftime ("%a, %d %b %Y %H:%M:%S GMT", gmtime(time+($period{$scale}-($time%$period{$scale})))), "\n"; 128 print "Last-Modified: $last_modified\n"; 129 print "\n"; 118 130 119 131 120 &graph ($filename); 132 &graph ($filename); 133 } 134 # END FAST-CGI LOOP 135 121 136 122 137 sub graph 123 138 { … … 191 206 if (!$dom) 192 207 { 193 208 print STDERR "Warning: Request for graph without specifying domain. Bailing out.\n"; 194 exit 1;209 return 0; 195 210 } 196 211 if (!$host) 197 212 { 198 213 print STDERR "Warning: Request for graph without specifying host. Bailing out.\n"; 199 exit 1;214 return 0; 200 215 } 201 216 if (!$serv) 202 217 { 203 218 print STDERR "Warning: Request for graph without specifying service. Bailing out.\n"; 204 exit 1;219 return 0; 205 220 } 206 221 207 222 if (!$scale) 208 223 { 209 224 print STDERR "Warning: Request for graph without specifying scale. Bailing out.\n"; 210 exit 1;225 return 0; 211 226 } 212 227 else 213 228 { 214 229 if (!defined $TIMES{$scale}) 215 230 { 216 231 print STDERR "Warning: Weird scale setting \"$scale\". Bailing out.\n"; 217 exit 1;232 return 0; 218 233 } 219 234 } 235 return 1; 220 236 } 221 237 222 238 sub graph_usable
