smart_proxy: add asset domains concept
This commit is contained in:
parent
dfb4d66557
commit
d99cf88f38
6 changed files with 60 additions and 4 deletions
|
@ -13,6 +13,7 @@ class Origin(AbstractConfiguration):
|
|||
domain_name = db.Column(db.String(255), unique=True, nullable=False)
|
||||
auto_rotation = db.Column(db.Boolean, nullable=False)
|
||||
smart = db.Column(db.Boolean(), nullable=False)
|
||||
assets = db.Column(db.Boolean(), nullable=False)
|
||||
|
||||
group = db.relationship("Group", back_populates="origins")
|
||||
proxies = db.relationship("Proxy", back_populates="origin")
|
||||
|
|
|
@ -22,6 +22,7 @@ class NewOriginForm(FlaskForm): # type: ignore
|
|||
group = SelectField('Group', validators=[DataRequired()])
|
||||
auto_rotate = BooleanField("Enable auto-rotation?", default=True)
|
||||
smart_proxy = BooleanField("Requires smart proxy?", default=False)
|
||||
asset_domain = BooleanField("Used to host assets for other domains?", default=False)
|
||||
submit = SubmitField('Save Changes')
|
||||
|
||||
|
||||
|
@ -30,6 +31,7 @@ class EditOriginForm(FlaskForm): # type: ignore
|
|||
group = SelectField('Group', validators=[DataRequired()])
|
||||
auto_rotate = BooleanField("Enable auto-rotation?")
|
||||
smart_proxy = BooleanField("Requires smart proxy?")
|
||||
asset_domain = BooleanField("Used to host assets for other domains?", default=False)
|
||||
submit = SubmitField('Save Changes')
|
||||
|
||||
|
||||
|
@ -45,6 +47,7 @@ def origin_new(group_id: Optional[int] = None) -> ResponseReturnValue:
|
|||
origin.description = form.description.data
|
||||
origin.auto_rotation = form.auto_rotate.data
|
||||
origin.smart = form.smart_proxy.data
|
||||
origin.assets = form.asset_domain.data
|
||||
origin.created = datetime.utcnow()
|
||||
origin.updated = datetime.utcnow()
|
||||
try:
|
||||
|
@ -73,13 +76,15 @@ def origin_edit(origin_id: int) -> ResponseReturnValue:
|
|||
form = EditOriginForm(group=origin.group_id,
|
||||
description=origin.description,
|
||||
auto_rotate=origin.auto_rotation,
|
||||
smart_proxy=origin.smart)
|
||||
smart_proxy=origin.smart,
|
||||
asset_domain=origin.assets)
|
||||
form.group.choices = [(x.id, x.group_name) for x in Group.query.all()]
|
||||
if form.validate_on_submit():
|
||||
origin.group_id = form.group.data
|
||||
origin.description = form.description.data
|
||||
origin.auto_rotation = form.auto_rotate.data
|
||||
origin.smart = form.smart_proxy.data
|
||||
origin.assets = form.asset_domain.data
|
||||
origin.updated = datetime.utcnow()
|
||||
try:
|
||||
db.session.commit()
|
||||
|
|
|
@ -211,6 +211,7 @@
|
|||
<th scope="col">Description</th>
|
||||
<th scope="col">Auto-Rotation</th>
|
||||
<th scope="col">Smart Proxy</th>
|
||||
<th scope="col">Assets Origin</th>
|
||||
<th scope="col">Onion Service</th>
|
||||
<th scope="col">Group</th>
|
||||
<th scope="col">Actions</th>
|
||||
|
@ -228,6 +229,7 @@
|
|||
<td>{{ origin.description }}</td>
|
||||
<td>{% if origin.auto_rotation %}✅{% else %}❌{% endif %}</td>
|
||||
<td>{% if origin.smart %}✅{% else %}❌{% endif %}</td>
|
||||
<td>{% if origin.assets %}✅{% else %}❌{% endif %}</td>
|
||||
<td>{% if origin.onion() %}✅{% else %}❌{% endif %}</td>
|
||||
<td>
|
||||
<a href="{{ url_for("portal.group.group_edit", group_id=origin.group.id) }}">{{ origin.group.group_name }}</a>
|
||||
|
|
|
@ -167,7 +167,7 @@ class ProxyAutomation(TerraformAutomation):
|
|||
{% for origin in origins %}
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name origin-{{ origin.id }}.{{ provider }}.smart.censorship.guide;
|
||||
server_name origin-{{ origin.id }}.{{ provider }}.smart.{{ smart_zone[:-1] }};
|
||||
location / {
|
||||
proxy_set_header Accept-Encoding "";
|
||||
proxy_ssl_server_name on;
|
||||
|
@ -175,6 +175,13 @@ class ProxyAutomation(TerraformAutomation):
|
|||
subs_filter_types text/html text/css text/xml;
|
||||
subs_filter https://{{ origin.domain_name }}/ /;
|
||||
subs_filter "\\\"https://{{ origin.domain_name }}\\\"" /;
|
||||
{% for asset_origin in origin.group.origins | selectattr("origin", "true") %}
|
||||
{% for asset_proxy in asset_origin.proxies | selectattr("provider", provider) %}
|
||||
{% if loop.first %}
|
||||
subs_filter https://{{ asset_origin.domain_name }}/ {{ asset_proxy.url }}/
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
}
|
||||
ssl_certificate /etc/ssl/smart_proxy.crt;
|
||||
ssl_certificate_key /etc/ssl/private/smart_proxy.key;
|
||||
|
@ -182,4 +189,5 @@ class ProxyAutomation(TerraformAutomation):
|
|||
{% endfor %}
|
||||
""",
|
||||
provider=self.provider,
|
||||
origins=group_origins)
|
||||
origins=group_origins,
|
||||
smart_zone=app.config['SMART_ZONE'])
|
||||
|
|
|
@ -122,7 +122,7 @@ class ProxyCloudfrontAutomation(ProxyAutomation):
|
|||
{% for proxy in proxies %}
|
||||
module "cloudfront_{{ proxy.id }}" {
|
||||
source = "sr2c/bc-proxy/aws"
|
||||
version = "0.0.7"
|
||||
version = "0.0.10"
|
||||
{% if proxy.origin.smart %}
|
||||
origin_domain = "origin-{{ proxy.origin.id }}.cloudfront.smart.{{ smart_zone[:-1] }}"
|
||||
{% else %}
|
||||
|
|
40
migrations/versions/c644bb20d0e3_add_asset_origins.py
Normal file
40
migrations/versions/c644bb20d0e3_add_asset_origins.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
"""add asset origins
|
||||
|
||||
Revision ID: c644bb20d0e3
|
||||
Revises: 133961a48525
|
||||
Create Date: 2022-05-25 15:21:16.221418
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'c644bb20d0e3'
|
||||
down_revision = '133961a48525'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('origin', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('assets', sa.Boolean(), nullable=True))
|
||||
with op.batch_alter_table('origin', schema=None) as batch_op:
|
||||
batch_op.execute("UPDATE origin SET assets=false")
|
||||
batch_op.alter_column('assets',
|
||||
existing_type=sa.BOOLEAN(),
|
||||
nullable=False)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('origin', schema=None) as batch_op:
|
||||
batch_op.alter_column('smart',
|
||||
existing_type=sa.BOOLEAN(),
|
||||
nullable=True)
|
||||
batch_op.drop_column('assets')
|
||||
|
||||
# ### end Alembic commands ###
|
Loading…
Add table
Add a link
Reference in a new issue