block: log activities when auto-rotating proxies
This commit is contained in:
parent
74de24fce3
commit
3d280f391e
2 changed files with 22 additions and 0 deletions
|
@ -5,6 +5,7 @@ import requests
|
|||
|
||||
from app import app
|
||||
from app.extensions import db
|
||||
from app.models.activity import Activity
|
||||
from app.models.mirrors import Proxy
|
||||
from app.terraform import BaseAutomation
|
||||
|
||||
|
@ -36,6 +37,7 @@ class BlockExternalAutomation(BaseAutomation):
|
|||
results[h2[i].text] = []
|
||||
i += 1
|
||||
|
||||
activities = []
|
||||
for vp in results:
|
||||
if vp not in app.config['EXTERNAL_VANTAGE_POINTS']:
|
||||
continue
|
||||
|
@ -54,7 +56,16 @@ class BlockExternalAutomation(BaseAutomation):
|
|||
if proxy.deprecated:
|
||||
print("Proxy already marked blocked")
|
||||
continue
|
||||
activities.append(Activity(
|
||||
activity_type="block",
|
||||
text=(f"Proxy {p.url} for {p.origin.domain_name} detected blocked according to external source. "
|
||||
"Rotation scheduled.")
|
||||
))
|
||||
proxy.deprecate(reason="external")
|
||||
for a in activities:
|
||||
db.session.add(a)
|
||||
db.session.commit()
|
||||
for a in activities:
|
||||
a.notify()
|
||||
|
||||
return True, ""
|
||||
|
|
|
@ -4,6 +4,7 @@ from typing import Tuple, List
|
|||
import requests
|
||||
|
||||
from app.extensions import db
|
||||
from app.models.activity import Activity
|
||||
from app.models.mirrors import Proxy
|
||||
from app.terraform import BaseAutomation
|
||||
|
||||
|
@ -14,6 +15,7 @@ class BlockRoskomsvobodaAutomation(BaseAutomation):
|
|||
frequency = 90
|
||||
|
||||
def automate(self, full: bool = False) -> Tuple[bool, str]:
|
||||
activities = []
|
||||
proxies: List[Proxy] = Proxy.query.filter(
|
||||
Proxy.deprecated == None,
|
||||
Proxy.destroyed == None
|
||||
|
@ -30,5 +32,14 @@ class BlockRoskomsvobodaAutomation(BaseAutomation):
|
|||
print("Proxy already marked blocked")
|
||||
continue
|
||||
p.deprecate(reason="roskomsvoboda")
|
||||
activities.append(Activity(
|
||||
activity_type="block",
|
||||
text=(f"Proxy {p.url} for {p.origin.domain_name} detected blocked according to RosKomSvoboda. "
|
||||
"Rotation scheduled.")
|
||||
))
|
||||
for a in activities:
|
||||
db.session.add(a)
|
||||
db.session.commit()
|
||||
for a in activities:
|
||||
a.notify()
|
||||
return True, ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue