diff --git a/README.md b/README.md index 3287969..906e929 100644 --- a/README.md +++ b/README.md @@ -14,23 +14,23 @@ | Clearnet | TOR | I2P | Country | |-|-|-|-| | [librex.beparanoid.de](https://librex.beparanoid.de/) | [βœ…](http://librex.2356uhnbpv5nk3bni5bv6jg2cd6lgj664kwx3lhyelstpttpyv4kk2qd.onion/) | ❌ | πŸ‡­πŸ‡Ί HU (OFFICIAL INSTANCE) | -| [librex.extravi.dev](https://librex.extravi.dev/) | [βœ…](http://ncblhz7q4sfbf755bdbhebfzxcpypz7ewafgi4agatecojz7pln4i3id.onion/) | [βœ…](http://rra33hiaf6nmby7jfpqe2gqmng3jnzkvbu2n7jgce7vbhoyuhzya.b32.i2p/) | πŸ‡©πŸ‡ͺ DE | | [lx.vern.cc](https://lx.vern.cc/) | [βœ…](http://lx.vernccvbvyi5qhfzyqengccj7lkove6bjot2xhh5kajhwvidqafczrad.onion/) | [βœ…](http://vernziqfqvweijfaacmwazohgpdo2bt2ib2jlupt2pwwu27bhgxq.b32.i2p/) | πŸ‡ΊπŸ‡Έ US | -| [linxer.org/search](https://linxer.org/search/) | ❌ | ❌ | πŸ‡·πŸ‡΄ RO | | [search.davidovski.xyz](https://search.davidovski.xyz/) | ❌ | ❌ | πŸ‡¬πŸ‡§ UK | | [search.funami.tech](https://search.funami.tech/) | ❌ | ❌ | πŸ‡°πŸ‡· KR | -| [librex.catalyst.sx](https://librex.catalyst.sx/) | ❌ | ❌ | πŸ‡ΊπŸ‡Έ US | | [search.madreyk.xyz](https://search.madreyk.xyz/) | ❌ | ❌ | πŸ‡©πŸ‡ͺ DE | | [search.pabloferreiro.es](https://search.pabloferreiro.es/) | ❌ | ❌ | πŸ‡©πŸ‡ͺ DE | | [buscar.weblibre.org](https://buscar.weblibre.org/) | ❌ | ❌ | πŸ‡¨πŸ‡± CL | | [search.ahwx.org](https://search.ahwx.org/) | ❌ | ❌ | πŸ‡³πŸ‡± NL | | [pufe.org](https://pufe.org/) | ❌ | ❌ | :new_zealand: NZ | +| [librex.kitscomputer.tk](https://librex.kitscomputer.tk/) | ❌ | ❌ | πŸ‡ΊπŸ‡Έ US | +| [librex.smlan.dev](https://librex.smlan.dev/) | ❌ | ❌ | πŸ‡­πŸ‡Ί HU | +| [linxer.org](https://linxer.org/search/) | ❌ | ❌ | 🏳️ DYN (FORK) |
### About LibreX -LibreX gives you results from Google, Brave, Qwant and popular torrent sites without spying on you. +LibreX gives you results from Google, Brave, Qwant, Ahmia and popular torrent sites without spying on you.

If you would like to learn more about LibreX check out the [Wiki](https://github.com/hnhx/librex/wiki). diff --git a/api.php b/api.php index 374800f..e6666bf 100644 --- a/api.php +++ b/api.php @@ -46,6 +46,15 @@ $results = get_merged_torrent_results($query_encoded); } break; + case 4: + if ($config->disable_hidden_service_search) + $results = array("error" => "disabled"); + else + { + require "engines/ahmia/hidden_service.php"; + $results = get_hidden_service_results($query_encoded); + } + break; default: require "engines/google/text.php"; $results = get_text_results($query_encoded, $page); @@ -53,5 +62,5 @@ } header("Content-Type: application/json"); - echo json_encode($results, JSON_PRETTY_PRINT); + echo json_encode($results); ?> diff --git a/config.php.example b/config.php.example index 75e9717..dca7f39 100644 --- a/config.php.example +++ b/config.php.example @@ -10,6 +10,8 @@ "disable_bittorent_search" => false, "bittorent_trackers" => "&tr=http%3A%2F%2Fnyaa.tracker.wf%3A7777%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce", + "disable_hidden_service_search" => false, + /* Preset privacy friendly frontends for users, these can be overwritten by users in settings e.g.: "invidious" => "https://yewtu.be", @@ -39,7 +41,7 @@ // CURLOPT_PROXYTYPE => CURLPROXY_HTTP, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", - CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36", + CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36", CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP, diff --git a/engines/ahmia/hidden_service.php b/engines/ahmia/hidden_service.php new file mode 100644 index 0000000..eb267e1 --- /dev/null +++ b/engines/ahmia/hidden_service.php @@ -0,0 +1,53 @@ +query("//ol[@class='searchResults']//li[@class='result']") as $result) + { + $url = "http://" . $xpath->evaluate(".//cite", $result)[0]->textContent; + $title = remove_special($xpath->evaluate(".//h4", $result)[0]->textContent); + $description = $xpath->evaluate(".//p", $result)[0]->textContent; + + array_push($results, + array ( + "title" => htmlspecialchars($title), + "url" => htmlspecialchars($url), + "base_url" => htmlspecialchars(get_base_url($url)), + "description" => htmlspecialchars($description) + ) + ); + } + + return $results; + } + + function print_hidden_service_results($results) + { + echo "
"; + + foreach($results as $result) + { + $title = $result["title"]; + $url = $result["url"]; + $base_url = $result["base_url"]; + $description = $result["description"]; + + echo "
"; + echo ""; + echo "$base_url"; + echo "

$title

"; + echo "
"; + echo "$description"; + echo "
"; + } + + echo "
"; + } +?> diff --git a/engines/google/text.php b/engines/google/text.php index 4f1a7e8..6f6447e 100644 --- a/engines/google/text.php +++ b/engines/google/text.php @@ -1,55 +1,9 @@ = 4) // currency - { - $amount_to_convert = floatval($split_query[0]); - if ($amount_to_convert != 0) - return 1; - } - else if (strpos($query_lower, "mean") && count($split_query) >= 2) // definition - { - return 2; - } - else if (strpos($query_lower, "my") !== false) - { - if (strpos($query_lower, "ip")) - { - return 3; - } - else if (strpos($query_lower, "user agent") || strpos($query_lower, "ua")) - { - return 4; - } - } - else if (strpos($query_lower, "weather") !== false) - { - return 5; - } - else if (strpos($query_lower, "tor") !== false) - { - return 6; - } - else if (3 > count(explode(" ", $query))) // wikipedia - { - return 7; - } - - return 0; - } - - function get_text_results($query, $page=0) + function get_text_results($query, $page) { global $config; $mh = curl_multi_init(); - $query_lower = strtolower($query); $query_encoded = urlencode($query); $results = array(); @@ -58,8 +12,7 @@ curl_setopt_array($google_ch, $config->curl_settings); curl_multi_add_handle($mh, $google_ch); - - $special_search = $page == 0 ? check_for_special_search($query) : 0; + $special_search = check_for_special_search($query); $special_ch = null; $url = null; if ($special_search != 0) @@ -85,13 +38,15 @@ $url = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded"; break; } - - $special_ch = curl_init($url); - curl_setopt_array($special_ch, $config->curl_settings); - curl_multi_add_handle($mh, $special_ch); + + if ($url != NULL) + { + $special_ch = curl_init($url); + curl_setopt_array($special_ch, $config->curl_settings); + curl_multi_add_handle($mh, $special_ch); + } } - $running = null; do { curl_multi_exec($mh, $running); diff --git a/instances.json b/instances.json index 4d924ae..26b538e 100644 --- a/instances.json +++ b/instances.json @@ -6,12 +6,6 @@ "i2p": null, "country": "HU" }, - { - "clearnet": "https://librex.extravi.dev/", - "tor": "http://ncblhz7q4sfbf755bdbhebfzxcpypz7ewafgi4agatecojz7pln4i3id.onion/", - "i2p": "http://rra33hiaf6nmby7jfpqe2gqmng3jnzkvbu2n7jgce7vbhoyuhzya.b32.i2p/", - "country": "DE" - }, { "clearnet": "https://search.davidovski.xyz/", "tor": null, @@ -24,12 +18,6 @@ "i2p": null, "country": "KR" }, - { - "clearnet": "https://librex.catalyst.sx/", - "tor": null, - "i2p": null, - "country": "US" - }, { "clearnet": "https://search.madreyk.xyz/", "tor": null, @@ -48,17 +36,29 @@ "i2p": null, "country": "NL" }, - { - "clearnet": "https://linxer.org/search/", - "tor": null, - "i2p": null, - "country": "RO" - }, { "clearnet": "https://pufe.org/", "tor": null, "i2p": null, "country": "NZ" + }, + { + "clearnet": "https://librex.kitscomputer.tk/", + "tor": null, + "i2p": null, + "country": "US" + }, + { + "clearnet": "https://librex.smlan.dev/", + "tor": null, + "i2p": null, + "country": "HU" + }, + { + "clearnet": "https://linxer.org/search/", + "tor": null, + "i2p": null, + "country": "DYN" } ] } diff --git a/misc/tools.php b/misc/tools.php index 45d5ca8..9b7e9ad 100644 --- a/misc/tools.php +++ b/misc/tools.php @@ -97,6 +97,51 @@ } } + function check_for_special_search($query) + { + if (isset($_COOKIE["disable_special"]) || isset($_REQUEST["disable_special"])) + return 0; + + $query_lower = strtolower($query); + $split_query = explode(" ", $query); + + if (strpos($query_lower, "to") && count($split_query) >= 4) // currency + { + $amount_to_convert = floatval($split_query[0]); + if ($amount_to_convert != 0) + return 1; + } + else if (strpos($query_lower, "mean") && count($split_query) >= 2) // definition + { + return 2; + } + else if (strpos($query_lower, "my") !== false) + { + if (strpos($query_lower, "ip")) + { + return 3; + } + else if (strpos($query_lower, "user agent") || strpos($query_lower, "ua")) + { + return 4; + } + } + else if (strpos($query_lower, "weather") !== false) + { + return 5; + } + else if ($query_lower == "tor") + { + return 6; + } + else if (3 > count(explode(" ", $query))) // wikipedia + { + return 7; + } + + return 0; + } + function get_xpath($response) { $htmlDom = new DOMDocument; @@ -127,9 +172,8 @@ function remove_special($string) { - $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens. - - return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars. + $string = preg_replace("/[\r\n]+/", "\n", $string); + return trim(preg_replace("/\s+/", ' ', $string)); } function print_elapsed_time($start_time) diff --git a/opensearch.xml.example b/opensearch.xml.example index e04cc2c..fac6052 100644 --- a/opensearch.xml.example +++ b/opensearch.xml.example @@ -1,7 +1,7 @@ LibreX - A meta search engine for Google. + A privacy respecting meta search engine. UTF-8 LibreX search diff --git a/search.php b/search.php index c03bb90..f0b444d 100644 --- a/search.php +++ b/search.php @@ -42,6 +42,7 @@ +
@@ -90,9 +91,19 @@ $results = get_merged_torrent_results($query_encoded); print_elapsed_time($start_time); print_merged_torrent_results($results); - break; } + break; + case 4: + if ($config->disable_hidden_service_search) + echo "

The host disabled this feature! :C

"; + else + { + require "engines/ahmia/hidden_service.php"; + $results = get_hidden_service_results($query_encoded); + print_elapsed_time($start_time); + print_hidden_service_results($results); + } break; default: diff --git a/static/images/hidden_service_result.png b/static/images/hidden_service_result.png new file mode 100644 index 0000000..a579cbb Binary files /dev/null and b/static/images/hidden_service_result.png differ