schemas: generate some good schemas
This commit is contained in:
parent
ed56ed5368
commit
b7a2201ad6
10 changed files with 205 additions and 122 deletions
0
app/lists/__init__.py
Normal file
0
app/lists/__init__.py
Normal file
58
app/lists/bc2.py
Normal file
58
app/lists/bc2.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
from datetime import datetime
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from app.models.mirrors import Origin
|
||||
|
||||
|
||||
class BC2Alternative(BaseModel):
|
||||
proto: str
|
||||
type: str
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
url: str
|
||||
|
||||
|
||||
class BC2Site(BaseModel):
|
||||
main_domain: str = Field(
|
||||
description="The main domain name of the website, excluding \"www.\" if present.",
|
||||
examples=["bbc.co.uk", "bbc.com", "guardianproject.info"]
|
||||
)
|
||||
available_alternatives: List[BC2Alternative]
|
||||
|
||||
|
||||
class BypassCensorship2(BaseModel):
|
||||
version: str = Field(
|
||||
description="Version number of the Bypass Censorship Extension schema in use",
|
||||
)
|
||||
sites: List[BC2Site]
|
||||
|
||||
class Config:
|
||||
title = "Bypass Censorship Version 2"
|
||||
|
||||
def mirror_sites():
|
||||
return {
|
||||
"version": "2.0",
|
||||
"sites": [{
|
||||
"main_domain": x.description[len("proxy:"):].replace("www.", "") if x.description.startswith("proxy:") else x.domain_name.replace("www.", ""),
|
||||
"available_alternatives": [
|
||||
{
|
||||
"proto": "tor" if ".onion" in a.url else "https",
|
||||
"type": "eotk" if ".onion" in a.url else "mirror",
|
||||
"created_at": str(a.added),
|
||||
"updated_at": str(a.updated),
|
||||
"url": a.url
|
||||
} for a in x.mirrors if not a.deprecated and not a.destroyed
|
||||
] + [
|
||||
{
|
||||
"proto": "https",
|
||||
"type": "mirror",
|
||||
"created_at": str(a.added),
|
||||
"updated_at": str(a.updated),
|
||||
"url": a.url
|
||||
} for a in x.proxies if
|
||||
a.url is not None and not a.deprecated and not a.destroyed and a.provider == "cloudfront"
|
||||
]} for x in Origin.query.order_by(Origin.domain_name).all() if x.destroyed is None
|
||||
]
|
||||
}
|
34
app/lists/bridgelines.py
Normal file
34
app/lists/bridgelines.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
from typing import List
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from app.models.bridges import Bridge
|
||||
|
||||
|
||||
class Bridgelines(BaseModel):
|
||||
version: str = Field(
|
||||
description="Version number of the bridgelines schema in use"
|
||||
)
|
||||
bridgelines: List[str] = Field(
|
||||
description="List of bridgelines, ready for use in a torrc file",
|
||||
examples = [
|
||||
"obfs4 71.73.124.31:8887 E81B1237F6D13497B166060F55861565593CFF8E cert=b54NsV6tK1g+LHaThPOTCibdpx3wHm9NFe0PzGF1nwz+4M/tq6SkfOaShzPnZsIRCFRIHg iat-mode=0",
|
||||
"obfs4 172.105.176.101:80 D18BC7E082D7EBF8E851029AC89A12A3F44A50BF cert=KHfAAUptXWRmLy3ehS9ETMO5luY06d0w7tEBDiAI0z62nC5Qo/APrzZxodkYWX2bNko/Mw iat-mode=0",
|
||||
"obfs4 141.101.36.55:9023 045EF272F08BC11CDB985889E4E9FE35DC6F9C67 cert=6KEdf/5aDSyuYEqvo14JE8Cks3i7PQtj9EFX2wTCiEaUPsp/I7eaOm4uSWdqwvV4vTVlFw iat-mode=0"
|
||||
]
|
||||
)
|
||||
|
||||
class Config:
|
||||
title = "Bridgelines Version 2"
|
||||
|
||||
|
||||
def bridgelines():
|
||||
return Bridgelines(
|
||||
version="1.0",
|
||||
bridgelines=[
|
||||
b.bridgeline for b in Bridge.query.filter(
|
||||
Bridge.destroyed == None,
|
||||
Bridge.bridgeline != None
|
||||
)
|
||||
]
|
||||
).dict()
|
31
app/lists/mirror_mapping.py
Normal file
31
app/lists/mirror_mapping.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
from typing import Dict
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from tldextract import extract
|
||||
|
||||
from app import Proxy
|
||||
|
||||
|
||||
class MMMirror(BaseModel):
|
||||
origin_domain: str = Field(description="The full origin domain name")
|
||||
origin_domain_normalized: str = Field(description="The origin_domain with \"www.\" removed, if present")
|
||||
origin_domain_root: str = Field(description="The registered domain name of the origin, excluding subdomains")
|
||||
|
||||
|
||||
class MirrorMapping(BaseModel):
|
||||
__root__: Dict[str, MMMirror] = Field(
|
||||
description="The domain name for the mirror"
|
||||
)
|
||||
|
||||
class Config:
|
||||
title = "Mirror Mapping Version 1"
|
||||
|
||||
|
||||
def mirror_mapping():
|
||||
return MirrorMapping(**{
|
||||
d.url.lstrip("https://"): MMMirror(
|
||||
origin_domain=d.origin.domain_name,
|
||||
origin_domain_normalized=d.origin.domain_name.lstrip("www."),
|
||||
origin_domain_root=extract(d.origin.domain_name).registered_domain
|
||||
) for d in Proxy.query.all() if d.url is not None
|
||||
}).dict()
|
Loading…
Add table
Add a link
Reference in a new issue