From 4c9d82d7907f9dc5b5ba8df2f674f2391f5361d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Sat, 17 Feb 2018 23:21:04 +0100 Subject: [PATCH] Equivalent domains --- src/api/core/global_domains.json | 650 +++++++++++++++++++++++++++++++ src/api/core/mod.rs | 53 ++- 2 files changed, 692 insertions(+), 11 deletions(-) create mode 100644 src/api/core/global_domains.json diff --git a/src/api/core/global_domains.json b/src/api/core/global_domains.json new file mode 100644 index 0000000..e852bf0 --- /dev/null +++ b/src/api/core/global_domains.json @@ -0,0 +1,650 @@ +[ + { + "Type": 2, + "Domains": [ + "ameritrade.com", + "tdameritrade.com" + ], + "Excluded": false + }, + { + "Type": 3, + "Domains": [ + "bankofamerica.com", + "bofa.com", + "mbna.com", + "usecfo.com" + ], + "Excluded": false + }, + { + "Type": 4, + "Domains": [ + "sprint.com", + "sprintpcs.com", + "nextel.com" + ], + "Excluded": false + }, + { + "Type": 0, + "Domains": [ + "youtube.com", + "google.com", + "gmail.com" + ], + "Excluded": false + }, + { + "Type": 1, + "Domains": [ + "apple.com", + "icloud.com" + ], + "Excluded": false + }, + { + "Type": 5, + "Domains": [ + "wellsfargo.com", + "wf.com" + ], + "Excluded": false + }, + { + "Type": 6, + "Domains": [ + "mymerrill.com", + "ml.com", + "merrilledge.com" + ], + "Excluded": false + }, + { + "Type": 7, + "Domains": [ + "accountonline.com", + "citi.com", + "citibank.com", + "citicards.com", + "citibankonline.com" + ], + "Excluded": false + }, + { + "Type": 8, + "Domains": [ + "cnet.com", + "cnettv.com", + "com.com", + "download.com", + "news.com", + "search.com", + "upload.com" + ], + "Excluded": false + }, + { + "Type": 9, + "Domains": [ + "bananarepublic.com", + "gap.com", + "oldnavy.com", + "piperlime.com" + ], + "Excluded": false + }, + { + "Type": 10, + "Domains": [ + "bing.com", + "hotmail.com", + "live.com", + "microsoft.com", + "msn.com", + "passport.net", + "windows.com", + "microsoftonline.com", + "office365.com", + "microsoftstore.com" + ], + "Excluded": false + }, + { + "Type": 11, + "Domains": [ + "ua2go.com", + "ual.com", + "united.com", + "unitedwifi.com" + ], + "Excluded": false + }, + { + "Type": 12, + "Domains": [ + "overture.com", + "yahoo.com", + "flickr.com" + ], + "Excluded": false + }, + { + "Type": 13, + "Domains": [ + "zonealarm.com", + "zonelabs.com" + ], + "Excluded": false + }, + { + "Type": 14, + "Domains": [ + "paypal.com", + "paypal-search.com" + ], + "Excluded": false + }, + { + "Type": 15, + "Domains": [ + "avon.com", + "youravon.com" + ], + "Excluded": false + }, + { + "Type": 16, + "Domains": [ + "diapers.com", + "soap.com", + "wag.com", + "yoyo.com", + "beautybar.com", + "casa.com", + "afterschool.com", + "vine.com", + "bookworm.com", + "look.com", + "vinemarket.com" + ], + "Excluded": false + }, + { + "Type": 17, + "Domains": [ + "1800contacts.com", + "800contacts.com" + ], + "Excluded": false + }, + { + "Type": 18, + "Domains": [ + "amazon.com", + "amazon.co.uk", + "amazon.ca", + "amazon.de", + "amazon.fr", + "amazon.es", + "amazon.it", + "amazon.com.au", + "amazon.co.nz", + "amazon.co.jp", + "amazon.in" + ], + "Excluded": false + }, + { + "Type": 19, + "Domains": [ + "cox.com", + "cox.net", + "coxbusiness.com" + ], + "Excluded": false + }, + { + "Type": 20, + "Domains": [ + "mynortonaccount.com", + "norton.com" + ], + "Excluded": false + }, + { + "Type": 21, + "Domains": [ + "verizon.com", + "verizon.net" + ], + "Excluded": false + }, + { + "Type": 22, + "Domains": [ + "rakuten.com", + "buy.com" + ], + "Excluded": false + }, + { + "Type": 23, + "Domains": [ + "siriusxm.com", + "sirius.com" + ], + "Excluded": false + }, + { + "Type": 24, + "Domains": [ + "ea.com", + "origin.com", + "play4free.com", + "tiberiumalliance.com" + ], + "Excluded": false + }, + { + "Type": 25, + "Domains": [ + "37signals.com", + "basecamp.com", + "basecamphq.com", + "highrisehq.com" + ], + "Excluded": false + }, + { + "Type": 26, + "Domains": [ + "steampowered.com", + "steamcommunity.com" + ], + "Excluded": false + }, + { + "Type": 27, + "Domains": [ + "chart.io", + "chartio.com" + ], + "Excluded": false + }, + { + "Type": 28, + "Domains": [ + "gotomeeting.com", + "citrixonline.com" + ], + "Excluded": false + }, + { + "Type": 29, + "Domains": [ + "gogoair.com", + "gogoinflight.com" + ], + "Excluded": false + }, + { + "Type": 30, + "Domains": [ + "mysql.com", + "oracle.com" + ], + "Excluded": false + }, + { + "Type": 31, + "Domains": [ + "discover.com", + "discovercard.com" + ], + "Excluded": false + }, + { + "Type": 32, + "Domains": [ + "dcu.org", + "dcu-online.org" + ], + "Excluded": false + }, + { + "Type": 33, + "Domains": [ + "healthcare.gov", + "cms.gov" + ], + "Excluded": false + }, + { + "Type": 34, + "Domains": [ + "pepco.com", + "pepcoholdings.com" + ], + "Excluded": false + }, + { + "Type": 35, + "Domains": [ + "century21.com", + "21online.com" + ], + "Excluded": false + }, + { + "Type": 36, + "Domains": [ + "comcast.com", + "comcast.net", + "xfinity.com" + ], + "Excluded": false + }, + { + "Type": 37, + "Domains": [ + "cricketwireless.com", + "aiowireless.com" + ], + "Excluded": false + }, + { + "Type": 38, + "Domains": [ + "mandtbank.com", + "mtb.com" + ], + "Excluded": false + }, + { + "Type": 39, + "Domains": [ + "dropbox.com", + "getdropbox.com" + ], + "Excluded": false + }, + { + "Type": 40, + "Domains": [ + "snapfish.com", + "snapfish.ca" + ], + "Excluded": false + }, + { + "Type": 41, + "Domains": [ + "alibaba.com", + "aliexpress.com", + "aliyun.com", + "net.cn", + "www.net.cn" + ], + "Excluded": false + }, + { + "Type": 42, + "Domains": [ + "playstation.com", + "sonyentertainmentnetwork.com" + ], + "Excluded": false + }, + { + "Type": 43, + "Domains": [ + "mercadolivre.com", + "mercadolivre.com.br", + "mercadolibre.com", + "mercadolibre.com.ar", + "mercadolibre.com.mx" + ], + "Excluded": false + }, + { + "Type": 44, + "Domains": [ + "zendesk.com", + "zopim.com" + ], + "Excluded": false + }, + { + "Type": 45, + "Domains": [ + "autodesk.com", + "tinkercad.com" + ], + "Excluded": false + }, + { + "Type": 46, + "Domains": [ + "railnation.ru", + "railnation.de", + "rail-nation.com", + "railnation.gr", + "railnation.us", + "trucknation.de", + "traviangames.com" + ], + "Excluded": false + }, + { + "Type": 47, + "Domains": [ + "wpcu.coop", + "wpcuonline.com" + ], + "Excluded": false + }, + { + "Type": 48, + "Domains": [ + "mathletics.com", + "mathletics.com.au", + "mathletics.co.uk" + ], + "Excluded": false + }, + { + "Type": 49, + "Domains": [ + "discountbank.co.il", + "telebank.co.il" + ], + "Excluded": false + }, + { + "Type": 50, + "Domains": [ + "mi.com", + "xiaomi.com" + ], + "Excluded": false + }, + { + "Type": 52, + "Domains": [ + "postepay.it", + "poste.it" + ], + "Excluded": false + }, + { + "Type": 51, + "Domains": [ + "facebook.com", + "messenger.com" + ], + "Excluded": false + }, + { + "Type": 53, + "Domains": [ + "skysports.com", + "skybet.com", + "skyvegas.com" + ], + "Excluded": false + }, + { + "Type": 54, + "Domains": [ + "disneymoviesanywhere.com", + "go.com", + "disney.com", + "dadt.com" + ], + "Excluded": false + }, + { + "Type": 55, + "Domains": [ + "pokemon-gl.com", + "pokemon.com" + ], + "Excluded": false + }, + { + "Type": 56, + "Domains": [ + "myuv.com", + "uvvu.com" + ], + "Excluded": false + }, + { + "Type": 58, + "Domains": [ + "mdsol.com", + "imedidata.com" + ], + "Excluded": false + }, + { + "Type": 57, + "Domains": [ + "bank-yahav.co.il", + "bankhapoalim.co.il" + ], + "Excluded": false + }, + { + "Type": 59, + "Domains": [ + "sears.com", + "shld.net" + ], + "Excluded": false + }, + { + "Type": 60, + "Domains": [ + "xiami.com", + "alipay.com" + ], + "Excluded": false + }, + { + "Type": 61, + "Domains": [ + "belkin.com", + "seedonk.com" + ], + "Excluded": false + }, + { + "Type": 62, + "Domains": [ + "turbotax.com", + "intuit.com" + ], + "Excluded": false + }, + { + "Type": 63, + "Domains": [ + "shopify.com", + "myshopify.com" + ], + "Excluded": false + }, + { + "Type": 64, + "Domains": [ + "ebay.com", + "ebay.de", + "ebay.ca", + "ebay.in", + "ebay.co.uk", + "ebay.com.au" + ], + "Excluded": false + }, + { + "Type": 65, + "Domains": [ + "techdata.com", + "techdata.ch" + ], + "Excluded": false + }, + { + "Type": 66, + "Domains": [ + "schwab.com", + "schwabplan.com" + ], + "Excluded": false + }, + { + "Type": 68, + "Domains": [ + "tesla.com", + "teslamotors.com" + ], + "Excluded": false + }, + { + "Type": 69, + "Domains": [ + "morganstanley.com", + "morganstanleyclientserv.com", + "stockplanconnect.com", + "ms.com" + ], + "Excluded": false + }, + { + "Type": 70, + "Domains": [ + "taxact.com", + "taxactonline.com" + ], + "Excluded": false + }, + { + "Type": 71, + "Domains": [ + "mediawiki.org", + "wikibooks.org", + "wikidata.org", + "wikimedia.org", + "wikinews.org", + "wikipedia.org", + "wikiquote.org", + "wikisource.org", + "wikiversity.org", + "wikivoyage.org", + "wiktionary.org" + ], + "Excluded": false + } +] \ No newline at end of file diff --git a/src/api/core/mod.rs b/src/api/core/mod.rs index 7d4f146..17118f6 100644 --- a/src/api/core/mod.rs +++ b/src/api/core/mod.rs @@ -71,7 +71,7 @@ use rocket_contrib::{Json, Value}; use db::DbConn; -use api::JsonResult; +use api::{JsonResult, EmptyResult}; use auth::Headers; #[put("/devices/identifier//clear-token")] @@ -88,23 +88,54 @@ fn put_device_token(uuid: String, conn: DbConn) -> JsonResult { #[derive(Deserialize, Debug)] #[allow(non_snake_case)] struct EquivDomainData { - ExcludedGlobalEquivalentDomains: Vec, - EquivalentDomains: Vec>, + ExcludedGlobalEquivalentDomains: Option>, + EquivalentDomains: Option>>, } +#[derive(Serialize, Deserialize, Debug)] +#[allow(non_snake_case)] +struct GlobalDomain { + Type: i32, + Domains: Vec, + Excluded: bool, +} + +const GLOBAL_DOMAINS: &'static str = include_str!("global_domains.json"); + #[get("/settings/domains")] -fn get_eq_domains() -> JsonResult { - err!("Not implemented") +fn get_eq_domains(headers: Headers, conn: DbConn) -> JsonResult { + let user = headers.user; + use serde_json::from_str; + + let equivalent_domains: Vec> = from_str(&user.equivalent_domains).unwrap(); + let excluded_globals: Vec = from_str(&user.excluded_globals).unwrap(); + + let mut globals: Vec = from_str(GLOBAL_DOMAINS).unwrap(); + + for global in &mut globals { + global.Excluded = excluded_globals.contains(&global.Type); + } + + Ok(Json(json!({ + "EquivalentDomains": equivalent_domains, + "GlobalEquivalentDomains": globals + }))) } #[post("/settings/domains", data = "")] -fn post_eq_domains(data: Json, headers: Headers, conn: DbConn) -> JsonResult { - let excluded_globals = &data.ExcludedGlobalEquivalentDomains; - let equivalent_domains = &data.EquivalentDomains; +fn post_eq_domains(data: Json, headers: Headers, conn: DbConn) -> EmptyResult { + let data: EquivDomainData = data.into_inner(); - let user = headers.user; + let excluded_globals = data.ExcludedGlobalEquivalentDomains.unwrap_or(Vec::new()); + let equivalent_domains = data.EquivalentDomains.unwrap_or(Vec::new()); - //BODY. "{\"ExcludedGlobalEquivalentDomains\":[2],\"EquivalentDomains\":[[\"example.org\",\"example.net\"]]}" + let mut user = headers.user; + use serde_json::to_string; - err!("Not implemented") + user.excluded_globals = to_string(&excluded_globals).unwrap_or("[]".to_string()); + user.equivalent_domains = to_string(&equivalent_domains).unwrap_or("[]".to_string()); + + user.save(&conn); + + Ok(()) }