diff --git a/Cargo.lock b/Cargo.lock index 71ad5fc0b..4f86b1df4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2037,6 +2037,7 @@ dependencies = [ "parity-hash-fetch 1.11.0", "parity-reactor 0.1.0", "parity-ui 1.11.0", + "parity-ui-deprecation 1.10.0", "parity-version 1.11.0", "parking_lot 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2256,6 +2257,13 @@ dependencies = [ "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parity-ui-deprecation" +version = "1.10.0" +dependencies = [ + "parity-dapps-glue 1.9.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "parity-ui-dev" version = "1.9.0" diff --git a/dapps/Cargo.toml b/dapps/Cargo.toml index d63150b0a..fdd497763 100644 --- a/dapps/Cargo.toml +++ b/dapps/Cargo.toml @@ -35,6 +35,7 @@ node-health = { path = "./node-health" } parity-hash-fetch = { path = "../hash-fetch" } parity-reactor = { path = "../util/reactor" } parity-ui = { path = "./ui" } +parity-ui-deprecation = { path = "./ui-deprecation" } keccak-hash = { path = "../util/hash" } parity-version = { path = "../util/version" } registrar = { path = "../registrar" } diff --git a/dapps/src/apps/mod.rs b/dapps/src/apps/mod.rs index 0b8865e76..21947b928 100644 --- a/dapps/src/apps/mod.rs +++ b/dapps/src/apps/mod.rs @@ -23,7 +23,6 @@ use page; use proxypac::ProxyPac; use web::Web; use fetch::Fetch; -use parity_ui; use {WebProxyTokens, ParentFrameSettings}; mod app; @@ -43,11 +42,15 @@ pub const WEB_PATH: &'static str = "web"; pub const URL_REFERER: &'static str = "__referer="; pub fn utils(pool: CpuPool) -> Box { - Box::new(page::builtin::Dapp::new(pool, parity_ui::App::default())) + Box::new(page::builtin::Dapp::new(pool, ::parity_ui::App::default())) } pub fn ui(pool: CpuPool) -> Box { - Box::new(page::builtin::Dapp::with_fallback_to_index(pool, parity_ui::App::default())) + Box::new(page::builtin::Dapp::with_fallback_to_index(pool, ::parity_ui::App::default())) +} + +pub fn ui_deprecation(pool: CpuPool) -> Box { + Box::new(page::builtin::Dapp::with_fallback_to_index(pool, ::parity_ui_deprecation::App::default())) } pub fn ui_redirection(embeddable: Option) -> Box { @@ -77,13 +80,13 @@ pub fn all_endpoints( // NOTE [ToDr] Dapps will be currently embeded on 8180 pages.insert( "ui".into(), - Box::new(page::builtin::Dapp::new_safe_to_embed(pool.clone(), parity_ui::App::default(), embeddable.clone())) + Box::new(page::builtin::Dapp::new_safe_to_embed(pool.clone(), ::parity_ui::App::default(), embeddable.clone())) ); // old version pages.insert( "v1".into(), Box::new({ - let mut page = page::builtin::Dapp::new_safe_to_embed(pool.clone(), parity_ui::old::App::default(), embeddable.clone()); + let mut page = page::builtin::Dapp::new_safe_to_embed(pool.clone(), ::parity_ui::old::App::default(), embeddable.clone()); // allow JS eval on old Wallet page.allow_js_eval(); page diff --git a/dapps/src/lib.rs b/dapps/src/lib.rs index 482ee3959..c4e244b25 100644 --- a/dapps/src/lib.rs +++ b/dapps/src/lib.rs @@ -39,6 +39,7 @@ extern crate node_health; extern crate parity_dapps_glue as parity_dapps; extern crate parity_hash_fetch as hash_fetch; extern crate parity_ui; +extern crate parity_ui_deprecation; extern crate keccak_hash as hash; extern crate parity_version; extern crate registrar; @@ -159,6 +160,7 @@ impl Middleware { registrar: Arc>, sync_status: Arc, fetch: F, + info_page_only: bool, ) -> Self { let content_fetcher = Arc::new(apps::fetcher::ContentFetcher::new( hash_fetch::urlhint::URLHintContract::new(registrar), @@ -166,6 +168,23 @@ impl Middleware { fetch.clone(), pool.clone(), ).embeddable_on(None).allow_dapps(false)); + + if info_page_only { + let mut special = HashMap::default(); + special.insert(router::SpecialEndpoint::Home, Some(apps::ui_deprecation(pool.clone()))); + + return Middleware { + endpoints: Default::default(), + router: router::Router::new( + content_fetcher, + None, + special, + None, + dapps_domain.to_owned(), + ), + } + } + let special = { let mut special = special_endpoints( pool.clone(), diff --git a/dapps/src/router.rs b/dapps/src/router.rs index e5770ca72..d5f464704 100644 --- a/dapps/src/router.rs +++ b/dapps/src/router.rs @@ -150,10 +150,20 @@ impl Router { } }, // RPC by default - _ => { + _ if self.special.contains_key(&SpecialEndpoint::Rpc) => { trace!(target: "dapps", "Resolving to RPC call."); Response::None(req) - } + }, + // 404 otherwise + _ => { + Response::Some(Box::new(future::ok(handlers::ContentHandler::error( + hyper::StatusCode::NotFound, + "404 Not Found", + "Requested content was not found.", + None, + self.embeddable_on.clone(), + ).into()))) + }, }) } } diff --git a/dapps/src/tests/helpers/mod.rs b/dapps/src/tests/helpers/mod.rs index 3a1311578..41df0db61 100644 --- a/dapps/src/tests/helpers/mod.rs +++ b/dapps/src/tests/helpers/mod.rs @@ -240,6 +240,7 @@ impl Server { registrar, sync_status, fetch, + false, ) } else { Middleware::dapps( diff --git a/dapps/ui-deprecation/Cargo.toml b/dapps/ui-deprecation/Cargo.toml new file mode 100644 index 000000000..f4479c236 --- /dev/null +++ b/dapps/ui-deprecation/Cargo.toml @@ -0,0 +1,18 @@ +[package] +description = "Parity UI deprecation notice." +name = "parity-ui-deprecation" +version = "1.10.0" +license = "GPL-3.0" +authors = ["Parity Technologies "] +build = "build.rs" + +[features] +default = ["with-syntex", "use-precompiled-js"] +use-precompiled-js = ["parity-dapps-glue/use-precompiled-js"] +with-syntex = ["parity-dapps-glue/with-syntex"] + +[build-dependencies] +parity-dapps-glue = "1.9" + +[dependencies] +parity-dapps-glue = "1.9" diff --git a/dapps/ui-deprecation/build.rs b/dapps/ui-deprecation/build.rs new file mode 100644 index 000000000..c427f3d54 --- /dev/null +++ b/dapps/ui-deprecation/build.rs @@ -0,0 +1,21 @@ +// Copyright 2015-2018 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +extern crate parity_dapps_glue; + +fn main() { + parity_dapps_glue::generate(); +} diff --git a/dapps/ui-deprecation/build/index.html b/dapps/ui-deprecation/build/index.html new file mode 100644 index 000000000..07059743c --- /dev/null +++ b/dapps/ui-deprecation/build/index.html @@ -0,0 +1,119 @@ + + + + + + Parity + + + +
+
+
+

The Parity UI has been split off into a standalone project.

+

Get the standalone Parity UI from here

+

+ +

+
+
+
+ + diff --git a/dapps/ui-deprecation/src/lib.rs b/dapps/ui-deprecation/src/lib.rs new file mode 100644 index 000000000..79a4a4249 --- /dev/null +++ b/dapps/ui-deprecation/src/lib.rs @@ -0,0 +1,21 @@ +// Copyright 2015-2018 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +#[cfg(feature = "with-syntex")] +include!(concat!(env!("OUT_DIR"), "/lib.rs")); + +#[cfg(not(feature = "with-syntex"))] +include!("lib.rs.in"); diff --git a/dapps/ui-deprecation/src/lib.rs.in b/dapps/ui-deprecation/src/lib.rs.in new file mode 100644 index 000000000..892ebbded --- /dev/null +++ b/dapps/ui-deprecation/src/lib.rs.in @@ -0,0 +1,55 @@ +// Copyright 2015-2018 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +extern crate parity_dapps_glue; + +use std::collections::HashMap; +use parity_dapps_glue::{WebApp, File, Info}; + +#[derive(WebAppFiles)] +#[webapp(path = "../build")] +pub struct App { + pub files: HashMap<&'static str, File>, +} + +impl Default for App { + fn default() -> App { + App { + files: Self::files(), + } + } +} + +impl WebApp for App { + fn file(&self, path: &str) -> Option<&File> { + self.files.get(path) + } + + fn info(&self) -> Info { + Info { + name: "Parity Wallet info page", + version: env!("CARGO_PKG_VERSION"), + author: "Parity ", + description: "Deprecation notice for Parity Wallet", + icon_url: "icon.png", + } + } +} + +#[test] +fn test_js() { + parity_dapps_glue::js::build(env!("CARGO_MANIFEST_DIR"), "build"); +} diff --git a/parity/configuration.rs b/parity/configuration.rs index d1c02d5bc..96f819cba 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -581,11 +581,13 @@ impl Configuration { } fn ui_config(&self) -> UiConfiguration { + let ui = self.ui_enabled(); UiConfiguration { - enabled: self.ui_enabled(), + enabled: ui.enabled, interface: self.ui_interface(), port: self.ui_port(), hosts: self.ui_hosts(), + info_page_only: ui.info_page_only, } } @@ -1176,16 +1178,22 @@ impl Configuration { into_secretstore_service_contract_address(self.args.arg_secretstore_doc_sretr_contract.as_ref()) } - fn ui_enabled(&self) -> bool { + fn ui_enabled(&self) -> UiEnabled { if self.args.flag_force_ui { - return true; + return UiEnabled { + enabled: true, + info_page_only: false, + }; } let ui_disabled = self.args.arg_unlock.is_some() || self.args.flag_geth || self.args.flag_no_ui; - self.args.cmd_ui && !ui_disabled && cfg!(feature = "ui-enabled") + return UiEnabled { + enabled: (self.args.cmd_ui || !ui_disabled) && cfg!(feature = "ui-enabled"), + info_page_only: !self.args.cmd_ui, + } } fn verifier_settings(&self) -> VerifierSettings { @@ -1206,6 +1214,12 @@ impl Configuration { } } +#[derive(Debug, PartialEq, Eq, Clone, Copy)] +struct UiEnabled { + pub enabled: bool, + pub info_page_only: bool, +} + fn into_secretstore_service_contract_address(s: &str) -> Result, String> { match s { "none" => Ok(None), @@ -1418,15 +1432,16 @@ mod tests { origins: Some(vec!["parity://*".into(),"chrome-extension://*".into(), "moz-extension://*".into()]), hosts: Some(vec![]), signer_path: expected.into(), - ui_address: None, + ui_address: Some("127.0.0.1:8180".into()), dapps_address: Some("127.0.0.1:8545".into()), support_token_api: true, max_connections: 100, }, UiConfiguration { - enabled: false, + enabled: true, interface: "127.0.0.1".into(), port: 8180, hosts: Some(vec![]), + info_page_only: true, }, LogConfig { color: true, mode: None, @@ -1698,10 +1713,26 @@ mod tests { // when let conf0 = parse(&["parity", "--geth"]); let conf1 = parse(&["parity", "--geth", "--force-ui"]); + let conf2 = parse(&["parity", "--geth", "ui"]); + let conf3 = parse(&["parity"]); // then - assert_eq!(conf0.ui_enabled(), false); - assert_eq!(conf1.ui_enabled(), true); + assert_eq!(conf0.ui_enabled(), UiEnabled { + enabled: false, + info_page_only: true, + }); + assert_eq!(conf1.ui_enabled(), UiEnabled { + enabled: true, + info_page_only: false, + }); + assert_eq!(conf2.ui_enabled(), UiEnabled { + enabled: true, + info_page_only: false, + }); + assert_eq!(conf3.ui_enabled(), UiEnabled { + enabled: true, + info_page_only: true, + }); } #[test] @@ -1712,7 +1743,10 @@ mod tests { let conf0 = parse(&["parity", "--unlock", "0x0"]); // then - assert_eq!(conf0.ui_enabled(), false); + assert_eq!(conf0.ui_enabled(), UiEnabled { + enabled: false, + info_page_only: true, + }); } #[test] @@ -1730,11 +1764,45 @@ mod tests { // then assert_eq!(conf0.directories().signer, "signer".to_owned()); assert_eq!(conf0.ui_config(), UiConfiguration { - enabled: false, + enabled: true, interface: "127.0.0.1".into(), port: 8180, hosts: Some(vec![]), + info_page_only: true, }); + + assert!(conf1.ws_config().unwrap().hosts.is_some()); + assert_eq!(conf1.ws_config().unwrap().origins, None); + assert_eq!(conf1.directories().signer, "signer".to_owned()); + assert_eq!(conf1.ui_config(), UiConfiguration { + enabled: true, + interface: "127.0.0.1".into(), + port: 8180, + hosts: Some(vec![]), + info_page_only: true, + }); + assert_eq!(conf1.dapps_config().extra_embed_on, vec![("127.0.0.1".to_owned(), 3000)]); + + assert!(conf2.ws_config().unwrap().hosts.is_some()); + assert_eq!(conf2.directories().signer, "signer".to_owned()); + assert_eq!(conf2.ui_config(), UiConfiguration { + enabled: true, + interface: "127.0.0.1".into(), + port: 3123, + hosts: Some(vec![]), + info_page_only: true, + }); + + assert!(conf3.ws_config().unwrap().hosts.is_some()); + assert_eq!(conf3.directories().signer, "signer".to_owned()); + assert_eq!(conf3.ui_config(), UiConfiguration { + enabled: true, + interface: "test".into(), + port: 8180, + hosts: Some(vec![]), + info_page_only: true, + }); + assert!(conf4.ws_config().unwrap().hosts.is_some()); assert_eq!(conf4.directories().signer, "signer".to_owned()); assert_eq!(conf4.ui_config(), UiConfiguration { @@ -1742,8 +1810,9 @@ mod tests { interface: "127.0.0.1".into(), port: 8180, hosts: Some(vec![]), + info_page_only: false, }); - assert!(conf5.ws_config().unwrap().hosts.is_some()); + assert!(conf5.ws_config().unwrap().hosts.is_some()); assert_eq!(conf5.directories().signer, "signer".to_owned()); assert_eq!(conf5.ui_config(), UiConfiguration { @@ -1751,33 +1820,8 @@ mod tests { interface: "127.0.0.1".into(), port: 8180, hosts: Some(vec![]), + info_page_only: false, }); - assert!(conf5.ws_config().unwrap().hosts.is_some()); - assert_eq!(conf1.directories().signer, "signer".to_owned()); - assert_eq!(conf1.ui_config(), UiConfiguration { - enabled: false, - interface: "127.0.0.1".into(), - port: 8180, - hosts: Some(vec![]), - }); - assert_eq!(conf1.dapps_config().extra_embed_on, vec![("127.0.0.1".to_owned(), 3000)]); - assert_eq!(conf1.ws_config().unwrap().origins, None); - assert_eq!(conf2.directories().signer, "signer".to_owned()); - assert_eq!(conf2.ui_config(), UiConfiguration { - enabled: false, - interface: "127.0.0.1".into(), - port: 3123, - hosts: Some(vec![]), - }); - assert!(conf2.ws_config().unwrap().hosts.is_some()); - assert_eq!(conf3.directories().signer, "signer".to_owned()); - assert_eq!(conf3.ui_config(), UiConfiguration { - enabled: false, - interface: "test".into(), - port: 8180, - hosts: Some(vec![]), - }); - assert!(conf3.ws_config().unwrap().hosts.is_some()); } #[test] diff --git a/parity/dapps.rs b/parity/dapps.rs index 42ff21b58..2219f7cbe 100644 --- a/parity/dapps.rs +++ b/parity/dapps.rs @@ -164,6 +164,7 @@ pub struct Dependencies { pub pool: CpuPool, pub signer: Arc, pub ui_address: Option<(String, u16)>, + pub info_page_only: bool, } pub fn new(configuration: Configuration, deps: Dependencies) -> Result, String> { @@ -281,6 +282,7 @@ mod server { deps.contract_client, deps.sync_status, deps.fetch, + deps.info_page_only, )) } diff --git a/parity/rpc.rs b/parity/rpc.rs index a1b2271c4..66a2715d4 100644 --- a/parity/rpc.rs +++ b/parity/rpc.rs @@ -74,6 +74,7 @@ pub struct UiConfiguration { pub interface: String, pub port: u16, pub hosts: Option>, + pub info_page_only: bool, } impl UiConfiguration { @@ -110,10 +111,11 @@ impl From for HttpConfiguration { impl Default for UiConfiguration { fn default() -> Self { UiConfiguration { - enabled: false, + enabled: cfg!(feature = "ui-enabled"), port: 8180, interface: "127.0.0.1".into(), hosts: Some(vec![]), + info_page_only: true, } } } @@ -168,7 +170,7 @@ impl Default for WsConfiguration { hosts: Some(Vec::new()), signer_path: replace_home(&data_dir, "$BASE/signer").into(), support_token_api: true, - ui_address: None, + ui_address: Some("127.0.0.1:8180".into()), dapps_address: Some("127.0.0.1:8545".into()), } } diff --git a/parity/run.rs b/parity/run.rs index 8fa76693b..4cc7b29b0 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -365,6 +365,7 @@ fn execute_light_impl(cmd: RunCmd, logger: Arc) -> Result(cmd: RunCmd, logger: Arc, on_client_rq: pool: cpu_pool.clone(), signer: signer_service.clone(), ui_address: cmd.ui_conf.redirection_address(), + info_page_only: cmd.ui_conf.info_page_only, }) }; let dapps_middleware = dapps::new(cmd.dapps_conf.clone(), dapps_deps.clone())?; @@ -970,7 +972,7 @@ impl RunningClient { } pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc) -> Result<(bool, Option), String> { - if cmd.ui_conf.enabled { + if cmd.ui_conf.enabled && !cmd.ui_conf.info_page_only { warn!("{}", Style::new().bold().paint("Parity browser interface is deprecated. It's going to be removed in the next version, use standalone Parity UI instead.")); warn!("{}", Style::new().bold().paint("Standalone Parity UI: https://github.com/Parity-JS/shell/releases")); }