mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Http_server: Add special_pages_safelist
This commit is contained in:
parent
c1e66a7e7d
commit
1dbe526051
@ -44,6 +44,7 @@ public class Gfo_cmd_arg_itm {
|
||||
}
|
||||
}
|
||||
public boolean Val_as_bool() {return Bool_.Cast(val);}
|
||||
public boolean Val_as_bool_or(boolean or) {return val == null ? or : String_.Eq((String)val, "y");}
|
||||
public String Val_as_str_or(String or) {return val == null ? or : (String)val;}
|
||||
public String Val_as_str() {return (String)val;}
|
||||
public int Val_as_int_or(int or) {return val == null ? or : Int_.parse_or((String)val, or);}
|
||||
|
@ -18,12 +18,15 @@ import gplx.core.net.qargs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.specials.*; import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
|
||||
import gplx.xowa.addons.apps.cfgs.*;
|
||||
import gplx.xowa.parsers.amps.*;
|
||||
import gplx.xowa.htmls.core.htmls.*;
|
||||
class Xofulltext_searcher_html extends Xow_special_wtr__base implements Mustache_doc_itm {
|
||||
private final Hash_adp props = Hash_adp_.New();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
public Xofulltext_searcher_html(Xocfg_mgr cfg_mgr, Gfo_qarg_mgr url_args, Xow_wiki wiki, Guid_adp page_guid, boolean lucene_exists) {
|
||||
String search_text = url_args.Read_str_or("search", "");
|
||||
search_text = String_.Replace(search_text, "_", " "); // xofulltext_searcher.js chains multiple words with "_"; convert back to space
|
||||
props.Add("qarg_search", search_text);
|
||||
props.Add("qarg_search", Xoh_html_wtr_escaper.Escape_str(Xop_amp_mgr.Instance, tmp_bfr, search_text));
|
||||
props.Add("page_guid", page_guid.To_str());
|
||||
props.Add("cur_wiki", wiki.Domain_str());
|
||||
|
||||
|
@ -92,6 +92,15 @@ public class Xoa_boot_mgr {
|
||||
server_mgr.Home_(Bry_.new_u8(arg_mgr.Http__home_page()));
|
||||
server_mgr.Wkr_pool().Init(arg_mgr.Http__max_clients(), arg_mgr.Http__max_clients_timeout());
|
||||
|
||||
// add safelisted Special pages
|
||||
String special_pages_safelist = arg_mgr.Http__special_pages_safelist();
|
||||
if (String_.Len_gt_0(special_pages_safelist)) {
|
||||
byte[][] special_pages = Bry_split_.Split(Bry_.new_u8(special_pages_safelist), Byte_ascii.Pipe);
|
||||
for (byte[] special_page : special_pages) {
|
||||
app.Special_regy().Safelist_pages().Add_as_key_and_val(special_page);
|
||||
}
|
||||
}
|
||||
|
||||
Gfo_usr_dlg_.Instance.Log_wkr().Log_to_session_fmt("app.boot:app.init");
|
||||
app.Init_by_app();
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ public class Xoa_cmd_arg_mgr {
|
||||
public String Http__home_page() {return http__home_page;} private String http__home_page;
|
||||
public int Http__max_clients() {return http__max_clients;} private int http__max_clients;
|
||||
public int Http__max_clients_timeout() {return http__max_clients_timeout;} private int http__max_clients_timeout;
|
||||
public String Http__special_pages_safelist() {return http__special_pages_safelist;} private String http__special_pages_safelist;
|
||||
public String Gui__home_page() {return gui__home_page;} private String gui__home_page;
|
||||
public boolean Process(Gfo_usr_dlg usr_dlg, String[] args, Io_url jar_dir) {
|
||||
arg_mgr.Parse(args);
|
||||
@ -48,6 +49,7 @@ public class Xoa_cmd_arg_mgr {
|
||||
this.http__home_page = arg_mgr.Get_by("http_server_home").Val_as_str_or("home/wiki/Main_Page");
|
||||
this.http__max_clients = arg_mgr.Get_by("http_server.max_clients").Val_as_int_or(0);
|
||||
this.http__max_clients_timeout = arg_mgr.Get_by("http_server.max_clients_timeout").Val_as_int_or(50);
|
||||
this.http__special_pages_safelist = arg_mgr.Get_by("http_server.special_pages_safelist").Val_as_str_or("");
|
||||
this.gui__home_page = arg_mgr.Get_by("url").Val_as_str_or(null);
|
||||
this.fsys__bin_dir = arg_mgr.Get_by("bin_dir_name").Val_as_str_or(Bin_dir_name());
|
||||
return true;
|
||||
@ -78,6 +80,7 @@ public class Xoa_cmd_arg_mgr {
|
||||
, Gfo_cmd_arg_itm_.opt_("http_server_home").Example_("home/wiki/Main_Page").Note_("applies to --app_mode http_server; default home page for root address. EX: navigating to localhost:8080 will navigate to localhost:8080/home/wiki/Main_Page. To navigate to a wiki's main page, use the domain name only. EX: --http_server_home en.wikipedia.org")
|
||||
, Gfo_cmd_arg_itm_.opt_("http_server.max_clients").Example_("15").Note_("applies to --app_mode http_server; limits maximum number of concurrent connections; default is 0 (no limit)")
|
||||
, Gfo_cmd_arg_itm_.opt_("http_server.max_clients_timeout").Example_("50").Note_("applies to --app_mode http_server; time in milliseconds to wait before checking again to see if a connection is free; default is 50 (wait 50 ms)")
|
||||
, Gfo_cmd_arg_itm_.opt_("http_server.special_pages_safelist").Example_("Random|XowaSearch|AllPages").Note_("specifies list of permitted special pages; special-page name is case-insensitive and must be separated by pipes (|); default is '' which permits all special pages")
|
||||
, Gfo_cmd_arg_itm_.sys_("show_license").Dflt_(true)
|
||||
, Gfo_cmd_arg_itm_.sys_("show_args").Dflt_(true)
|
||||
, Gfo_cmd_arg_itm_.new_(Gfo_cmd_arg_itm_.Tid_system, "help", Bool_.N, Gfo_cmd_arg_itm_.Val_tid_string)
|
||||
|
@ -18,6 +18,9 @@ import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.entitys.*;
|
||||
import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.xndes.*;
|
||||
public class Xoh_html_wtr_escaper {
|
||||
public static String Escape_str(Xop_amp_mgr amp_mgr, Bry_bfr tmp_bfr, String src) {
|
||||
return String_.new_u8(Escape(amp_mgr, tmp_bfr, Bry_.new_u8(src)));
|
||||
}
|
||||
public static byte[] Escape(Xop_amp_mgr amp_mgr, Bry_bfr tmp_bfr, byte[] src) {
|
||||
Escape(amp_mgr, tmp_bfr, src, 0, src.length, true, false);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
|
@ -19,9 +19,10 @@ import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.guis.*; import gplx.xowa.addons.htmls.sidebars.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.apps.apis.xowa.html.*;
|
||||
import gplx.xowa.langs.vnts.*; import gplx.xowa.htmls.portal.vnts.*;
|
||||
import gplx.xowa.parsers.amps.*;
|
||||
public class Xow_portal_mgr implements Gfo_invk {
|
||||
private Xowe_wiki wiki; private boolean lang_is_rtl; private Xoapi_toggle_itm toggle_itm;
|
||||
private final Vnt_mnu_grp_fmtr vnt_menu_fmtr = new Vnt_mnu_grp_fmtr();
|
||||
@ -111,8 +112,13 @@ public class Xow_portal_mgr implements Gfo_invk {
|
||||
vnt_menu_fmtr.Init(vnt_mgr.Regy(), wiki.Domain_bry(), ttl.Full_db(), vnt_mgr.Cur_itm().Key());
|
||||
vnt_menu = wiki.Lang().Vnt_mgr().Enabled() ? vnt_menu_fmtr : null;
|
||||
}
|
||||
|
||||
// NOTE: need to escape args href for Search page b/c user can enter in quotes and apos; EX:localhost:8080/en.wikipedia.org/wiki/Special:XowaSearch?search=title:(%2Breturn%20%2B"abc") ; DATE:2017-07-16
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
div_ns_fmtr.Bld_bfr_many(tmp_bfr, Bry_.Add(Xoh_href_.Bry__wiki, ttl.Subj_txt()), subj_cls, Bry_.Add(Xoh_href_.Bry__wiki, ttl.Talk_txt()), talk_cls, vnt_menu);
|
||||
byte[] subj_href = Xoh_html_wtr_escaper.Escape(Xop_amp_mgr.Instance, tmp_bfr, Bry_.Add(Xoh_href_.Bry__wiki, ttl.Subj_txt()));
|
||||
byte[] talk_href = Xoh_html_wtr_escaper.Escape(Xop_amp_mgr.Instance, tmp_bfr, Bry_.Add(Xoh_href_.Bry__wiki, ttl.Talk_txt()));
|
||||
|
||||
div_ns_fmtr.Bld_bfr_many(tmp_bfr, subj_href, subj_cls, talk_href, talk_cls, vnt_menu);
|
||||
return tmp_bfr.To_bry_and_rls();
|
||||
}
|
||||
private byte[] Ns_cls_by_ord(Xow_ns_mgr ns_mgr, int ns_ord) {
|
||||
|
@ -22,6 +22,7 @@ import gplx.xowa.specials.xowa.system_data.*; import gplx.xowa.specials.xowa.def
|
||||
import gplx.xowa.xtns.wbases.specials.*;
|
||||
import gplx.xowa.users.data.*; import gplx.xowa.users.bmks.*;
|
||||
import gplx.xowa.specials.mgrs.*; import gplx.xowa.addons.wikis.searchs.specials.*;
|
||||
import gplx.xowa.wikis.pages.*;
|
||||
public class Xow_special_mgr {
|
||||
private final Hash_adp_bry hash;
|
||||
private Xoa_app app;
|
||||
@ -89,11 +90,23 @@ public class Xow_special_mgr {
|
||||
public void Special__gen(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
int slash_pos = Bry_find_.Find_fwd(ttl.Page_txt_wo_qargs(), Xoa_ttl.Subpage_spr); // check for slash
|
||||
byte[] special_name = slash_pos == Bry_find_.Not_found
|
||||
? ttl.Base_txt_wo_qarg() // no slash found; use base_txt; ignore qry args and just get page_names; EX: Search/Earth?fulltext=y; Allpages?from=Earth...
|
||||
: Bry_.Mid(ttl.Page_txt_wo_qargs(), 0, slash_pos); // slash found; use root page; EX: Special:ItemByTitle/enwiki/Earth
|
||||
? ttl.Base_txt_wo_qarg() // slash absent; use base_txt; ignore qry args and just get page_names; EX: Search/Earth?fulltext=y; Allpages?from=Earth...
|
||||
: Bry_.Mid(ttl.Page_txt_wo_qargs(), 0, slash_pos); // slash exists; use root page; EX: Special:ItemByTitle/enwiki/Earth
|
||||
special_name = Xoa_ttl.Replace_spaces(special_name); // handle spaces; EX:Spezial:Zufällige_Seite
|
||||
|
||||
Xow_special_page special = (Xow_special_page)hash.Get_by_bry(special_name);
|
||||
if (special != null) { // special found; generate it;
|
||||
// check safelisted pages; DATE:2017-07-22
|
||||
Hash_adp safelist = app.Special_regy().Safelist_pages();
|
||||
if (safelist.Count() > 0) { // safelist pages enabled
|
||||
if (!safelist.Has(special_name)) {
|
||||
byte[] safelist_failed = Bry_.new_u8("This special page is not listed in the special_pages safelist. Re-run XOWA and list it in the command-line arguments similar to this: \"--http_server.special_pages_safelist " + String_.new_u8(special_name) + "\"");
|
||||
Xopage_html_data page_data = new Xopage_html_data(special.Special__meta().Display_ttl(), safelist_failed);
|
||||
page_data.Apply(page);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
special = special.Special__clone();
|
||||
page.Db().Page().Modified_on_(Datetime_now.Get());
|
||||
try {special.Special__gen(wiki, page, url, ttl);}
|
||||
|
@ -17,6 +17,7 @@ package gplx.xowa.specials.mgrs; import gplx.*; import gplx.xowa.*; import gplx.
|
||||
import gplx.xowa.specials.*;
|
||||
public class Xoa_special_regy {
|
||||
private final Ordered_hash hash = Ordered_hash_.New_bry(); // NOTE: case-sensitive; case-insensitive requires lang, but regy is at app level
|
||||
public Hash_adp_bry Safelist_pages() {return safelist_pages;} private final Hash_adp_bry safelist_pages = Hash_adp_bry.ci_u8(gplx.xowa.langs.cases.Xol_case_mgr_.U8());
|
||||
public int Len() {return hash.Len();}
|
||||
public Xow_special_page Get_at(int i) {return (Xow_special_page)hash.Get_at(i);}
|
||||
public Xow_special_page Get_by_or_null(byte[] key) {return (Xow_special_page)hash.Get_by(key);}
|
||||
|
Loading…
Reference in New Issue
Block a user