mirrors: allow selective auto-rotation

This commit is contained in:
Iain Learmonth 2022-05-01 16:38:41 +01:00
parent 18e046dc42
commit 80890c2127
5 changed files with 25 additions and 34 deletions

View file

@ -106,6 +106,7 @@ def new_origin(group_id=None):
origin.group_id = form.group.data
origin.domain_name = form.domain_name.data
origin.description = form.description.data
origin.auto_rotation = form.auto_rotate.data
origin.created = datetime.utcnow()
origin.updated = datetime.utcnow()
try:
@ -137,6 +138,7 @@ def edit_origin(origin_id):
if form.validate_on_submit():
origin.group_id = form.group.data
origin.description = form.description.data
origin.auto_rotation = form.auto_rotate.data
origin.updated = datetime.utcnow()
try:
db.session.commit()
@ -306,9 +308,9 @@ def edit_bridgeconf(bridgeconf_id):
bridgeconf = BridgeConf.query.filter(BridgeConf.id == bridgeconf_id).first()
if bridgeconf is None:
return Response(render_template("error.html.j2",
section="origin",
header="404 Origin Not Found",
message="The requested origin could not be found."),
section="bridge",
header="404 Bridge Configuration Not Found",
message="The requested bridge configuration could not be found."),
status=404)
form = EditBridgeConfForm(description=bridgeconf.description,
number=bridgeconf.number)

View file

@ -20,12 +20,14 @@ class NewOriginForm(FlaskForm):
domain_name = StringField('Domain Name', validators=[DataRequired()])
description = StringField('Description', validators=[DataRequired()])
group = SelectField('Group', validators=[DataRequired()])
auto_rotate = BooleanField("Enable auto-rotation?", default=True)
submit = SubmitField('Save Changes')
class EditOriginForm(FlaskForm):
description = StringField('Description', validators=[DataRequired()])
group = SelectField('Group', validators=[DataRequired()])
auto_rotate = BooleanField("Enable auto-rotation?")
submit = SubmitField('Save Changes')

View file

@ -19,7 +19,7 @@
<tr>
<td>{{ group.group_name }}</td>
<td>{{ group.description }}</td>
<td>{% if group.eotk %}√{% else %}x{% endif %}</td>
<td>{% if group.eotk %}✅{% else %}❌{% endif %}</td>
<td>{{ group.origins | length }}</td>
<td><a href="{{ url_for("portal.edit_group", group_id=group.id) }}" class="btn btn-primary btn-sm">View/Edit</a></td>
</tr>

View file

@ -21,8 +21,7 @@
{{ origin.domain_name }}
</td>
<td>{{ origin.description }}</td>
<td>{{ origin.mirrors | length }}</td>
<td>{{ origin.proxies | length }}</td>
<td>{% if origin.auto_rotation %}✅{% else %}❌{% endif %}</td>
<td>
<a href="{{ url_for("portal.edit_group", group_id=origin.group.id) }}">{{ origin.group.group_name }}</a>
</td>

View file

@ -7,7 +7,7 @@ from app.models.mirrors import Proxy
def check_blocks():
user_agent = {'User-agent': 'BypassCensorship/1.0 (contact@sr2.uk for info)'}
user_agent = {'User-agent': 'BypassCensorship/1.0'}
page = requests.get(app.config['EXTERNAL_CHECK_URL'], headers=user_agent)
soup = BeautifulSoup(page.content, 'html.parser')
h2 = soup.find_all('h2')
@ -33,33 +33,21 @@ def check_blocks():
if vp not in app.config['EXTERNAL_VANTAGE_POINTS']:
continue
for url in results[vp]:
if "cloudfront.net" in url:
print(f"Found {url} blocked")
proxy = Proxy.query.filter(
Proxy.provider == "cloudfront",
Proxy.url == f"https://{url}"
).first()
if not proxy:
print("Proxy not found")
continue
if proxy.deprecated:
print("Proxy already marked blocked")
continue
proxy.deprecate(reason="external")
if "azureedge.net" in url:
slug = url[len('https://'):][:-len('.azureedge.net')]
print(f"Found {slug} blocked")
proxy = Proxy.query.filter(
Proxy.provider == "azure_cdn",
Proxy.slug == slug
).first()
if not proxy:
print("Proxy not found")
continue
if proxy.deprecated:
print("Proxy already marked blocked")
continue
proxy.deprecate(reason="external")
print(f"Found {url} blocked")
proxy = Proxy.query.filter(
Proxy.provider == "cloudfront",
Proxy.url == f"https://{url}"
).first()
if not proxy:
print("Proxy not found")
continue
if not proxy.origin.auto_rotation:
print("Proxy auto-rotation forbidden for origin")
if proxy.deprecated:
print("Proxy already marked blocked")
continue
proxy.deprecate(reason="external")
db.session.commit()