-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip violation rules and caching of access logs within 3hours
- Loading branch information
Showing
4 changed files
with
78 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const defaultRuleDuration = Duration(minutes: 15); | ||
|
||
class ViolationRule { | ||
final String url; | ||
final bool exact; | ||
final int count; | ||
final Duration duration; | ||
ViolationRule(this.url, | ||
{this.exact: false, this.count: 1, this.duration: defaultRuleDuration}); | ||
} | ||
|
||
final Map<String, List<ViolationRule>> violationConfig = { | ||
'apache.log': [ViolationRule('/wp-login.php')] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,2 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
/// store | ||
abstract class Store {} | ||
|
||
class AccessClientHandler { | ||
List<String> logs; | ||
String ip; | ||
|
||
AccessClientHandler(List<String> logs, String ip}) { | ||
this.logs = logs; | ||
this.ip = ip; | ||
loadConfig(); | ||
} | ||
|
||
loadConfig() async { | ||
String path = "ip-"+ip+'.json'; | ||
var file = File(path); | ||
if (!await file.exists()) { | ||
return; | ||
} | ||
|
||
String content = await file.readAsString(); | ||
Map<String,dynamic> data = json.decode(content); | ||
logs = []; | ||
if (data.containsKey('log')) { | ||
(data['log'] as List).forEach((String log) { | ||
logs.add(log); | ||
}); | ||
} | ||
|
||
} | ||
|
||
save() { | ||
Map<String, dynamic> res = { | ||
'log': logs, | ||
'ip': ips, | ||
}; | ||
} | ||
|
||
static load(String ip) { | ||
var cli = AccessClientHandler([], ip ); | ||
return cli; | ||
} | ||
} | ||
/// store | ||
abstract class StoreClient {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
class AccessClientHandler { | ||
Map<String, dynamic> logs; | ||
String ip; | ||
String configPath; | ||
|
||
AccessClientHandler(Map<String, dynamic> this.logs, String this.ip, | ||
{String this.configPath = ""}) { | ||
loadConfig(); | ||
} | ||
/// store count of access | ||
addAccessCount(String file, String url, { int count = 1}) { | ||
if(! logs.containsKey(file)) { | ||
this.resetAccessCount(file); | ||
} | ||
logs[file]['count'] += 1; | ||
return logs[file]; | ||
} | ||
|
||
resetAccessCount(String file) { | ||
logs[file] = { 'count': 0 }; | ||
} | ||
|
||
save() async { | ||
Map<String, dynamic> res = { | ||
'log': logs, | ||
'ip': ip, | ||
}; | ||
var file = File(pathToConfig); | ||
String content = await json.encode(res); | ||
return file.writeAsStringSync(content); | ||
} | ||
|
||
load(String ip) { | ||
var cli = AccessClientHandler({}, ip); | ||
return cli; | ||
} | ||
|
||
get pathToConfig() { | ||
return | ||
configPath.isEmpty ? "" : configPath + '/' + "ip-" + ip + '.json'; | ||
} | ||
|
||
loadConfig() async { | ||
var file = File(pathToConfig); | ||
if (!await file.exists()) { | ||
return; | ||
} | ||
|
||
String content = await file.readAsString(); | ||
Map<String, dynamic> data = json.decode(content); | ||
logs = {}; | ||
if (data.containsKey('log')) { | ||
logs = data['log']; | ||
} | ||
} | ||
|
||
} |