Browse Source

Init (once again)

poesty 1 year ago
parent
commit
2ef157823b

+ 0 - 46
Dockerfile

@@ -1,46 +0,0 @@
-# syntax = edrevo/dockerfile-plus
-ARG VERSION="3.17"
-FROM alpine:${VERSION} AS librex
-WORKDIR "/var/www/html"
-
-# Docker metadata contains information about the maintainer, such as the name, repository, and support email
-# Please add any necessary information or correct any incorrect information
-# See more: https://docs.docker.com/config/labels-custom-metadata/
-LABEL name="LibreX" \
-      description="Framework and javascript free privacy respecting meta search engine" \
-      version="1.0" \
-      vendor="Hnhx Femboy<femboy.hu>" \
-      maintainer="Hnhx Femboy<femboy.hu>, Junior L. Botelho<juniorbotelho.com.br>" \
-      url="https://github.com/hnhx/librex" \
-      usage="https://github.com/hnhx/librex/wiki" \
-      authors="https://github.com/hnhx/librex/contributors"
-
-# Include arguments as temporary environment variables to be handled by Docker during the image build process
-# Change or add new arguments to customize the image generated by 'docker build' command
-ARG DOCKER_SCRIPTS="docker"
-ARG NGINX_PORT=8080
-
-# Customize the environment during both execution and build time by modifying the environment variables added to the container's shell
-# When building your image, make sure to set the 'TZ' environment variable to your desired time zone location, for example 'America/Sao_Paulo'
-# See more: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
-ENV TZ="America/New_York"
-
-RUN apk add gettext --no-cache
-
-# The following lines import all Dockerfiles from other folders so that they can be built together in the final build
-INCLUDE+ docker/php/php.dockerfile
-INCLUDE+ docker/server/nginx.dockerfile
-
-# Include docker scripts, docker images, and the 'GNU License' in the Librex container
-ADD "." "/var/www/html"
-
-# Set permissions for script files as executable scripts inside 'docker/scripts' directory
-RUN chmod u+x "${DOCKER_SCRIPTS}/php/prepare.sh" &&\
-    chmod u+x "${DOCKER_SCRIPTS}/server/prepare.sh" &&\
-    chmod u+x "${DOCKER_SCRIPTS}/entrypoint.sh" &&\
-    chmod u+x "${DOCKER_SCRIPTS}/attributes.sh"
-
-EXPOSE ${NGINX_PORT}
-
-# Configures the container to be run as an executable.
-ENTRYPOINT ["/bin/sh", "-c", "docker/entrypoint.sh"]

+ 5 - 0
config.php.example

@@ -146,6 +146,11 @@
             CURLOPT_MAXREDIRS => 5,
             CURLOPT_TIMEOUT => 18,
             CURLOPT_VERBOSE => false
+        ),
+        "instances" => array(
+            // put public instances here
+            // like:
+            "search.femboy.hu",
         )
     );
 ?>

+ 0 - 21
docker-compose.yml

@@ -1,21 +0,0 @@
-version: "2.1"
-services:
-  librex:
-    image: librex/librex:latest
-    container_name: librex
-    network_mode: bridge
-    ports:
-      - 8080:8080
-    environment:
-      - PUID=1000
-      - PGID=1000
-      - VERSION=docker
-      - TZ=America/New_York
-      - CONFIG_GOOGLE_DOMAIN=com
-      - CONFIG_GOOGLE_LANGUAGE_SITE=en
-      - CONFIG_GOOGLE_LANGUAGE_RESULTS=en
-      - CONFIG_WIKIPEDIA_LANGUAGE=en
-    volumes:
-      - ./nginx_logs:/var/log/nginx
-      - ./php_logs:/var/log/php7
-    restart: unless-stopped

+ 0 - 192
docker/README.md

