config file, yaml import
This commit is contained in:
@ -2,6 +2,6 @@ arrow
|
||||
pyufw
|
||||
requests
|
||||
peewee
|
||||
#playhouse.sqlite_ext
|
||||
click
|
||||
fabric
|
||||
pyyaml
|
||||
|
18
waf3.py
18
waf3.py
@ -8,6 +8,20 @@ import click
|
||||
from path import Path
|
||||
import pyufw as ufw
|
||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||
import yaml
|
||||
|
||||
base_path = Path('/var/opt/waf')
|
||||
conf_file = base_path / 'config.yml'
|
||||
db_path = base_path / 'waf.db'
|
||||
if conf_file.exists():
|
||||
conf = yaml.safe_load(conf_file.text())
|
||||
else:
|
||||
conf = {
|
||||
'vroots': "/srv",
|
||||
}
|
||||
conf_file.touch()
|
||||
yaml.dump(conf, conf_file.open('w'))
|
||||
# with open('names.yaml', 'w') as file:
|
||||
|
||||
now = arrow.utcnow()
|
||||
last_hour = now.shift(hours=-1).floor('hour')
|
||||
@ -15,7 +29,7 @@ last_thirty_min = now.shift(minutes=-30)
|
||||
# last_period = last_thirty_min
|
||||
last_period = last_hour
|
||||
|
||||
vroots = Path("/srv")
|
||||
vroots = Path(conf['vroots'])
|
||||
logs = vroots.glob('*/logs/*access*.log')
|
||||
whitelist_ips = [
|
||||
'127.0.0.1',
|
||||
@ -24,7 +38,7 @@ whitelist_ips = [
|
||||
'78.47.46.238',
|
||||
]
|
||||
|
||||
db = SqliteExtDatabase('/var/opt/waf/waf.db', pragmas={'journal_mode': 'wal'})
|
||||
db = SqliteExtDatabase(db_path, pragmas={'journal_mode': 'wal'})
|
||||
class Attack(peewee.Model):
|
||||
ip = peewee.CharField(unique=True)
|
||||
host = peewee.CharField(index = True)
|
||||
|
Reference in New Issue
Block a user