| Project: | Munin |
| Version: | 0.8-dev |
| Component: | User interface |
| Category: | bug report |
| Priority: | normal |
| Assigned: | fastest963 |
| Status: | fixed |
Hello I always get the following message when I will rebuild the Rules:
Warning: fwrite(): supplied argument is not a valid stream resource in /public_html/firewall/functions.php on line 124
Warning: fwrite(): supplied argument is not a valid stream resource in /public_html/firewall/functions.php on line 124
Warning: fwrite(): supplied argument is not a valid stream resource in /public_html/firewall/functions.php on line 124
Warning: fwrite(): supplied argument is not a valid stream resource in /public_html/firewall/functions.php on line 124
Warning: fwrite(): supplied argument is not a valid stream resource in /public_html/firewall/functions.php on line 124
Can you help me please ?
Updates
The problem is that on line 76 in functions.php, all files in the rules folder are being parsed as if they actually contain rules. The problem with this is that the README file is also being parsed, which does not have the correct syntax which the parser is looking for.
There are 2 solutions:
1) Delete the README (please read it first :)
2) Add this to line 76, right after && $file != ".htaccess"
&& $file != "README"
This will stop the the Munin rebuilder from parsing the README.
Hope this helps,
Thomas
| Priority: | critical | » normal |
| Assigned to: | mOskito | » fastest963 |
| Status: | active | » patch (code needs review) |
The problem is that the script is parsing a file that it shouldn't and trying to edit a file that is nonexistent. here is the fix...
file: functions.php
replace all of parseRules() with
------------------------------------
function parseRules() {
//use fopen(w) instead of unlink becuase unlink removes 777 permissions and replaces with system default!
//faster way???
$fp1=fopen('./data/HTTP_HEADERS', 'w'); //clear contents of headers
$fp2=fopen('./data/HTTP_GET', 'w'); //clear contents of get
$fp3=fopen('./data/HTTP_POST', 'w'); //clear contents of post
$fp4=fopen('./data/HTTP_COOKIE', 'w'); //clear contents of cookie
fclose($fp1);
fclose($fp2);
fclose($fp3);
fclose($fp4);
if ($handle = opendir('./rules')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != ".htaccess") {
parseRuleSet('./rules/'.$file);
}
}
closedir($handle);
}
echo "Successfully Rebuilt Database!"; //just a little reminder
muninAddLog("Rebuilt rules", "system", "info");
}
------------------------------------
replace all of parseRuleSet($ruleFile) with
------------------------------------
function parseRuleSet($ruleFile) {
$dataSets=array('HTTP_HEADERS'=>array('HTTP_HEADERS', 'data'=> ''),'HTTP_GET'=>array('HTTP_GET', 'data'=> ''),'HTTP_POST'=>array('HTTP_POST', 'data'=> ''),'HTTP_COOKIE'=>array('HTTP_COOKIE', 'data'=> '')); //start the writing array off
$fp['HTTP_HEADERS']=fopen('./data/HTTP_HEADERS', 'a') or die("cannot open file!");
$fp['HTTP_GET']=fopen('./data/HTTP_GET', 'a') or die("cannot open file!");
$fp['HTTP_POST']=fopen('./data/HTTP_POST', 'a') or die("cannot open file!");
$fp['HTTP_COOKIE']=fopen('./data/HTTP_COOKIE', 'a') or die("cannot open file!");
if(file_exists($ruleFile)) {
$bufferLines = file($ruleFile);
foreach($bufferLines as $buffer) {
$buffer = str_replace("\t"," ", $buffer);
$buffer = preg_replace("/\s+/i", ' ', $buffer);
if(substr($buffer,0,1) != ' ' && substr($buffer,0,1) != '#' && substr($buffer,0,1) != '$') {
$ruleData = quotesplit(' ', $buffer, 5);
//echo "";
//print_r($ruleData);
//echo "";
$title = '';
$alert = 1;
$where = $ruleData[0];
$what = str_replace('"','',$ruleData[1]);
$string = str_replace('"','',$ruleData[2]);
$action = $ruleData[3];
$msg = $ruleData[4];
$ruleArray=array(
'what' => $what,
'string' => $string,
'action' => $action,
'msg' => $msg
);
if (!empty($dataSets[$where])){//check to see if valid location
$dataSets[$where]['data'] = $dataSets[$where]['data'].serialize($ruleArray)."\n"; //store into array to write to file in one write
}
}
}
}
foreach($dataSets as $where) {
if (!empty($where['data'])){//if data is empty, don't write
fwrite($fp[$where[0]], $where['data']);//optimize into one fwrite for each file!
}
}
fclose($fp['HTTP_HEADERS']);
fclose($fp['HTTP_GET']);
fclose($fp['HTTP_POST']);
fclose($fp['HTTP_COOKIE']);
}
------------------------------------
Hope that helps!
-fastest963
| Title: | Get Error when rebuild Rules | » put back on main page |
| Status: | patch (code needs review) | » fixed |
seems like it was removed from the main issues page, sorry
| Title: | put back on main page | » Get Error when rebuild Rules |
just in case anyone has any problems with the copy/paste I made (I forgot to htmlentities() it), here is a link to my full version...
http://fastest963.us.to/munin/echo.php?p=2
from there you can update your version with mine!
once again, sorry for all of the confusion!