@@ -1,192 +0,0 @@
-
-### Introduction
-
-- [Introduction](#introduction)
-  - [Running a docker container](#running-a-docker-container)
-  - [Running a Docker container through the Docker hub](#running-a-docker-container-through-the-docker-hub)
-  - [Running a Docker container with composer](#running-a-docker-container-with-composer)
-  - [Environment variables that can be set in the Docker container](#environment-variables-that-can-be-set-in-the-docker-container)
-    - [OpenSearch](#opensearch)
-    - [Search Config](#search-config)
-    - [Wikipedia](#wikipedia)
-    - [Applications](#applications)
-    - [Curl](#curl)
-- [Docker version issues](#docker-version-issues)
-- [Building a docker image](#building-a-docker-image)
-- [Support for different architectures](#support-for-different-architectures)
-
-### Running a docker container
-
-Dockerized Librex is a way to provide users with yet another way to self-host their own projects with a view to privacy. If you wish to help, please start by looking for bugs in used docker configurations.
-
-### Running a Docker container through the Docker hub
-
-To run librex in a docker container, you can simply use the command:
-
-```sh
-docker run -d \
-  --name librex \
-  -e TZ="America/New_York" \
-  -e CONFIG_GOOGLE_DOMAIN="com" \
-  -e CONFIG_GOOGLE_LANGUAGE="en" \
-  -e CONFIG_WIKIPEDIA_LANGUAGE="en" \
-  -p 8080:8080 \
-  librex/librex:latest
-```
-
-<br>
-
-### Running a Docker container with composer
-
-```yml
-version: "2.1"
-services:
-  librex:
-    image: librex/librex:latest
-    container_name: librex
-    network_mode: bridge
-    ports:
-      - 8080:8080
-    environment:
-      - PUID=1000
-      - PGID=1000
-      - VERSION=docker
-      - TZ="America/New_York"
-      - CONFIG_GOOGLE_DOMAIN="com"
-      - CONFIG_GOOGLE_LANGUAGE="en"
-      - CONFIG_WIKIPEDIA_LANGUAGE="en"
-    volumes:
-      - ./nginx_logs:/var/log/nginx
-      - ./php_logs:/var/log/php7
-    restart: unless-stopped
-```
-
-<br>
-
-### Environment variables that can be set in the Docker container
-
-This docker image was developed with high configurability in mind, so here is the list of environment variables that can be changed according to your use case, no matter how specific.
-
-<br>
-
-### OpenSearch
-
-| Variables | Default | Examples | Description |
-|:----------|:-------------|:---------|:------|
-| OPEN_SEARCH_TITLE |  "LibreX" | string | [OpenSearch XML](https://developer.mozilla.org/en-US/docs/Web/OpenSearch) |
-| OPEN_SEARCH_DESCRIPTION | "Framework and javascript free privacy respecting meta search engine" | string | [OpenSearch XML](https://developer.mozilla.org/en-US/docs/Web/OpenSearch) |
-| OPEN_SEARCH_ENCODING | "UTF-8" | "UTF-8" | [OpenSearch XML](https://developer.mozilla.org/en-US/docs/Web/OpenSearch) |
-| OPEN_SEARCH_LONG_NAME | "Librex Search" | string | [OpenSearch XML](https://developer.mozilla.org/en-US/docs/Web/OpenSearch) |
-| OPEN_SEARCH_HOST | "http://localhost:8080" | string | Host used to identify Librex on the network |
-
-<br>
-
-### Search Config
-
-| Variables | Default | Examples | Description |
-|:----------|:-------------|:---------|:------|
-| CONFIG_GOOGLE_DOMAIN |  "com" | "com", "com.br", "com.es" | Defines which Google domain the search will be done, change according to your country |
-| CONFIG_GOOGLE_LANGUAGE | "en" | "pt", "es", "ru" | Defines the language in which searches will be done, see the list of supported languages [here](https://developers.google.com/custom-search/docs/ref_languages). |
-| CONFIG_INVIDIOUS_INSTANCE | "https://invidious.namazso.eu" | string | Defines the host that will be used to do video searches using invidious |
-| CONFIG_HIDDEN_SERVICE_SEARCH | false | boolean | Defines whether safesearch will be enabled or disabled |
-| CONFIG_DISABLE_BITTORRENT_SEARCH | false | boolean | Defines whether bittorrent support will be enabled or disabled |
-| CONFIG_BITTORRENT_TRACKERS | "http://nyaa.tracker.wf:7777/announce" | string | Bittorrent trackers, see the complete example in the `config.php` file. |
-
-<br>
-
-### Wikipedia
-
-| Variables | Default | Examples | Description |
-|:----------|:-------------|:---------|:------|
-| CONFIG_WIKIPEDIA_LANGUAGE | "en" | "pt", "es", "hu" | Adds language support for Wikipedia results |
-
-<br>
-
-### Applications
-
-| Variables | Default | Examples | Description |
-|:----------|:-------------|:---------|:------|
-| APP_INVIDIOUS | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_RIMGO | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_SCRIBE | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_LIBRARIAN | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_GOTHUB | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_NITTER | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_LIBREREDDIT | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_PROXITOK | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_WIKILESS | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_QUETRE | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_LIBREMDB | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_BREEZEWIKI | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_ANONYMOUS_OVERFLOW | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_SUDS | "" | string | Integration with external self-hosted apps, configure the desired host. |
-| APP_BIBLIOREADS | "" | string | Integration with external self-hosted apps, configure the desired host. |
-
-<br>
-
-### Curl
-
-| Variables | Default | Examples | Description |
-|:----------|:-------------|:---------|:------|
-| CURLOPT_PROXY_ENABLED | false | boolean | If you want to use a proxy, you need to set this variable to true. |
-| CURLOPT_PROXY | "" | "127.0.0.1:8080" | Set the proxy using the ip and port to be used |
-| CURLOPT_RETURNTRANSFER | true | boolean | **TODO** |
-| CURLOPT_ENCODING | "" | string | Defines the encode that curl should use to display the texts correctly |
-| CURLOPT_USERAGENT | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" | string | This variable defines the 'User-Agent' that curl will use to attempt to avoid being blocked |
-| CURLOPT_CUSTOMREQUEST | "GET" | "HEAD", "OPTIONS" | Defines the HTTP method that curl will use to make the request |
-| CURLOPT_MAXREDIRS | 5 | number | **TODO** |
-| CURLOPT_TIMEOUT | 18 | number | Sets the maximum time curl will wait for a response before timing out |
-| CURLOPT_VERBOSE | false | boolean | Specifies whether curl should display detailed information on stdout about the request and response when making requests. Setting to 'true' enables verbose mode |
-
-<br>
-
-### Docker version issues
-
-If you are going to build your own docker image based on this repository, pay attention to your Docker version, because depending on how recent the installed version is, maybe you should use the `buildx` command instead of `build`.
-
-Docker <= 20.10: `docker build`
-
-Docker > 20.10: `docker buildx build`
-
-<br>
-
-### Building a docker image
-
-If you don't want to use the image that is already available on `docker hub`, then you can simply build the Dockerfile directly from the github repository using the command:
-
-```sh
-docker build https://github.com/hnhx/librex.git -t librex:latest
-```
-
-```sh
-docker run -d --name librex \
-    -e CONFIG_GOOGLE_DOMAIN="com" \
-    -e CONFIG_GOOGLE_LANGUAGE="en" \
-    -p 8080:8080 \
-    librex:latest
-```
-
-Or, instead of doing the build remotely, you still have the opportunity to `git clone` the repository, and build it locally with the command:
-
-```sh
-git clone https://github.com/hnhx/librex.git
-cd librex/
-docker build -t librex:latest .
-```
-
-<br>
-
-### Support for different architectures
-
-Supported architectures for the official Librex images include the same ones supported by Alpine itself, which are typically denoted as `linux/386`, `linux/amd64`, `linux/arm/v6`. If you need support for a different architecture, such as `linux/arm/v7`, you can modify the 'Dockerfile' to use a more comprehensive base image like `ubuntu:latest` instead.
-
-In this case, you must run the `build` process specifying the desired architecture as shown in the example below:
-
-```sh
-docker buildx build \
-    --no-cache \
-    --platform linux/arm/v7 \
-    --tag librex/librex:latest .
-```
-
-**OBS:** Keep in mind that this can cause some issues at build time, so you need to know a little about Dockerfiles to solve this problem for your specific case.

+ 0 - 65
docker/attributes.sh

@@ -1,65 +0,0 @@
-#!/bin/sh
-
-# YOU DON'T NEED TO EDIT THIS FILE. IF YOU WANT TO SET CUSTOM ENVIRONMENT VARIABLES,
-# USE THE 'DOCKERFILE IMAGE' FROM ROOT DIRECTORY AND PASS THE ENVIRONMENT PARAMETERS
-
-# These templates will be used to create configuration files that incorporate values from environment variables
-# If these locations do not already exist within the Docker container, they will be created
-export CONFIG_PHP_TEMPLATE="$(pwd)/config.php"
-export CONFIG_OPEN_SEARCH_TEMPLATE="$(pwd)/opensearch.xml"
-export CONFIG_NGINX_TEMPLATE="/etc/nginx/http.d/librex.conf"
-
-# Configure 'opensearch.xml' with Librex configuration metadata, such as the encoding and the host that stores the site
-# These configurations will replace the 'opensearch.xml' inside '.dockers/templates' for the best setup for your instance
-export OPEN_SEARCH_TITLE=${OPEN_SEARCH_TITLE:-"LibreX"}
-export OPEN_SEARCH_DESCRIPTION=${OPEN_SEARCH_DESCRIPTION:-"Framework and javascript free privacy respecting meta search engine"}
-export OPEN_SEARCH_ENCODING=${OPEN_SEARCH_ENCODING:-"UTF-8"}
-export OPEN_SEARCH_LONG_NAME=${OPEN_SEARCH_LONG_NAME:-"LibreX Search"}
-export OPEN_SEARCH_HOST=${OPEN_SEARCH_HOST:-"127.0.0.1"}
-
-# Replace the 'config.php' script, which contains the most common search engine configurations, with these environment setups
-# These environment setups can be found in 'config.php', and the default configurations can be useful for most use cases
-export CONFIG_GOOGLE_DOMAIN="${CONFIG_GOOGLE_DOMAIN:-"com"}"
-export CONFIG_GOOGLE_LANGUAGE_SITE="${CONFIG_GOOGLE_LANGUAGE_SITE:-"en"}"
-export CONFIG_GOOGLE_LANGUAGE_RESULTS="${CONFIG_GOOGLE_LANGUAGE_RESULTS:-"en"}"
-export CONFIG_INVIDIOUS_INSTANCE="${CONFIG_INVIDIOUS_INSTANCE:-"invidious.snopyta.org"}"
-export CONFIG_HIDDEN_SERVICE_SEARCH=${CONFIG_HIDDEN_SERVICE_SEARCH:-false}
-export CONFIG_DISABLE_BITTORRENT_SEARCH=${CONFIG_DISABLE_BITTORRENT_SEARCH:-false}
-export CONFIG_BITTORRENT_TRACKERS="${CONFIG_BITTORRENT_TRACKERS:-"&tr=http://nyaa.tracker.wf:7777/announce&tr=udp://open.stealth.si:80/announce&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce&tr=udp://tracker.torrent.eu.org:451/announce"}"
-
-# The settings that will be used to handle Wikipedia results displayed on the libreX search page
-# the settings below can be edited via environment variables.
-export CONFIG_WIKIPEDIA_LANGUAGE=${CONFIG_WIKIPEDIA_LANGUAGE:-${CONFIG_GOOGLE_LANGUAGE}}
-
-# Supported apps integration configuration. These empty spaces can be set up using free hosts as pointers
-# A particular example is using the "https://yewtu.be" or a self-hosted host to integrate the invidious app to librex
-export APP_INVIDIOUS=${APP_INVIDIOUS:-""}
-export APP_RIMGO=${APP_RIMGO:-""}
-export APP_SCRIBE=${APP_SCRIBE:-""}
-export APP_LIBRARIAN=${APP_LIBRARIAN:-""}
-export APP_GOTHUB=${APP_GOTHUB:-""}
-export APP_NITTER=${APP_NITTER:-""}
-export APP_LIBREREDDIT=${APP_LIBREREDDIT:-""}
-export APP_PROXITOK=${APP_PROXITOK:-""}
-export APP_WIKILESS=${APP_WIKILESS:-""}
-export APP_QUETRE=${APP_QUETRE:-""}
-export APP_LIBREMDB=${APP_LIBREMDB:-""}
-export APP_BREEZEWIKI=${APP_BREEZEWIKI:-""}
-export APP_ANONYMOUS_OVERFLOW=${APP_ANONYMOUS_OVERFLOW:-""}
-export APP_SUDS=${APP_SUDS:-""}
-export APP_BIBLIOREADS=${APP_BIBLIOREADS:-""}
-
-# GNU/Curl configurations. Leave 'CURLOPT_PROXY' blank whether you don't need to use a proxy for requests
-# Generally, a proxy is needed when your IP address is blocked by search engines in response to multiple requests within a short time frame. In these cases, it is recommended to use rotating proxies
-export CURLOPT_PROXY_ENABLED=${CURLOPT_PROXY_ENABLED:-false}
-export CURLOPT_PROXY=${CURLOPT_PROXY:-""}
-export CURLOPT_RETURNTRANSFER=${CURLOPT_RETURNTRANSFER:-true}
-export CURLOPT_ENCODING=${CURLOPT_ENCODING:-""}
-export CURLOPT_USERAGENT="${CURLOPT_USERAGENT:-"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"}"
-export CURLOPT_CUSTOMREQUEST="${CURLOPT_CUSTOMREQUEST:-"GET"}"
-export CURLOPT_MAXREDIRS=${CURLOPT_MAXREDIRS:-5}
-export CURLOPT_TIMEOUT=${CURLOPT_TIMEOUT:-18}
-export CURLOPT_VERBOSE=${CURLOPT_VERBOSE:-true}
-
-# These shell functions will be available for use by any function calls
-function AwkTrim() { awk '{$1=$1};1'; }

+ 0 - 10
docker/entrypoint.sh

@@ -1,10 +0,0 @@
-#!/bin/sh
-
-# Due to an issue with Docker's 'CMD' directive, the following scripts are not executing as expected.
-# This workaround has been implemented to resolve the issue for now
-sh "docker/php/prepare.sh"
-sh "docker/server/prepare.sh"
-
-/bin/sh -c /usr/sbin/php-fpm7
-
-exec nginx -g "daemon off;"

+ 0 - 124
docker/php/config.php

@@ -1,124 +0,0 @@
-<?php
-    return (object) array(
-        "google_domain" => "${CONFIG_GOOGLE_DOMAIN}",
-        "google_language_site" => "${CONFIG_GOOGLE_LANGUAGE_SITE}",
-        "google_language_results" => "${CONFIG_GOOGLE_LANGUAGE_RESULTS}",
-
-        "wikipedia_language" => "${CONFIG_WIKIPEDIA_LANGUAGE}",
-        "invidious_instance_for_video_results" => "${CONFIG_INVIDIOUS_INSTANCE}",
-
-        "disable_bittorent_search" => ${CONFIG_DISABLE_BITTORRENT_SEARCH},
-        "bittorent_trackers" => "${CONFIG_BITTORRENT_TRACKERS}",
-        "disable_hidden_service_search" => ${CONFIG_HIDDEN_SERVICE_SEARCH},
-
-        "frontends" => array(
-            "invidious" => array(
-                "instance_url" => "${APP_INVIDIOUS}",
-                "project_url" => "https://docs.invidious.io/instances/",
-                "original_name" => "YouTube",
-                "original_url" => "youtube.com"
-            ),
-            "rimgo" => array(
-                "instance_url" => "${APP_RIMGO}",
-                "project_url" => "https://codeberg.org/video-prize-ranch/rimgo#instances",
-                "original_name" => "Imgur",
-                "original_url" => "imgur.com"
-            ),
-            "scribe" => array(
-                "instance_url" => "${APP_SCRIBE}",
-                "project_url" => "https://git.sr.ht/~edwardloveall/scribe/tree/main/docs/instances.md",
-                "original_name" => "Medium",
-                "original_url" => "medium.com"
-            ),
-            "gothub" => array(
-                "instance_url" => "${APP_GOTHUB}",
-                "project_url" => "https://codeberg.org/gothub/gothub/wiki/Instances",
-                "original_name" => "GitHub",
-                "original_url" => "github.com"
-            ),
-            "librarian" => array(
-                "instance_url" => "${APP_LIBRARIAN}",
-                "project_url" => "https://codeberg.org/librarian/librarian#clearnet",
-                "original_name" => "Odysee",
-                "original_url" => "odysee.com"
-            ),
-
-            "nitter" => array(
-                "instance_url" => "${APP_NITTER}",
-                "project_url" => "https://github.com/zedeus/nitter/wiki/Instances",
-                "original_name" => "Twitter",
-                "original_url" => "twitter.com"
-            ),
-
-            "libreddit" => array(
-                "instance_url" => "${APP_LIBREREDDIT}",
-                "project_url" => "https://github.com/spikecodes/libreddit",
-                "original_name" => "Reddit",
-                "original_url" => "reddit.com"
-            ),
-            "proxitok" => array(
-                "instance_url" => "${APP_PROXITOK}",
-                "project_url" => "https://github.com/pablouser1/ProxiTok/wiki/Public-instances",
-                "original_name" => "TikTok",
-                "original_url" => "tiktok.com"
-            ),
-            "wikiless" => array(
-                "instance_url" => "${APP_WIKILESS}",
-                "project_url" => "https://github.com/Metastem/wikiless#instances",
-                "original_name" => "Wikipedia",
-                "original_url" => "wikipedia.com"
-            ),
-            "quetre" => array(
-                "instance_url" => "${APP_QUETRE}",
-                "project_url" => "https://github.com/zyachel/quetre",
-                "original_name" => "Quora",
-                "original_url" => "quora.com"
-            ),
-            "libremdb" => array(
-                "instance_url" => "${APP_LIBREMDB}",
-                "project_url" => "https://github.com/zyachel/libremdb",
-                "original_name" => "IMDb",
-                "original_url" => "imdb.com"
-            ),
-            "breezewiki" => array(
-                "instance_url" => "${APP_BREEZEWIKI}",
-                "project_url" => "https://gitdab.com/cadence/breezewiki",
-                "original_name" => "Fandom",
-                "original_url" => "fandom.com"
-            ),
-            "anonymousoverflow" => array(
-                "instance_url" => "${APP_ANONYMOUS_OVERFLOW}",
-                "project_url" => "https://github.com/httpjamesm/AnonymousOverflow#clearnet-instances",
-                "original_name" => "StackOverflow",
-                "original_url" => "stackoverflow.com"
-            ),
-            "suds" => array(
-                "instance_url" => "${APP_SUDS}",
-                "project_url" => "https://git.vern.cc/cobra/Suds/src/branch/main/instances.json",
-                "original_name" => "Snopes",
-                "original_url" => "snopes.com"
-            ),
-            "biblioreads" => array(
-                "instance_url" => "${APP_BIBLIOREADS}",
-                "project_url" => "https://github.com/nesaku/BiblioReads#instances",
-                "original_name" => "Goodreads",
-                "original_url" => "goodreads.com"
-            )
-        ),
-
-        "curl_settings" => array(
-            CURLOPT_PROXY => "${CURLOPT_PROXY}",
-            CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
-            CURLOPT_RETURNTRANSFER => ${CURLOPT_RETURNTRANSFER},
-            CURLOPT_ENCODING => "${CURLOPT_ENCODING}",
-            CURLOPT_USERAGENT => "${CURLOPT_USERAGENT}",
-            CURLOPT_IPRESOLVE => CURL_IPRESOLVE_WHATEVER,
-            CURLOPT_CUSTOMREQUEST => "${CURLOPT_CUSTOMREQUEST}",
-            CURLOPT_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP,
-            CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP,
-            CURLOPT_MAXREDIRS => ${CURLOPT_MAXREDIRS},
-            CURLOPT_TIMEOUT => ${CURLOPT_TIMEOUT},
-            CURLOPT_VERBOSE => ${CURLOPT_VERBOSE}
-        )
-    );
-?>

+ 0 - 9
docker/php/opensearch.xml

@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
-  <ShortName>${OPEN_SEARCH_TITLE}</ShortName>
-  <Description>${OPEN_SEARCH_DESCRIPTION}</Description>
-  <InputEncoding>${OPEN_SEARCH_ENCODING}</InputEncoding>
-  <LongName>${OPEN_SEARCH_LONG_NAME}</LongName>
-  <Url rel="results" type="text/html" method="get" template="${OPEN_SEARCH_HOST}/search.php?q={searchTerms}" />
-  <Url type="application/opensearchdescription+xml" rel="self" template="/opensearch.xml?method=GET" />
-</OpenSearchDescription>

+ 0 - 61
docker/php/php.dockerfile

@@ -1,61 +0,0 @@
-# Set this argument during build time to indicate that the path is for php's www.conf
-ARG WWW_CONFIG="/etc/php7/php-fpm.d/www.conf"
-
-# Configure 'opensearch.xml' with Librex configuration metadata, such as the encoding and the host that stores the site
-# These configurations will replace the 'opensearch.xml' inside '.dockers/templates' for the best setup for your instance
-ENV OPEN_SEARCH_TITLE="LibreX"
-ENV OPEN_SEARCH_DESCRIPTION="Framework and javascript free privacy respecting meta search engine"
-ENV OPEN_SEARCH_ENCODING="UTF-8"
-ENV OPEN_SEARCH_LONG_NAME="LibreX search"
-ENV OPEN_SEARCH_HOST="http://127.0.0.1:${NGINX_PORT}"
-
-# Replace the 'config.php' script, which contains the most common search engine configurations, with these environment setups
-# These environment setups can be found in 'config.php', and the default configurations can be useful for most use cases
-ENV CONFIG_GOOGLE_DOMAIN="com"
-ENV CONFIG_GOOGLE_LANGUAGE_SITE="en"
-ENV CONFIG_GOOGLE_LANGUAGE_RESULTS="en"
-ENV CONFIG_INVIDIOUS_INSTANCE="https://invidious.snopyta.org"
-ENV CONFIG_HIDDEN_SERVICE_SEARCH=false
-ENV CONFIG_DISABLE_BITTORRENT_SEARCH=false
-ENV CONFIG_BITTORRENT_TRACKERS="&tr=http://nyaa.tracker.wf:7777/announce&tr=udp://open.stealth.si:80/announce&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce&tr=udp://tracker.torrent.eu.org:451/announce"
-
-# Supported apps integration configuration. These empty spaces can be set up using free hosts as pointers
-# A particular example is using the "https://yewtu.be" or a self-hosted host to integrate the invidious app to librex
-ENV APP_INVIDIOUS=""
-ENV APP_RIMGO=""
-ENV APP_SCRIBE=""
-ENV APP_LIBRARIAN=""
-ENV APP_GOTHUB=""
-ENV APP_NITTER=""
-ENV APP_LIBREREDDIT=""
-ENV APP_PROXITOK=""
-ENV APP_WIKILESS=""
-ENV APP_QUETRE=""
-ENV APP_LIBREMDB=""
-ENV APP_BREEZEWIKI=""
-ENV APP_ANONYMOUS_OVERFLOW=""
-ENV APP_SUDS=""
-ENV APP_BIBLIOREADS=""
-
-
-# GNU/Curl configurations. Leave 'CURLOPT_PROXY' blank whether you don't need to use a proxy for requests
-# Generally, a proxy is needed when your IP address is blocked by search engines in response to multiple requests within a short time frame. In these cases, it is recommended to use rotating proxies
-ENV CURLOPT_PROXY_ENABLED=false
-ENV CURLOPT_PROXY=""
-ENV CURLOPT_RETURNTRANSFER=true
-ENV CURLOPT_ENCODING=""
-ENV CURLOPT_USERAGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
-ENV CURLOPT_CUSTOMREQUEST="GET"
-ENV CURLOPT_MAXREDIRS=5
-ENV CURLOPT_TIMEOUT=18
-ENV CURLOPT_VERBOSE=true
-
-# Install PHP-FPM using Alpine's package manager, apk
-# Configure PHP-FPM to listen on a Unix socket instead of a TCP port, which is more secure and efficient
-RUN apk add php7 php7-fpm php7-dom php7-curl php7-json --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing &&\
-    sed -i 's/^\s*listen = 127.0.0.1:9000/listen = \/run\/php7\/php-fpm7.sock/' ${WWW_CONFIG} &&\
-    sed -i 's/^\s*;\s*listen.owner = nobody/listen.owner = nginx/' ${WWW_CONFIG} &&\
-    sed -i 's/^\s*;\s*listen.group = nobody/listen.group = nginx/' ${WWW_CONFIG} &&\
-    sed -i 's/^\s*;\s*listen.mode = 0660/listen.mode = 0660/' ${WWW_CONFIG}
-    
-CMD [ "/bin/sh", "-c", "docker/php/prepare.sh" ]

+ 0 - 28
docker/php/prepare.sh

@@ -1,28 +0,0 @@
-#!/bin/sh
-
-echo "[PREPARE] docker/server/prepare.sh'"
-
-# Load all environment variables from 'attributes.sh' using the command 'source /path/attributes.sh'
-source "docker/attributes.sh"
-
-# This condition creates the Unix socket if 'php-fpm7.sock' does not already exist.
-# This fixes an issue where Nginx starts but does not serve content
-if [ ! -d "/run/php7" ] || [ ! -S "/run/php7/php-fpm7.sock" ]; then
-    mkdir "/run/php7"
-    touch "/run/php7/php-fpm7.sock"
-    chmod 660 "/run/php7/php-fpm7.sock"
-    chown nginx:nginx "/run/php7/php-fpm7.sock"
-fi
-
-# The lines below will replace the environment variables in the templates with the corresponding variables listed above. To accomplish this, the GNU 'envsubst' package will be used
-# Although not recommended (if you do not know what you are doing), you still have the option to add new substitution file templates using any required environment variables
-[[ ! -s ${CONFIG_PHP_TEMPLATE} ]] && cat 'docker/php/config.php' | envsubst > ${CONFIG_PHP_TEMPLATE};
-[[ ! -s ${CONFIG_OPEN_SEARCH_TEMPLATE} ]] && cat 'docker/php/opensearch.xml' | envsubst > ${CONFIG_OPEN_SEARCH_TEMPLATE};
-
-# If it is empty or proxy is not enabled, we are using sed to delete
-# any line that contains the string 'CURLOPT_PROXY' or 'CURLOPT_PROXYTYPE'
-# from the file 'config.php' defined on top of 'attributes.sh'
-if [[ -z "${CURLOPT_PROXY}" || "${CURLOPT_PROXY_ENABLED}" = false ]]; then
-    sed -i "/CURLOPT_PROXY/d" ${CONFIG_PHP_TEMPLATE};
-    sed -i "/CURLOPT_PROXYTYPE/d" ${CONFIG_PHP_TEMPLATE};
-fi

+ 0 - 26
docker/server/fastcgi.conf

@@ -1,26 +0,0 @@
-# These settings should work well for serving as a front-end of many search engines
-# on our PHP website. However, we may need to adjust them based on our specific requirements.
-fastcgi_param SCRIPT_FILENAME       $document_root$fastcgi_script_name;
-fastcgi_param QUERY_STRING          $query_string;
-fastcgi_param REQUEST_METHOD        $request_method;
-fastcgi_param CONTENT_TYPE          $content_type;
-fastcgi_param CONTENT_LENGTH        $content_length;
-
-fastcgi_param SCRIPT_NAME           $fastcgi_script_name;
-fastcgi_param REQUEST_URI           $request_uri;
-fastcgi_param DOCUMENT_URI          $document_uri;
-fastcgi_param DOCUMENT_ROOT         $document_root;
-fastcgi_param SERVER_PROTOCOL       $server_protocol;
-
-fastcgi_param GATEWAY_INTERFACE     CGI/1.1;
-fastcgi_param SERVER_SOFTWARE       nginx/$nginx_version;
-
-fastcgi_param REMOTE_ADDR           $remote_addr;
-fastcgi_param REMOTE_PORT           $remote_port;
-fastcgi_param SERVER_ADDR           $server_addr;
-fastcgi_param SERVER_PORT           $server_port;
-fastcgi_param SERVER_NAME           $server_name;
-
-# PHP only, required if PHP was built with --enable-force-cgi-redirect
-fastcgi_param HTTPS                 $https if_not_empty;
-fastcgi_param REDIRECT_STATUS       200;

+ 0 - 17
docker/server/nginx.conf

@@ -1,17 +0,0 @@
-server {
-    listen       8080;
-    server_name  ${OPEN_SEARCH_HOST_FOR_NGINX} localhost;
-
-    root   /var/www/html;
-    index  index.php;
-
-    location / {
-        try_files $uri $uri/ /index.php?$args;
-    }
-
-    location ~ \.php$ {
-        fastcgi_pass   unix:/run/php7/php-fpm7.sock;
-        fastcgi_index  index.php;
-        include        fastcgi.conf;
-    }
-}

+ 0 - 9
docker/server/nginx.dockerfile

@@ -1,9 +0,0 @@
-# Install Nginx with FastCGI enabled, optimizing its performance for serving content
-RUN apk add nginx
-
-# Forward request and error logs to docker log collector
-# RUN ln -sf /dev/stdout /var/log/nginx/access.log &&\
-#     ln -sf /dev/stderr /var/log/nginx/error.log
-
-# After executing the 'docker run' command, run the 'prepare.sh' script
-CMD [ "/bin/sh", "-c", "docker/server/prepare.sh" ]

+ 0 - 21
docker/server/prepare.sh

@@ -1,21 +0,0 @@
-#!/bin/sh
-
-echo "[PREPARE] docker/server/prepare.sh'"
-
-# Load all environment variables from 'attributes.sh' using the command 'source /path/attributes.sh'
-source "docker/attributes.sh"
-
-export OPEN_SEARCH_HOST_FOR_NGINX="$(echo "${OPEN_SEARCH_HOST}" | cut -d "/" -f 3 | cut -d ":" -f 1)"
-
-# The lines below will replace the environment variables in the templates with the corresponding variables listed above. To accomplish this, the GNU 'envsubst' package will be used
-# Although not recommended (if you do not know what you are doing), you still have the option to add new substitution file templates using any required environment variables
-if [[ ! -s ${CONFIG_NGINX_TEMPLATE} ]]; then
-    cp "docker/server/fastcgi.conf" /etc/nginx/fastcgi.conf
-    cp "docker/server/nginx.conf" /etc/nginx/http.d/librex.conf
-
-    # To address issues with 'nginx.conf', the following lines will ensure that these configurations remain executable
-    chmod u+x "/etc/nginx/fastcgi.conf"
-    chmod u+x "/etc/nginx/http.d/librex.conf"
-
-    cat 'docker/server/nginx.conf' | envsubst '${OPEN_SEARCH_HOST_FOR_NGINX}' > ${CONFIG_NGINX_TEMPLATE};
-fi

+ 14 - 18
engines/ahmia/hidden_service.php

@@ -3,28 +3,24 @@
     {
         global $config;
 
-        $url = "https://ahmia.fi/search/?q=$query";
-        $response = request($url);
-        $xpath = get_xpath($response);
+        // Randomly choose a instance
 
         $results = array();
+        $num = array_rand($config->instances);
+        $instance = $config->instances[$num];
+        $url = "https://$instance/api.php";
 
-        foreach($xpath->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" => $title ? htmlspecialchars($title) : "No description provided",
-                    "url" =>  htmlspecialchars($url),
-                    "base_url" => htmlspecialchars(get_base_url($url)),
-                    "description" => htmlspecialchars($description)
-                )
-            );
-        }
+        // API POST field
+        $post_string = "q=$query&t=4";
+
+        $api_ch = curl_init($url);
+        curl_setopt_array($api_ch, $config->curl_settings);
+        curl_setopt($api_ch, CURLOPT_CUSTOMREQUEST, "POST");
+        curl_setopt($api_ch, CURLOPT_COOKIE, http_build_query($cookies, '', ';'));
+        curl_setopt($api_ch, CURLOPT_POSTFIELDS, $post_string);
+        $results = json_decode(curl_exec($api_ch),true);
 
+        if($results == null) $results = "$instance is broken";
         return $results;
     }
 

+ 0 - 34
engines/bittorrent/1337x.php

@@ -1,34 +0,0 @@
-<?php
-    $_1337x_url = "https://1337x.to/search/$query/1/";
-
-    function get_1337x_results($response)
-    {
-        global $config;
-        $xpath = get_xpath($response);
-        $results = array();
-
-        foreach($xpath->query("//table/tbody/tr") as $result)
-        {
-
-            $name = $xpath->evaluate(".//td[@class='coll-1 name']/a", $result)[1]->textContent;
-            $magnet = "/engines/bittorrent/get_magnet_1337x.php?url=https://1337x.to" . $xpath->evaluate(".//td[@class='coll-1 name']/a/@href", $result)[1]->textContent;
-            $size_unformatted = explode(" ", $xpath->evaluate(".//td[contains(@class, 'coll-4 size')]", $result)[0]->textContent);
-            $size = $size_unformatted[0] . " " . preg_replace("/[0-9]+/", "", $size_unformatted[1]);
-            $seeders = $xpath->evaluate(".//td[@class='coll-2 seeds']", $result)[0]->textContent;
-            $leechers = $xpath->evaluate(".//td[@class='coll-3 leeches']", $result)[0]->textContent;
-
-            array_push($results, 
-                array (
-                    "name" => htmlspecialchars($name),
-                    "seeders" => (int) $seeders,
-                    "leechers" => (int) $leechers,
-                    "magnet" => htmlspecialchars($magnet),
-                    "size" => htmlspecialchars($size),
-                    "source" => "1337x.to"
-                )
-            );
-        }
-
-        return $results;
-    }
-?>

+ 0 - 15
engines/bittorrent/get_magnet_1337x.php

@@ -1,15 +0,0 @@
-<?php
-    require "../../misc/tools.php";
-    $config = require "../../config.php";
-
-    $url = $_REQUEST["url"];
-
-    $response = request($url);
-    $xpath = get_xpath($response);
-
-    $magnet = $xpath->query("//main/div/div/div/div/div/ul/li/a/@href")[0]->textContent;
-    $magnet_without_tracker = explode("&tr=", $magnet)[0];
-    $magnet = $magnet_without_tracker . $config->bittorent_trackers;
-
-    header("Location: $magnet")
-?>

+ 17 - 71
engines/bittorrent/merge.php

@@ -4,83 +4,29 @@
     {
         global $config;
 
-        require "engines/bittorrent/thepiratebay.php";
-        require "engines/bittorrent/rutor.php";
-        require "engines/bittorrent/nyaa.php";
-        require "engines/bittorrent/yts.php";
-        require "engines/bittorrent/torrentgalaxy.php";
-        require "engines/bittorrent/1337x.php";
-        require "engines/bittorrent/sukebei.php";
-
-        $query = urlencode($query);
-
-        $torrent_urls = array(
-            $thepiratebay_url,
-            $rutor_url,
-            $nyaa_url,
-            $yts_url,
-            $torrentgalaxy_url,
-            $_1337x_url,
-            $sukebei_url
-        );
- 
-        $mh = curl_multi_init();
-        $chs = $results = array();
-
-        foreach ($torrent_urls as $url)
-        {
-            $ch = curl_init($url);
-            curl_setopt_array($ch, $config->curl_settings);
-            array_push($chs, $ch);
-            curl_multi_add_handle($mh, $ch);    
-        }
-
-        $running = null;
-        do {
-            curl_multi_exec($mh, $running);
-        } while ($running);
-
-        for ($i=0; count($chs)>$i; $i++)
-        {
-            $response = curl_multi_getcontent($chs[$i]);
-
-            switch ($i)
-            {
-                case 0:
-                    $results = array_merge($results, get_thepiratebay_results($response));
-                    break;
-                case 1:
-                    $results = array_merge($results, get_rutor_results($response));
-                    break;
-                case 2:
-                    $results = array_merge($results, get_nyaa_results($response));
-                    break;
-                case 3:
-                    $results = array_merge($results, get_yts_results($response));
-                    break;
-                case 4:
-                    $results = array_merge($results, get_torrentgalaxy_results($response));
-                    break;
-                case 5:
-                    $results = array_merge($results, get_1337x_results($response));
-                    break;
-                case 6:
-                    $results = array_merge($results, get_sukebei_results($response));
-                    break;
-            }
-        }
-        
-        $seeders = array_column($results, "seeders");
-        array_multisort($seeders, SORT_DESC, $results);
-
-        return $results; 
+        $results = array();
+        $num = array_rand($config->instances);
+        $instance = $config->instances[$num];
+        $url = "https://$instance/api.php";
+
+        $post_string = "q=$query&t=3";
+
+        $api_ch = curl_init($url);
+        curl_setopt_array($api_ch, $config->curl_settings);
+        curl_setopt($api_ch, CURLOPT_CUSTOMREQUEST, "POST");
+        curl_setopt($api_ch, CURLOPT_TIMEOUT, 20); // what
+        curl_setopt($api_ch, CURLOPT_POSTFIELDS, $post_string);
+        $results = json_decode(curl_exec($api_ch),true);
+
+        //if($results == null) $results = "$instance is broken";
+        return $results;
     }
 
     function print_merged_torrent_results($results)
     {
         echo "<div class=\"text-result-container\">";
 
-        if (!empty($results)) 
+        if (!empty($results))
         {
             foreach($results as $result)
             {

+ 0 - 35
engines/bittorrent/nyaa.php

@@ -1,35 +0,0 @@
-<?php
-    $nyaa_url = "https://nyaa.si/?q=$query";
-
-    function get_nyaa_results($response)
-    {
-        global $config;
-        $xpath = get_xpath($response);
-        $results = array();
-
-        foreach($xpath->query("//tbody/tr") as $result)
-        {
-            $name = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result)[0]->textContent;
-            $centered = $xpath->evaluate(".//td[@class='text-center']", $result);
-            $magnet = $xpath->evaluate(".//a[2]/@href", $centered[0])[0]->textContent;
-            $magnet_without_tracker = explode("&tr=", $magnet)[0];
-            $magnet = $magnet_without_tracker . $config->bittorent_trackers;
-            $size =  $centered[1]->textContent;
-            $seeders =  $centered[3]->textContent;
-            $leechers =  $centered[4]->textContent;
-
-            array_push($results, 
-                array (
-                    "name" => htmlspecialchars($name),
-                    "seeders" => (int) $seeders,
-                    "leechers" => (int) $leechers,
-                    "magnet" => htmlspecialchars($magnet),
-                    "size" => htmlspecialchars($size),
-                    "source" => "nyaa.si"
-                )
-            );
-        }
-
-        return $results;
-    }
-?>

+ 0 - 36
engines/bittorrent/rutor.php

@@ -1,36 +0,0 @@
-<?php
-    $rutor_url = "http://rutor.info/search/$query";
-
-    function get_rutor_results($response)
-    {
-        global $config;
-        $xpath = get_xpath($response);
-        $results = array();
-
-
-        foreach($xpath->query("//table/tr[@class='gai' or @class='tum']") as $result)
-        {
-
-            $name = $xpath->evaluate(".//td/a", $result)[2]->textContent;
-            $magnet =  $xpath->evaluate(".//td/a/@href", $result)[1]->textContent;
-            $magnet_without_tracker = explode("&tr=", $magnet)[0];
-            $magnet = $magnet_without_tracker . $config->bittorent_trackers;
-            $size = $xpath->evaluate(".//td", $result)[3]->textContent;
-            $seeders = $xpath->evaluate(".//span", $result)[0]->textContent;
-            $leechers = $xpath->evaluate(".//span", $result)[1]->textContent;
-
-            array_push($results, 
-                array (
-                    "name" => htmlspecialchars($name),
-                    "seeders" => (int) remove_special($seeders),
-                    "leechers" => (int) remove_special($leechers),
-                    "magnet" => htmlspecialchars($magnet),
-                    "size" => htmlspecialchars($size),
-                    "source" => "rutor.info"
-                )
-            );
-        }
-
-        return $results;
-    }
-?>

+ 0 - 44
engines/bittorrent/sukebei.php

@@ -1,44 +0,0 @@
-<?php
-    $sukebei_url = "https://sukebei.nyaa.si/?q=$query";
-
-    function get_sukebei_results($response)
-    {
-        global $config;
-        $xpath = get_xpath($response);
-        $results = array();
-
-        foreach($xpath->query("//tbody/tr") as $result)
-        {
-            $name_node = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result);
-            if ($name_node->length > 0) {
-                $name = $name_node[0]->textContent;
-            } else {
-                $name = "";
-            }
-            $centered = $xpath->evaluate(".//td[@class='text-center']", $result);
-            $magnet_node = $xpath->evaluate(".//a[2]/@href", $centered[0]);
-            if ($magnet_node->length > 0) {
-                $magnet = $magnet_node[0]->textContent;
-                $magnet_without_tracker = explode("&tr=", $magnet)[0];
-                $magnet = $magnet_without_tracker . $config->bittorent_trackers;
-            } else {
-                $magnet = "";
-            }
-            $size =  $centered[1]->textContent;
-            $seeders =  $centered[3]->textContent;
-            $leechers =  $centered[4]->textContent;
-
-            array_push($results, 
-                array (
-                    "name" => htmlspecialchars($name),
-                    "seeders" => (int) $seeders,
-                    "leechers" => (int) $leechers,
-                    "magnet" => htmlspecialchars($magnet),
-                    "size" => htmlspecialchars($size),
-                    "source" => "sukebei.nyaa.si"
-                )
-            );
-        }
-        return $results;
-    }
-?>

+ 0 - 44
engines/bittorrent/thepiratebay.php

@@ -1,44 +0,0 @@
-<?php
-
-    $thepiratebay_url = "https://apibay.org/q.php?q=$query";
-
-    function get_thepiratebay_results($response)
-    {
-        global $config;
-        $results = array();
-        $json_response = json_decode($response, true);
-
-        if (empty($json_response))
-        {
-            return $results;
-        }
-
-        foreach ($json_response as $response)
-        {
-            $size = human_filesize($response["size"]);
-            $hash = $response["info_hash"]; 
-            $name = $response["name"];
-            $seeders = (int) $response["seeders"];
-            $leechers = (int) $response["leechers"];
-
-            $magnet = "magnet:?xt=urn:btih:$hash&dn=$name" . $config->bittorent_trackers;
-
-            if ($name == "No results returned")
-                break;
-
-            array_push($results, 
-                array (
-                    "size" => htmlspecialchars($size),
-                    "name" => htmlspecialchars($name),
-                    "seeders" => (int) htmlspecialchars($seeders),
-                    "leechers" => (int) htmlspecialchars($leechers),
-                    "magnet" => htmlspecialchars($magnet),
-                    "source" => "thepiratebay.org"
-                )
-            );
-        }
-
-        return $results;
-       
-    }
-?>

+ 0 - 34
engines/bittorrent/torrentgalaxy.php

@@ -1,34 +0,0 @@
-<?php
-    $torrentgalaxy_url = "https://torrentgalaxy.to/torrents.php?search=$query#results";
-
-    function get_torrentgalaxy_results($response)
-    {
-        global $config;
-        $xpath = get_xpath($response);
-        $results = array();
-
-        foreach($xpath->query("//div[@class='tgxtablerow txlight']") as $result)
-        {
-            $name = $xpath->evaluate(".//div[contains(@class, 'clickable-row')]", $result)[0]->textContent;
-            $magnet = $xpath->evaluate(".//div[@class='tgxtablecell collapsehide rounded txlight']/a/@href", $result)[1]->textContent;
-            $magnet_without_tracker = explode("&tr=", $magnet)[0];
-            $magnet = $magnet_without_tracker . $config->bittorent_trackers;
-            $size = $xpath->evaluate(".//div[@class='tgxtablecell collapsehide rounded txlight']/span", $result)[0]->textContent;
-            $seeders = $xpath->evaluate(".//div[@class='tgxtablecell collapsehide rounded txlight']/span/font", $result)[1]->textContent;
-            $leechers = $xpath->evaluate(".//div[@class='tgxtablecell collapsehide rounded txlight']/span/font", $result)[2]->textContent;
-
-            array_push($results, 
-                array (
-                    "name" => htmlspecialchars($name),
-                    "seeders" => (int) $seeders,
-                    "leechers" => (int) $leechers,
-                    "magnet" => htmlspecialchars($magnet),
-                    "size" => htmlspecialchars($size),
-                    "source" => "torrentgalaxy.to"
-                )
-            );
-        }
-
-        return $results;
-    }
-?>

+ 0 - 45
engines/bittorrent/yts.php

@@ -1,45 +0,0 @@
-<?php
-    $yts_url = "https://yts.mx/api/v2/list_movies.json?query_term=$query";
-
-    function get_yts_results($response)
-    {
-        global $config;
-        $results = array();
-        $json_response = json_decode($response, true);
-
-        if ($json_response["status"] == "ok" && $json_response["data"]["movie_count"] != 0)
-        {
-            foreach ($json_response["data"]["movies"] as $movie)
-            {
-                    $name = $movie["title"];
-                    $name_encoded = urlencode($name);
-
-                    foreach ($movie["torrents"] as $torrent)
-                    {
-
-                        $hash = $torrent["hash"];
-                        $seeders = $torrent["seeds"];
-                        $leechers = $torrent["peers"];
-                        $size = $torrent["size"];
-
-                        $magnet = "magnet:?xt=urn:btih:$hash&dn=$name_encoded$config->bittorent_trackers";
-
-                        array_push($results, 
-                        array (
-                            "size" => htmlspecialchars($size),
-                            "name" => htmlspecialchars($name),
-                            "seeders" => htmlspecialchars($seeders),
-                            "leechers" => htmlspecialchars($leechers),
-                            "magnet" => htmlspecialchars($magnet),
-                            "source" => "yts.mx"
-                        )
-                    );
-                    
-                    }
-            }
-        }
-
-        return $results;
-       
-    }
-?>

+ 64 - 135
engines/google/text.php

@@ -3,150 +3,79 @@
     {
         global $config;
 
-        $mh = curl_multi_init();
-        $query_encoded = urlencode($query);
+        // Randomly choose a instance
+
         $results = array();
+        $num = array_rand($config->instances);
+        $instance = $config->instances[$num];
+        $url = "https://$instance/api.php";
+
+        // Create parameters in cookies
+        // Long time ago parameters like google_language or alternative_frontends are in POST field
+        // IMO those changes are not good for privacy, I will consider to create a fork to bring back POST field method
+        // BTW domain (google) can't be changed but mostly .com is used
 
-        $domain = $config->google_domain;
         $site_language = isset($_COOKIE["google_language_site"]) ? trim(htmlspecialchars($_COOKIE["google_language_site"])) : $config->google_language_site;
         $results_language = isset($_COOKIE["google_language_results"]) ? trim(htmlspecialchars($_COOKIE["google_language_results"])) : $config->google_language_results;
         $number_of_results = isset($_COOKIE["google_number_of_results"]) ? trim(htmlspecialchars($_COOKIE["google_number_of_results"])) : $config->google_number_of_results;
+        $wikipedia_language = isset($_COOKIE["wikipedia_language"]) ? trim(htmlspecialchars($_COOKIE["wikipedia_language"])) : $config->wikipedia_language;
+
+        $cookies = array(
+            "google_language_site" => ((3 > strlen($site_language) && 0 < strlen($site_language))) ? $site_language : null,
+            "google_language_results" => ((3 > strlen($results_language) && 0 < strlen($results_language))) ? $results_language : null,
+            "google_number_of_results" => ((3 > strlen($number_of_results) && 0 < strlen($number_of_results))) ? $number_of_results : null,
+            "wikipedia_language" => $wikipedia_language, // need some fix
+            "safe_search" => isset($_COOKIE["safe_search"]) ? $_COOKIE["safe_search"] : null,
+            "disable_special" => isset($_COOKIE["disable_special"]) ? $_COOKIE["disable_special"] : null
+        );
+
+        // API POST field
+        // Query should be encoded in api/search.php first but dunno why original repo still encode query in this function
+        $query_encoded = urlencode($query);
+        $post_string = "q=$query_encoded&p=$page&t=0";
 
-        $url = "https://www.google.$domain/search?q=$query_encoded&start=$page";
-
-        if (3 > strlen($site_language) && 0 < strlen($site_language))
-            $url .= "&hl=$site_language";
-
-        if (3 > strlen($results_language) && 0 < strlen($results_language))
-            $url .= "&lr=lang_$results_language";
-
-        if (3 > strlen($number_of_results) && 0 < strlen($number_of_results))
-            $url .= "&num=$number_of_results";
-
-        if (isset($_COOKIE["safe_search"]))
-            $url .= "&safe=medium";
-
-        $google_ch = curl_init($url);
-        curl_setopt_array($google_ch, $config->curl_settings);
-        curl_multi_add_handle($mh, $google_ch);
-
-        $special_search = $page ? 0 : check_for_special_search($query);
-        $special_ch = null;
-        $url = null;
-        if ($special_search != 0)
-        {
-            switch ($special_search)
-            {
-                case 1:
-                    $url = "https://cdn.moneyconvert.net/api/latest.json";
-                    break;
-                case 2:
-                    $split_query = explode(" ", $query);
-                    $reversed_split_q = array_reverse($split_query);
-                    $word_to_define = $reversed_split_q[1];
-                    $url = "https://api.dictionaryapi.dev/api/v2/entries/en/$word_to_define";
-                    break;
-                case 5:
-                    $url = "https://wttr.in/@" . $_SERVER["REMOTE_ADDR"] . "?format=j1";
-                    break;
-                case 6:
-                    $url = "https://check.torproject.org/torbulkexitlist";
-                    break;
-                case 7:
-                    $wikipedia_language = isset($_COOKIE["wikipedia_language"]) ? trim(htmlspecialchars($_COOKIE["wikipedia_language"])) : $config->wikipedia_language;
-                    $url = "https://$wikipedia_language.wikipedia.org/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded";
-                    break;
-            }
-            
-            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);
-        } while ($running);
-
-
-        if ($special_search != 0)
-        {
-            $special_result = null;
-
-            switch ($special_search)
-            {
-                case 1:
-                    require "engines/special/currency.php";
-                    $special_result = currency_results($query, curl_multi_getcontent($special_ch));
-                    break;
-                case 2:
-                    require "engines/special/definition.php";
-                    $special_result = definition_results($query, curl_multi_getcontent($special_ch));
-                    break;
-
-                case 3:
-                    require "engines/special/ip.php";
-                    $special_result = ip_result();
-                    break;
-                case 4:
-                    require "engines/special/user_agent.php";
-                    $special_result = user_agent_result();
-                    break;
-                case 5:
-                    require "engines/special/weather.php";
-                    $special_result = weather_results(curl_multi_getcontent($special_ch));
-                    break;
-                case 6:
-                    require "engines/special/tor.php";
-                    $special_result = tor_result(curl_multi_getcontent($special_ch));
-                    break;
-                case 7:
-                    require "engines/special/wikipedia.php";
-                    $special_result = wikipedia_results($query, curl_multi_getcontent($special_ch));
-                    break;
-            }
-
-            if ($special_result != null)
-                array_push($results, $special_result);
-        }
-
-        $xpath = get_xpath(curl_multi_getcontent($google_ch));
-
-        foreach($xpath->query("//div[@id='search']//div[contains(@class, 'g')]") as $result)
+        // Alternative frontends
+        // Fuck the cookie abuse in API
+        if (!isset($_COOKIE["disable_frontends"]))
         {
-            $url = $xpath->evaluate(".//div[@class='yuRUbf']//a/@href", $result)[0];
-
-            if ($url == null)
-                continue;
-
-            if (!empty($results)) // filter duplicate results, ignore special result
-            {
-                if (!array_key_exists("special_response", end($results)))
-                    if (end($results)["url"] == $url->textContent)
-                        continue;
-            }
-
-            $url = $url->textContent;
-
-            $url = check_for_privacy_frontend($url);
-
-            $title = $xpath->evaluate(".//h3", $result)[0];
-            $description = $xpath->evaluate(".//div[contains(@class, 'VwiC3b')]", $result)[0];
-
-            array_push($results,
-                array (
-                    "title" => htmlspecialchars($title->textContent),
-                    "url" =>  htmlspecialchars($url),
-                    "base_url" => htmlspecialchars(get_base_url($url)),
-                    "description" =>  $description == null ?
-                                      "No description was provided for this site." :
-                                      htmlspecialchars($description->textContent)
-                )
+            $frontends = array(
+                "invidious"=>null,
+                "rimgo"=>null,
+                "scribe"=>null,
+                "gothub"=>null,
+                "librarian"=>null,
+                "nitter"=>null,
+                "libreddit"=>null,
+                "proxitok"=>null,
+                "wikiless"=>null,
+                "quetre"=>null,
+                "libremdb"=>null,
+                "breezewiki"=>null,
+                "anonymousoverflow"=>null,
+                "suds"=>null,
+                "biblioreads"=>null
             );
+            foreach ($frontends as $i => $value) {
+                if (isset($_COOKIE[$i]))
+                    $frontends[$i] = $_COOKIE[$i];
+                else if (!empty($config->frontends[$i]["instance_url"]))
+                    $frontends[$i] = $config->frontends[$i]["instance_url"];
+            }
+            $cookies=array_merge($cookies, $frontends);
         }
+        else
+            $cookies=array_merge($cookies, array("disable_frontends"=>$_COOKIE["disable_frontends"]));
+
+        $api_ch = curl_init($url);
+        curl_setopt_array($api_ch, $config->curl_settings);
+        curl_setopt($api_ch, CURLOPT_CUSTOMREQUEST, "POST");
+        //curl_setopt($api_ch, CURLOPT_POST, true);
+        curl_setopt($api_ch, CURLOPT_COOKIE, urldecode(http_build_query($cookies, '', ';')));
+        curl_setopt($api_ch, CURLOPT_POSTFIELDS, $post_string);
+        $results = json_decode(curl_exec($api_ch),true);
+
+        // In case some instances were broken...
+        if($results == null) $results = "$instance is broken";
 
         return $results;
     }

+ 28 - 28
engines/invidious/video.php

@@ -2,39 +2,39 @@
     function get_video_results($query)
     {
         global $config;
-        $instance_url = $config->invidious_instance_for_video_results;
-        
-        $url = "$instance_url/api/v1/search?q=$query";
-        $response = request($url);
-        $json_response = json_decode($response, true);
+
+        // Randomly choose a instance
+
         $results = array();
+        $num = array_rand($config->instances);
+        $instance = $config->instances[$num];
+        $url = "https://$instance/api.php";
 
-        foreach ($json_response as $response)
-        {
-            if ($response["type"] == "video")
-            {
-                $title = $response["title"];
-                $url = "https://youtube.com/watch?v=" . $response["videoId"];
-                $url = check_for_privacy_frontend($url);
-                $uploader = $response["author"];
-                $views = $response["viewCount"];
-                $date = $response["publishedText"];
-                $thumbnail = $instance_url . "/vi/" . explode("/vi/" ,$response["videoThumbnails"][4]["url"])[1];
+        // API POST field
+        $post_string = "q=$query&t=2";
 
-                array_push($results,
-                    array (
-                        "title" => htmlspecialchars($title),
-                        "url" =>  htmlspecialchars($url),
-                        "base_url" => htmlspecialchars(get_base_url($url)),
-                        "uploader" => htmlspecialchars($uploader),
-                        "views" => htmlspecialchars($views),
-                        "date" => htmlspecialchars($date),
-                        "thumbnail" => htmlspecialchars($thumbnail)
-                    )
-                );
-            }
+        // alternative frontends
+        // fuck the cookie abuse in API
+        if (!isset($_COOKIE["disable_frontends"]))
+        {
+            if (isset($_COOKIE["invidious"]))
+                $cookies=array("invidious"=>$_COOKIE["invidious"]);
+            else if (!empty($config->frontends["invidious"]["instance_url"]))
+                $cookies=array("invidious"=>$config->frontends["invidious"]["instance_url"]);
+            else
+                $cookies=array("invidious"=>null);
         }
+        else
+            $cookies=array("disable_frontends"=>$_COOKIE["disable_frontends"]);
+
+        $api_ch = curl_init($url);
+        curl_setopt_array($api_ch, $config->curl_settings);
+        curl_setopt($api_ch, CURLOPT_CUSTOMREQUEST, "POST");
+        curl_setopt($api_ch, CURLOPT_COOKIE, http_build_query($cookies, '', ';'));
+        curl_setopt($api_ch, CURLOPT_POSTFIELDS, $post_string);
+        $results = json_decode(curl_exec($api_ch),true);
 
+        if($results == null) $results = "$instance is broken";
         return $results;
     }
 

+ 46 - 30
engines/qwant/image.php

@@ -1,42 +1,58 @@
 <?php
-    function get_image_results($query, $page) 
+    function get_image_results($query, $page)
     {
         global $config;
 
-        $page = $page / 10 + 1; // qwant has a different page system
-        
-        $url = "https://lite.qwant.com/?q=$query&t=images&p=$page";
-        $response = request($url);
-        $xpath = get_xpath($response);
+        // Randomly choose a instance
 
         $results = array();
+        $num = array_rand($config->instances);
+        $instance = $config->instances[$num];
+        $url = "https://$instance/api.php";
 
-        foreach($xpath->query("//a[@rel='noopener']") as $result)
-        {       
-                $image = $xpath->evaluate(".//img", $result)[0];
-
-                if ($image)
-                {
-                    $encoded_url = $result->getAttribute("href");
-                    $encoded_url_split1 = explode("==/", $encoded_url)[1];
-                    $encoded_url_split2 = explode("?position", $encoded_url_split1)[0];
-                    $real_url = urldecode(base64_decode($encoded_url_split2));
-                    $real_url = check_for_privacy_frontend($real_url);
-
-                    $alt = $image->getAttribute("alt");
-                    $thumbnail = urlencode($image->getAttribute("src"));
-
-                    array_push($results, 
-                        array (
-                            "thumbnail" => urldecode(htmlspecialchars($thumbnail)),
-                            "alt" => htmlspecialchars($alt),
-                            "url" => htmlspecialchars($real_url)
-                        )
-                    );
-    
-                }
+        // API POST field
+        $post_string = "q=$query&p=$page&t=1";
+
+        // alternative frontends
+        // fuck the cookie abuse in API
+        if (!isset($_COOKIE["disable_frontends"]))
+        {
+            $frontends = array(
+                "invidious"=>null,
+                "rimgo"=>null,
+                "scribe"=>null,
+                "gothub"=>null,
+                "librarian"=>null,
+                "nitter"=>null,
+                "libreddit"=>null,
+                "proxitok"=>null,
+                "wikiless"=>null,
+                "quetre"=>null,
+                "libremdb"=>null,
+                "breezewiki"=>null,
+                "anonymousoverflow"=>null,
+                "suds"=>null,
+                "biblioreads"=>null
+            );
+            foreach ($frontends as $i => $value) {
+                if (isset($_COOKIE[$i]))
+                    $frontends[$i] = $_COOKIE[$i];
+                else if (!empty($config->frontends[$i]["instance_url"]))
+                    $frontends[$i] = $config->frontends[$i]["instance_url"];
+            }
+            $cookies=array_merge($cookies, $frontends);
         }
+        else
+            $cookies=array_merge($cookies, array("disable_frontends"=>$_COOKIE["disable_frontends"]));
+
+        $api_ch = curl_init($url);
+        curl_setopt_array($api_ch, $config->curl_settings);
+        curl_setopt($api_ch, CURLOPT_CUSTOMREQUEST, "POST");
+        curl_setopt($api_ch, CURLOPT_COOKIE, http_build_query($cookies, '', ';'));
+        curl_setopt($api_ch, CURLOPT_POSTFIELDS, $post_string);
+        $results = json_decode(curl_exec($api_ch),true);
 
+        if($results == null) $results = "$instance is broken";
         return $results;
     }
 

+ 0 - 31
engines/special/currency.php

@@ -1,31 +0,0 @@
-<?php
-    function currency_results($query, $response)
-    { 
-        $split_query = explode(" ", $query);
-
-        $base_currency = strtoupper($split_query[1]);
-        $currency_to_convert = strtoupper($split_query[3]);
-        $amount_to_convert = floatval($split_query[0]);   
-        
-        $json_response = json_decode($response, true);
-                
-        $rates =  $json_response["rates"];
-
-        if (array_key_exists($base_currency, $rates) && array_key_exists($currency_to_convert, $rates))
-        {
-            $base_currency_response = $rates[$base_currency];
-            $currency_to_convert_response = $rates[$currency_to_convert];
-
-            $conversion_result = ($currency_to_convert_response / $base_currency_response) * $amount_to_convert;
-
-            $formatted_response = "$amount_to_convert $base_currency = $conversion_result $currency_to_convert";
-            $source = "https://moneyconvert.net/";
-            return array(
-                "special_response" => array(
-                    "response" => htmlspecialchars($formatted_response),
-                    "source" => $source
-                )
-            );
-        }                    
-    }
-?>

+ 0 - 24
engines/special/definition.php

@@ -1,24 +0,0 @@
-<?php
-    function definition_results($query, $response) 
-    {        
-            $split_query = explode(" ", $query);
-            $reversed_split_q = array_reverse($split_query);
-            $word_to_define = $reversed_split_q[1];
-
-            $json_response = json_decode($response, true);
-
-            if (!array_key_exists("title", $json_response))
-            {
-                $definition = $json_response[0]["meanings"][0]["definitions"][0]["definition"];
-
-                $source = "https://dictionaryapi.dev";
-                return array(
-                    "special_response" => array(
-                        "response" => htmlspecialchars($definition),
-                        "source" => $source
-                    )
-                );
-            }
-        
-    }
-?>

+ 0 - 11
engines/special/ip.php

@@ -1,11 +0,0 @@
-<?php
-    function ip_result()
-    {
-            return array(
-                "special_response" => array(
-                    "response" => $_SERVER["REMOTE_ADDR"],
-                    "source" => null
-                )
-            );
-    }
-?>

+ 0 - 18
engines/special/tor.php

@@ -1,18 +0,0 @@
-<?php
-    function tor_result($response)
-    {
-            $formatted_response = "It seems like you are not using Tor";
-            if (strpos($response, $_SERVER["REMOTE_ADDR"]) !== false)
-            {
-                $formatted_response = "It seems like you are using Tor";
-            }
-
-            $source = "https://check.torproject.org";
-            return array(
-                "special_response" => array(
-                    "response" => $formatted_response,
-                    "source" => $source
-                )
-            );
-    }
-?>

+ 0 - 11
engines/special/user_agent.php

@@ -1,11 +0,0 @@
-<?php
-    function user_agent_result()
-    {
-            return array(
-                "special_response" => array(
-                    "response" => $_SERVER["HTTP_USER_AGENT"], 
-                    "source" => null
-                )
-            );                   
-    }
-?>

+ 0 - 26
engines/special/weather.php

@@ -1,26 +0,0 @@
-<?php
-    function weather_results($response)
-    {
-            $json_response = json_decode($response, true);
-
-            if ($json_response)
-            {
-                $current_weather = $json_response["current_condition"][0];
-
-                $temp_c = $current_weather["temp_C"];
-                $temp_f = $current_weather["temp_F"];
-                $description = $current_weather["weatherDesc"][0]["value"];
-
-                $formatted_response = "$description - $temp_c °C | $temp_f °F";
-
-                $source = "https://wttr.in";
-                return array(
-                    "special_response" => array(
-                        "response" => htmlspecialchars($formatted_response),
-                        "source" => $source
-                    )
-                );
-            }
-
-    }
-?>

+ 0 - 35
engines/special/wikipedia.php

@@ -1,35 +0,0 @@
-<?php
-    function wikipedia_results($query, $response) 
-    {
-        global $config;
-
-        $query_encoded = urlencode($query);
-
-        $json_response = json_decode($response, true);
-
-        $first_page = array_values($json_response["query"]["pages"])[0];
-
-        if (!array_key_exists("missing", $first_page))
-        {
-            $description = substr($first_page["extract"], 0, 250) . "...";
-
-            $wikipedia_language = isset($_COOKIE["wikipedia_language"]) ? trim(htmlspecialchars($_COOKIE["wikipedia_language"])) : $config->wikipedia_language;
-
-            $source = check_for_privacy_frontend("https://$wikipedia_language.wikipedia.org/wiki/$query");
-            $response = array(
-                "special_response" => array(
-                    "response" => htmlspecialchars($description),
-                    "source" => $source
-                )
-            );
-
-            if (array_key_exists("thumbnail",  $first_page))
-            {
-                $image_url = $first_page["thumbnail"]["source"];
-                $response["special_response"]["image"] = $image_url;
-            }
-
-            return $response;
-        }
-    }
-?>

+ 2 - 2
index.php

@@ -3,7 +3,7 @@
     <title>LibreX</title>
     </head>
     <body>
-        <form class="search-container" action="search.php" method="get" autocomplete="off">
+        <form class="search-container" action="search.php" method="post" enctype="multipart/form-data" autocomplete="off">
                 <h1>Libre<span class="X">X</span></h1>
                 <input type="text" name="q" autofocus/>
                 <input type="hidden" name="p" value="0"/>
@@ -15,4 +15,4 @@
                 </div>
         </form>
 
-<?php require "misc/footer.php"; ?>
+<?php require "misc/footer.php"; ?>

+ 5 - 152
misc/tools.php

@@ -1,11 +1,4 @@
 <?php
-    function get_base_url($url)
-    {
-        $split_url = explode("/", $url);
-        $base_url = $split_url[0] . "//" . $split_url[2] . "/";
-        return $base_url;
-    }
-
     function get_root_domain($url)
     {
         $split_url = explode("/", $url);
@@ -13,81 +6,8 @@
 
         $base_url_main_split = explode(".", strrev($base_url));
         $root_domain = strrev($base_url_main_split[1]) . "." . strrev($base_url_main_split[0]);
-    
-        return $root_domain;
-    }
-
-    function try_replace_with_frontend($url, $frontend, $original)
-    {
-        global $config;
-        $frontends = $config->frontends;
-
-        if (isset($_COOKIE[$frontend]) || !empty($frontends[$frontend]["instance_url"]))
-        {
-            
-            if (isset($_COOKIE[$frontend]))
-                $frontend = $_COOKIE[$frontend];
-            else if (!empty($frontends[$frontend]["instance_url"]))
-                $frontend = $frontends[$frontend]["instance_url"];
-
-            if (empty(trim($frontend)))
-                return $url;
-
-            if (strpos($url, "wikipedia.org") !== false)
-            {
-                $wiki_split = explode(".", $url);
-                if (count($wiki_split) > 1)
-                {
-                    $lang = explode("://", $wiki_split[0])[1];
-                    $url =  $frontend . explode($original, $url)[1] . (strpos($url, "?") !== false ? "&" : "?")  . "lang=" . $lang;
-                }
-            }
-            else if (strpos($url, "fandom.com") !== false)
-            {
-                $fandom_split = explode(".", $url);
-                if (count($fandom_split) > 1)
-                {
-                    $wiki_name = explode("://", $fandom_split[0])[1];
-                    $url =  $frontend . "/" . $wiki_name . explode($original, $url)[1];
-                }
-            }
-            else if (strpos($url, "gist.github.com") !== false)
-            {
-                $gist_path = explode("gist.github.com", $url)[1];
-                $url = $frontend . "/gist" . $gist_path;
-            }
-            else
-            {
-                $url =  $frontend . explode($original, $url)[1];
-            }
-
-
-            return $url;
-        }
-
-        return $url;
-    }
-
-    function check_for_privacy_frontend($url)
-    {
-
-        global $config;
 
-        if (isset($_COOKIE["disable_frontends"]))
-            return $url;
-
-        foreach($config->frontends as $frontend => $data)
-        {
-            $original = $data["original_url"];
-
-            if (strpos($url, $original))
-            {
-                $url = try_replace_with_frontend($url, $frontend, $original);
-                break;
-            }
-        }
-
-        return $url;
+        return $root_domain;
     }
 
     function check_ddg_bang($query)
@@ -100,7 +20,7 @@
             $search_word = substr(explode(" ", $query)[0], 1);
         else
             $search_word = substr(end(explode(" ", $query)), 1);
-        
+
         $bang_url = null;
 
         foreach($bangs as $bang)
@@ -118,67 +38,14 @@
             $bang_query = trim(implode("", $bang_query_array));
 
             $request_url = str_replace("{{{s}}}", $bang_query, $bang_url);
-            $request_url = check_for_privacy_frontend($request_url);
+            // $request_url = check_for_privacy_frontend($request_url);
 
             header("Location: " . $request_url);
             die();
         }
     }
 
-    function check_for_special_search($query)
-    {
-        if (isset($_COOKIE["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;
-        @$htmlDom->loadHTML($response);
-        $xpath = new DOMXPath($htmlDom);
-
-        return $xpath;
-    }
-
+    // Only works in indivious (original), ahmia (original) and image proxy
     function request($url)
     {
         global $config;
@@ -190,20 +57,6 @@
         return $response;
     }
 
-    function human_filesize($bytes, $dec = 2)
-    {
-        $size   = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
-        $factor = floor((strlen($bytes) - 1) / 3);
-
-        return sprintf("%.{$dec}f ", $bytes / pow(1024, $factor)) . @$size[$factor];
-    }
-
-    function remove_special($string)
-    {
-        $string = preg_replace("/[\r\n]+/", "\n", $string);
-        return trim(preg_replace("/\s+/", ' ', $string));
-     }
-
     function print_elapsed_time($start_time)
         {
             $end_time = number_format(microtime(true) - $start_time, 2, '.', '');
@@ -212,7 +65,7 @@
 
     function print_next_page_button($text, $page, $query, $type)
     {
-        echo "<form class=\"page\" action=\"search.php\" target=\"_top\" method=\"get\" autocomplete=\"off\">";
+        echo "<form class=\"page\" action=\"search.php\" target=\"_top\" method=\"post\" enctype=\"multipart/form-data\" autocomplete=\"off\">";
         echo "<input type=\"hidden\" name=\"p\" value=\"" . $page . "\" />";
         echo "<input type=\"hidden\" name=\"q\" value=\"$query\" />";
         echo "<input type=\"hidden\" name=\"t\" value=\"$type\" />";

+ 5 - 2
opensearch.xml.example

@@ -4,8 +4,11 @@
   <Description>Framework and javascript free privacy respecting meta search engine</Description>
   <InputEncoding>UTF-8</InputEncoding>
   <LongName>LibreX search</LongName>
-  <Url rel="results" type="text/html" method="get" template="http://localhost:80/search.php?q={searchTerms}" />
+  <Url rel="results" type="text/html" method="post" template="http://localhost:80/search.php">
+      <Param name="q" value="{searchTerms}" />
+  </Url>
+
   <Url type="application/opensearchdescription+xml"
       rel="self"
-      template="/opensearch.xml?method=GET" />
+      template="opensearch.xml?method=POST" />
 </OpenSearchDescription>

+ 2 - 2
search.php

@@ -12,7 +12,7 @@
 ?> - LibreX</title>
 </head>
     <body>
-        <form class="sub-search-container" method="get" autocomplete="off">
+        <form class="sub-search-container" method="post" enctype="multipart/form-data" autocomplete="off">
             <h1 class="logomobile"><a class="no-decoration" href="./">Libre<span class="X">X</span></a></h1>
             <input type="text" name="q"
                 <?php
@@ -48,7 +48,7 @@
                             continue;
                         }
 
-                        echo "<a " . (($category_index == $type) ? "class=\"active\"" : "") . "href=\"/search.php?q=" . $query . "&p=0&t=" . $category_index . "\"><img src=\"static/images/" . $category . "_result.png\" alt=\"" . $category . " result\" />" . ucfirst($category)  . "</a>";
+                        echo "<button name=\"t\" value=\"$category_index\" " . (($category_index == $type) ? "class=\"active\"" : "") . "><img src=\"static/images/" . $category . "_result.png\" alt=\"" . $category . " result\" />" . ucfirst($category)  . "</button>";
                     }
                 ?>
             </div>

+ 3 - 4
static/css/styles.css

@@ -30,8 +30,7 @@ a,
 
 .text-result-wrapper a:visited h2,
 .special-result-container a,
-.sub-search-button-wrapper a,
-.sub-search-button-wrapper a:visited{
+.sub-search-button-wrapper button {
     color: #bd93f9;
 }
 
@@ -131,7 +130,7 @@ a:hover,
     margin-right: 5px;
 }
 
-.sub-search-button-wrapper a {
+.sub-search-button-wrapper button {
     border: none;
     background-color: inherit;
     font-size: 15px;
@@ -431,7 +430,7 @@ a[title] {
         padding: 0;
     }
 
-    .sub-search-button-wrapper a {
+    .sub-search-button-wrapper button {
         margin-left: auto;
         margin-right: auto;
         padding: 0;