-
Notifications
You must be signed in to change notification settings - Fork 10
/
LongTail_make_graph_sshpsycho.php
executable file
·177 lines (153 loc) · 4.79 KB
/
LongTail_make_graph_sshpsycho.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php // content="text/plain; charset=utf-8"
// Example for use of JpGraph,
//Lightly modified from http://jpgraph.net/download/manuals/chunkhtml/ch08s04.html
require_once ('/usr/local/php/jpgraph-3.5.0b1/src/jpgraph.php');
require_once ('/usr/local/php/jpgraph-3.5.0b1/src/jpgraph_bar.php');
$date=`date +"%Y-%m-%d %H:%M"`;
$URL_LINE="http://longtail.it.marist.edu";
// php /usr/local/etc/LongTail_make_graph_sshpsycho.php $HTML_DIR/last-30-days-attack-count.data $HTML_DIR/last-30-days-sshpsycho-attack-count.data $HTML_DIR/last-30-days-friends-of-sshpsycho-attack-count.data $HTML_DIR/last-30-days-associates-of-sshpsycho-attack-count.data "Last 30 Days Attack Count (Red=sshPsycho, Yellow=Friends of sshPsycho, Green=Associates of sshPsycho, Blue=others)" "" "" "wide" > $GRAPHIC_FILE
// Must pass full filename to read and "Quote delimited text header"
// And redirect the output to a file
$file1 = $argv[1];
$file2 = $argv[2];
$file3 = $argv[3];
$file4 = $argv[4];
$header = $argv[5];
$x_axis_title = $argv[6];
$y_axis_title = $argv[7];
$size=$argv[8];
// We need some data
$counter=0;
# Initialize it just in case there's no data
$datay[$counter]=0;
$datay2[$counter]=0;
$datay3[$counter]=0;
$datay4[$counter]=0;
$datax[$counter]="NO DATA";
$myfile = fopen($file1, "r")
or die("Unable to open file!");
if ($myfile) {
while (($buffer = fgets($myfile, 4096)) !== false) {
list($count,$account) = explode(" ",$buffer);
$account = chop($account);
if ($count <0){
$count=0;
}
$datay[$counter]=$count;
$datax[$counter]=$account;
// print "counter is $counter, account is $account, count is $count\n";
$counter++;
}
if (!feof($myfile)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($myfile);
}
$counter=0;
$myfile = fopen($file2, "r")
or die("Unable to open file!");
if ($myfile) {
while (($buffer = fgets($myfile, 4096)) !== false) {
list($count,$account) = explode(" ",$buffer);
$account = chop($account);
if ($count <0){
$count=0;
}
$datay2[$counter]=$count;
$datay[$counter]=$datay[$counter]-$count;
$datax[$counter]=$account;
// print "counter is $counter, account is $account, count is $count\n";
$counter++;
}
if (!feof($myfile)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($myfile);
}
$counter=0;
$myfile = fopen($file3, "r")
or die("Unable to open file!");
if ($myfile) {
while (($buffer = fgets($myfile, 4096)) !== false) {
list($count,$account) = explode(" ",$buffer);
$account = chop($account);
if ($count <0){
$count=0;
}
$datay3[$counter]=$count;
$datay[$counter]=$datay[$counter]-$count;
$datax[$counter]=$account;
$counter++;
}
if (!feof($myfile)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($myfile);
}
$counter=0;
$myfile = fopen($file4, "r")
or die("Unable to open file!");
if ($myfile) {
while (($buffer = fgets($myfile, 4096)) !== false) {
list($count,$account) = explode(" ",$buffer);
$account = chop($account);
if ($count <0){
$count=0;
}
$datay4[$counter]=$count;
$datay[$counter]=$datay[$counter]-$count;
if ( $datay[$counter] < 0 ){
$datay[$counter] =0;
}
$datax[$counter]=$account;
$counter++;
}
if (!feof($myfile)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($myfile);
}
// Setup the graph.
if ($size == "wide"){
$graph = new Graph(810,240);
}
else {
$graph = new Graph(400,240);
}
$graph->img->SetMargin(60,20,35,75);
$graph->SetScale("textlin");
$graph->SetMarginColor("lightblue:1.1");
$graph->SetShadow();
// Set up the title for the graph
$graph->title->Set("$header");
$graph->subtitle->Set("$URL_LINE $date");
//$graph->title->Set("$header\n$URL_LINE $date");
$graph->xaxis->title->Set("$x_axis_title","left");
$graph->yaxis->title->Set("$y_axis_title","middle");
// Setup font for axis
$graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
$graph->yaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
// Show 0 label on Y-axis (default is not to show)
$graph->yscale->ticks->SupressZeroLabel(false);
// Setup X-axis labels
$graph->xaxis->SetTickLabels($datax);
$graph->xaxis->SetLabelAngle(45);
// Create the bar pot
$bplot = new BarPlot($datay);
$bplot2 = new BarPlot($datay2);
$bplot3 = new BarPlot($datay3);
$bplot4 = new BarPlot($datay4);
$bplot->SetWidth(0.7);
// Setup color for gradient fill style
$bplot->SetFillGradient("blue:0.9","blue:1.85",GRAD_LEFT_REFLECTION);
$bplot2->SetFillGradient("red:0.9","red:1.85",GRAD_LEFT_REFLECTION);
$bplot3->SetFillGradient("yellow:0.9","yellow:1.85",GRAD_LEFT_REFLECTION);
$bplot4->SetFillGradient("green:0.9","yellow:1.85",GRAD_LEFT_REFLECTION);
// Set color for the frame of each bar
$bplot->SetColor("white");
// Create the grouped bar plot
$gbplot = new AccBarPlot(array($bplot,$bplot2,$bplot3,$bplot4));
$graph->Add($gbplot);
// Finally send the graph to the browser
$graph->Stroke();
?>