mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-02 08:57:19 -04:00
[ecmascript] Read also ~/.elinks/disallowed.txt
Lines in disallowed.txt may contain prefixes of bad sites. If current url matches any of line with disallowed prefixes, ecmascript is not executed. If disallowed.txt is empty or not matched, then if allow.txt is not empty, and some prefix from this file matches current url, ecmascript is allowed. If allow.txt is empty, ecmascript is allowed too, otherwise ecmascript is disabled on given page.
This commit is contained in:
parent
7ba9caf227
commit
004a778382
@ -74,6 +74,7 @@ static union option_info ecmascript_options[] = {
|
||||
static int interpreter_count;
|
||||
|
||||
static INIT_LIST_OF(struct string_list_item, allowed_urls);
|
||||
static INIT_LIST_OF(struct string_list_item, disallowed_urls);
|
||||
|
||||
char *console_log_filename;
|
||||
|
||||
@ -100,19 +101,33 @@ read_url_list(void)
|
||||
|
||||
filename = straconcat(elinks_home, STRING_DIR_SEP, ALLOWED_ECMASCRIPT_URL_PREFIXES, NULL);
|
||||
|
||||
if (!filename) {
|
||||
return;
|
||||
}
|
||||
if (filename) {
|
||||
|
||||
f = fopen(filename, "r");
|
||||
f = fopen(filename, "r");
|
||||
|
||||
if (f) {
|
||||
while (fgets(line, 4096, f)) {
|
||||
add_to_string_list(&allowed_urls, line, strlen(line) - 1);
|
||||
if (f) {
|
||||
while (fgets(line, 4096, f)) {
|
||||
add_to_string_list(&allowed_urls, line, strlen(line) - 1);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
fclose(f);
|
||||
mem_free(filename);
|
||||
}
|
||||
|
||||
filename = straconcat(elinks_home, STRING_DIR_SEP, DISALLOWED_ECMASCRIPT_URL_PREFIXES, NULL);
|
||||
|
||||
if (filename) {
|
||||
|
||||
f = fopen(filename, "r");
|
||||
|
||||
if (f) {
|
||||
while (fgets(line, 4096, f)) {
|
||||
add_to_string_list(&disallowed_urls, line, strlen(line) - 1);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
mem_free(filename);
|
||||
}
|
||||
mem_free(filename);
|
||||
}
|
||||
|
||||
int
|
||||
@ -127,7 +142,7 @@ get_ecmascript_enable(struct ecmascript_interpreter *interpreter)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (list_empty(allowed_urls)) {
|
||||
if (list_empty(allowed_urls) && list_empty(disallowed_urls)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -136,6 +151,19 @@ get_ecmascript_enable(struct ecmascript_interpreter *interpreter)
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach(item, disallowed_urls) {
|
||||
struct string *string = &item->string;
|
||||
|
||||
if (string->length <= 0) {
|
||||
continue;
|
||||
}
|
||||
if (!is_prefix(string->source, url, string->length)) {
|
||||
mem_free(url);
|
||||
move_to_top_of_list(disallowed_urls, item);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
foreach(item, allowed_urls) {
|
||||
struct string *string = &item->string;
|
||||
|
||||
@ -150,7 +178,7 @@ get_ecmascript_enable(struct ecmascript_interpreter *interpreter)
|
||||
}
|
||||
|
||||
mem_free(url);
|
||||
return 0;
|
||||
return list_empty(allowed_urls);
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#define ELINKS_TEMPNAME_PREFIX "elinks"
|
||||
|
||||
#define ALLOWED_ECMASCRIPT_URL_PREFIXES "allow.txt"
|
||||
#define DISALLOWED_ECMASCRIPT_URL_PREFIXES "disallow.txt"
|
||||
|
||||
#define DNS_CACHE_TIMEOUT 3600 /* in seconds */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user