Compare commits
99 Commits
indev
...
05cb1387f4
| Author | SHA1 | Date | |
|---|---|---|---|
| 05cb1387f4 | |||
| 1e0eb470c6 | |||
| 6a60c0fd5d | |||
|
|
e72fadc791 | ||
|
|
186f66619c | ||
|
|
b8c920ef0a | ||
|
|
09e1f7e1ea | ||
|
|
250898c638 | ||
|
|
bd3da22325 | ||
|
|
e5a836e135 | ||
|
|
c9471adb9c | ||
|
|
2d2bb4916d | ||
|
|
7a584d8a97 | ||
|
|
3fb6f96d13 | ||
|
|
a17f023821 | ||
|
|
f41fa9e4b3 | ||
|
|
acdff2d3a2 | ||
|
|
892acdc7f2 | ||
|
|
4a705bd1b8 | ||
|
|
aace4b8f91 | ||
|
|
e352971bc5 | ||
|
|
12f046669e | ||
|
|
68d9d46e5e | ||
|
|
bc0bc73044 | ||
|
|
b23e5eeb6d | ||
|
|
f1c35fde85 | ||
|
|
a20a9e8878 | ||
|
|
10d44e7ff5 | ||
|
|
f20d8f7115 | ||
|
|
d93fead0ae | ||
|
|
296021e0ce | ||
|
|
499bb9b126 | ||
|
|
11acc93f43 | ||
|
|
2419dec7f8 | ||
|
|
7b587d82c8 | ||
|
|
9c68a8ae6f | ||
|
|
953937cfa2 | ||
|
|
1b36b1a23e | ||
|
|
de6d8d1bfd | ||
|
|
36a7cabc3b | ||
|
|
4d54ded6e6 | ||
|
|
ad949a452f | ||
|
|
b8fd03344d | ||
|
|
c26a08c6a2 | ||
|
|
24f9909bad | ||
|
|
5808459c75 | ||
|
|
3c856f93ed | ||
|
|
ba6dae676a | ||
|
|
a9db276fd8 | ||
|
|
92dd87eb57 | ||
|
|
7665efca73 | ||
|
|
6738ab0eac | ||
|
|
3a99a37b0c | ||
|
|
4368e16368 | ||
|
|
3570cb5fb5 | ||
|
|
896b6cd266 | ||
|
|
eb2773f91c | ||
|
|
f6c8242e72 | ||
|
|
e0c209c974 | ||
|
|
deb3c308b8 | ||
|
|
7c5062dd07 | ||
|
|
8cd861fd86 | ||
|
|
a675d19d4f | ||
|
|
ccbb5d71de | ||
|
|
627a219bea | ||
|
|
db02c4cc80 | ||
|
|
c9709029ca | ||
|
|
0eff62bf68 | ||
|
|
96b57648dd | ||
|
|
37f18d148f | ||
|
|
62e6d0c3d6 | ||
|
|
08c1aa8abe | ||
|
|
b9f775fc2d | ||
|
|
821e670ddd | ||
|
|
2fb5f975de | ||
|
|
d2e0c7f481 | ||
|
|
f66686a959 | ||
|
|
f29fa38398 | ||
|
|
478aafcf87 | ||
|
|
1382d73d53 | ||
|
|
8176078105 | ||
|
|
614bd26cb3 | ||
|
|
c6bdeecb2a | ||
|
|
116069c8e9 | ||
|
|
c41ab84738 | ||
|
|
335b6f4683 | ||
|
|
71d3d0dcb0 | ||
|
|
0ea4bc726c | ||
|
|
f38fe3c42e | ||
|
|
c3ed901738 | ||
|
|
9e6e763064 | ||
|
|
6b8a278b4f | ||
|
|
252ed2fcfb | ||
|
|
ebdbbc2ff0 | ||
|
|
82075a664e | ||
|
|
1b9187b153 | ||
|
|
86a9ebb90a | ||
|
|
783a58d954 | ||
|
|
e9b01902d9 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
/bin
|
||||
/obj
|
||||
config.ini
|
||||
.session
|
||||
|
||||
46
Dockerfile
Normal file
46
Dockerfile
Normal file
@@ -0,0 +1,46 @@
|
||||
# ---------- Build stage ----------
|
||||
FROM alpine:3.20 AS builder
|
||||
|
||||
RUN apk add --no-cache \
|
||||
build-base \
|
||||
curl-dev \
|
||||
libxml2-dev \
|
||||
openssl-dev \
|
||||
git \
|
||||
pkgconf
|
||||
|
||||
WORKDIR /app
|
||||
COPY . /app
|
||||
|
||||
RUN git clone https://git.bwaaa.space/beaker /tmp/beaker && \
|
||||
cd /tmp/beaker && \
|
||||
make && make install && \
|
||||
rm -rf /tmp/beaker
|
||||
|
||||
RUN make clean && make && strip bin/omnisearch
|
||||
|
||||
# ---------- Runtime stage ----------
|
||||
FROM alpine:3.20
|
||||
|
||||
RUN apk add --no-cache \
|
||||
libcurl \
|
||||
libxml2 \
|
||||
openssl
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy only required artifacts
|
||||
COPY --from=builder /app/bin/omnisearch /app/omnisearch
|
||||
COPY --from=builder /usr/lib/libbeaker.so /usr/lib/libbeaker.so
|
||||
COPY --from=builder /app/templates /app/templates
|
||||
COPY --from=builder /app/static /app/static
|
||||
|
||||
# Security: non-root user
|
||||
RUN adduser -D appuser && chmod +x /app/omnisearch
|
||||
USER appuser
|
||||
|
||||
ENV LD_LIBRARY_PATH=/usr/lib
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["/app/omnisearch"]
|
||||
44
Makefile
44
Makefile
@@ -3,13 +3,23 @@ UNAME_S := $(shell uname -s)
|
||||
PKG_CONFIG ?= pkg-config
|
||||
PKG_DEPS := libxml-2.0 libcurl openssl
|
||||
|
||||
GIT_HASH := $(shell git rev-parse --short HEAD)
|
||||
GIT_DATE := $(shell git log -1 --format='%ad' --date='format:%y.%m.%d')
|
||||
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
||||
GIT_REMOTE := $(shell git remote get-url origin)
|
||||
GIT_TAG := $(shell git describe --tags --exact-match HEAD 2>/dev/null)
|
||||
|
||||
VERSION := $(if $(GIT_TAG),$(GIT_TAG),$(GIT_DATE)+$(GIT_HASH)_$(GIT_BRANCH))
|
||||
|
||||
CFLAGS := -Wall -Wextra -O2 -Isrc -DVERSION='"$(VERSION)"' -DGIT_REMOTE='"$(GIT_REMOTE)"'
|
||||
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
DEP_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PKG_DEPS) 2>/dev/null)
|
||||
DEP_LIBS := $(shell $(PKG_CONFIG) --libs $(PKG_DEPS) 2>/dev/null)
|
||||
CFLAGS := -Wall -Wextra -O2 -Isrc $(DEP_CFLAGS)
|
||||
CFLAGS += $(DEP_CFLAGS)
|
||||
LIBS := -lbeaker $(DEP_LIBS) -lpthread -lm
|
||||
else
|
||||
CFLAGS := -Wall -Wextra -O2 -Isrc -I/usr/include/libxml2
|
||||
CFLAGS += -I/usr/include/libxml2
|
||||
LIBS := -lbeaker -lcurl -lxml2 -lpthread -lm -lssl -lcrypto
|
||||
endif
|
||||
|
||||
@@ -76,6 +86,7 @@ USER := omnisearch
|
||||
GROUP := omnisearch
|
||||
|
||||
SYSTEMD_DIR := /etc/systemd/system
|
||||
RUNIT_DIR ?= $(error Please set RUNIT_DIR to your services directory)
|
||||
OPENRC_DIR := /etc/init.d
|
||||
DINIT_DIR := /etc/dinit.d
|
||||
LAUNCHD_DIR ?= /Library/LaunchDaemons
|
||||
@@ -94,9 +105,10 @@ install:
|
||||
@echo "Example: doas/sudo make install-openrc"
|
||||
|
||||
install-launchd: $(TARGET)
|
||||
@mkdir -p $(DATA_DIR)/templates $(DATA_DIR)/static $(INSTALL_BIN_DIR) $(LOG_DIR)
|
||||
@mkdir -p $(DATA_DIR)/templates $(DATA_DIR)/static $(DATA_DIR)/locales $(INSTALL_BIN_DIR) $(LOG_DIR)
|
||||
@cp -rf templates/* $(DATA_DIR)/templates/
|
||||
@cp -rf static/* $(DATA_DIR)/static/
|
||||
@cp -rf locales/* $(DATA_DIR)/locales/
|
||||
@cp -n example-config.ini $(DATA_DIR)/config.ini || true
|
||||
install -m 755 $(TARGET) $(INSTALL_BIN_DIR)/omnisearch
|
||||
@mkdir -p $(LAUNCHD_DIR)
|
||||
@@ -115,9 +127,10 @@ install-launchd: $(TARGET)
|
||||
@echo "Start with: sudo launchctl kickstart -k system/$(LAUNCHD_LABEL)"
|
||||
|
||||
install-systemd: $(TARGET)
|
||||
@mkdir -p $(DATA_DIR)/templates $(DATA_DIR)/static $(LOG_DIR) $(CACHE_DIR)
|
||||
@mkdir -p $(DATA_DIR)/templates $(DATA_DIR)/static $(DATA_DIR)/locales $(LOG_DIR) $(CACHE_DIR)
|
||||
@cp -rf templates/* $(DATA_DIR)/templates/
|
||||
@cp -rf static/* $(DATA_DIR)/static/
|
||||
@cp -rf locales/* $(DATA_DIR)/locales/
|
||||
@cp -n example-config.ini $(DATA_DIR)/config.ini || true
|
||||
install -m 755 $(TARGET) $(INSTALL_BIN_DIR)/omnisearch
|
||||
@echo "Setting up user '$(USER)'..."
|
||||
@@ -133,9 +146,10 @@ install-systemd: $(TARGET)
|
||||
@echo "Run 'systemctl enable --now omnisearch' to start"
|
||||
|
||||
install-openrc: $(TARGET)
|
||||
@mkdir -p $(DATA_DIR)/templates $(DATA_DIR)/static $(LOG_DIR) $(CACHE_DIR)
|
||||
@mkdir -p $(DATA_DIR)/templates $(DATA_DIR)/static $(DATA_DIR)/locales $(LOG_DIR) $(CACHE_DIR)
|
||||
@cp -rf templates/* $(DATA_DIR)/templates/
|
||||
@cp -rf static/* $(DATA_DIR)/static/
|
||||
@cp -rf locales/* $(DATA_DIR)/locales/
|
||||
@cp -n example-config.ini $(DATA_DIR)/config.ini || true
|
||||
install -m 755 $(TARGET) $(INSTALL_BIN_DIR)/omnisearch
|
||||
@echo "Setting up user '$(USER)'..."
|
||||
@@ -151,9 +165,10 @@ install-openrc: $(TARGET)
|
||||
@echo "Run 'rc-update add omnisearch default' to enable"
|
||||
|
||||
install-runit: $(TARGET)
|
||||
@mkdir -p $(DATA_DIR)/templates $(DATA_DIR)/static $(LOG_DIR) $(CACHE_DIR) /etc/service/omnisearch/log/
|
||||
@mkdir -p $(DATA_DIR)/templates $(DATA_DIR)/static $(DATA_DIR)/locales $(LOG_DIR) $(CACHE_DIR) $(RUNIT_DIR)/omnisearch/log/
|
||||
@cp -rf templates/* $(DATA_DIR)/templates/
|
||||
@cp -rf static/* $(DATA_DIR)/static/
|
||||
@cp -rf locales/* $(DATA_DIR)/locales/
|
||||
@cp -n example-config.ini $(DATA_DIR)/config.ini || true
|
||||
install -m 755 $(TARGET) $(INSTALL_BIN_DIR)/omnisearch
|
||||
@echo "Setting up user '$(USER)'..."
|
||||
@@ -161,20 +176,21 @@ install-runit: $(TARGET)
|
||||
@id -u $(USER) >/dev/null 2>&1 || useradd --system --home $(DATA_DIR) --shell /usr/sbin/nologin -g $(GROUP) $(USER)
|
||||
@chown -R $(USER):$(GROUP) $(LOG_DIR) $(CACHE_DIR) $(VAR_DIR) $(DATA_DIR) 2>/dev/null || true
|
||||
@chown $(USER):$(GROUP) $(DATA_DIR)/config.ini 2>/dev/null || true
|
||||
install -m 755 init/runit/run /etc/service/omnisearch/run
|
||||
install -m 755 init/runit/log/run /etc/service/omnisearch/log/run
|
||||
install -m 755 init/runit/run $(RUNIT_DIR)/omnisearch/run
|
||||
install -m 755 init/runit/log/run $(RUNIT_DIR)/omnisearch/log/run
|
||||
@echo ""
|
||||
@echo "Config: $(DATA_DIR)/config.ini"
|
||||
@echo "Edit config with: nano $(DATA_DIR)/config.ini"
|
||||
@echo "Installed runit service to /etc/service/omnisearch"
|
||||
@echo "Installed runit service to $(RUNIT_DIR)/omnisearch"
|
||||
@echo "You need to start the service manually"
|
||||
@echo "Void: ln -s /etc/service/omnisearch/ /var/service"
|
||||
@echo "Artix: ln -s /etc/service/omnisearch/ /run/runit/"
|
||||
@echo "Void: ln -s $(RUNIT_DIR)/omnisearch/ /var/service/"
|
||||
@echo "Artix: ln -s $(RUNIT_DIR)/omnisearch/ /run/runit/"
|
||||
|
||||
install-s6: $(TARGET)
|
||||
@mkdir -p $(DATA_DIR)/templates $(DATA_DIR)/static $(LOG_DIR) $(CACHE_DIR)
|
||||
@mkdir -p $(DATA_DIR)/templates $(DATA_DIR)/static $(DATA_DIR)/locales $(LOG_DIR) $(CACHE_DIR)
|
||||
@cp -rf templates/* $(DATA_DIR)/templates/
|
||||
@cp -rf static/* $(DATA_DIR)/static/
|
||||
@cp -rf locales/* $(DATA_DIR)/locales/
|
||||
@cp -n example-config.ini $(DATA_DIR)/config.ini || true
|
||||
install -m 755 $(TARGET) $(INSTALL_BIN_DIR)/omnisearch
|
||||
@echo "Setting up user '$(USER)'..."
|
||||
@@ -193,9 +209,10 @@ install-s6: $(TARGET)
|
||||
@echo "Service will start automatically"
|
||||
|
||||
install-dinit: $(TARGET)
|
||||
@mkdir -p $(DATA_DIR)/templates $(DATA_DIR)/static $(LOG_DIR) $(CACHE_DIR)
|
||||
@mkdir -p $(DATA_DIR)/templates $(DATA_DIR)/static $(DATA_DIR)/locales $(LOG_DIR) $(CACHE_DIR)
|
||||
@cp -rf templates/* $(DATA_DIR)/templates/
|
||||
@cp -rf static/* $(DATA_DIR)/static/
|
||||
@cp -rf locales/* $(DATA_DIR)/locales/
|
||||
@cp -n example-config.ini $(DATA_DIR)/config.ini || true
|
||||
install -m 755 $(TARGET) $(INSTALL_BIN_DIR)/omnisearch
|
||||
@echo "Setting up user '$(USER)'..."
|
||||
@@ -218,6 +235,7 @@ uninstall:
|
||||
rm -f $(DINIT_DIR)/omnisearch
|
||||
rm -rf /etc/service/omnisearch
|
||||
rm -rf /var/service/omnisearch
|
||||
@echo "You might need to unlink omnisearch if you're using runit"
|
||||
@id -u $(USER) >/dev/null 2>&1 && userdel $(USER) 2>/dev/null || true
|
||||
@grep -q '^$(GROUP):' /etc/group 2>/dev/null && groupdel $(GROUP) 2>/dev/null || true
|
||||
@echo "Uninstalled omnisearch"
|
||||
|
||||
50
README.md
50
README.md
@@ -11,7 +11,7 @@ Create a config.ini, there is an example included in the root. Or if you install
|
||||
## Dependencies
|
||||
- libxml2
|
||||
- libcurl (may be replaced in the future with curl-impersonate)
|
||||
- beaker [(source)](https://git.bwaaa.monster/beaker/)
|
||||
- beaker [(source)](https://git.bwaaa.space/beaker/)
|
||||
|
||||
## First Setup
|
||||
Depending on your system, you may first need to install libcurl and libxml2.
|
||||
@@ -23,7 +23,7 @@ Depending on your system, you may first need to install libcurl and libxml2.
|
||||
|
||||
### Debian/Ubuntu
|
||||
```
|
||||
# apt install libxml2-dev libcurl4-openssl-dev
|
||||
# apt install build-essential libssl-dev libxml2-dev libcurl4-openssl-dev
|
||||
```
|
||||
|
||||
### Fedora
|
||||
@@ -47,32 +47,6 @@ On Alpine, `shadow` is needed for the user creation process during the install.
|
||||
# xbps-install -S libxml2-devel libcurl-devel
|
||||
```
|
||||
|
||||
### NixOS
|
||||
Add the flake to your inputs and import the module. That is all you need.
|
||||
Here's an example of using the modules in a flake:
|
||||
```
|
||||
# flake.nix
|
||||
{
|
||||
inputs = {
|
||||
omnisearch = {
|
||||
url = "git+https://git.bwaaa.monster/omnisearch";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, omnisearch, ... }: {
|
||||
nixosConfigurations.mySystem = nixpkgs.lib.nixosSystem {
|
||||
modules = [
|
||||
omnisearch.nixosModules.default
|
||||
{
|
||||
services.omnisearch.enable = true;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### macOS (Homebrew)
|
||||
```
|
||||
$ brew install libxml2 curl openssl pkg-config
|
||||
@@ -87,7 +61,7 @@ On macOS the build uses `pkg-config` to discover `libxml2`, `libcurl` and OpenSS
|
||||
|
||||
Install libbeaker:
|
||||
```
|
||||
$ git clone https://git.bwaaa.monster/beaker
|
||||
$ git clone https://git.bwaaa.space/beaker
|
||||
$ cd beaker
|
||||
$ make
|
||||
# make install
|
||||
@@ -97,7 +71,7 @@ On macOS `beaker` installs to `/usr/local/` by default and installs `libbeaker.d
|
||||
|
||||
And then install omnisearch:
|
||||
```
|
||||
$ git clone https://git.bwaaa.monster/omnisearch
|
||||
$ git clone https://git.bwaaa.space/omnisearch
|
||||
$ cd omnisearch
|
||||
$ make
|
||||
# make install-<init>
|
||||
@@ -108,6 +82,20 @@ On macOS, use `install-launchd`.
|
||||
## Hosting
|
||||
Run it normally behind a reverse proxy (like nginx)
|
||||
|
||||
## Deploy with Docker Compose
|
||||
|
||||
You need Docker or Podman and Docker Compose installed on your system.
|
||||
|
||||
Run the container:
|
||||
|
||||
```
|
||||
$ git clone https://git.bwaaa.space/omnisearch
|
||||
$ cd omnisearch
|
||||
$ docker compose up -d --build
|
||||
```
|
||||
|
||||
By default it can be reached on port 8087.
|
||||
|
||||
## Customisation
|
||||
To make your own changes while still being able to receive upstream updates:
|
||||
|
||||
@@ -125,6 +113,6 @@ $ git merge origin/master
|
||||
If there are conflicts in the files you modified, resolve them manually. You should also make the changes to the cloned repository, and then run the install command again if you installed omnisearch. Changes made directly to the configuration/assets folder will be overwritten on reinstall.
|
||||
|
||||
## Contribution
|
||||
Generate a patch with ```git format-patch HEAD~1``` and email to [gabriel@bwaaa.monster](mailto:gabriel@bwaaa.monster), beginning the subject line with [PATCH omnisearch]
|
||||
Generate a patch with ```git format-patch HEAD~1``` and email to [frostinator33@airmail.cc](mailto:frostinator33@airmail.cc), beginning the subject line with [PATCH omnisearch]
|
||||
|
||||
*If you are sending a revised version of a previous patch, please use [PATCH omnisearch v2, v3, etc].*
|
||||
|
||||
10
docker-compose.yml
Normal file
10
docker-compose.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
services:
|
||||
omnisearch:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- "8087:8087"
|
||||
volumes:
|
||||
- ./locales:/app/locales
|
||||
- ./example-config.ini:/etc/omnisearch/config.ini
|
||||
@@ -1,7 +1,9 @@
|
||||
[server]
|
||||
host = 0.0.0.0
|
||||
port = 8087
|
||||
domain = https://search.example.com
|
||||
|
||||
# Default locale (default: en_gb)
|
||||
#locale = en_gb
|
||||
|
||||
[proxy]
|
||||
# Single proxy (comment out to use list_file instead)
|
||||
@@ -29,5 +31,19 @@ domain = https://search.example.com
|
||||
[engines]
|
||||
# Use * for all engines, or specify comma-separated list (e.g., ddg,yahoo)
|
||||
# Use *,-engine to exclude specific engines (e.g., *,-startpage)
|
||||
# Available engines: ddg, startpage, yahoo, mojeek
|
||||
# Available engines: ddg, startpage, yahoo, mojeek, yacy
|
||||
engines="*"
|
||||
# YaCy instance to use for the yacy engine (optional, default: http://127.0.0.1:8090)
|
||||
# Requires "yacy" to be in the engines list above.
|
||||
#yacy_instance = http://127.0.0.1:8090
|
||||
|
||||
[rate_limit]
|
||||
# Rate limit searches per interval
|
||||
|
||||
# /search
|
||||
#search_requests = 10
|
||||
#search_interval = 60
|
||||
|
||||
# /images
|
||||
#images_requests = 20
|
||||
#images_interval = 60
|
||||
|
||||
18
flake.lock
generated
18
flake.lock
generated
@@ -3,28 +3,28 @@
|
||||
"beaker-src": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1773884524,
|
||||
"narHash": "sha256-1dnlofWaxI/YRID+WPz2jHZNDyloBubDt/bAQk9ePLU=",
|
||||
"lastModified": 1793900580,
|
||||
"narHash": "sha256-TWJAVS60lHQO+4Gmt86qlT7RN25HrqCSl3n7EE+OP1o=",
|
||||
"ref": "refs/heads/master",
|
||||
"rev": "abc598baf15d6f8a4de395a27ba34b1e769558e1",
|
||||
"revCount": 21,
|
||||
"rev": "aedf6c0c93acb2a8f57ef3f94498332b3ab6db89",
|
||||
"revCount": 48,
|
||||
"shallow": false,
|
||||
"type": "git",
|
||||
"url": "https://git.bwaaa.monster/beaker"
|
||||
"url": "https://git.bwaaa.space/beaker"
|
||||
},
|
||||
"original": {
|
||||
"shallow": false,
|
||||
"type": "git",
|
||||
"url": "https://git.bwaaa.monster/beaker"
|
||||
"url": "https://git.bwaaa.space/beaker"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1773734432,
|
||||
"narHash": "sha256-IF5ppUWh6gHGHYDbtVUyhwy/i7D261P7fWD1bPefOsw=",
|
||||
"lastModified": 1794386569,
|
||||
"narHash": "sha256-x9sADJvoVG0L6RejZB+/BB4YiGZFBZrfTlhF4uBq1tQ=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "cda48547b432e8d3b18b4180ba07473762ec8558",
|
||||
"rev": "d4f25a3e562008648d45bcf2d70bcc7422cad84e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
19
flake.nix
19
flake.nix
@@ -2,29 +2,25 @@
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
beaker-src = {
|
||||
url = "git+https://git.bwaaa.monster/beaker?shallow=0";
|
||||
url = "git+https://git.bwaaa.space/beaker?shallow=0";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
beaker-src,
|
||||
}:
|
||||
let
|
||||
}: let
|
||||
supportedSystems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
];
|
||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||
in
|
||||
{
|
||||
in {
|
||||
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt);
|
||||
packages = forAllSystems (
|
||||
system:
|
||||
let
|
||||
system: let
|
||||
pkgs = import nixpkgs {inherit system;};
|
||||
|
||||
beaker = pkgs.stdenv.mkDerivation {
|
||||
@@ -36,8 +32,7 @@
|
||||
"LDCONFIG=true"
|
||||
];
|
||||
};
|
||||
in
|
||||
{
|
||||
in {
|
||||
default = pkgs.stdenv.mkDerivation {
|
||||
pname = "omnisearch";
|
||||
version = "git";
|
||||
@@ -61,7 +56,7 @@
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin $out/share/omnisearch
|
||||
install -Dm755 bin/omnisearch $out/bin/omnisearch
|
||||
cp -r templates static -t $out/share/omnisearch/
|
||||
cp -r templates static locales -t $out/share/omnisearch/
|
||||
'';
|
||||
|
||||
meta = {
|
||||
|
||||
@@ -7,3 +7,4 @@ logfile-uid = omnisearch
|
||||
logfile-gid = omnisearch
|
||||
restart = yes
|
||||
restart-delay = 5
|
||||
waits-for = login.target
|
||||
34
locales/af_za.ini
Normal file
34
locales/af_za.ini
Normal file
@@ -0,0 +1,34 @@
|
||||
[Meta]
|
||||
Id = "af_za"
|
||||
Name = "Afrikaans (ZA)"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "Soek op die web..."
|
||||
search_button = "Soek"
|
||||
surprise_me_button = "Verras my"
|
||||
all_tab = "Alles"
|
||||
images_tab = "Foto's"
|
||||
settings_tab = "Instellings"
|
||||
settings_title = "Instellings"
|
||||
theme_label = "Kleurinstelling"
|
||||
theme_desc = "Kies jou voorkeur kleurskema."
|
||||
theme_system = "Stelsel"
|
||||
theme_light = "Lig"
|
||||
theme_dark = "Donker"
|
||||
language_label = "Taal"
|
||||
display_language_label = "Vertoontaal"
|
||||
language_desc = "Kies jou voorkeurtaal."
|
||||
engines_label = "Soekenjins"
|
||||
engines_desc = "Kies watter soekenjins om te gebruik. Slegs enjins wat op die bediener geaktiveer is, word gewys.."
|
||||
save_settings_button = "Stoor Instellings"
|
||||
no_results = "Geen resultate gevind nie"
|
||||
error_images = "Fout tydens die haal van foto's"
|
||||
rate_limit = "Stadiger! Te veel soektogte van jou!"
|
||||
warning_fetch_error = "versoek het misluk voordat OmniSearch soekresultate kon lees."
|
||||
warning_parse_mismatch = "het soekresultate in 'n formaat teruggegee wat OmniSearch nie kon ontleed nie."
|
||||
warning_blocked = "het 'n captcha of 'n ander blokkerende bladsy in plaas van soekresultate teruggegee."
|
||||
read_more = "Lees Meer"
|
||||
view_cached = "Gekasgeheue"
|
||||
view_image = "Foto"
|
||||
visit_site = "Webwerf"
|
||||
34
locales/bn_bd.ini
Normal file
34
locales/bn_bd.ini
Normal file
@@ -0,0 +1,34 @@
|
||||
[Meta]
|
||||
Id = "bn_bd"
|
||||
Name = "বাংলা"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "ওয়েব অনুসন্ধান করুন..."
|
||||
search_button = "অনুসন্ধান"
|
||||
surprise_me_button = "চমক প্রদর্শন"
|
||||
all_tab = "যাবতীয়"
|
||||
images_tab = "ছবি"
|
||||
settings_tab = "সেটিংস"
|
||||
settings_title = "সেটিংস"
|
||||
theme_label = "বাহ্যরূপ"
|
||||
theme_desc = "আপনার পছন্দের বর্ণবিন্যাস নির্ধারণ করুন।"
|
||||
theme_system = "সিস্টেম"
|
||||
theme_light = "আলো"
|
||||
theme_dark = "আঁধার"
|
||||
language_label = "ভাষা"
|
||||
display_language_label = "প্রদর্শিত ভাষা"
|
||||
language_desc = "আপনার পছন্দের ভাষা নির্ধারণ করুন।"
|
||||
engines_label = "সার্চ ইঞ্জিন"
|
||||
engines_desc = "ব্যবহৃত সার্চ ইঞ্জিন নির্ধারণ করুন। শুধু সার্ভারে চলনকৃত সার্চ ইঞ্জিন দেখানো।"
|
||||
save_settings_button = "সেটিংস সংরক্ষণ করুন"
|
||||
no_results = "কোনো ফলাফল পাওয়া যায়নি"
|
||||
error_images = "ছবি অনুসন্ধান করায় অক্ষম"
|
||||
rate_limit = "আস্তে-ধীরে! বহুত অনুসন্ধান করছেন দেখি!"
|
||||
warning_fetch_error = "অমনিসার্চ ফলাফল বোঝার আগেই আবেদন ব্যার্থ হয়েছে।"
|
||||
warning_parse_mismatch = "অমনিসার্চ বুঝতে অক্ষম এমনপ্রকার ফলাফল ফিরেছে।"
|
||||
warning_blocked = "অনুসন্ধানের ফলাফলের বদলে ক্যাপ্চা অথবা অন্য ব্লককারী পেজ ফিরেছে।"
|
||||
read_more = "পড়তে থাকুন"
|
||||
view_cached = "ক্যাশকৃত"
|
||||
view_image = "ছবি"
|
||||
visit_site = "সাইট"
|
||||
34
locales/de_de.ini
Normal file
34
locales/de_de.ini
Normal file
@@ -0,0 +1,34 @@
|
||||
[Meta]
|
||||
Id = "de_de"
|
||||
Name = "Deutsch (DE)"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "Suche das Internet..."
|
||||
search_button = "Suchen"
|
||||
surprise_me_button = "Überrasche mich"
|
||||
all_tab = "Alle"
|
||||
images_tab = "Bilder"
|
||||
settings_tab = "Einstellungen"
|
||||
settings_title = "Einstellungen"
|
||||
theme_label = "Aussehen"
|
||||
theme_desc = "Wähle ein Erscheinungsbild."
|
||||
theme_system = "System"
|
||||
theme_light = "Hell"
|
||||
theme_dark = "Dunkel"
|
||||
language_label = "Sprache"
|
||||
display_language_label = "Anzeigesprache"
|
||||
language_desc = "Wähle deine Sprache."
|
||||
engines_label = "Suchmaschinen"
|
||||
engines_desc = "Wähle die Suchmachinen die verwendet werden sollen. Nur Suchmachinen, die am Server aktiviert sind, werden gezeigt."
|
||||
save_settings_button = "Einstellungen speichern"
|
||||
no_results = "Keine Ergebnisse gefunden"
|
||||
error_images = "Error beim Holen von Bildern"
|
||||
rate_limit = "Langsam! Es kommen zu viele Anfragen von dir!"
|
||||
warning_fetch_error = "Anfrage fehlgeschlagen bevor Omnisearch Suchergebnisse lesen konnte."
|
||||
warning_parse_mismatch = "Bekam Suchergebnisse die von Omnisearch nicht geparst werden konnte."
|
||||
warning_blocked = "Bekam ein Captcha oder Blocking-Seite statt Suchergebnisse"
|
||||
read_more = "Mehr lesen"
|
||||
view_cached = "Zwischengespeichert"
|
||||
view_image = "Bild"
|
||||
visit_site = "Seite"
|
||||
36
locales/en_gb.ini
Normal file
36
locales/en_gb.ini
Normal file
@@ -0,0 +1,36 @@
|
||||
[Meta]
|
||||
Id = "en_gb"
|
||||
Name = "English"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "Search the web..."
|
||||
search_button = "Search"
|
||||
surprise_me_button = "Surprise me"
|
||||
all_tab = "All"
|
||||
images_tab = "Images"
|
||||
settings_tab = "Settings"
|
||||
settings_title = "Settings"
|
||||
theme_label = "Appearance"
|
||||
theme_desc = "Choose your preferred colour scheme."
|
||||
theme_system = "System"
|
||||
theme_light = "Light"
|
||||
theme_dark = "Dark"
|
||||
language_label = "Language"
|
||||
display_language_label = "Display Language"
|
||||
language_desc = "Choose your preferred language."
|
||||
engines_label = "Search Engines"
|
||||
engines_desc = "Choose which search engines to use. Only engines enabled on the server are shown."
|
||||
default_engine_label = "Default Search Engine"
|
||||
all_engines_option = "All enabled engines"
|
||||
save_settings_button = "Save Settings"
|
||||
no_results = "No results found"
|
||||
error_images = "Error fetching images"
|
||||
rate_limit = "Slow down! Too many searches from you!"
|
||||
warning_fetch_error = "request failed before OmniSearch could read search results."
|
||||
warning_parse_mismatch = "returned search results in a format OmniSearch could not parse."
|
||||
warning_blocked = "returned a captcha or another blocking page instead of search results."
|
||||
read_more = "Read More"
|
||||
view_cached = "Cached"
|
||||
view_image = "Image"
|
||||
visit_site = "Site"
|
||||
36
locales/en_us.ini
Normal file
36
locales/en_us.ini
Normal file
@@ -0,0 +1,36 @@
|
||||
[Meta]
|
||||
Id = "en_us"
|
||||
Name = "English (US)"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "Search the web..."
|
||||
search_button = "Search"
|
||||
surprise_me_button = "Surprise me"
|
||||
all_tab = "All"
|
||||
images_tab = "Images"
|
||||
settings_tab = "Settings"
|
||||
settings_title = "Settings"
|
||||
theme_label = "Appearance"
|
||||
theme_desc = "Choose your preferred color scheme."
|
||||
theme_system = "System"
|
||||
theme_light = "Light"
|
||||
theme_dark = "Dark"
|
||||
language_label = "Language"
|
||||
display_language_label = "Display Language"
|
||||
language_desc = "Choose your preferred language."
|
||||
engines_label = "Search Engines"
|
||||
engines_desc = "Choose which search engines to use. Only engines enabled on the server are shown."
|
||||
default_engine_label = "Default Search Engine"
|
||||
all_engines_option = "All enabled engines"
|
||||
save_settings_button = "Save Settings"
|
||||
no_results = "No results found"
|
||||
error_images = "Error fetching images"
|
||||
rate_limit = "Slow down! Too many searches from you!"
|
||||
warning_fetch_error = "request failed before OmniSearch could read search results."
|
||||
warning_parse_mismatch = "returned search results in a format OmniSearch could not parse."
|
||||
warning_blocked = "returned a captcha or another blocking page instead of search results."
|
||||
read_more = "Read More"
|
||||
view_cached = "Cached"
|
||||
view_image = "Image"
|
||||
visit_site = "Site"
|
||||
34
locales/es_es.ini
Normal file
34
locales/es_es.ini
Normal file
@@ -0,0 +1,34 @@
|
||||
[Meta]
|
||||
Id = "es_es"
|
||||
Name = "Español (España)"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "Buscar en internet..."
|
||||
search_button = "Buscar"
|
||||
surprise_me_button = "Sorpréndeme"
|
||||
all_tab = "Todo"
|
||||
images_tab = "Imágenes"
|
||||
settings_tab = "Configuración"
|
||||
settings_title = "Configuración"
|
||||
theme_label = "Apariencia"
|
||||
theme_desc = "Elige tu paleta de color preferida."
|
||||
theme_system = "Sistema"
|
||||
theme_light = "Claro"
|
||||
theme_dark = "Oscuro"
|
||||
language_label = "Idioma"
|
||||
display_language_label = "Idioma de la interfaz"
|
||||
language_desc = "Elige tu idioma preferido."
|
||||
engines_label = "Motores de búsqueda"
|
||||
engines_desc = "Elige qué motores de búsqueda usar. Solo se muestran los motores habilitados en el servidor."
|
||||
save_settings_button = "Guardar configuración"
|
||||
no_results = "No se encontraron resultados"
|
||||
error_images = "Error al obtener imágenes"
|
||||
rate_limit = "¡Más despacio! ¡Demasiadas búsquedas tuyas!"
|
||||
warning_fetch_error = "la petición falló antes de que OmniSearch pudiése leer los resultados de búsqueda."
|
||||
warning_parse_mismatch = "devolvió resultados de búsqueda en un formato que OmniSearch no pudo leer."
|
||||
warning_blocked = "devolvió un captcha u otra página de bloqueo en lugar de resultados de búsqueda."
|
||||
read_more = "Leer más"
|
||||
view_cached = "En caché"
|
||||
view_image = "Imagen"
|
||||
visit_site = "Página web"
|
||||
36
locales/fi_fi.ini
Normal file
36
locales/fi_fi.ini
Normal file
@@ -0,0 +1,36 @@
|
||||
[Meta]
|
||||
Id = "fi_fi"
|
||||
Name = "Suomi"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "Hae netistä..."
|
||||
search_button = "Hae"
|
||||
surprise_me_button = "Kokeilen onneani"
|
||||
all_tab = "Kaikki"
|
||||
images_tab = "Kuvat"
|
||||
settings_tab = "Asetukset"
|
||||
settings_title = "Asetukset"
|
||||
theme_label = "Ulkonäkö"
|
||||
theme_desc = "Valitse haluamasi väriteema."
|
||||
theme_system = "Järjestelmä"
|
||||
theme_light = "Vaalea"
|
||||
theme_dark = "Tumma"
|
||||
language_label = "Kieli"
|
||||
display_language_label = "Näyttökieli"
|
||||
language_desc = "Valitse haluamasi kieli."
|
||||
engines_label = "Hakukoneet"
|
||||
engines_desc = "Valitse mitä hakukoneita käytetään. Vain palvelimella käyttöön otetut hakukoneet näytetään."
|
||||
default_engine_label = "Oletushakukone"
|
||||
all_engines_option = "Kaikki valitut hakukoneet"
|
||||
save_settings_button = "Tallenna asetukset"
|
||||
no_results = "Ei tuloksia"
|
||||
error_images = "Virhe kuvien haussa"
|
||||
rate_limit = "Hidasta hieman! Sinulta on tullut liian monta hakupyyntöä!"
|
||||
warning_fetch_error = "pyyntö epäonnistui ennen kuin OmniSearch ehti lukea hakutuloksia."
|
||||
warning_parse_mismatch = "palautti hakutulokset muodossa jota OmniSearch ei osaa jäsentää."
|
||||
warning_blocked = "palautti captchan tai muun estosivun hakutulosten sijaan."
|
||||
read_more = "Lue Lisää"
|
||||
view_cached = "Välimuistissa"
|
||||
view_image = "Kuva"
|
||||
visit_site = "Sivu"
|
||||
34
locales/fr_fr.ini
Normal file
34
locales/fr_fr.ini
Normal file
@@ -0,0 +1,34 @@
|
||||
[Meta]
|
||||
Id = "fr_fr"
|
||||
Name = "Français"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "Rechercher le web..."
|
||||
search_button = "Rechercher"
|
||||
surprise_me_button = "Surprenez-moi"
|
||||
all_tab = "Tout"
|
||||
images_tab = "Images"
|
||||
settings_tab = "Paramètres"
|
||||
settings_title = "Paramètres"
|
||||
theme_label = "Apparence"
|
||||
theme_desc = "Choisissez votre palette de couleurs préférée."
|
||||
theme_system = "Système"
|
||||
theme_light = "Clair"
|
||||
theme_dark = "Sombre"
|
||||
language_label = "Langue"
|
||||
display_language_label = "Afficher les Langues"
|
||||
language_desc = "Choisissez votre langue."
|
||||
engines_label = "Moteur de Recherche"
|
||||
engines_desc = "Choisissez les moteurs de recherche que vous souhaitez utiliser. Seulement les moteurs de recherche activer sur le serveur sont affichés."
|
||||
save_settings_button = "Enregistrer les paramètres"
|
||||
no_results = "Aucun résultats"
|
||||
error_images = "Erreur lors du chargement des images"
|
||||
rate_limit = "Woah ralentissez! Vous effectuer trop de Rechercher!"
|
||||
warning_fetch_error = "La requête a échoué avant que OmniSearch puisse lire les résultats de la recherche."
|
||||
warning_parse_mismatch = "Les résultats de la recherche ont été retourné dans un format que OmniSearch ne peux pas analyser."
|
||||
warning_blocked = "Un captcha ou une autre page bloquante a été retourné au lieu d'un résultat de recherche."
|
||||
read_more = "Lire Plus"
|
||||
view_cached = "En cache"
|
||||
view_image = "Image"
|
||||
visit_site = "Site"
|
||||
34
locales/it_it.ini
Normal file
34
locales/it_it.ini
Normal file
@@ -0,0 +1,34 @@
|
||||
[Meta]
|
||||
Id = "it_it"
|
||||
Name = "Italiano (Italia)"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "Ricerca sul web..."
|
||||
search_button = "Cerca"
|
||||
surprise_me_button = "Sorprendimi"
|
||||
all_tab = "Tutti"
|
||||
images_tab = "Immagini"
|
||||
settings_tab = "Impostazioni"
|
||||
settings_title = "Impostazioni"
|
||||
theme_label = "Aspetto"
|
||||
theme_desc = "Scegli la tua combinazione di colori desiderata."
|
||||
theme_system = "Sistema"
|
||||
theme_light = "Chiaro"
|
||||
theme_dark = "Scuro"
|
||||
language_label = "Lingua"
|
||||
display_language_label = "Lingua di visualizzazione"
|
||||
language_desc = "Scegli la tua lingua desiderata."
|
||||
engines_label = "Motori di ricerca"
|
||||
engines_desc = "Scegli quali motori di ricerca usare. Solo i motori di ricerca abilitati verranno mostrati."
|
||||
save_settings_button = "Salva Impostazioni"
|
||||
no_results = "Nessun risultato trovato"
|
||||
error_images = "Errore nel riportare le immagini"
|
||||
rate_limit = "Rallenta! Troppe ricerche da parte tua!"
|
||||
warning_fetch_error = "richiesta fallita prima che OmniSearch potesse leggere i risultati."
|
||||
warning_parse_mismatch = "I risultati della ricerca restituiti sono in un formato che OmniSearch non è riuscito ad analizzare."
|
||||
warning_blocked = "È stato restituito un captcha o un'altra pagina di blocco invece dei risultati della ricerca."
|
||||
read_more = "Leggi di più"
|
||||
view_cached = "Nella Cache"
|
||||
view_image = "Immagine"
|
||||
visit_site = "Sito"
|
||||
34
locales/lv_lv.ini
Normal file
34
locales/lv_lv.ini
Normal file
@@ -0,0 +1,34 @@
|
||||
[Meta]
|
||||
Id = "lv_lv"
|
||||
Name = "Latviešu"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "Meklēt tīmeklī..."
|
||||
search_button = "Meklēt"
|
||||
surprise_me_button = "Pārsteidz mani"
|
||||
all_tab = "Viss"
|
||||
images_tab = "Attēli"
|
||||
settings_tab = "Iestatījumi"
|
||||
settings_title = "Iestatījumi"
|
||||
theme_label = "Izskats"
|
||||
theme_desc = "Izvēlieties vēlamo krāsu shēmu."
|
||||
theme_system = "Sistēma"
|
||||
theme_light = "Gaišs"
|
||||
theme_dark = "Tumšs"
|
||||
language_label = "Valoda"
|
||||
display_language_label = "Saskarnes valoda"
|
||||
language_desc = "Izvēlieties vēlamo valodu."
|
||||
save_settings_button = "Saglabāt iestatījumus"
|
||||
no_results = "Rezultāti nav atrasti"
|
||||
error_images = "Kļūda, ielādējot attēlus"
|
||||
rate_limit = "Lēnāk! Pārāk daudz jūsu meklēšanas vaicājumu!"
|
||||
warning_fetch_error = "Neizdevās izpildīt pieprasījumu, pirms OmniSearch varēja nolasīt meklēšanas rezultātus."
|
||||
warning_parse_mismatch = "Meklēšanas rezultāti tika atgriezti formātā, kuru OmniSearch nevarēja apstrādāt."
|
||||
warning_blocked = "Tika atgriezta captcha vai cita bloķējoša lapa meklēšanas rezultātu vietā."
|
||||
read_more = "Lasīt vairāk"
|
||||
view_cached = "Saglabātā kopija"
|
||||
view_image = "Skatīt attēlu"
|
||||
visit_site = "Apmeklēt vietni"
|
||||
engines_label = "Meklēšanas dzinēji"
|
||||
engines_desc = "Izvēlieties, kurus meklēšanas dzinējus izmantot. Tiek rādīti tikai serverī iespējotie."
|
||||
34
locales/nl_nl.ini
Normal file
34
locales/nl_nl.ini
Normal file
@@ -0,0 +1,34 @@
|
||||
[Meta]
|
||||
Id = "nl_nl"
|
||||
Name = "Nederlands"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "Zoek op het web..."
|
||||
search_button = "Zoek"
|
||||
surprise_me_button = "Verras me"
|
||||
all_tab = "Alle"
|
||||
images_tab = "Plaatjes"
|
||||
settings_tab = "Instellingen"
|
||||
settings_title = "Instellingen"
|
||||
theme_label = "Kleurinstelling"
|
||||
theme_desc = "Kies welke stijl je gebruikt."
|
||||
theme_system = "Systeemkleur"
|
||||
theme_light = "Licht"
|
||||
theme_dark = "Donker"
|
||||
language_label = "Taal"
|
||||
display_language_label = "Geselecteerde taal"
|
||||
language_desc = "Kies de taal van OmniSearch."
|
||||
engines_label = "Zoekmachines"
|
||||
engines_desc = "Kies welke zoekmachines je gebruikt. Alleen de ingeschakelde zoekmachines worden gebruikt."
|
||||
save_settings_button = "Opslaan"
|
||||
no_results = "Geen resultaten"
|
||||
error_images = "Foutmelding bij het zoeken naar plaatjes."
|
||||
rate_limit = "Te veel zoekopdrachten! Ga wat langzamer!"
|
||||
warning_fetch_error = "stuurde een foutmelding voordat OmniSearch de resultaten kon lezen."
|
||||
warning_parse_mismatch = "stuurde een foutmelding in een format dat OmniSearch niet kon lezen."
|
||||
warning_blocked = "stuurde een captcha of een andere pagina, maar geen zoekresultaten."
|
||||
read_more = "Lees meer"
|
||||
view_cached = "Tijdelijk Opgeslagen"
|
||||
view_image = "Bekijk"
|
||||
visit_site = "Website"
|
||||
34
locales/pt_br.ini
Normal file
34
locales/pt_br.ini
Normal file
@@ -0,0 +1,34 @@
|
||||
[Meta]
|
||||
Id = "pt_br"
|
||||
Name = "Portuguese (Brazil)"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "Pesquisar na internet..."
|
||||
search_button = "Pesquisar"
|
||||
surprise_me_button = "Me surpreenda"
|
||||
all_tab = "Tudo"
|
||||
images_tab = "Imagens"
|
||||
settings_tab = "Configurações"
|
||||
settings_title = "Configurações"
|
||||
theme_label = "Aparência"
|
||||
theme_desc = "Escolha o esquema de cores de sua preferência."
|
||||
theme_system = "Padrão do Sistema"
|
||||
theme_light = "Claro"
|
||||
theme_dark = "Escuro"
|
||||
language_label = "Idioma"
|
||||
display_language_label = "Idioma de exibição"
|
||||
language_desc = "Escolha o idioma de sua preferência"
|
||||
engines_label = "Mecanismos de pesquisa"
|
||||
engines_desc = "Escolha quais mecanismos de pesquisa serão utilizados. Apenas mecanismos habilitados no servidor serão mostrados."
|
||||
save_settings_button = "Salvar configurações"
|
||||
no_results = "Nenhum resultado encontrado"
|
||||
error_images = "Erro ao buscar imagens"
|
||||
rate_limit = "Calma aí! Muitas pesquisas vindo de você!"
|
||||
warning_fetch_error = "pedido falhou antes que o Omnisearch pudesse ler resultados de pesquisa."
|
||||
warning_parse_mismatch = "retornou resultados em um formato que o Omnisearch não pode processar."
|
||||
warning_blocked = "retornou um captcha ou outra página de bloqueio ao invés de resultados de pesquisa."
|
||||
read_more = "Ler mais"
|
||||
view_cached = "Armazenado em cache"
|
||||
view_image = "Imagem"
|
||||
visit_site = "Site"
|
||||
34
locales/ru_ru.ini
Normal file
34
locales/ru_ru.ini
Normal file
@@ -0,0 +1,34 @@
|
||||
[Meta]
|
||||
Id = "ru_ru"
|
||||
Name = "Русский"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "Поиск в интернете..."
|
||||
search_button = "Найти"
|
||||
surprise_me_button = "Удиви меня"
|
||||
all_tab = "Все"
|
||||
images_tab = "Изображения"
|
||||
settings_tab = "Настройки"
|
||||
settings_title = "Настройки"
|
||||
theme_label = "Внешний вид"
|
||||
theme_desc = "Выберите предпочитаемую цветовую схему."
|
||||
theme_system = "Системная"
|
||||
theme_light = "Светлая"
|
||||
theme_dark = "Тёмная"
|
||||
language_label = "Язык"
|
||||
display_language_label = "Язык интерфейса"
|
||||
language_desc = "Выберите предпочитаемый язык."
|
||||
save_settings_button = "Сохранить настройки"
|
||||
no_results = "Ничего не найдено"
|
||||
error_images = "Ошибка загрузки изображений"
|
||||
rate_limit = "Слишком много поисковых запросов. Пожалуйста, попробуйте позже."
|
||||
warning_fetch_error = "Не удалось выполнить запрос до того, как OmniSearch смог прочитать результаты поиска."
|
||||
warning_parse_mismatch = "Результаты поиска возвращены в формате, который OmniSearch не смог обработать."
|
||||
warning_blocked = "Вместо результатов поиска возвращена капча или страница блокировки."
|
||||
read_more = "Подробнее"
|
||||
view_cached = "Сохранённая копия"
|
||||
view_image = "Просмотр изображения"
|
||||
visit_site = "Перейти на сайт"
|
||||
engines_label = "Поисковые системы"
|
||||
engines_desc = "Выберите, какие поисковые системы использовать. Отображаются только включённые на сервере."
|
||||
34
locales/vi_vn.ini
Normal file
34
locales/vi_vn.ini
Normal file
@@ -0,0 +1,34 @@
|
||||
[Meta]
|
||||
Id = "vi_vn"
|
||||
Name = "tiếng việt"
|
||||
Direction = "ltr"
|
||||
|
||||
[Keys]
|
||||
search_placeholder = "tìm kiếm trên web..."
|
||||
search_button = "tìm kiếm"
|
||||
surprise_me_button = "bất ngờ"
|
||||
all_tab = "tất cả"
|
||||
images_tab = "hình ảnh"
|
||||
settings_tab = "cài đặt"
|
||||
settings_title = "cài đặt"
|
||||
theme_label = "giao diện"
|
||||
theme_desc = "chọn bảng màu mà bạn muốn"
|
||||
theme_system = "hệ thống"
|
||||
theme_light = "sáng"
|
||||
theme_dark = "tối"
|
||||
language_label = "ngôn ngữ"
|
||||
display_language_label = "ngôn ngữ hiển thị"
|
||||
language_desc = "chọn ngôn ngữ mà bn muốn"
|
||||
engines_label = "công cụ tìm kiếm"
|
||||
engines_desc = "chọn các công cụ tìm kiếm để sử dụng, chỉ những công cụ dc bật trên máy chủ ms đc hiển thị."
|
||||
save_settings_button = "lưu cài đặt"
|
||||
no_results = "k tìm thấy kết quả"
|
||||
error_images = "lỗi khi tải hình ảnh"
|
||||
rate_limit = "chậm lại! dừng lại! bạn đã tìm kiếm quá nhiều lần!"
|
||||
warning_fetch_error = "yêu cầu thất bại trước khi omnisearch có thể đọc kết quả tìm kiếm."
|
||||
warning_parse_mismatch = "kết quả tìm kiếm được trả về ở định dạng omnisearch k thể phân tích."
|
||||
warning_blocked = "trang trả về captcha hoặc trang chặn khác thay vì kết quả tìm kiếm."
|
||||
read_more = "đọc thêm"
|
||||
view_cached = "bản lưu"
|
||||
view_image = "hình ảnh"
|
||||
visit_site = "truy cập trang"
|
||||
136
module.nix
136
module.nix
@@ -1,136 +0,0 @@
|
||||
self:
|
||||
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.services.omnisearch;
|
||||
pkg = cfg.package;
|
||||
|
||||
finalConfigFile =
|
||||
if cfg.configFile != null then
|
||||
cfg.configFile
|
||||
else
|
||||
pkgs.writeText "omnisearch.ini" ''
|
||||
[server]
|
||||
host = ${cfg.settings.server.host}
|
||||
port = ${toString cfg.settings.server.port}
|
||||
domain = ${cfg.settings.server.domain}
|
||||
|
||||
[proxy]
|
||||
${lib.optionalString (cfg.settings.proxy.proxy != null) "proxy = \"${cfg.settings.proxy.proxy}\""}
|
||||
${lib.optionalString (
|
||||
cfg.settings.proxy.list_file != null
|
||||
) "list_file = ${cfg.settings.proxy.list_file}"}
|
||||
max_retries = ${toString cfg.settings.proxy.max_retries}
|
||||
randomize_username = ${lib.boolToString cfg.settings.proxy.randomize_username}
|
||||
randomize_password = ${lib.boolToString cfg.settings.proxy.randomize_password}
|
||||
|
||||
[cache]
|
||||
dir = ${cfg.settings.cache.dir}
|
||||
ttl_search = ${toString cfg.settings.cache.ttl_search}
|
||||
ttl_infobox = ${toString cfg.settings.cache.ttl_infobox}
|
||||
'';
|
||||
in
|
||||
{
|
||||
options.services.omnisearch = {
|
||||
enable = lib.mkEnableOption "OmniSearch metasearch engine";
|
||||
|
||||
package = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
default = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
||||
description = "The omnisearch package to use.";
|
||||
};
|
||||
|
||||
configFile = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
description = "Path to a custom config.ini. Overrides 'settings'.";
|
||||
};
|
||||
|
||||
settings = {
|
||||
server = {
|
||||
host = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "0.0.0.0";
|
||||
};
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 8087;
|
||||
};
|
||||
domain = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "http://localhost:8087";
|
||||
};
|
||||
};
|
||||
proxy = {
|
||||
proxy = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
};
|
||||
list_file = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
};
|
||||
max_retries = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 3;
|
||||
};
|
||||
randomize_username = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
};
|
||||
randomize_password = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
};
|
||||
};
|
||||
cache = {
|
||||
dir = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/var/cache/omnisearch";
|
||||
};
|
||||
ttl_search = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 3600;
|
||||
};
|
||||
ttl_infobox = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 86400;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.services.omnisearch = {
|
||||
description = "OmniSearch Service";
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart = "${pkg}/bin/omnisearch";
|
||||
|
||||
WorkingDirectory = "/var/lib/omnisearch";
|
||||
StateDirectory = "omnisearch";
|
||||
CacheDirectory = "omnisearch";
|
||||
|
||||
BindReadOnlyPaths = [
|
||||
"${pkg}/share/omnisearch/templates:/var/lib/omnisearch/templates"
|
||||
"${pkg}/share/omnisearch/static:/var/lib/omnisearch/static"
|
||||
"${finalConfigFile}:/var/lib/omnisearch/config.ini"
|
||||
];
|
||||
|
||||
DynamicUser = true;
|
||||
ProtectSystem = "strict";
|
||||
ProtectHome = true;
|
||||
PrivateTmp = true;
|
||||
Restart = "always";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -11,15 +11,20 @@
|
||||
static char cache_dir[BUFFER_SIZE_MEDIUM] = {0};
|
||||
static int cache_ttl_search_val = DEFAULT_CACHE_TTL_SEARCH;
|
||||
static int cache_ttl_infobox_val = DEFAULT_CACHE_TTL_INFOBOX;
|
||||
static int cache_ttl_image_val = DEFAULT_CACHE_TTL_IMAGE;
|
||||
|
||||
void set_cache_ttl_search(int ttl) { cache_ttl_search_val = ttl; }
|
||||
|
||||
void set_cache_ttl_infobox(int ttl) { cache_ttl_infobox_val = ttl; }
|
||||
|
||||
void set_cache_ttl_image(int ttl) { cache_ttl_image_val = ttl; }
|
||||
|
||||
int get_cache_ttl_search(void) { return cache_ttl_search_val; }
|
||||
|
||||
int get_cache_ttl_infobox(void) { return cache_ttl_infobox_val; }
|
||||
|
||||
int get_cache_ttl_image(void) { return cache_ttl_image_val; }
|
||||
|
||||
static void md5_hash(const char *str, char *output) {
|
||||
unsigned char hash[EVP_MAX_MD_SIZE];
|
||||
unsigned int hash_len;
|
||||
@@ -31,7 +36,7 @@ static void md5_hash(const char *str, char *output) {
|
||||
EVP_DigestFinal_ex(ctx, hash, &hash_len);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
for (unsigned int i = 0; i < hash_len; i++) {
|
||||
sprintf(output + (i * 2), "%02x", hash[i]);
|
||||
snprintf(output + (i * 2), 3, "%02x", hash[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,11 +50,9 @@ static time_t get_file_mtime(const char *filepath) {
|
||||
|
||||
int cache_init(const char *dir) {
|
||||
if (!dir || strlen(dir) == 0) {
|
||||
strncpy(cache_dir, DEFAULT_CACHE_DIR, sizeof(cache_dir) - 1);
|
||||
cache_dir[sizeof(cache_dir) - 1] = '\0';
|
||||
snprintf(cache_dir, sizeof(cache_dir), "%s", DEFAULT_CACHE_DIR);
|
||||
} else {
|
||||
strncpy(cache_dir, dir, sizeof(cache_dir) - 1);
|
||||
cache_dir[sizeof(cache_dir) - 1] = '\0';
|
||||
snprintf(cache_dir, sizeof(cache_dir), "%s", dir);
|
||||
}
|
||||
|
||||
struct stat st;
|
||||
|
||||
@@ -17,7 +17,9 @@ char *cache_compute_key(const char *query, int page, const char *engine_name);
|
||||
|
||||
void set_cache_ttl_search(int ttl);
|
||||
void set_cache_ttl_infobox(int ttl);
|
||||
void set_cache_ttl_image(int ttl);
|
||||
int get_cache_ttl_search(void);
|
||||
int get_cache_ttl_infobox(void);
|
||||
int get_cache_ttl_image(void);
|
||||
|
||||
#endif
|
||||
|
||||
238
src/Config.c
238
src/Config.c
@@ -1,107 +1,189 @@
|
||||
#include "Config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
typedef enum {
|
||||
CONFIG_STRING,
|
||||
CONFIG_INTEGER,
|
||||
CONFIG_BOOLEAN,
|
||||
} ConfigValueType;
|
||||
|
||||
typedef struct {
|
||||
const char *section;
|
||||
const char *key;
|
||||
ConfigValueType type;
|
||||
size_t offset;
|
||||
size_t size;
|
||||
} ConfigOption;
|
||||
|
||||
#define STRING_OPTION(section_name, key_name, field) \
|
||||
{section_name, key_name, CONFIG_STRING, offsetof(Config, field), \
|
||||
sizeof(((Config *)0)->field)}
|
||||
#define INTEGER_OPTION(section_name, key_name, field) \
|
||||
{section_name, key_name, CONFIG_INTEGER, offsetof(Config, field), 0}
|
||||
#define BOOLEAN_OPTION(section_name, key_name, field) \
|
||||
{section_name, key_name, CONFIG_BOOLEAN, offsetof(Config, field), 0}
|
||||
|
||||
static const ConfigOption CONFIG_OPTIONS[] = {
|
||||
STRING_OPTION("server", "host", host),
|
||||
INTEGER_OPTION("server", "port", port),
|
||||
STRING_OPTION("server", "locale", default_locale),
|
||||
STRING_OPTION("proxy", "proxy", proxy),
|
||||
STRING_OPTION("proxy", "list_file", proxy_list_file),
|
||||
INTEGER_OPTION("proxy", "max_retries", max_proxy_retries),
|
||||
BOOLEAN_OPTION("proxy", "randomize_username", randomize_username),
|
||||
BOOLEAN_OPTION("proxy", "randomize_password", randomize_password),
|
||||
STRING_OPTION("cache", "dir", cache_dir),
|
||||
INTEGER_OPTION("cache", "ttl_search", cache_ttl_search),
|
||||
INTEGER_OPTION("cache", "ttl_infobox", cache_ttl_infobox),
|
||||
INTEGER_OPTION("cache", "ttl_image", cache_ttl_image),
|
||||
STRING_OPTION("engines", "engines", engines),
|
||||
STRING_OPTION("engines", "yacy_instance", yacy_instance),
|
||||
INTEGER_OPTION("rate_limit", "search_requests", rate_limit_search_requests),
|
||||
INTEGER_OPTION("rate_limit", "search_interval", rate_limit_search_interval),
|
||||
INTEGER_OPTION("rate_limit", "images_requests", rate_limit_images_requests),
|
||||
INTEGER_OPTION("rate_limit", "images_interval", rate_limit_images_interval),
|
||||
};
|
||||
|
||||
void config_set_defaults(Config *config) {
|
||||
if (!config) {
|
||||
return;
|
||||
}
|
||||
|
||||
*config = (Config){
|
||||
.host = DEFAULT_HOST,
|
||||
.port = DEFAULT_PORT,
|
||||
.default_locale = "en_gb",
|
||||
.max_proxy_retries = DEFAULT_MAX_PROXY_RETRIES,
|
||||
.cache_dir = DEFAULT_CACHE_DIR,
|
||||
.cache_ttl_search = DEFAULT_CACHE_TTL_SEARCH,
|
||||
.cache_ttl_infobox = DEFAULT_CACHE_TTL_INFOBOX,
|
||||
.cache_ttl_image = DEFAULT_CACHE_TTL_IMAGE,
|
||||
};
|
||||
}
|
||||
|
||||
static char *trim(char *value) {
|
||||
while (*value == ' ' || *value == '\t') {
|
||||
value++;
|
||||
}
|
||||
|
||||
char *end = value + strlen(value);
|
||||
while (end > value && (end[-1] == ' ' || end[-1] == '\t')) {
|
||||
end--;
|
||||
}
|
||||
*end = '\0';
|
||||
return value;
|
||||
}
|
||||
|
||||
static char *unquote(char *value) {
|
||||
size_t length = strlen(value);
|
||||
if (length >= 2 && (value[0] == '"' || value[0] == '\'') &&
|
||||
value[length - 1] == value[0]) {
|
||||
value[length - 1] = '\0';
|
||||
return value + 1;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static int parse_integer(const char *value, int *result) {
|
||||
char *end;
|
||||
errno = 0;
|
||||
long parsed = strtol(value, &end, 10);
|
||||
|
||||
if (value == end || *end != '\0' || errno == ERANGE || parsed < INT_MIN ||
|
||||
parsed > INT_MAX) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*result = (int)parsed;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_boolean(const char *value, int *result) {
|
||||
if (strcmp(value, "1") == 0 || strcasecmp(value, "true") == 0 ||
|
||||
strcasecmp(value, "yes") == 0 || strcasecmp(value, "on") == 0) {
|
||||
*result = 1;
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(value, "0") == 0 || strcasecmp(value, "false") == 0 ||
|
||||
strcasecmp(value, "no") == 0 || strcasecmp(value, "off") == 0) {
|
||||
*result = 0;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void set_option(Config *config, const char *section, const char *key,
|
||||
const char *value) {
|
||||
size_t option_count = sizeof(CONFIG_OPTIONS) / sizeof(CONFIG_OPTIONS[0]);
|
||||
|
||||
for (size_t i = 0; i < option_count; i++) {
|
||||
const ConfigOption *option = &CONFIG_OPTIONS[i];
|
||||
if (strcmp(section, option->section) != 0 ||
|
||||
strcmp(key, option->key) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
void *destination = (char *)config + option->offset;
|
||||
if (option->type == CONFIG_STRING) {
|
||||
snprintf(destination, option->size, "%s", value);
|
||||
} else if (option->type == CONFIG_INTEGER) {
|
||||
parse_integer(value, destination);
|
||||
} else {
|
||||
parse_boolean(value, destination);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int load_config(const char *filename, Config *config) {
|
||||
if (!filename || !config) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE *file = fopen(filename, "r");
|
||||
if (!file) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
char line[512];
|
||||
char line[1024];
|
||||
char section[64] = "";
|
||||
|
||||
while (fgets(line, sizeof(line), file)) {
|
||||
line[strcspn(line, "\r\n")] = 0;
|
||||
line[strcspn(line, "\r\n")] = '\0';
|
||||
char *content = trim(line);
|
||||
|
||||
if (line[0] == '\0' || line[0] == '#' || line[0] == ';') {
|
||||
if (*content == '\0' || *content == '#' || *content == ';') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line[0] == '[') {
|
||||
char *end = strchr(line, ']');
|
||||
if (*content == '[') {
|
||||
char *end = strchr(content + 1, ']');
|
||||
if (end) {
|
||||
*end = '\0';
|
||||
snprintf(section, sizeof(section), "%.*s", (int)(sizeof(section) - 1),
|
||||
line + 1);
|
||||
section[sizeof(section) - 1] = '\0';
|
||||
snprintf(section, sizeof(section), "%s", trim(content + 1));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
char *delimiter = strchr(line, '=');
|
||||
if (delimiter) {
|
||||
char *delimiter = strchr(content, '=');
|
||||
if (!delimiter) {
|
||||
continue;
|
||||
}
|
||||
|
||||
*delimiter = '\0';
|
||||
char *key = line;
|
||||
char *value = delimiter + 1;
|
||||
|
||||
while (*key == ' ' || *key == '\t')
|
||||
key++;
|
||||
while (*value == ' ' || *value == '\t')
|
||||
value++;
|
||||
|
||||
char *key_end = key + strlen(key) - 1;
|
||||
while (key_end > key && (*key_end == ' ' || *key_end == '\t')) {
|
||||
*key_end = '\0';
|
||||
key_end--;
|
||||
}
|
||||
|
||||
char *value_end = value + strlen(value) - 1;
|
||||
while (value_end > value && (*value_end == ' ' || *value_end == '\t' ||
|
||||
*value_end == '"' || *value_end == '\'')) {
|
||||
*value_end = '\0';
|
||||
value_end--;
|
||||
}
|
||||
|
||||
while (*value == ' ' || *value == '\t')
|
||||
value++;
|
||||
while (*value == '"' || *value == '\'')
|
||||
value++;
|
||||
|
||||
if (strcmp(section, "server") == 0) {
|
||||
if (strcmp(key, "host") == 0) {
|
||||
strncpy(config->host, value, sizeof(config->host) - 1);
|
||||
config->host[sizeof(config->host) - 1] = '\0';
|
||||
} else if (strcmp(key, "port") == 0) {
|
||||
config->port = atoi(value);
|
||||
} else if (strcmp(key, "domain") == 0) {
|
||||
strncpy(config->domain, value, sizeof(config->domain) - 1);
|
||||
config->domain[sizeof(config->domain) - 1] = '\0';
|
||||
}
|
||||
} else if (strcmp(section, "proxy") == 0) {
|
||||
if (strcmp(key, "proxy") == 0) {
|
||||
strncpy(config->proxy, value, sizeof(config->proxy) - 1);
|
||||
config->proxy[sizeof(config->proxy) - 1] = '\0';
|
||||
} else if (strcmp(key, "list_file") == 0) {
|
||||
strncpy(config->proxy_list_file, value,
|
||||
sizeof(config->proxy_list_file) - 1);
|
||||
config->proxy_list_file[sizeof(config->proxy_list_file) - 1] = '\0';
|
||||
} else if (strcmp(key, "max_retries") == 0) {
|
||||
config->max_proxy_retries = atoi(value);
|
||||
} else if (strcmp(key, "randomize_username") == 0) {
|
||||
config->randomize_username = atoi(value);
|
||||
} else if (strcmp(key, "randomize_password") == 0) {
|
||||
config->randomize_password = atoi(value);
|
||||
}
|
||||
} else if (strcmp(section, "cache") == 0) {
|
||||
if (strcmp(key, "dir") == 0) {
|
||||
strncpy(config->cache_dir, value, sizeof(config->cache_dir) - 1);
|
||||
config->cache_dir[sizeof(config->cache_dir) - 1] = '\0';
|
||||
} else if (strcmp(key, "ttl_search") == 0) {
|
||||
config->cache_ttl_search = atoi(value);
|
||||
} else if (strcmp(key, "ttl_infobox") == 0) {
|
||||
config->cache_ttl_infobox = atoi(value);
|
||||
}
|
||||
} else if (strcmp(section, "engines") == 0) {
|
||||
if (strcmp(key, "engines") == 0) {
|
||||
strncpy(config->engines, value, sizeof(config->engines) - 1);
|
||||
config->engines[sizeof(config->engines) - 1] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
char *key = trim(content);
|
||||
char *value = unquote(trim(delimiter + 1));
|
||||
set_option(config, section, key, value);
|
||||
}
|
||||
|
||||
int result = ferror(file) ? -1 : 0;
|
||||
fclose(file);
|
||||
return 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
10
src/Config.h
10
src/Config.h
@@ -6,7 +6,9 @@
|
||||
#define DEFAULT_CACHE_DIR "/tmp/omnisearch_cache"
|
||||
#define DEFAULT_CACHE_TTL_SEARCH 3600
|
||||
#define DEFAULT_CACHE_TTL_INFOBOX 86400
|
||||
#define DEFAULT_CACHE_TTL_IMAGE 604800
|
||||
#define DEFAULT_MAX_PROXY_RETRIES 3
|
||||
#define DEFAULT_YACY_INSTANCE "http://127.0.0.1:8090"
|
||||
|
||||
#define BUFFER_SIZE_SMALL 256
|
||||
#define BUFFER_SIZE_MEDIUM 512
|
||||
@@ -34,6 +36,7 @@ typedef struct {
|
||||
char host[256];
|
||||
int port;
|
||||
char domain[256];
|
||||
char default_locale[32];
|
||||
char proxy[256];
|
||||
char proxy_list_file[256];
|
||||
int max_proxy_retries;
|
||||
@@ -42,9 +45,16 @@ typedef struct {
|
||||
char cache_dir[512];
|
||||
int cache_ttl_search;
|
||||
int cache_ttl_infobox;
|
||||
int cache_ttl_image;
|
||||
char engines[512];
|
||||
char yacy_instance[512];
|
||||
int rate_limit_search_requests;
|
||||
int rate_limit_search_interval;
|
||||
int rate_limit_images_requests;
|
||||
int rate_limit_images_interval;
|
||||
} Config;
|
||||
|
||||
void config_set_defaults(Config *config);
|
||||
int load_config(const char *filename, Config *config);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -38,14 +38,31 @@ static double parse_factor(Parser *p) {
|
||||
return val;
|
||||
}
|
||||
|
||||
static double parse_term(Parser *p) {
|
||||
static double parse_exponent(Parser *p) {
|
||||
double left = parse_factor(p);
|
||||
skip_ws(p);
|
||||
if (p->buffer[p->pos] == '^') {
|
||||
p->pos++;
|
||||
double right = parse_exponent(p);
|
||||
double old = left;
|
||||
left = pow(old, right);
|
||||
|
||||
char step[256];
|
||||
snprintf(step, sizeof(step), "<div>%g ^ %g = <b>%g</b></div>", old, right,
|
||||
left);
|
||||
strncat(logic_log, step, sizeof(logic_log) - strlen(logic_log) - 1);
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
static double parse_term(Parser *p) {
|
||||
double left = parse_exponent(p);
|
||||
while (1) {
|
||||
skip_ws(p);
|
||||
char op = p->buffer[p->pos];
|
||||
if (op == '*' || op == '/') {
|
||||
p->pos++;
|
||||
double right = parse_factor(p);
|
||||
double right = parse_exponent(p);
|
||||
double old = left;
|
||||
left = (op == '*') ? left * right : left / right;
|
||||
|
||||
|
||||
166
src/Infobox/ColourCode.c
Normal file
166
src/Infobox/ColourCode.c
Normal file
@@ -0,0 +1,166 @@
|
||||
#include "ColourCode.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static const unsigned char HEX_VALS[256] = {
|
||||
['0'] = 0, ['1'] = 1, ['2'] = 2, ['3'] = 3, ['4'] = 4, ['5'] = 5,
|
||||
['6'] = 6, ['7'] = 7, ['8'] = 8, ['9'] = 9, ['a'] = 10, ['b'] = 11,
|
||||
['c'] = 12, ['d'] = 13, ['e'] = 14, ['f'] = 15, ['A'] = 10, ['B'] = 11,
|
||||
['C'] = 12, ['D'] = 13, ['E'] = 14, ['F'] = 15,
|
||||
};
|
||||
|
||||
static int is_hex_digit(char c) {
|
||||
return HEX_VALS[(unsigned char)c] || c == '0';
|
||||
}
|
||||
|
||||
static int is_valid_hex(const char *s, int len) {
|
||||
if (len != 3 && len != 6)
|
||||
return 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (!is_hex_digit(s[i]))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void hex_to_rgb(const char *hex, int *r, int *g, int *b, int len) {
|
||||
*r = *g = *b = 0;
|
||||
if (len == 3) {
|
||||
*r = HEX_VALS[(unsigned char)hex[0]] * 17;
|
||||
*g = HEX_VALS[(unsigned char)hex[1]] * 17;
|
||||
*b = HEX_VALS[(unsigned char)hex[2]] * 17;
|
||||
} else if (len == 6) {
|
||||
*r = HEX_VALS[(unsigned char)hex[0]] * 16 + HEX_VALS[(unsigned char)hex[1]];
|
||||
*g = HEX_VALS[(unsigned char)hex[2]] * 16 + HEX_VALS[(unsigned char)hex[3]];
|
||||
*b = HEX_VALS[(unsigned char)hex[4]] * 16 + HEX_VALS[(unsigned char)hex[5]];
|
||||
}
|
||||
}
|
||||
|
||||
static void rgb_to_hsl(int r, int g, int b, int *h, int *s, int *l) {
|
||||
int max = r > g ? (r > b ? r : b) : (g > b ? g : b);
|
||||
int min = r < g ? (r < b ? r : b) : (g < b ? g : b);
|
||||
int delta = max - min;
|
||||
*l = (max + min) / 2;
|
||||
*s = 0;
|
||||
*h = 0;
|
||||
if (delta > 0) {
|
||||
*s = (int)((double)delta / (1.0 - fabs(2.0 * *l / 255.0 - 1.0)) * 100.0);
|
||||
if (max == r) {
|
||||
*h = (int)(60.0 * fmod((double)(g - b) / delta, 6.0));
|
||||
} else if (max == g) {
|
||||
*h = (int)(60.0 * (((b - r) / delta) + 2.0));
|
||||
} else {
|
||||
*h = (int)(60.0 * (((r - g) / delta) + 4.0));
|
||||
}
|
||||
if (*h < 0)
|
||||
*h += 360;
|
||||
}
|
||||
}
|
||||
|
||||
static void rgb_to_hsv(int r, int g, int b, int *h, int *s, int *v) {
|
||||
int max = r > g ? (r > b ? r : b) : (g > b ? g : b);
|
||||
int min = r < g ? (r < b ? r : b) : (g < b ? g : b);
|
||||
int delta = max - min;
|
||||
*v = max * 100 / 255;
|
||||
*s = max > 0 ? delta * 100 / max : 0;
|
||||
*h = 0;
|
||||
if (delta > 0) {
|
||||
if (max == r) {
|
||||
*h = (int)(60.0 * fmod((double)(g - b) / delta, 6.0));
|
||||
} else if (max == g) {
|
||||
*h = (int)(60.0 * (((b - r) / delta) + 2.0));
|
||||
} else {
|
||||
*h = (int)(60.0 * (((r - g) / delta) + 4.0));
|
||||
}
|
||||
if (*h < 0)
|
||||
*h += 360;
|
||||
}
|
||||
}
|
||||
|
||||
static void rgb_to_cmyk(int r, int g, int b, int *c, int *m, int *y, int *k) {
|
||||
int max = r > g ? (r > b ? r : b) : (g > b ? g : b);
|
||||
double kf = 1.0 - max / 255.0;
|
||||
if (kf >= 0.99) {
|
||||
*c = *m = *y = *k = 100;
|
||||
} else {
|
||||
*c = (int)((1.0 - r / 255.0 - kf) / (1.0 - kf) * 100);
|
||||
*m = (int)((1.0 - g / 255.0 - kf) / (1.0 - kf) * 100);
|
||||
*y = (int)((1.0 - b / 255.0 - kf) / (1.0 - kf) * 100);
|
||||
*k = (int)(kf * 100);
|
||||
}
|
||||
}
|
||||
|
||||
int is_colour_code_query(const char *query) {
|
||||
if (!query)
|
||||
return 0;
|
||||
const char *p = query;
|
||||
if (p[0] == '#') {
|
||||
p++;
|
||||
while (*p == ' ')
|
||||
p++;
|
||||
const char *end = p;
|
||||
while (is_hex_digit(*end))
|
||||
end++;
|
||||
int len = end - p;
|
||||
return is_valid_hex(p, len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
InfoBox fetch_colour_data(char *query) {
|
||||
InfoBox info = {NULL, NULL, NULL, NULL};
|
||||
if (!query)
|
||||
return info;
|
||||
|
||||
const char *p = query;
|
||||
if (p[0] != '#')
|
||||
return info;
|
||||
p++;
|
||||
while (*p == ' ')
|
||||
p++;
|
||||
const char *end = p;
|
||||
while (is_hex_digit(*end))
|
||||
end++;
|
||||
int len = end - p;
|
||||
if (!is_valid_hex(p, len))
|
||||
return info;
|
||||
|
||||
int r, g, b;
|
||||
hex_to_rgb(p, &r, &g, &b, len);
|
||||
|
||||
int h, s, l;
|
||||
rgb_to_hsl(r, g, b, &h, &s, &l);
|
||||
|
||||
int h2, s2, v;
|
||||
rgb_to_hsv(r, g, b, &h2, &s2, &v);
|
||||
|
||||
int c, m, y, k;
|
||||
rgb_to_cmyk(r, g, b, &c, &m, &y, &k);
|
||||
|
||||
char html[1024];
|
||||
snprintf(html, sizeof(html),
|
||||
"<div class='colour-container' style='line-height: 1.6;'>"
|
||||
"<div style='display: flex; align-items: flex-start; gap: 16px;'>"
|
||||
"<div style='width: 100px; height: 100px; border-radius: 12px; "
|
||||
"border: 1px solid #ddd; background-color: #%.*s; flex-shrink: 0;'></div>"
|
||||
"<div>"
|
||||
"<div style='font-size: 1.3em; font-weight: bold; margin-bottom: 8px;'>"
|
||||
"#%.*s</div>"
|
||||
"<div style='color: #666; margin-bottom: 4px;'>RGB(%d, %d, %d)</div>"
|
||||
"<div style='color: #666; margin-bottom: 4px;'>HSL(%d, %d%%, %d%%)</div>"
|
||||
"<div style='color: #666; margin-bottom: 4px;'>HSV(%d, %d%%, %d%%)</div>"
|
||||
"<div style='color: #666;'>CMYK(%d%%, %d%%, %d%%, %d%%)</div>"
|
||||
"</div>"
|
||||
"</div>"
|
||||
"</div>",
|
||||
len, p, len, p, r, g, b, h, s, l, h2, s2, v, c, m, y, k);
|
||||
|
||||
info.title = strdup("Colour");
|
||||
info.extract = strdup(html);
|
||||
info.thumbnail_url = NULL;
|
||||
info.url = strdup("#");
|
||||
|
||||
return info;
|
||||
}
|
||||
9
src/Infobox/ColourCode.h
Normal file
9
src/Infobox/ColourCode.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef COLOURCODE_H
|
||||
#define COLOURCODE_H
|
||||
|
||||
#include "Infobox.h"
|
||||
|
||||
int is_colour_code_query(const char *query);
|
||||
InfoBox fetch_colour_data(char *query);
|
||||
|
||||
#endif
|
||||
@@ -207,8 +207,7 @@ char *construct_dictionary_url(const char *query) {
|
||||
const char *base = "https://dictionary.cambridge.org/dictionary/english/";
|
||||
char *url = malloc(strlen(base) + strlen(escaped) + 1);
|
||||
if (url) {
|
||||
strcpy(url, base);
|
||||
strcat(url, escaped);
|
||||
snprintf(url, strlen(base) + strlen(escaped) + 1, "%s%s", base, escaped);
|
||||
}
|
||||
|
||||
curl_free(escaped);
|
||||
|
||||
@@ -360,7 +360,7 @@ static int parse_conversion_query(const char *query, double *value,
|
||||
while (try_len > 0) {
|
||||
*to_unit = find_unit(try_buf);
|
||||
if (*to_unit) {
|
||||
strcpy(to_part, try_buf);
|
||||
snprintf(to_part, sizeof(to_part), "%s", try_buf);
|
||||
break;
|
||||
}
|
||||
char *last_space = strrchr(try_buf, ' ');
|
||||
@@ -443,34 +443,34 @@ static const char *pluralize(const char *unit, double value, char *buf,
|
||||
if (len == 0 || bufsize == 0)
|
||||
return unit;
|
||||
|
||||
strncpy(buf, unit, bufsize - 1);
|
||||
buf[bufsize - 1] = '\0';
|
||||
snprintf(buf, bufsize, "%s", unit);
|
||||
|
||||
if (strcmp(unit, "foot") == 0 || strcmp(unit, "square foot") == 0) {
|
||||
if (is_one)
|
||||
strcpy(buf, unit);
|
||||
snprintf(buf, bufsize, "%s", unit);
|
||||
else
|
||||
strcpy(buf, strcmp(unit, "square foot") == 0 ? "square feet" : "feet");
|
||||
snprintf(buf, bufsize, "%s",
|
||||
strcmp(unit, "square foot") == 0 ? "square feet" : "feet");
|
||||
return buf;
|
||||
}
|
||||
if (strcmp(unit, "inch") == 0 || strcmp(unit, "square inch") == 0) {
|
||||
if (is_one)
|
||||
strcpy(buf, unit);
|
||||
snprintf(buf, bufsize, "%s", unit);
|
||||
else
|
||||
strcpy(buf,
|
||||
snprintf(buf, bufsize, "%s",
|
||||
strcmp(unit, "square inch") == 0 ? "square inches" : "inches");
|
||||
return buf;
|
||||
}
|
||||
if (strcmp(unit, "stone") == 0) {
|
||||
if (is_one)
|
||||
strcpy(buf, "stone");
|
||||
snprintf(buf, bufsize, "%s", "stone");
|
||||
else
|
||||
strcpy(buf, "stones");
|
||||
snprintf(buf, bufsize, "%s", "stones");
|
||||
return buf;
|
||||
}
|
||||
if (strcmp(unit, "celsius") == 0 || strcmp(unit, "fahrenheit") == 0 ||
|
||||
strcmp(unit, "kelvin") == 0) {
|
||||
strcpy(buf, unit);
|
||||
snprintf(buf, bufsize, "%s", unit);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ static void shorten_summary(char **extract_ptr, int max_chars) {
|
||||
if (new_text) {
|
||||
strncpy(new_text, text, end_pos);
|
||||
new_text[end_pos] = '\0';
|
||||
strcat(new_text, "...");
|
||||
strncat(new_text, "...", 3);
|
||||
free(*extract_ptr);
|
||||
*extract_ptr = new_text;
|
||||
}
|
||||
@@ -65,8 +65,8 @@ static void extract_wiki_info(xmlNode *node, InfoBox *info) {
|
||||
info->url =
|
||||
malloc(strlen(base_article_url) + strlen(formatted_title) + 1);
|
||||
if (info->url) {
|
||||
strcpy(info->url, base_article_url);
|
||||
strcat(info->url, formatted_title);
|
||||
snprintf(info->url, strlen(base_article_url) + strlen(formatted_title) + 1,
|
||||
"%s%s", base_article_url, formatted_title);
|
||||
}
|
||||
free(formatted_title);
|
||||
xmlFree(title);
|
||||
@@ -177,9 +177,9 @@ static char *get_first_search_result(const char *search_term) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(search_url, search_base);
|
||||
strcat(search_url, escaped_term);
|
||||
strcat(search_url, search_suffix);
|
||||
snprintf(search_url, strlen(search_base) + strlen(escaped_term) +
|
||||
strlen(search_suffix) + 1, "%s%s%s", search_base,
|
||||
escaped_term, search_suffix);
|
||||
|
||||
curl_free(escaped_term);
|
||||
|
||||
@@ -226,8 +226,8 @@ char *construct_wiki_url(const char *search_term) {
|
||||
|
||||
char *full_url = malloc(strlen(base) + strlen(escaped_title) + 1);
|
||||
if (full_url) {
|
||||
strcpy(full_url, base);
|
||||
strcat(full_url, escaped_title);
|
||||
snprintf(full_url, strlen(base) + strlen(escaped_title) + 1, "%s%s", base,
|
||||
escaped_title);
|
||||
}
|
||||
|
||||
curl_free(escaped_title);
|
||||
|
||||
210
src/Limiter/RateLimit.c
Normal file
210
src/Limiter/RateLimit.c
Normal file
@@ -0,0 +1,210 @@
|
||||
#include "RateLimit.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <beaker.h>
|
||||
#include <ctype.h>
|
||||
#include <netinet/in.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef struct RateLimitEntry {
|
||||
char client_key[64];
|
||||
char scope[32];
|
||||
time_t window_start;
|
||||
time_t last_seen;
|
||||
int count;
|
||||
struct RateLimitEntry *next;
|
||||
} RateLimitEntry;
|
||||
|
||||
extern __thread int current_client_socket;
|
||||
extern __thread char current_request_buffer[];
|
||||
|
||||
static pthread_mutex_t rate_limit_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static RateLimitEntry *rate_limit_entries = NULL;
|
||||
|
||||
static int is_blank_char(char c) {
|
||||
return c == ' ' || c == '\t' || c == '\r' || c == '\n';
|
||||
}
|
||||
|
||||
static const char *str_case_str(const char *haystack, const char *needle) {
|
||||
size_t nlen = strlen(needle);
|
||||
for (; *haystack; haystack++) {
|
||||
if (tolower((unsigned char)*haystack) == tolower((unsigned char)*needle)) {
|
||||
size_t i;
|
||||
for (i = 1; i < nlen; i++) {
|
||||
if (tolower((unsigned char)haystack[i]) !=
|
||||
tolower((unsigned char)needle[i]))
|
||||
break;
|
||||
}
|
||||
if (i == nlen)
|
||||
return haystack;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void trim_copy(char *dest, size_t dest_size, const char *src,
|
||||
size_t src_len) {
|
||||
while (src_len > 0 && is_blank_char(*src)) {
|
||||
src++;
|
||||
src_len--;
|
||||
}
|
||||
|
||||
while (src_len > 0 && is_blank_char(src[src_len - 1])) {
|
||||
src_len--;
|
||||
}
|
||||
|
||||
if (dest_size == 0)
|
||||
return;
|
||||
|
||||
if (src_len >= dest_size)
|
||||
src_len = dest_size - 1;
|
||||
|
||||
memcpy(dest, src, src_len);
|
||||
dest[src_len] = '\0';
|
||||
}
|
||||
|
||||
static void get_client_key(char *client_key, size_t client_key_size) {
|
||||
const char *header = str_case_str(current_request_buffer, "x-forwarded-for:");
|
||||
if (!header)
|
||||
return;
|
||||
|
||||
header += strlen("X-Forwarded-For:");
|
||||
const char *line_end = strpbrk(header, "\r\n");
|
||||
size_t line_len = line_end ? (size_t)(line_end - header) : strlen(header);
|
||||
const char *comma = memchr(header, ',', line_len);
|
||||
size_t value_len = comma ? (size_t)(comma - header) : line_len;
|
||||
|
||||
trim_copy(client_key, client_key_size, header, value_len);
|
||||
}
|
||||
|
||||
static void get_client_key_from_socket(char *client_key,
|
||||
size_t client_key_size) {
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t addr_len = sizeof(addr);
|
||||
|
||||
if (getpeername(current_client_socket, (struct sockaddr *)&addr, &addr_len) !=
|
||||
0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (addr.ss_family == AF_INET) {
|
||||
struct sockaddr_in *ipv4 = (struct sockaddr_in *)&addr;
|
||||
inet_ntop(AF_INET, &ipv4->sin_addr, client_key, client_key_size);
|
||||
} else if (addr.ss_family == AF_INET6) {
|
||||
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&addr;
|
||||
inet_ntop(AF_INET6, &ipv6->sin6_addr, client_key, client_key_size);
|
||||
} else if (addr.ss_family == AF_UNIX) {
|
||||
snprintf(client_key, client_key_size, "unix:%d", current_client_socket);
|
||||
}
|
||||
}
|
||||
|
||||
void rate_limit_get_client_key(char *client_key, size_t client_key_size) {
|
||||
if (!client_key || client_key_size == 0)
|
||||
return;
|
||||
|
||||
client_key[0] = '\0';
|
||||
get_client_key(client_key, client_key_size);
|
||||
|
||||
if (client_key[0] == '\0') {
|
||||
get_client_key_from_socket(client_key, client_key_size);
|
||||
}
|
||||
|
||||
if (client_key[0] == '\0') {
|
||||
snprintf(client_key, client_key_size, "nun");
|
||||
}
|
||||
}
|
||||
|
||||
static void prune_stale_entries(time_t now) {
|
||||
RateLimitEntry **cursor = &rate_limit_entries;
|
||||
|
||||
while (*cursor) {
|
||||
RateLimitEntry *entry = *cursor;
|
||||
if (now - entry->last_seen > 9999) {
|
||||
*cursor = entry->next;
|
||||
free(entry);
|
||||
continue;
|
||||
}
|
||||
cursor = &entry->next;
|
||||
}
|
||||
}
|
||||
|
||||
static RateLimitEntry *find_entry(const char *client_key, const char *scope) {
|
||||
for (RateLimitEntry *entry = rate_limit_entries; entry; entry = entry->next) {
|
||||
if (strcmp(entry->client_key, client_key) == 0 &&
|
||||
strcmp(entry->scope, scope) == 0) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static RateLimitEntry *create_entry(const char *client_key, const char *scope,
|
||||
time_t now) {
|
||||
RateLimitEntry *entry = (RateLimitEntry *)calloc(1, sizeof(RateLimitEntry));
|
||||
if (!entry)
|
||||
return NULL;
|
||||
|
||||
snprintf(entry->client_key, sizeof(entry->client_key), "%s", client_key);
|
||||
snprintf(entry->scope, sizeof(entry->scope), "%s", scope);
|
||||
entry->window_start = now;
|
||||
entry->last_seen = now;
|
||||
entry->next = rate_limit_entries;
|
||||
rate_limit_entries = entry;
|
||||
return entry;
|
||||
}
|
||||
|
||||
RateLimitResult rate_limit_check(const char *scope,
|
||||
const RateLimitConfig *config) {
|
||||
RateLimitResult result = {.limited = 0, .retry_after_seconds = 0};
|
||||
|
||||
if (!scope || !config || config->max_requests <= 0 ||
|
||||
config->interval_seconds <= 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
char client_key[64];
|
||||
time_t now = time(NULL);
|
||||
|
||||
rate_limit_get_client_key(client_key, sizeof(client_key));
|
||||
|
||||
pthread_mutex_lock(&rate_limit_mutex);
|
||||
|
||||
prune_stale_entries(now);
|
||||
|
||||
RateLimitEntry *entry = find_entry(client_key, scope);
|
||||
if (!entry) {
|
||||
entry = create_entry(client_key, scope, now);
|
||||
if (!entry) {
|
||||
pthread_mutex_unlock(&rate_limit_mutex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
entry->last_seen = now;
|
||||
|
||||
if (now - entry->window_start >= config->interval_seconds) {
|
||||
entry->window_start = now;
|
||||
entry->count = 0;
|
||||
}
|
||||
|
||||
if (entry->count >= config->max_requests) {
|
||||
result.limited = 1;
|
||||
result.retry_after_seconds =
|
||||
config->interval_seconds - (int)(now - entry->window_start);
|
||||
if (result.retry_after_seconds < 1) {
|
||||
result.retry_after_seconds = 1;
|
||||
}
|
||||
pthread_mutex_unlock(&rate_limit_mutex);
|
||||
return result;
|
||||
}
|
||||
|
||||
entry->count++;
|
||||
pthread_mutex_unlock(&rate_limit_mutex);
|
||||
return result;
|
||||
}
|
||||
20
src/Limiter/RateLimit.h
Normal file
20
src/Limiter/RateLimit.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef RATE_LIMIT_H
|
||||
#define RATE_LIMIT_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
int max_requests;
|
||||
int interval_seconds;
|
||||
} RateLimitConfig;
|
||||
|
||||
typedef struct {
|
||||
int limited;
|
||||
int retry_after_seconds;
|
||||
} RateLimitResult;
|
||||
|
||||
void rate_limit_get_client_key(char *client_key, size_t client_key_size);
|
||||
RateLimitResult rate_limit_check(const char *scope,
|
||||
const RateLimitConfig *config);
|
||||
|
||||
#endif
|
||||
78
src/Main.c
78
src/Main.c
@@ -12,21 +12,46 @@
|
||||
#include "Routes/Home.h"
|
||||
#include "Routes/ImageProxy.h"
|
||||
#include "Routes/Images.h"
|
||||
#include "Routes/Info.h"
|
||||
#include "Routes/Search.h"
|
||||
#include "Routes/Settings.h"
|
||||
#include "Routes/SettingsSave.h"
|
||||
#include "Scraping/Scraping.h"
|
||||
#include "Utility/Utility.h"
|
||||
|
||||
Config global_config;
|
||||
|
||||
int handle_opensearch(UrlParams *params) {
|
||||
(void)params;
|
||||
extern Config global_config;
|
||||
TemplateContext ctx = new_context();
|
||||
context_set(&ctx, "domain", global_config.domain);
|
||||
|
||||
const char *http_host = beaker_get_header("Host");
|
||||
if (http_host == NULL) {
|
||||
http_host = "localhost";
|
||||
}
|
||||
|
||||
const char *req_scheme =
|
||||
"https"; // not sure if it's a good idea to just assume https, but you
|
||||
// should probably be using https for anything other than testing
|
||||
// or local network anyways.
|
||||
|
||||
if (strncmp(http_host, "localhost", 9) == 0 ||
|
||||
strncmp(http_host, "127.", 4) == 0 ||
|
||||
strncmp(http_host, "192.168.", 8) == 0 ||
|
||||
strncmp(http_host, "10.", 3) == 0) {
|
||||
req_scheme = "http";
|
||||
}
|
||||
|
||||
context_set(&ctx, "domain", http_host);
|
||||
context_set(&ctx, "scheme", req_scheme);
|
||||
|
||||
char *rendered = render_template("opensearch.xml", &ctx);
|
||||
serve_data(rendered, strlen(rendered), "application/opensearchdescription+xml");
|
||||
serve_data(rendered, strlen(rendered),
|
||||
"application/opensearchdescription+xml");
|
||||
|
||||
free(rendered);
|
||||
free_context(&ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -41,26 +66,44 @@ int main() {
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
|
||||
Config cfg = {.host = DEFAULT_HOST,
|
||||
.port = DEFAULT_PORT,
|
||||
.domain = "",
|
||||
.proxy = "",
|
||||
.proxy_list_file = "",
|
||||
.max_proxy_retries = DEFAULT_MAX_PROXY_RETRIES,
|
||||
.randomize_username = 0,
|
||||
.randomize_password = 0,
|
||||
.cache_dir = DEFAULT_CACHE_DIR,
|
||||
.cache_ttl_search = DEFAULT_CACHE_TTL_SEARCH,
|
||||
.cache_ttl_infobox = DEFAULT_CACHE_TTL_INFOBOX,
|
||||
.engines = ""};
|
||||
Config cfg;
|
||||
config_set_defaults(&cfg);
|
||||
|
||||
if (load_config("config.ini", &cfg) != 0) {
|
||||
fprintf(stderr, "[WARN] Could not load config file, using defaults\n");
|
||||
}
|
||||
|
||||
set_default_locale(cfg.default_locale);
|
||||
init_themes("static");
|
||||
|
||||
global_config = cfg;
|
||||
|
||||
int loaded = beaker_load_locales();
|
||||
if (loaded > 0) {
|
||||
fprintf(stderr, "[INFO] Loaded %d locales\n", loaded);
|
||||
} else {
|
||||
fprintf(stderr, "[WARN] No locales loaded (make sure to run from "
|
||||
"omnisearch directory)\n");
|
||||
}
|
||||
|
||||
apply_engines_config(cfg.engines);
|
||||
configure_yacy_engine(cfg.yacy_instance);
|
||||
|
||||
if (cfg.yacy_instance[0] != '\0') {
|
||||
int yacy_enabled = 0;
|
||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||
if (strcmp(ENGINE_REGISTRY[i].id, "yacy") == 0) {
|
||||
yacy_enabled = ENGINE_REGISTRY[i].enabled;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!yacy_enabled) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"[INFO] YaCy instance configured but the yacy engine is not "
|
||||
"enabled (add it to the engines list, e.g. engines=\"*,yacy\")\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (cache_init(cfg.cache_dir) != 0) {
|
||||
fprintf(stderr,
|
||||
@@ -72,6 +115,7 @@ int main() {
|
||||
|
||||
set_cache_ttl_search(cfg.cache_ttl_search);
|
||||
set_cache_ttl_infobox(cfg.cache_ttl_infobox);
|
||||
set_cache_ttl_image(cfg.cache_ttl_image);
|
||||
|
||||
if (cfg.proxy_list_file[0] != '\0') {
|
||||
if (load_proxy_list(cfg.proxy_list_file) < 0) {
|
||||
@@ -95,6 +139,9 @@ int main() {
|
||||
set_handler("/search", results_handler);
|
||||
set_handler("/images", images_handler);
|
||||
set_handler("/proxy", image_proxy_handler);
|
||||
set_handler("/info", info_handler);
|
||||
set_handler("/settings", settings_handler);
|
||||
set_handler("/save_settings", settings_save_handler);
|
||||
|
||||
fprintf(stderr, "[INFO] Starting Omnisearch on %s:%d\n", cfg.host, cfg.port);
|
||||
|
||||
@@ -109,6 +156,7 @@ int main() {
|
||||
|
||||
curl_global_cleanup();
|
||||
xmlCleanupParser();
|
||||
beaker_free_locales();
|
||||
free_proxy_list();
|
||||
cache_shutdown();
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -25,8 +25,7 @@ static void generate_random_string(char *buf, size_t len) {
|
||||
|
||||
void set_proxy_config(const char *proxy_str, int rand_user, int rand_pass) {
|
||||
if (proxy_str && proxy_str[0]) {
|
||||
strncpy(proxy_url, proxy_str, sizeof(proxy_url) - 1);
|
||||
proxy_url[sizeof(proxy_url) - 1] = '\0';
|
||||
snprintf(proxy_url, sizeof(proxy_url), "%s", proxy_str);
|
||||
}
|
||||
randomize_username = rand_user;
|
||||
randomize_password = rand_pass;
|
||||
@@ -144,7 +143,8 @@ int load_proxy_list(const char *filename) {
|
||||
|
||||
if (temp_count >= temp_capacity) {
|
||||
temp_capacity *= 2;
|
||||
Proxy *new_list = (Proxy *)realloc(temp_list, temp_capacity * sizeof(Proxy));
|
||||
Proxy *new_list =
|
||||
(Proxy *)realloc(temp_list, temp_capacity * sizeof(Proxy));
|
||||
if (!new_list) {
|
||||
free(temp_list);
|
||||
fclose(file);
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
#include "Home.h"
|
||||
#include "../Utility/Utility.h"
|
||||
#include <beaker.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int home_handler(UrlParams *params) {
|
||||
(void)params;
|
||||
char *theme = get_theme("");
|
||||
char *locale = get_locale(NULL);
|
||||
|
||||
char **themes = NULL;
|
||||
int themes_count = 0;
|
||||
get_available_themes(&themes, &themes_count);
|
||||
|
||||
TemplateContext ctx = new_context();
|
||||
context_set(&ctx, "theme", theme);
|
||||
context_set(&ctx, "version", VERSION);
|
||||
context_set(&ctx, "git_remote", GIT_REMOTE);
|
||||
beaker_set_locale(&ctx, locale);
|
||||
char *rendered_html = render_template("home.html", &ctx);
|
||||
send_response(rendered_html);
|
||||
|
||||
free(rendered_html);
|
||||
free_context(&ctx);
|
||||
free(theme);
|
||||
free(locale);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,31 @@
|
||||
#include "ImageProxy.h"
|
||||
#include "../Cache/Cache.h"
|
||||
#include "../Proxy/Proxy.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <curl/curl.h>
|
||||
#include <curl/urlapi.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <time.h>
|
||||
|
||||
#define MAX_IMAGE_SIZE (10 * 1024 * 1024)
|
||||
#define DNS_CACHE_TTL 300
|
||||
|
||||
typedef struct DnsCacheEntry {
|
||||
char hostname[256];
|
||||
char ip_str[INET6_ADDRSTRLEN];
|
||||
time_t resolved_at;
|
||||
struct DnsCacheEntry *next;
|
||||
} DnsCacheEntry;
|
||||
|
||||
static DnsCacheEntry *dns_cache = NULL;
|
||||
static pthread_mutex_t dns_cache_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
typedef struct {
|
||||
char *data;
|
||||
@@ -13,7 +33,157 @@ typedef struct {
|
||||
size_t capacity;
|
||||
} MemoryBuffer;
|
||||
|
||||
static int is_allowed_domain(const char *url) {
|
||||
static int dns_cache_lookup(const char *hostname, char *out_ip) {
|
||||
time_t now = time(NULL);
|
||||
pthread_mutex_lock(&dns_cache_mutex);
|
||||
for (DnsCacheEntry *e = dns_cache; e; e = e->next) {
|
||||
if (strcmp(e->hostname, hostname) == 0) {
|
||||
if ((now - e->resolved_at) < DNS_CACHE_TTL) {
|
||||
snprintf(out_ip, INET6_ADDRSTRLEN, "%s", e->ip_str);
|
||||
pthread_mutex_unlock(&dns_cache_mutex);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&dns_cache_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void dns_cache_insert(const char *hostname, const char *ip_str) {
|
||||
time_t now = time(NULL);
|
||||
pthread_mutex_lock(&dns_cache_mutex);
|
||||
|
||||
DnsCacheEntry **cursor = &dns_cache;
|
||||
while (*cursor) {
|
||||
DnsCacheEntry *entry = *cursor;
|
||||
if ((now - entry->resolved_at) >= DNS_CACHE_TTL) {
|
||||
*cursor = entry->next;
|
||||
free(entry);
|
||||
continue;
|
||||
}
|
||||
if (strcmp(entry->hostname, hostname) == 0) {
|
||||
snprintf(entry->ip_str, sizeof(entry->ip_str), "%s", ip_str);
|
||||
entry->resolved_at = now;
|
||||
pthread_mutex_unlock(&dns_cache_mutex);
|
||||
return;
|
||||
}
|
||||
cursor = &entry->next;
|
||||
}
|
||||
|
||||
DnsCacheEntry *new_entry = malloc(sizeof(DnsCacheEntry));
|
||||
if (new_entry) {
|
||||
snprintf(new_entry->hostname, sizeof(new_entry->hostname), "%s", hostname);
|
||||
snprintf(new_entry->ip_str, sizeof(new_entry->ip_str), "%s", ip_str);
|
||||
new_entry->resolved_at = now;
|
||||
new_entry->next = dns_cache;
|
||||
dns_cache = new_entry;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&dns_cache_mutex);
|
||||
}
|
||||
|
||||
static int is_private_ip(const char *ip_str) {
|
||||
struct in_addr addr;
|
||||
if (inet_pton(AF_INET, ip_str, &addr) != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t ip = ntohl(addr.s_addr);
|
||||
|
||||
// 10.0.0.0/8
|
||||
if ((ip >> 24) == 10) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 172.16.0.0/12
|
||||
if ((ip >> 20) == 0xAC) {
|
||||
uint8_t second = (ip >> 16) & 0xFF;
|
||||
if (second >= 16 && second <= 31) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 192.168.0.0/16
|
||||
if ((ip >> 16) == 0xC0A8) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 127.0.0.0/8
|
||||
if ((ip >> 24) == 127) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 169.254.0.0/16
|
||||
if ((ip >> 16) == 0xA9FE) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *is_private_hostname(const char *hostname, char *out_ip) {
|
||||
if (dns_cache_lookup(hostname, out_ip) == 0) {
|
||||
return out_ip;
|
||||
}
|
||||
|
||||
struct addrinfo hints, *res, *p;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
int err = getaddrinfo(hostname, NULL, &hints, &res);
|
||||
if (err != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (p = res; p != NULL; p = p->ai_next) {
|
||||
if (p->ai_family == AF_INET) {
|
||||
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
|
||||
char ip_str[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &(ipv4->sin_addr), ip_str, INET_ADDRSTRLEN);
|
||||
|
||||
if (is_private_ip(ip_str)) {
|
||||
freeaddrinfo(res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
freeaddrinfo(res);
|
||||
snprintf(out_ip, INET6_ADDRSTRLEN, "%s", ip_str);
|
||||
dns_cache_insert(hostname, ip_str);
|
||||
return out_ip;
|
||||
}
|
||||
}
|
||||
|
||||
freeaddrinfo(res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int is_allowed_domain(const char *url, char *resolved_ip) {
|
||||
CURLU *h = curl_url();
|
||||
if (!h) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
curl_url_set(h, CURLUPART_URL, url, 0);
|
||||
|
||||
char *scheme = NULL;
|
||||
curl_url_get(h, CURLUPART_SCHEME, &scheme, 0);
|
||||
|
||||
int valid_scheme = 0;
|
||||
if (scheme &&
|
||||
(strcasecmp(scheme, "http") == 0 || strcasecmp(scheme, "https") == 0)) {
|
||||
valid_scheme = 1;
|
||||
}
|
||||
|
||||
if (scheme)
|
||||
curl_free(scheme);
|
||||
|
||||
if (!valid_scheme) {
|
||||
curl_url_cleanup(h);
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *protocol = strstr(url, "://");
|
||||
if (!protocol) {
|
||||
protocol = url;
|
||||
@@ -30,23 +200,20 @@ static int is_allowed_domain(const char *url) {
|
||||
}
|
||||
strncpy(host, protocol, host_len);
|
||||
|
||||
const char *allowed_domains[] = {"mm.bing.net", "th.bing.com", NULL};
|
||||
|
||||
for (int i = 0; allowed_domains[i] != NULL; i++) {
|
||||
size_t domain_len = strlen(allowed_domains[i]);
|
||||
size_t host_str_len = strlen(host);
|
||||
|
||||
if (host_str_len >= domain_len) {
|
||||
const char *suffix = host + host_str_len - domain_len;
|
||||
if (strcmp(suffix, allowed_domains[i]) == 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
char *colon = strchr(host, ':');
|
||||
if (colon) {
|
||||
*colon = '\0';
|
||||
}
|
||||
|
||||
if (!is_private_hostname(host, resolved_ip)) {
|
||||
curl_url_cleanup(h);
|
||||
return 0;
|
||||
}
|
||||
|
||||
curl_url_cleanup(h);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static size_t write_callback(void *contents, size_t size, size_t nmemb,
|
||||
void *userp) {
|
||||
size_t realsize = size * nmemb;
|
||||
@@ -73,6 +240,31 @@ static size_t write_callback(void *contents, size_t size, size_t nmemb,
|
||||
return realsize;
|
||||
}
|
||||
|
||||
static char *url_encode_key(const char *url) {
|
||||
char *hash = malloc(33);
|
||||
if (!hash)
|
||||
return NULL;
|
||||
|
||||
unsigned char md5hash[16];
|
||||
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
||||
if (!ctx) {
|
||||
free(hash);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EVP_DigestInit_ex(ctx, EVP_md5(), NULL);
|
||||
EVP_DigestUpdate(ctx, url, strlen(url));
|
||||
EVP_DigestFinal_ex(ctx, md5hash, NULL);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
snprintf(hash + (i * 2), 3, "%02x", md5hash[i]);
|
||||
}
|
||||
hash[32] = '\0';
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
int image_proxy_handler(UrlParams *params) {
|
||||
const char *url = NULL;
|
||||
for (int i = 0; i < params->count; i++) {
|
||||
@@ -87,13 +279,67 @@ int image_proxy_handler(UrlParams *params) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!is_allowed_domain(url)) {
|
||||
send_response("Domain not allowed");
|
||||
char resolved_ip[INET6_ADDRSTRLEN] = {0};
|
||||
int domain_check = is_allowed_domain(url, resolved_ip);
|
||||
if (domain_check == -1) {
|
||||
send_response("Invalid URL scheme");
|
||||
return 0;
|
||||
}
|
||||
if (domain_check == 0) {
|
||||
send_response("Private addresses are not allowed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *cache_key = url_encode_key(url);
|
||||
if (!cache_key) {
|
||||
send_response("Failed to generate cache key");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *cached_data = NULL;
|
||||
size_t cached_size = 0;
|
||||
int cache_ttl = get_cache_ttl_image();
|
||||
|
||||
if (cache_get(cache_key, cache_ttl, &cached_data, &cached_size) == 0) {
|
||||
if (!cached_data || cached_size == 0) {
|
||||
free(cached_data);
|
||||
free(cache_key);
|
||||
send_response("Empty cached image response");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char content_type[64] = {0};
|
||||
|
||||
const char *ext = strrchr(url, '.');
|
||||
if (ext) {
|
||||
if (strcasecmp(ext, ".png") == 0) {
|
||||
strncpy(content_type, "image/png", sizeof(content_type) - 1);
|
||||
} else if (strcasecmp(ext, ".gif") == 0) {
|
||||
strncpy(content_type, "image/gif", sizeof(content_type) - 1);
|
||||
} else if (strcasecmp(ext, ".webp") == 0) {
|
||||
strncpy(content_type, "image/webp", sizeof(content_type) - 1);
|
||||
} else if (strcasecmp(ext, ".svg") == 0) {
|
||||
strncpy(content_type, "image/svg+xml", sizeof(content_type) - 1);
|
||||
} else if (strcasecmp(ext, ".ico") == 0) {
|
||||
strncpy(content_type, "image/x-icon", sizeof(content_type) - 1);
|
||||
} else if (strcasecmp(ext, ".bmp") == 0) {
|
||||
strncpy(content_type, "image/bmp", sizeof(content_type) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(content_type) == 0) {
|
||||
strncpy(content_type, "image/jpeg", sizeof(content_type) - 1);
|
||||
}
|
||||
|
||||
serve_data(cached_data, cached_size, content_type);
|
||||
free(cached_data);
|
||||
free(cache_key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CURL *curl = curl_easy_init();
|
||||
if (!curl) {
|
||||
free(cache_key);
|
||||
send_response("Failed to initialize curl");
|
||||
return 0;
|
||||
}
|
||||
@@ -102,6 +348,7 @@ int image_proxy_handler(UrlParams *params) {
|
||||
|
||||
if (!buf.data) {
|
||||
curl_easy_cleanup(curl);
|
||||
free(cache_key);
|
||||
send_response("Memory allocation failed");
|
||||
return 0;
|
||||
}
|
||||
@@ -111,8 +358,37 @@ int image_proxy_handler(UrlParams *params) {
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT,
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||
"Chrome/120.0.0.0 Safari/537.36");
|
||||
apply_proxy_settings(curl);
|
||||
|
||||
struct curl_slist *resolves = NULL;
|
||||
if (resolved_ip[0] != '\0') {
|
||||
CURLU *u = curl_url();
|
||||
if (u) {
|
||||
curl_url_set(u, CURLUPART_URL, url, 0);
|
||||
char *rhost = NULL;
|
||||
curl_url_get(u, CURLUPART_HOST, &rhost, 0);
|
||||
if (rhost) {
|
||||
char *rscheme = NULL;
|
||||
curl_url_get(u, CURLUPART_SCHEME, &rscheme, 0);
|
||||
int port = (rscheme && strcasecmp(rscheme, "https") == 0) ? 443 : 80;
|
||||
if (rscheme)
|
||||
curl_free(rscheme);
|
||||
|
||||
char resolve_str[512];
|
||||
snprintf(resolve_str, sizeof(resolve_str), "%s:%d:%s", rhost, port,
|
||||
resolved_ip);
|
||||
resolves = curl_slist_append(NULL, resolve_str);
|
||||
curl_easy_setopt(curl, CURLOPT_RESOLVE, resolves);
|
||||
curl_free(rhost);
|
||||
}
|
||||
curl_url_cleanup(u);
|
||||
}
|
||||
}
|
||||
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
|
||||
long response_code;
|
||||
@@ -126,18 +402,39 @@ int image_proxy_handler(UrlParams *params) {
|
||||
strncpy(content_type, content_type_ptr, sizeof(content_type) - 1);
|
||||
}
|
||||
|
||||
if (resolves)
|
||||
curl_slist_free_all(resolves);
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
if (res != CURLE_OK || response_code != 200) {
|
||||
free(buf.data);
|
||||
free(cache_key);
|
||||
send_response("Failed to fetch image");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (buf.size == 0) {
|
||||
free(buf.data);
|
||||
free(cache_key);
|
||||
send_response("Empty image response");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strlen(content_type) == 0 || strncmp(content_type, "image/", 6) != 0) {
|
||||
free(buf.data);
|
||||
free(cache_key);
|
||||
send_response("Invalid content type");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *mime_type =
|
||||
strlen(content_type) > 0 ? content_type : "image/jpeg";
|
||||
|
||||
cache_set(cache_key, buf.data, buf.size);
|
||||
|
||||
serve_data(buf.data, buf.size, mime_type);
|
||||
|
||||
free(buf.data);
|
||||
free(cache_key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,48 @@
|
||||
#include "Images.h"
|
||||
#include "../Cache/Cache.h"
|
||||
#include "../Limiter/RateLimit.h"
|
||||
#include "../Scraping/ImageScraping.h"
|
||||
#include "../Utility/Unescape.h"
|
||||
#include "../Utility/Utility.h"
|
||||
#include "Config.h"
|
||||
#include <beaker.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static char *build_images_request_cache_key(const char *query, int page,
|
||||
const char *client_key) {
|
||||
char scope_key[BUFFER_SIZE_MEDIUM];
|
||||
snprintf(scope_key, sizeof(scope_key), "images_request:%s",
|
||||
client_key ? client_key : "unknown");
|
||||
return cache_compute_key(query, page, scope_key);
|
||||
}
|
||||
|
||||
static char *build_images_href(const char *query, int page) {
|
||||
const char *safe_query = query ? query : "";
|
||||
size_t needed = strlen("/images?q=") + strlen(safe_query) + 1;
|
||||
if (page > 1)
|
||||
needed += strlen("&p=") + 16;
|
||||
|
||||
char *href = (char *)malloc(needed);
|
||||
if (!href)
|
||||
return NULL;
|
||||
|
||||
if (page > 1) {
|
||||
char page_buf[16];
|
||||
snprintf(page_buf, sizeof(page_buf), "%d", page);
|
||||
snprintf(href, needed, "/images?q=%s&p=%s", safe_query, page_buf);
|
||||
} else {
|
||||
snprintf(href, needed, "/images?q=%s", safe_query);
|
||||
}
|
||||
return href;
|
||||
}
|
||||
|
||||
static char *images_href_builder(int page, void *data) {
|
||||
return build_images_href((const char *)data, page);
|
||||
}
|
||||
|
||||
int images_handler(UrlParams *params) {
|
||||
extern Config global_config;
|
||||
TemplateContext ctx = new_context();
|
||||
char *raw_query = "";
|
||||
int page = 1;
|
||||
@@ -20,68 +59,126 @@ int images_handler(UrlParams *params) {
|
||||
}
|
||||
}
|
||||
|
||||
char page_str[16], prev_str[16], next_str[16], two_prev_str[16],
|
||||
two_next_str[16];
|
||||
|
||||
snprintf(page_str, sizeof(page_str), "%d", page);
|
||||
snprintf(prev_str, sizeof(prev_str), "%d", page > 1 ? page - 1 : 0);
|
||||
snprintf(next_str, sizeof(next_str), "%d", page + 1);
|
||||
snprintf(two_prev_str, sizeof(two_prev_str), "%d", page > 2 ? page - 2 : 0);
|
||||
snprintf(two_next_str, sizeof(two_next_str), "%d", page + 2);
|
||||
context_set(&ctx, "query", raw_query);
|
||||
context_set(&ctx, "page", page_str);
|
||||
context_set(&ctx, "prev_page", prev_str);
|
||||
context_set(&ctx, "next_page", next_str);
|
||||
context_set(&ctx, "two_prev_page", two_prev_str);
|
||||
context_set(&ctx, "two_next_page", two_next_str);
|
||||
|
||||
char *theme = get_theme("");
|
||||
context_set(&ctx, "theme", theme);
|
||||
free(theme);
|
||||
|
||||
char *locale = get_locale(NULL);
|
||||
beaker_set_locale(&ctx, locale);
|
||||
|
||||
const char *rate_limit_msg = beaker_get_locale_value(locale, "rate_limit");
|
||||
if (!rate_limit_msg)
|
||||
rate_limit_msg = "Slow down! Too many image searches from you!";
|
||||
const char *error_images_msg =
|
||||
beaker_get_locale_value(locale, "error_images");
|
||||
if (!error_images_msg)
|
||||
error_images_msg = "Error fetching images";
|
||||
|
||||
StringMatrix pagination;
|
||||
string_matrix_build_pagination(page, images_href_builder, (void *)raw_query,
|
||||
&pagination);
|
||||
if (pagination.count > 0) {
|
||||
context_set_array_of_arrays(&ctx, "pagination_links", pagination.rows,
|
||||
pagination.count, pagination.field_counts);
|
||||
}
|
||||
|
||||
char *display_query = url_decode_query(raw_query);
|
||||
context_set(&ctx, "query", display_query);
|
||||
|
||||
if (!raw_query || strlen(raw_query) == 0) {
|
||||
send_response("<h1>No query provided</h1>");
|
||||
if (display_query)
|
||||
send_redirect("/");
|
||||
string_matrix_free(&pagination);
|
||||
free(display_query);
|
||||
free(locale);
|
||||
free_context(&ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char client_key[BUFFER_SIZE_SMALL];
|
||||
rate_limit_get_client_key(client_key, sizeof(client_key));
|
||||
|
||||
char *request_cache_key =
|
||||
build_images_request_cache_key(raw_query, page, client_key);
|
||||
int request_is_cached = 0;
|
||||
|
||||
if (request_cache_key && get_cache_ttl_image() > 0) {
|
||||
char *cached_marker = NULL;
|
||||
size_t cached_marker_size = 0;
|
||||
|
||||
if (cache_get(request_cache_key, (time_t)get_cache_ttl_image(),
|
||||
&cached_marker, &cached_marker_size) == 0) {
|
||||
request_is_cached = 1;
|
||||
}
|
||||
|
||||
free(cached_marker);
|
||||
}
|
||||
|
||||
if (!request_is_cached) {
|
||||
RateLimitConfig rate_limit_config = {
|
||||
.max_requests = global_config.rate_limit_images_requests,
|
||||
.interval_seconds = global_config.rate_limit_images_interval,
|
||||
};
|
||||
RateLimitResult rate_limit_result =
|
||||
rate_limit_check("images", &rate_limit_config);
|
||||
if (rate_limit_result.limited) {
|
||||
char response[256];
|
||||
snprintf(response, sizeof(response), "<h1>%s</h1>", rate_limit_msg);
|
||||
send_response(response);
|
||||
free(request_cache_key);
|
||||
string_matrix_free(&pagination);
|
||||
free(display_query);
|
||||
free(locale);
|
||||
free_context(&ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (request_cache_key && get_cache_ttl_image() > 0) {
|
||||
cache_set(request_cache_key, "1", 1);
|
||||
}
|
||||
}
|
||||
|
||||
ImageResult *results = NULL;
|
||||
int result_count = 0;
|
||||
|
||||
if (scrape_images(raw_query, page, &results, &result_count) != 0 ||
|
||||
!results) {
|
||||
send_response("<h1>Error fetching images</h1>");
|
||||
char error_html[128];
|
||||
snprintf(error_html, sizeof(error_html), "<h1>%s</h1>", error_images_msg);
|
||||
send_response(error_html);
|
||||
free(request_cache_key);
|
||||
string_matrix_free(&pagination);
|
||||
free(display_query);
|
||||
free(locale);
|
||||
free_context(&ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char ***image_matrix = malloc(sizeof(char **) * result_count);
|
||||
int *inner_counts = malloc(sizeof(int) * result_count);
|
||||
|
||||
if (!image_matrix || !inner_counts) {
|
||||
if (image_matrix)
|
||||
free(image_matrix);
|
||||
if (inner_counts)
|
||||
free(inner_counts);
|
||||
free_image_results(results, result_count);
|
||||
free(display_query);
|
||||
free_context(&ctx);
|
||||
return -1;
|
||||
}
|
||||
StringMatrix images;
|
||||
string_matrix_init(&images);
|
||||
|
||||
for (int i = 0; i < result_count; i++) {
|
||||
image_matrix[i] = malloc(sizeof(char *) * IMAGE_RESULT_FIELDS);
|
||||
image_matrix[i][0] = strdup(results[i].thumbnail_url);
|
||||
image_matrix[i][1] = strdup(results[i].title);
|
||||
image_matrix[i][2] = strdup(results[i].page_url);
|
||||
image_matrix[i][3] = strdup(results[i].full_url);
|
||||
inner_counts[i] = IMAGE_RESULT_FIELDS;
|
||||
const char *values[IMAGE_RESULT_FIELDS] = {
|
||||
results[i].thumbnail_url,
|
||||
results[i].title,
|
||||
results[i].page_url,
|
||||
results[i].full_url,
|
||||
};
|
||||
if (string_matrix_append(&images, values, IMAGE_RESULT_FIELDS) != 0) {
|
||||
string_matrix_free(&images);
|
||||
string_matrix_free(&pagination);
|
||||
free_image_results(results, result_count);
|
||||
free(request_cache_key);
|
||||
free(display_query);
|
||||
free(locale);
|
||||
free_context(&ctx);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
context_set_array_of_arrays(&ctx, "images", image_matrix, result_count,
|
||||
inner_counts);
|
||||
context_set_array_of_arrays(&ctx, "images", images.rows, images.count,
|
||||
images.field_counts);
|
||||
|
||||
char *rendered = render_template("images.html", &ctx);
|
||||
if (rendered) {
|
||||
@@ -91,16 +188,13 @@ int images_handler(UrlParams *params) {
|
||||
send_response("<h1>Error rendering image results</h1>");
|
||||
}
|
||||
|
||||
for (int i = 0; i < result_count; i++) {
|
||||
for (int j = 0; j < IMAGE_RESULT_FIELDS; j++)
|
||||
free(image_matrix[i][j]);
|
||||
free(image_matrix[i]);
|
||||
}
|
||||
free(image_matrix);
|
||||
free(inner_counts);
|
||||
string_matrix_free(&images);
|
||||
string_matrix_free(&pagination);
|
||||
|
||||
free_image_results(results, result_count);
|
||||
free(request_cache_key);
|
||||
free(display_query);
|
||||
free(locale);
|
||||
free_context(&ctx);
|
||||
|
||||
return 0;
|
||||
|
||||
69
src/Routes/Info.c
Normal file
69
src/Routes/Info.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "Info.h"
|
||||
#include "../Config.h"
|
||||
#include "../Scraping/Scraping.h"
|
||||
#include "../Utility/Utility.h"
|
||||
#include <beaker.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int append_json(char *buf, size_t size, size_t *used, const char *format,
|
||||
...) {
|
||||
if (*used >= size) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int written = vsnprintf(buf + *used, size - *used, format, args);
|
||||
va_end(args);
|
||||
|
||||
if (written < 0 || (size_t)written >= size - *used) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*used += (size_t)written;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int info_handler(UrlParams *params) {
|
||||
(void)params;
|
||||
extern Config global_config;
|
||||
|
||||
char json[INITIAL_BUFFER_SIZE];
|
||||
size_t used = 0;
|
||||
|
||||
if (append_json(json, sizeof(json), &used, "{\"version\":\"%s\",", VERSION) !=
|
||||
0 ||
|
||||
append_json(json, sizeof(json), &used, "\"git_remote\":\"%s\",",
|
||||
GIT_REMOTE) != 0 ||
|
||||
append_json(json, sizeof(json), &used, "\"locale\":\"%s\",",
|
||||
global_config.default_locale) != 0 ||
|
||||
append_json(json, sizeof(json), &used, "\"engines\":[") != 0) {
|
||||
send_response("Failed to build instance info");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int first = 1;
|
||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||
if (!ENGINE_REGISTRY[i].enabled) {
|
||||
continue;
|
||||
}
|
||||
if (append_json(json, sizeof(json), &used,
|
||||
"%s{\"id\":\"%s\",\"name\":\"%s\"}", first ? "" : ",",
|
||||
ENGINE_REGISTRY[i].id, ENGINE_REGISTRY[i].name) != 0) {
|
||||
send_response("Failed to build instance info");
|
||||
return -1;
|
||||
}
|
||||
first = 0;
|
||||
}
|
||||
|
||||
if (append_json(json, sizeof(json), &used, "]}") != 0) {
|
||||
send_response("Failed to build instance info");
|
||||
return -1;
|
||||
}
|
||||
|
||||
serve_data(json, used, "application/json");
|
||||
|
||||
return 0;
|
||||
}
|
||||
8
src/Routes/Info.h
Normal file
8
src/Routes/Info.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef INFO_H
|
||||
#define INFO_H
|
||||
|
||||
#include <beaker.h>
|
||||
|
||||
int info_handler(UrlParams *params);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
170
src/Routes/Settings.c
Normal file
170
src/Routes/Settings.c
Normal file
@@ -0,0 +1,170 @@
|
||||
#include "Settings.h"
|
||||
#include "../Scraping/Scraping.h"
|
||||
#include "../Utility/Utility.h"
|
||||
#include <beaker.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static char *format_theme_name(const char *theme) {
|
||||
char *label = strdup(theme ? theme : "");
|
||||
if (!label)
|
||||
return NULL;
|
||||
|
||||
int capitalise_next = 1;
|
||||
for (size_t i = 0; label[i] != '\0'; i++) {
|
||||
if (label[i] == '-') {
|
||||
label[i] = ' ';
|
||||
capitalise_next = 1;
|
||||
continue;
|
||||
}
|
||||
if (capitalise_next) {
|
||||
if (label[i] >= 'a' && label[i] <= 'z')
|
||||
label[i] = label[i] - 'a' + 'A';
|
||||
capitalise_next = 0;
|
||||
}
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
int settings_handler(UrlParams *params) {
|
||||
const char *query = "";
|
||||
if (params) {
|
||||
for (int i = 0; i < params->count; i++) {
|
||||
if (strcmp(params->params[i].key, "q") == 0) {
|
||||
query = params->params[i].value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char *theme = get_theme("system");
|
||||
char *locale = get_locale(NULL);
|
||||
|
||||
LocaleInfo locales[32];
|
||||
int locale_count = beaker_get_all_locales(locales, 32);
|
||||
|
||||
char **locale_data[32];
|
||||
int inner_counts[32];
|
||||
for (int i = 0; i < locale_count; i++) {
|
||||
locale_data[i] = malloc(sizeof(char *) * 2);
|
||||
locale_data[i][0] = locales[i].meta.id;
|
||||
locale_data[i][1] = locales[i].meta.name;
|
||||
inner_counts[i] = 2;
|
||||
}
|
||||
|
||||
char **user_engines = NULL;
|
||||
int user_engine_count = 0;
|
||||
int has_user_pref =
|
||||
(get_user_engines(&user_engines, &user_engine_count) == 0);
|
||||
char *default_engine = get_default_search_engine();
|
||||
|
||||
if (strcmp(default_engine, "all") != 0 && has_user_pref &&
|
||||
!user_engines_contains(default_engine, user_engines,
|
||||
user_engine_count)) {
|
||||
free(default_engine);
|
||||
default_engine = strdup("all");
|
||||
}
|
||||
|
||||
int enabled_count = 0;
|
||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||
if (ENGINE_REGISTRY[i].enabled)
|
||||
enabled_count++;
|
||||
}
|
||||
|
||||
char ***engine_data = NULL;
|
||||
int *engine_inner = NULL;
|
||||
|
||||
if (enabled_count > 0) {
|
||||
engine_data = malloc(sizeof(char **) * enabled_count);
|
||||
engine_inner = malloc(sizeof(int) * enabled_count);
|
||||
|
||||
int idx = 0;
|
||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||
if (!ENGINE_REGISTRY[i].enabled)
|
||||
continue;
|
||||
|
||||
int is_selected = !has_user_pref;
|
||||
if (has_user_pref) {
|
||||
for (int j = 0; j < user_engine_count; j++) {
|
||||
if (strcmp(user_engines[j], ENGINE_REGISTRY[i].id) == 0) {
|
||||
is_selected = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
engine_data[idx] = malloc(sizeof(char *) * 4);
|
||||
engine_data[idx][0] = (char *)ENGINE_REGISTRY[i].id;
|
||||
engine_data[idx][1] = (char *)ENGINE_REGISTRY[i].name;
|
||||
engine_data[idx][2] = is_selected ? "checked" : "";
|
||||
engine_data[idx][3] =
|
||||
strcmp(default_engine, ENGINE_REGISTRY[i].id) == 0 ? "selected" : "";
|
||||
engine_inner[idx] = 4;
|
||||
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
TemplateContext ctx = new_context();
|
||||
beaker_set_locale(&ctx, locale);
|
||||
context_set(&ctx, "query", query);
|
||||
context_set(&ctx, "theme", theme);
|
||||
context_set(&ctx, "locale", locale);
|
||||
context_set(&ctx, "default_engine", default_engine);
|
||||
context_set_array_of_arrays(&ctx, "locales", locale_data, locale_count,
|
||||
inner_counts);
|
||||
|
||||
char **themes = NULL;
|
||||
int themes_count = 0;
|
||||
get_available_themes(&themes, &themes_count);
|
||||
|
||||
if (themes_count > 0) {
|
||||
char ***theme_ptrs = malloc(sizeof(char **) * themes_count);
|
||||
int *theme_inner = malloc(sizeof(int) * themes_count);
|
||||
for (int i = 0; i < themes_count; i++) {
|
||||
theme_ptrs[i] = malloc(sizeof(char *) * 2);
|
||||
theme_ptrs[i][0] = themes[i];
|
||||
theme_ptrs[i][1] = format_theme_name(themes[i]);
|
||||
theme_inner[i] = 2;
|
||||
}
|
||||
context_set_array_of_arrays(&ctx, "themes", theme_ptrs, themes_count,
|
||||
theme_inner);
|
||||
for (int i = 0; i < themes_count; i++) {
|
||||
free(theme_ptrs[i][1]);
|
||||
free(theme_ptrs[i]);
|
||||
}
|
||||
free(theme_ptrs);
|
||||
free(theme_inner);
|
||||
}
|
||||
|
||||
if (enabled_count > 0) {
|
||||
context_set_array_of_arrays(&ctx, "enabled_engines", engine_data,
|
||||
enabled_count, engine_inner);
|
||||
context_set(&ctx, "has_enabled_engines", "1");
|
||||
}
|
||||
|
||||
for (int i = 0; i < locale_count; i++) {
|
||||
free(locale_data[i]);
|
||||
}
|
||||
if (engine_data) {
|
||||
for (int i = 0; i < enabled_count; i++)
|
||||
free(engine_data[i]);
|
||||
free(engine_data);
|
||||
}
|
||||
free(engine_inner);
|
||||
if (has_user_pref) {
|
||||
for (int i = 0; i < user_engine_count; i++)
|
||||
free(user_engines[i]);
|
||||
free(user_engines);
|
||||
}
|
||||
|
||||
char *rendered_html = render_template("settings.html", &ctx);
|
||||
send_response(rendered_html);
|
||||
|
||||
free(rendered_html);
|
||||
free(default_engine);
|
||||
free(theme);
|
||||
free(locale);
|
||||
free_context(&ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
8
src/Routes/Settings.h
Normal file
8
src/Routes/Settings.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef SETTINGS_H
|
||||
#define SETTINGS_H
|
||||
|
||||
#include <beaker.h>
|
||||
|
||||
int settings_handler(UrlParams *params);
|
||||
|
||||
#endif
|
||||
114
src/Routes/SettingsSave.c
Normal file
114
src/Routes/SettingsSave.c
Normal file
@@ -0,0 +1,114 @@
|
||||
#include "SettingsSave.h"
|
||||
#include "../Scraping/Scraping.h"
|
||||
#include "../Utility/Utility.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_ENGINE_IDS ENGINE_COUNT
|
||||
|
||||
int settings_save_handler(UrlParams *params) {
|
||||
const char *theme = "";
|
||||
const char *locale = "";
|
||||
const char *query = "";
|
||||
const char *default_engine = "all";
|
||||
int default_engine_present = 0;
|
||||
int engines_present = 0;
|
||||
char selected_ids[ENGINE_COUNT][32];
|
||||
int selected_count = 0;
|
||||
|
||||
if (params) {
|
||||
for (int i = 0; i < params->count; i++) {
|
||||
if (strcmp(params->params[i].key, "theme") == 0) {
|
||||
theme = params->params[i].value;
|
||||
} else if (strcmp(params->params[i].key, "locale") == 0) {
|
||||
locale = params->params[i].value;
|
||||
} else if (strcmp(params->params[i].key, "q") == 0) {
|
||||
query = params->params[i].value;
|
||||
} else if (strcmp(params->params[i].key, "default_engine") == 0) {
|
||||
default_engine = params->params[i].value;
|
||||
default_engine_present = 1;
|
||||
} else if (strcmp(params->params[i].key, "engines_present") == 0) {
|
||||
engines_present = 1;
|
||||
} else if (strncmp(params->params[i].key, "engine_", 7) == 0 &&
|
||||
strcmp(params->params[i].value, "1") == 0) {
|
||||
const char *engine_id = params->params[i].key + 7;
|
||||
if (engine_id[0] != '\0' && is_engine_id_enabled(engine_id) &&
|
||||
selected_count < ENGINE_COUNT) {
|
||||
strncpy(selected_ids[selected_count], engine_id,
|
||||
sizeof(selected_ids[selected_count]) - 1);
|
||||
selected_ids[selected_count]
|
||||
[sizeof(selected_ids[selected_count]) - 1] = '\0';
|
||||
selected_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(theme) > 0) {
|
||||
set_cookie("theme", theme, "Fri, 31 Dec 2038 23:59:59 GMT", "/", false,
|
||||
false);
|
||||
}
|
||||
if (strlen(locale) > 0) {
|
||||
set_cookie("locale", locale, "Fri, 31 Dec 2038 23:59:59 GMT", "/", false,
|
||||
false);
|
||||
}
|
||||
|
||||
if (engines_present) {
|
||||
char cookie_value[512];
|
||||
cookie_value[0] = '\0';
|
||||
size_t used = 0;
|
||||
cookie_value[0] = '\0';
|
||||
for (int i = 0; i < selected_count; i++) {
|
||||
const char *id = selected_ids[i];
|
||||
size_t idlen = strlen(id);
|
||||
if (i > 0) {
|
||||
if (used + 1 < sizeof(cookie_value)) {
|
||||
cookie_value[used++] = '+';
|
||||
cookie_value[used] = '\0';
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (used + idlen < sizeof(cookie_value)) {
|
||||
memcpy(cookie_value + used, id, idlen);
|
||||
used += idlen;
|
||||
cookie_value[used] = '\0';
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
set_cookie("engines", cookie_value, "Fri, 31 Dec 2038 23:59:59 GMT", "/",
|
||||
false, false);
|
||||
}
|
||||
|
||||
if (default_engine_present) {
|
||||
const char *validated_default = "all";
|
||||
|
||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||
if (!ENGINE_REGISTRY[i].enabled ||
|
||||
strcmp(default_engine, ENGINE_REGISTRY[i].id) != 0)
|
||||
continue;
|
||||
|
||||
int selected = !engines_present;
|
||||
for (int j = 0; j < selected_count; j++) {
|
||||
if (strcmp(selected_ids[j], ENGINE_REGISTRY[i].id) == 0) {
|
||||
selected = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (selected)
|
||||
validated_default = ENGINE_REGISTRY[i].id;
|
||||
break;
|
||||
}
|
||||
|
||||
set_cookie("default_engine", validated_default,
|
||||
"Fri, 31 Dec 2038 23:59:59 GMT", "/", false, false);
|
||||
}
|
||||
|
||||
char redirect_url[512];
|
||||
snprintf(redirect_url, sizeof(redirect_url), "/settings?q=%s", query);
|
||||
send_redirect(redirect_url);
|
||||
|
||||
return 0;
|
||||
}
|
||||
8
src/Routes/SettingsSave.h
Normal file
8
src/Routes/SettingsSave.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef SETTINGS_SAVE_H
|
||||
#define SETTINGS_SAVE_H
|
||||
|
||||
#include <beaker.h>
|
||||
|
||||
int settings_save_handler(UrlParams *params);
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "ImageScraping.h"
|
||||
#include "../Utility/HttpClient.h"
|
||||
#include "../Utility/Unescape.h"
|
||||
#include "Config.h"
|
||||
#include <libxml/HTMLparser.h>
|
||||
#include <libxml/xpath.h>
|
||||
@@ -28,113 +29,61 @@ static char *build_proxy_url(const char *image_url) {
|
||||
return proxy_url;
|
||||
}
|
||||
|
||||
static int parse_image_node(xmlNodePtr node, ImageResult *result) {
|
||||
xmlNodePtr img_node = NULL;
|
||||
xmlNodePtr tit_node = NULL;
|
||||
xmlNodePtr des_node = NULL;
|
||||
xmlNodePtr thumb_link = NULL;
|
||||
static char *extract_json_string(const char *json, const char *key) {
|
||||
if (!json || !key) return NULL;
|
||||
|
||||
for (xmlNodePtr child = node->children; child; child = child->next) {
|
||||
if (child->type != XML_ELEMENT_NODE)
|
||||
continue;
|
||||
char search_key[64];
|
||||
snprintf(search_key, sizeof(search_key), "\"%s\"", key);
|
||||
|
||||
if (xmlStrcmp(child->name, (const xmlChar *)"a") == 0) {
|
||||
xmlChar *class = xmlGetProp(child, (const xmlChar *)"class");
|
||||
if (class) {
|
||||
if (xmlStrstr(class, (const xmlChar *)"thumb") != NULL) {
|
||||
thumb_link = child;
|
||||
for (xmlNodePtr thumb_child = child->children; thumb_child;
|
||||
thumb_child = thumb_child->next) {
|
||||
if (xmlStrcmp(thumb_child->name, (const xmlChar *)"div") == 0) {
|
||||
xmlChar *div_class =
|
||||
xmlGetProp(thumb_child, (const xmlChar *)"class");
|
||||
if (div_class &&
|
||||
xmlStrcmp(div_class, (const xmlChar *)"cico") == 0) {
|
||||
for (xmlNodePtr cico_child = thumb_child->children; cico_child;
|
||||
cico_child = cico_child->next) {
|
||||
if (xmlStrcmp(cico_child->name, (const xmlChar *)"img") ==
|
||||
0) {
|
||||
img_node = cico_child;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (div_class)
|
||||
xmlFree(div_class);
|
||||
}
|
||||
}
|
||||
} else if (xmlStrstr(class, (const xmlChar *)"tit") != NULL) {
|
||||
tit_node = child;
|
||||
}
|
||||
xmlFree(class);
|
||||
}
|
||||
} else if (xmlStrcmp(child->name, (const xmlChar *)"div") == 0) {
|
||||
xmlChar *class = xmlGetProp(child, (const xmlChar *)"class");
|
||||
if (class && xmlStrcmp(class, (const xmlChar *)"meta") == 0) {
|
||||
for (xmlNodePtr meta_child = child->children; meta_child;
|
||||
meta_child = meta_child->next) {
|
||||
if (xmlStrcmp(meta_child->name, (const xmlChar *)"div") == 0) {
|
||||
xmlChar *div_class =
|
||||
xmlGetProp(meta_child, (const xmlChar *)"class");
|
||||
if (div_class) {
|
||||
if (xmlStrcmp(div_class, (const xmlChar *)"des") == 0) {
|
||||
des_node = meta_child;
|
||||
}
|
||||
xmlFree(div_class);
|
||||
}
|
||||
} else if (xmlStrcmp(meta_child->name, (const xmlChar *)"a") == 0) {
|
||||
xmlChar *a_class = xmlGetProp(meta_child, (const xmlChar *)"class");
|
||||
if (a_class && xmlStrstr(a_class, (const xmlChar *)"tit") != NULL) {
|
||||
tit_node = meta_child;
|
||||
}
|
||||
if (a_class)
|
||||
xmlFree(a_class);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (class)
|
||||
xmlFree(class);
|
||||
const char *key_pos = strstr(json, search_key);
|
||||
if (!key_pos) return NULL;
|
||||
|
||||
const char *colon = strchr(key_pos + strlen(search_key), ':');
|
||||
if (!colon) return NULL;
|
||||
|
||||
colon++;
|
||||
while (*colon == ' ' || *colon == '\t' || *colon == '\n' || *colon == '\r') colon++;
|
||||
if (*colon != '"') return NULL;
|
||||
colon++;
|
||||
|
||||
const char *end = colon;
|
||||
while (*end && *end != '"') {
|
||||
if (*end == '\\' && end[1]) end += 2;
|
||||
else end += 1;
|
||||
}
|
||||
if (*end != '"') return NULL;
|
||||
|
||||
return json_string_unescape(colon, end);
|
||||
}
|
||||
|
||||
xmlChar *iurl =
|
||||
img_node ? xmlGetProp(img_node, (const xmlChar *)"src") : NULL;
|
||||
xmlChar *full_url =
|
||||
thumb_link ? xmlGetProp(thumb_link, (const xmlChar *)"href") : NULL;
|
||||
xmlChar *title = des_node ? xmlNodeGetContent(des_node)
|
||||
: (tit_node ? xmlNodeGetContent(tit_node) : NULL);
|
||||
xmlChar *rurl =
|
||||
tit_node ? xmlGetProp(tit_node, (const xmlChar *)"href") : NULL;
|
||||
|
||||
if (!iurl || strlen((char *)iurl) == 0) {
|
||||
if (iurl)
|
||||
xmlFree(iurl);
|
||||
if (title)
|
||||
xmlFree(title);
|
||||
if (rurl)
|
||||
xmlFree(rurl);
|
||||
if (full_url)
|
||||
xmlFree(full_url);
|
||||
static int parse_iusc_node(xmlNodePtr node, ImageResult *result) {
|
||||
xmlChar *m_attr = xmlGetProp(node, (const xmlChar *)"m");
|
||||
if (!m_attr)
|
||||
return 0;
|
||||
|
||||
char *turl = extract_json_string((const char *)m_attr, "turl");
|
||||
char *murl = extract_json_string((const char *)m_attr, "murl");
|
||||
char *purl = extract_json_string((const char *)m_attr, "purl");
|
||||
char *title = extract_json_string((const char *)m_attr, "t");
|
||||
|
||||
int ok = (turl != NULL && strlen(turl) > 0);
|
||||
if (ok) {
|
||||
char *proxy_url = build_proxy_url(turl);
|
||||
result->thumbnail_url = proxy_url ? strdup(proxy_url) : strdup(turl);
|
||||
free(proxy_url);
|
||||
result->title =
|
||||
title && strlen(title) > 0 ? strdup(title) : strdup("Image");
|
||||
result->page_url = purl && strlen(purl) > 0 ? strdup(purl) : strdup("#");
|
||||
result->full_url = murl && strlen(murl) > 0 ? strdup(murl) : strdup("#");
|
||||
}
|
||||
|
||||
char *proxy_url = build_proxy_url((char *)iurl);
|
||||
result->thumbnail_url = proxy_url ? strdup(proxy_url) : strdup((char *)iurl);
|
||||
free(proxy_url);
|
||||
result->title = strdup(title ? (char *)title : "Image");
|
||||
result->page_url = strdup(rurl ? (char *)rurl : "#");
|
||||
result->full_url = strdup(full_url ? (char *)full_url : "#");
|
||||
free(turl);
|
||||
free(murl);
|
||||
free(purl);
|
||||
free(title);
|
||||
|
||||
if (iurl)
|
||||
xmlFree(iurl);
|
||||
if (title)
|
||||
xmlFree(title);
|
||||
if (rurl)
|
||||
xmlFree(rurl);
|
||||
if (full_url)
|
||||
xmlFree(full_url);
|
||||
|
||||
return 1;
|
||||
xmlFree(m_attr);
|
||||
return ok;
|
||||
}
|
||||
|
||||
int scrape_images(const char *query, int page, ImageResult **out_results,
|
||||
@@ -157,18 +106,21 @@ int scrape_images(const char *query, int page, ImageResult **out_results,
|
||||
|
||||
char url[BUFFER_SIZE_LARGE];
|
||||
int first = (page - 1) * IMAGE_RESULTS_PER_PAGE + 1;
|
||||
snprintf(url, sizeof(url), "%s?q=%s&first=%d", BING_IMAGE_URL, encoded_query,
|
||||
first);
|
||||
snprintf(
|
||||
url, sizeof(url),
|
||||
"https://www.bing.com/images/async?q=%s&async=content&first=%d&count=%d",
|
||||
encoded_query, first, 35);
|
||||
free(encoded_query);
|
||||
|
||||
HttpResponse resp = http_get(
|
||||
url,
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko");
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, "
|
||||
"like Gecko) Chrome/120.0.0.0 Safari/537.36");
|
||||
if (!resp.memory) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
htmlDocPtr doc = htmlReadMemory(resp.memory, resp.size, NULL, NULL,
|
||||
htmlDocPtr doc = htmlReadMemory(resp.memory, resp.size, NULL, "UTF-8",
|
||||
HTML_PARSE_RECOVER | HTML_PARSE_NOERROR);
|
||||
if (!doc) {
|
||||
http_response_free(&resp);
|
||||
@@ -183,7 +135,7 @@ int scrape_images(const char *query, int page, ImageResult **out_results,
|
||||
}
|
||||
|
||||
xmlXPathObjectPtr xpathObj =
|
||||
xmlXPathEvalExpression((const xmlChar *)"//div[@class='item']", xpathCtx);
|
||||
xmlXPathEvalExpression((const xmlChar *)"//a[@class='iusc']", xpathCtx);
|
||||
|
||||
if (!xpathObj || !xpathObj->nodesetval) {
|
||||
if (xpathObj)
|
||||
@@ -210,7 +162,7 @@ int scrape_images(const char *query, int page, ImageResult **out_results,
|
||||
int count = 0;
|
||||
for (int i = 0; i < nodes && count < IMAGE_RESULTS_PER_PAGE; i++) {
|
||||
xmlNodePtr node = xpathObj->nodesetval->nodeTab[i];
|
||||
if (parse_image_node(node, &results[count])) {
|
||||
if (parse_iusc_node(node, &results[count])) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include "Scraping.h"
|
||||
#include "../Cache/Cache.h"
|
||||
#include "../Proxy/Proxy.h"
|
||||
#include "../Utility/XmlHelper.h"
|
||||
#include "Config.h"
|
||||
#include <curl/curl.h>
|
||||
#include <libxml/HTMLparser.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -13,6 +15,79 @@ static int response_contains(const char *response, const char *needle) {
|
||||
return response && needle && strstr(response, needle) != NULL;
|
||||
}
|
||||
|
||||
static int is_ddg_job(const ScrapeJob *job) {
|
||||
return job && job->engine && job->engine->id &&
|
||||
strcmp(job->engine->id, "ddg") == 0;
|
||||
}
|
||||
|
||||
static char *job_cache_key(const ScrapeJob *job, int page) {
|
||||
const char *scope = is_ddg_job(job) ? "ddg_pagination_v2" : job->engine->name;
|
||||
return cache_compute_key(job->query, page, scope);
|
||||
}
|
||||
|
||||
static char *ddg_request_data(ScrapeJob *job, const char *encoded_query) {
|
||||
job->current_page = 1;
|
||||
if (job->page > 1 && get_cache_ttl_search() > 0) {
|
||||
char *key = job_cache_key(job, job->page - 1);
|
||||
char *cached = NULL;
|
||||
size_t size = 0;
|
||||
char *data = NULL;
|
||||
if (key && cache_get(key, get_cache_ttl_search(), &cached, &size) == 0)
|
||||
data = build_ddg_next_page_data(cached, size);
|
||||
free(cached);
|
||||
free(key);
|
||||
if (data) {
|
||||
job->current_page = job->page;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
size_t size = strlen(encoded_query) + sizeof("q=&b=");
|
||||
char *data = malloc(size);
|
||||
if (data)
|
||||
snprintf(data, size, "q=%s&b=", encoded_query);
|
||||
return data;
|
||||
}
|
||||
|
||||
static int configure_ddg_request(ScrapeJob *job, char *url,
|
||||
const char *encoded_query) {
|
||||
char *data = ddg_request_data(job, encoded_query);
|
||||
if (!data)
|
||||
return -1;
|
||||
|
||||
char *query_start = strchr(url, '?');
|
||||
if (query_start)
|
||||
*query_start = '\0';
|
||||
|
||||
curl_easy_setopt(job->handle, CURLOPT_URL, url);
|
||||
curl_easy_setopt(job->handle, CURLOPT_USERAGENT, get_first_user_agent());
|
||||
CURLcode code = curl_easy_setopt(job->handle, CURLOPT_COPYPOSTFIELDS, data);
|
||||
free(data);
|
||||
return code == CURLE_OK ? 0 : -1;
|
||||
}
|
||||
|
||||
static int configure_job_request(ScrapeJob *job, char *url,
|
||||
const char *encoded_query) {
|
||||
job->handle = curl_easy_init();
|
||||
if (!job->handle)
|
||||
return -1;
|
||||
|
||||
job->response.memory = (char *)malloc(INITIAL_BUFFER_SIZE);
|
||||
job->response.size = 0;
|
||||
job->response.capacity = INITIAL_BUFFER_SIZE;
|
||||
if (!job->response.memory)
|
||||
return -1;
|
||||
|
||||
struct curl_slist *headers =
|
||||
build_request_headers(job->engine->host_header, job->engine->referer);
|
||||
|
||||
configure_curl_handle(job->handle, url, &job->response, headers);
|
||||
curl_easy_setopt(job->handle, CURLOPT_PRIVATE, headers);
|
||||
if (is_ddg_job(job))
|
||||
return configure_ddg_request(job, url, encoded_query);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int is_startpage_job(const ScrapeJob *job) {
|
||||
return job && job->engine && strcmp(job->engine->name, "Startpage") == 0;
|
||||
}
|
||||
@@ -24,7 +99,9 @@ static int response_is_startpage_captcha(const ScrapeJob *job,
|
||||
|
||||
return response_contains(response, "<title>Startpage Captcha</title>") ||
|
||||
response_contains(response, "Startpage Captcha") ||
|
||||
response_contains(response, "/static-pages-assets/page-data/captcha/");
|
||||
response_contains(response,
|
||||
"/static-pages-assets/page-data/captcha/") ||
|
||||
response_contains(response, ">Startpage Blocked</title>");
|
||||
}
|
||||
|
||||
static int response_looks_like_results_page(const ScrapeJob *job,
|
||||
@@ -38,7 +115,8 @@ static int response_looks_like_results_page(const ScrapeJob *job,
|
||||
}
|
||||
|
||||
if (strcmp(job->engine->name, "Startpage") == 0) {
|
||||
return response_contains(response, "<title>Startpage Search Results</title>") ||
|
||||
return response_contains(response,
|
||||
"<title>Startpage Search Results</title>") ||
|
||||
response_contains(response, "class=\"w-gl") ||
|
||||
response_contains(response, "data-testid=\"gl-title-link\"");
|
||||
}
|
||||
@@ -54,6 +132,11 @@ static int response_looks_like_results_page(const ScrapeJob *job,
|
||||
response_contains(response, "Mojeek Search");
|
||||
}
|
||||
|
||||
if (strcmp(job->engine->name, "YaCy") == 0) {
|
||||
return response_contains(response, "<item") ||
|
||||
response_contains(response, "<rss");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -66,23 +149,30 @@ static void classify_job_response(ScrapeJob *job, const char *response,
|
||||
return;
|
||||
}
|
||||
|
||||
if (response_is_startpage_captcha(job, response)) {
|
||||
if (response_is_startpage_captcha(job, response) ||
|
||||
(is_ddg_job(job) && response_contains(response, "id=\"challenge-form\""))) {
|
||||
job->status = SCRAPE_STATUS_BLOCKED;
|
||||
return;
|
||||
}
|
||||
|
||||
xmlDocPtr doc = htmlReadMemory(response, response_size, NULL, NULL,
|
||||
xmlDocPtr doc;
|
||||
if (job->engine->is_xml) {
|
||||
doc = xmlReadMemory(response, response_size, NULL, NULL,
|
||||
XML_PARSE_RECOVER | XML_PARSE_NOERROR |
|
||||
XML_PARSE_NOWARNING);
|
||||
} else {
|
||||
doc = htmlReadMemory(response, response_size, NULL, NULL,
|
||||
HTML_PARSE_RECOVER | HTML_PARSE_NOERROR |
|
||||
HTML_PARSE_NOWARNING);
|
||||
}
|
||||
|
||||
if (!doc) {
|
||||
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
job->results_count =
|
||||
job->engine->parser(job->engine->name, doc, job->out_results,
|
||||
job->max_results);
|
||||
job->results_count = job->engine->parser(job->engine->name, doc,
|
||||
job->out_results, job->max_results);
|
||||
xmlFreeDoc(doc);
|
||||
|
||||
if (job->results_count > 0) {
|
||||
@@ -107,7 +197,7 @@ int check_cache_for_job(ScrapeJob *job) {
|
||||
if (get_cache_ttl_search() <= 0)
|
||||
return 0;
|
||||
|
||||
char *key = cache_compute_key(job->query, job->page, job->engine->name);
|
||||
char *key = job_cache_key(job, job->page);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
@@ -148,50 +238,86 @@ void parse_and_cache_response(ScrapeJob *job) {
|
||||
classify_job_response(job, job->response.memory, job->response.size);
|
||||
|
||||
if (job->status == SCRAPE_STATUS_OK || job->status == SCRAPE_STATUS_EMPTY) {
|
||||
char *key = cache_compute_key(job->query, job->page, job->engine->name);
|
||||
char *key = job_cache_key(job, job->current_page);
|
||||
if (key && get_cache_ttl_search() > 0)
|
||||
cache_set(key, job->response.memory, job->response.size);
|
||||
free(key);
|
||||
}
|
||||
}
|
||||
|
||||
void cleanup_job_handle(ScrapeJob *job, CURL *handle) {
|
||||
static void cleanup_job_results(ScrapeJob *job) {
|
||||
if (!job || !job->out_results)
|
||||
return;
|
||||
|
||||
xml_result_free(*job->out_results, job->results_count);
|
||||
*job->out_results = NULL;
|
||||
job->results_count = 0;
|
||||
}
|
||||
|
||||
static void cleanup_job_handle(ScrapeJob *job, CURL *handle) {
|
||||
struct curl_slist *headers = NULL;
|
||||
if (handle)
|
||||
curl_easy_getinfo(handle, CURLINFO_PRIVATE, &headers);
|
||||
if (headers)
|
||||
curl_slist_free_all(headers);
|
||||
|
||||
free(job->response.memory);
|
||||
job->response.memory = NULL;
|
||||
job->response.size = 0;
|
||||
job->response.capacity = 0;
|
||||
}
|
||||
|
||||
void process_response(ScrapeJob *job, CURL *handle, CURLMsg *msg) {
|
||||
static int process_response(ScrapeJob *job, CURL *handle, CURLcode result) {
|
||||
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &job->http_status);
|
||||
|
||||
if (msg->data.result == CURLE_OK)
|
||||
if (result == CURLE_OK)
|
||||
parse_and_cache_response(job);
|
||||
else {
|
||||
job->results_count = 0;
|
||||
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
||||
}
|
||||
|
||||
if (is_ddg_job(job) && job->current_page < job->page &&
|
||||
(job->status == SCRAPE_STATUS_OK || job->status == SCRAPE_STATUS_EMPTY)) {
|
||||
char *data = build_ddg_next_page_data(job->response.memory,
|
||||
job->response.size);
|
||||
cleanup_job_results(job);
|
||||
if (data) {
|
||||
CURLcode code = curl_easy_setopt(handle, CURLOPT_COPYPOSTFIELDS, data);
|
||||
free(data);
|
||||
if (code == CURLE_OK) {
|
||||
job->current_page++;
|
||||
job->response.size = 0;
|
||||
job->response.memory[0] = '\0';
|
||||
job->http_status = 0;
|
||||
job->status = SCRAPE_STATUS_PENDING;
|
||||
return 1;
|
||||
}
|
||||
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
||||
} else {
|
||||
job->status = SCRAPE_STATUS_EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup_job_handle(job, handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setup_job(ScrapeJob *job, CURLM *multi_handle) {
|
||||
cleanup_job_handle(job, job->handle);
|
||||
if (job->handle)
|
||||
curl_easy_cleanup(job->handle);
|
||||
if (job->response.memory)
|
||||
free(job->response.memory);
|
||||
job->handle = NULL;
|
||||
|
||||
job->results_count = 0;
|
||||
cleanup_job_results(job);
|
||||
job->http_status = 0;
|
||||
job->status = SCRAPE_STATUS_PENDING;
|
||||
job->current_page = job->page;
|
||||
|
||||
if (check_cache_for_job(job)) {
|
||||
job->results_count = job->results_count > 0 ? job->results_count : 0;
|
||||
if (check_cache_for_job(job))
|
||||
return 0;
|
||||
}
|
||||
|
||||
cleanup_job_results(job);
|
||||
|
||||
char *encoded_query = curl_easy_escape(NULL, job->query, 0);
|
||||
if (!encoded_query) {
|
||||
@@ -199,44 +325,52 @@ int setup_job(ScrapeJob *job, CURLM *multi_handle) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (char *p = encoded_query + strlen(encoded_query) - 3; p >= encoded_query; p--) {
|
||||
if (p[0] == '%' && p[1] == '2' && p[2] == '0') {
|
||||
*p = '+';
|
||||
memmove(p + 1, p + 3, strlen(p + 3) + 1);
|
||||
char *read = encoded_query;
|
||||
char *write = encoded_query;
|
||||
while (*read) {
|
||||
if (read[0] == '%' && read[1] == '2' && read[2] == '0') {
|
||||
*write++ = '+';
|
||||
read += 3;
|
||||
} else {
|
||||
*write++ = *read++;
|
||||
}
|
||||
}
|
||||
*write = '\0';
|
||||
|
||||
char *full_url =
|
||||
build_search_url(job->engine->base_url, job->engine->page_param,
|
||||
job->engine->page_multiplier, job->engine->page_base,
|
||||
encoded_query, job->page);
|
||||
free(encoded_query);
|
||||
|
||||
if (!full_url) {
|
||||
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
job->handle = curl_easy_init();
|
||||
if (!job->handle) {
|
||||
free(full_url);
|
||||
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
job->response.memory = (char *)malloc(INITIAL_BUFFER_SIZE);
|
||||
job->response.size = 0;
|
||||
job->response.capacity = INITIAL_BUFFER_SIZE;
|
||||
|
||||
struct curl_slist *headers =
|
||||
build_request_headers(job->engine->host_header, job->engine->referer);
|
||||
|
||||
configure_curl_handle(job->handle, full_url, &job->response, headers);
|
||||
curl_easy_setopt(job->handle, CURLOPT_PRIVATE, headers);
|
||||
int ready = full_url &&
|
||||
configure_job_request(job, full_url, encoded_query) == 0;
|
||||
|
||||
free(full_url);
|
||||
curl_multi_add_handle(multi_handle, job->handle);
|
||||
curl_free(encoded_query);
|
||||
if (ready && curl_multi_add_handle(multi_handle, job->handle) == CURLM_OK)
|
||||
return 0;
|
||||
|
||||
cleanup_job_handle(job, job->handle);
|
||||
if (job->handle)
|
||||
curl_easy_cleanup(job->handle);
|
||||
job->handle = NULL;
|
||||
job->status = SCRAPE_STATUS_FETCH_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void cleanup_unfinished_jobs(CURLM *multi_handle, ScrapeJob *jobs,
|
||||
int num_jobs) {
|
||||
for (int i = 0; i < num_jobs; i++) {
|
||||
if (!jobs[i].handle)
|
||||
continue;
|
||||
|
||||
curl_multi_remove_handle(multi_handle, jobs[i].handle);
|
||||
cleanup_job_handle(&jobs[i], jobs[i].handle);
|
||||
curl_easy_cleanup(jobs[i].handle);
|
||||
jobs[i].handle = NULL;
|
||||
|
||||
if (jobs[i].status == SCRAPE_STATUS_PENDING)
|
||||
jobs[i].status = SCRAPE_STATUS_FETCH_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
int handle_responses(CURLM *multi_handle, ScrapeJob *jobs, int num_jobs) {
|
||||
@@ -251,8 +385,14 @@ int handle_responses(CURLM *multi_handle, ScrapeJob *jobs, int num_jobs) {
|
||||
|
||||
for (int i = 0; i < num_jobs; i++) {
|
||||
if (jobs[i].handle && jobs[i].handle == handle) {
|
||||
process_response(&jobs[i], handle, msg);
|
||||
CURLcode result = msg->data.result;
|
||||
curl_multi_remove_handle(multi_handle, handle);
|
||||
if (process_response(&jobs[i], handle, result)) {
|
||||
if (curl_multi_add_handle(multi_handle, handle) == CURLM_OK)
|
||||
break;
|
||||
jobs[i].status = SCRAPE_STATUS_FETCH_ERROR;
|
||||
cleanup_job_handle(&jobs[i], handle);
|
||||
}
|
||||
curl_easy_cleanup(handle);
|
||||
jobs[i].handle = NULL;
|
||||
break;
|
||||
@@ -278,34 +418,37 @@ int should_retry(ScrapeJob *jobs, int num_jobs) {
|
||||
int scrape_engines_parallel(ScrapeJob *jobs, int num_jobs) {
|
||||
int retries = 0;
|
||||
|
||||
retry:
|
||||
;
|
||||
retry:;
|
||||
CURLM *multi_handle = curl_multi_init();
|
||||
if (!multi_handle)
|
||||
return -1;
|
||||
|
||||
for (int i = 0; i < num_jobs; i++) {
|
||||
if (setup_job(&jobs[i], multi_handle) != 0 && jobs[i].handle) {
|
||||
curl_multi_remove_handle(multi_handle, jobs[i].handle);
|
||||
curl_easy_cleanup(jobs[i].handle);
|
||||
jobs[i].handle = NULL;
|
||||
}
|
||||
setup_job(&jobs[i], multi_handle);
|
||||
}
|
||||
|
||||
http_delay();
|
||||
|
||||
while (1) {
|
||||
int still_running = 0;
|
||||
curl_multi_perform(multi_handle, &still_running);
|
||||
|
||||
do {
|
||||
int numfds = 0;
|
||||
CURLMcode mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
|
||||
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
|
||||
handle_responses(multi_handle, jobs, num_jobs);
|
||||
if (mc != CURLM_OK)
|
||||
break;
|
||||
curl_multi_perform(multi_handle, &still_running);
|
||||
} while (still_running);
|
||||
|
||||
handle_responses(multi_handle, jobs, num_jobs);
|
||||
int active = 0;
|
||||
for (int i = 0; i < num_jobs; i++)
|
||||
active += jobs[i].handle != NULL;
|
||||
if (!active)
|
||||
break;
|
||||
|
||||
int numfds = 0;
|
||||
mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
|
||||
if (mc != CURLM_OK)
|
||||
break;
|
||||
}
|
||||
|
||||
cleanup_unfinished_jobs(multi_handle, jobs, num_jobs);
|
||||
curl_multi_cleanup(multi_handle);
|
||||
|
||||
if (retries < max_proxy_retries && should_retry(jobs, num_jobs)) {
|
||||
|
||||
@@ -26,6 +26,7 @@ typedef struct {
|
||||
int page_base;
|
||||
ParserFunc parser;
|
||||
int enabled;
|
||||
int is_xml;
|
||||
} SearchEngine;
|
||||
|
||||
typedef struct {
|
||||
@@ -49,6 +50,7 @@ typedef struct {
|
||||
SearchResult **out_results;
|
||||
int max_results;
|
||||
int page;
|
||||
int current_page;
|
||||
CURL *handle;
|
||||
MemoryBuffer response;
|
||||
int results_count;
|
||||
@@ -59,15 +61,18 @@ typedef struct {
|
||||
extern SearchEngine ENGINE_REGISTRY[];
|
||||
extern const int ENGINE_COUNT;
|
||||
void apply_engines_config(const char *engines_str);
|
||||
void configure_yacy_engine(const char *instance);
|
||||
|
||||
size_t write_memory_callback(void *contents, size_t size, size_t nmemb,
|
||||
void *userp);
|
||||
const char *get_random_user_agent(void);
|
||||
const char *get_first_user_agent(void);
|
||||
void configure_curl_handle(CURL *curl, const char *full_url,
|
||||
MemoryBuffer *chunk, struct curl_slist *headers);
|
||||
char *build_search_url(const char *base_url, const char *page_param,
|
||||
int page_multiplier, int page_base,
|
||||
const char *encoded_query, int page);
|
||||
char *build_ddg_next_page_data(const char *html, size_t size);
|
||||
struct curl_slist *build_request_headers(const char *host_header,
|
||||
const char *referer);
|
||||
void http_delay(void);
|
||||
|
||||
@@ -53,6 +53,8 @@ const char *get_random_user_agent(void) {
|
||||
return USER_AGENTS[rand() % USER_AGENT_COUNT];
|
||||
}
|
||||
|
||||
const char *get_first_user_agent(void) { return USER_AGENTS[0]; }
|
||||
|
||||
void configure_curl_handle(CURL *curl, const char *full_url,
|
||||
MemoryBuffer *chunk, struct curl_slist *headers) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, full_url);
|
||||
@@ -75,25 +77,92 @@ void configure_curl_handle(CURL *curl, const char *full_url,
|
||||
char *build_search_url(const char *base_url, const char *page_param,
|
||||
int page_multiplier, int page_base,
|
||||
const char *encoded_query, int page) {
|
||||
int page_value = (page < 1 ? 1 : page - 1) * page_multiplier + page_base;
|
||||
long long page_value =
|
||||
(long long)(page > 1 ? page - 1 : 0) * page_multiplier + page_base;
|
||||
char *url = malloc(BUFFER_SIZE_LARGE);
|
||||
if (!url)
|
||||
return NULL;
|
||||
snprintf(url, BUFFER_SIZE_LARGE, "%s%s&%s=%d", base_url, encoded_query,
|
||||
snprintf(url, BUFFER_SIZE_LARGE, "%s%s&%s=%lld", base_url, encoded_query,
|
||||
page_param, page_value);
|
||||
return url;
|
||||
}
|
||||
|
||||
char *build_ddg_next_page_data(const char *html, size_t size) {
|
||||
htmlDocPtr doc = htmlReadMemory(html, size, NULL, NULL,
|
||||
HTML_PARSE_RECOVER | HTML_PARSE_NOERROR |
|
||||
HTML_PARSE_NOWARNING);
|
||||
if (!doc)
|
||||
return NULL;
|
||||
|
||||
xmlXPathContextPtr ctx = create_xpath_context(doc);
|
||||
if (!ctx) {
|
||||
xmlFreeDoc(doc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xmlXPathObjectPtr inputs = xmlXPathEvalExpression(
|
||||
(const xmlChar *)"(//form[.//input[@name='s'] and "
|
||||
".//input[@name='vqd' and string-length(@value)>0] and "
|
||||
"(.//input[@type='submit' and contains(@value, 'Next')] or "
|
||||
".//button[contains(., 'Next')])])[1]"
|
||||
"//input[@name and not(@disabled) and "
|
||||
"(not(@type) or @type='hidden')]",
|
||||
ctx);
|
||||
|
||||
if (!inputs || !inputs->nodesetval) {
|
||||
free_xpath_objects(ctx, inputs);
|
||||
xmlFreeDoc(doc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *data = NULL;
|
||||
size_t length = 0;
|
||||
int failed = 0;
|
||||
for (int i = 0; i < inputs->nodesetval->nodeNr; i++) {
|
||||
xmlNodePtr node = inputs->nodesetval->nodeTab[i];
|
||||
xmlChar *name = xmlGetProp(node, (const xmlChar *)"name");
|
||||
xmlChar *value = xmlGetProp(node, (const xmlChar *)"value");
|
||||
char *key = curl_easy_escape(NULL, (const char *)name, 0);
|
||||
char *val = curl_easy_escape(NULL, value ? (const char *)value : "", 0);
|
||||
size_t needed = key && val ? strlen(key) + strlen(val) + 2 : 0;
|
||||
char *expanded = needed ? realloc(data, length + needed + 1) : NULL;
|
||||
if (expanded) {
|
||||
data = expanded;
|
||||
length += snprintf(data + length, needed + 1, "%s%s=%s",
|
||||
length ? "&" : "", key, val);
|
||||
} else {
|
||||
failed = 1;
|
||||
}
|
||||
curl_free(key);
|
||||
curl_free(val);
|
||||
xmlFree(name);
|
||||
xmlFree(value);
|
||||
if (failed)
|
||||
break;
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
free(data);
|
||||
data = NULL;
|
||||
}
|
||||
free_xpath_objects(ctx, inputs);
|
||||
xmlFreeDoc(doc);
|
||||
return data;
|
||||
}
|
||||
|
||||
struct curl_slist *build_request_headers(const char *host_header,
|
||||
const char *referer) {
|
||||
struct curl_slist *headers = NULL;
|
||||
char host_buf[BUFFER_SIZE_MEDIUM], ref_buf[BUFFER_SIZE_MEDIUM];
|
||||
|
||||
if (host_header && host_header[0] != '\0') {
|
||||
snprintf(host_buf, sizeof(host_buf), "Host: %s", host_header);
|
||||
snprintf(ref_buf, sizeof(ref_buf), "Referer: %s", referer);
|
||||
|
||||
headers = curl_slist_append(headers, host_buf);
|
||||
}
|
||||
if (referer && referer[0] != '\0') {
|
||||
snprintf(ref_buf, sizeof(ref_buf), "Referer: %s", referer);
|
||||
headers = curl_slist_append(headers, ref_buf);
|
||||
}
|
||||
headers = curl_slist_append(
|
||||
headers,
|
||||
"Accept: "
|
||||
|
||||
@@ -249,8 +249,8 @@ static int parse_mojeek(const char *engine_name, xmlDocPtr doc,
|
||||
if (!ctx)
|
||||
return 0;
|
||||
|
||||
xmlXPathObjectPtr obj =
|
||||
xml_xpath_eval(ctx, "//ul[@class='results-standard']/li[starts-with(@class, 'r')]");
|
||||
xmlXPathObjectPtr obj = xml_xpath_eval(
|
||||
ctx, "//ul[@class='results-standard']/li[starts-with(@class, 'r')]");
|
||||
|
||||
if (!obj || !obj->nodesetval || obj->nodesetval->nodeNr == 0) {
|
||||
free_xpath_objects(ctx, obj);
|
||||
@@ -268,16 +268,15 @@ static int parse_mojeek(const char *engine_name, xmlDocPtr doc,
|
||||
xmlNodePtr result_node = obj->nodesetval->nodeTab[i];
|
||||
ctx->node = result_node;
|
||||
|
||||
xmlXPathObjectPtr link_obj =
|
||||
xml_xpath_eval(ctx, ".//a[@class='title']");
|
||||
xmlXPathObjectPtr link_obj = xml_xpath_eval(ctx, ".//a[@class='title']");
|
||||
char *url =
|
||||
(link_obj && link_obj->nodesetval && link_obj->nodesetval->nodeNr > 0)
|
||||
? (char *)xmlGetProp(link_obj->nodesetval->nodeTab[0],
|
||||
(xmlChar *)"href")
|
||||
: NULL;
|
||||
|
||||
char *title = (link_obj && link_obj->nodesetval &&
|
||||
link_obj->nodesetval->nodeNr > 0)
|
||||
char *title =
|
||||
(link_obj && link_obj->nodesetval && link_obj->nodesetval->nodeNr > 0)
|
||||
? xml_node_content(link_obj->nodesetval->nodeTab[0])
|
||||
: NULL;
|
||||
|
||||
@@ -310,6 +309,90 @@ static int parse_yahoo(const char *engine_name, xmlDocPtr doc,
|
||||
static int parse_mojeek(const char *engine_name, xmlDocPtr doc,
|
||||
SearchResult **out_results, int max_results);
|
||||
|
||||
static int parse_yacy(const char *engine_name, xmlDocPtr doc,
|
||||
SearchResult **out_results, int max_results) {
|
||||
(void)engine_name;
|
||||
int found_count = 0;
|
||||
|
||||
xmlXPathContextPtr ctx = create_xpath_context(doc);
|
||||
if (!ctx)
|
||||
return 0;
|
||||
|
||||
xmlXPathObjectPtr obj = xml_xpath_eval(ctx, "//item");
|
||||
|
||||
if (!obj || !obj->nodesetval || obj->nodesetval->nodeNr == 0) {
|
||||
free_xpath_objects(ctx, obj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int num_items = obj->nodesetval->nodeNr;
|
||||
*out_results = alloc_results_array(num_items, max_results);
|
||||
if (!*out_results) {
|
||||
free_xpath_objects(ctx, obj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < num_items && found_count < max_results; i++) {
|
||||
xmlNodePtr item_node = obj->nodesetval->nodeTab[i];
|
||||
ctx->node = item_node;
|
||||
|
||||
xmlXPathObjectPtr title_obj = xml_xpath_eval(ctx, "./title");
|
||||
char *title = (title_obj && title_obj->nodesetval &&
|
||||
title_obj->nodesetval->nodeNr > 0)
|
||||
? xml_node_content(title_obj->nodesetval->nodeTab[0])
|
||||
: NULL;
|
||||
|
||||
xmlXPathObjectPtr link_obj = xml_xpath_eval(ctx, "./link");
|
||||
char *url =
|
||||
(link_obj && link_obj->nodesetval && link_obj->nodesetval->nodeNr > 0)
|
||||
? xml_node_content(link_obj->nodesetval->nodeTab[0])
|
||||
: NULL;
|
||||
|
||||
xmlXPathObjectPtr desc_obj = xml_xpath_eval(ctx, "./description");
|
||||
char *snippet_text =
|
||||
(desc_obj && desc_obj->nodesetval && desc_obj->nodesetval->nodeNr > 0)
|
||||
? xml_node_content(desc_obj->nodesetval->nodeTab[0])
|
||||
: NULL;
|
||||
|
||||
if (url && title) {
|
||||
assign_result(&(*out_results)[found_count], url, title, snippet_text, 0);
|
||||
found_count++;
|
||||
}
|
||||
|
||||
free_xml_node_list(title, url, snippet_text);
|
||||
if (title_obj)
|
||||
xmlXPathFreeObject(title_obj);
|
||||
if (link_obj)
|
||||
xmlXPathFreeObject(link_obj);
|
||||
if (desc_obj)
|
||||
xmlXPathFreeObject(desc_obj);
|
||||
}
|
||||
|
||||
ctx->node = NULL;
|
||||
free_xpath_objects(ctx, obj);
|
||||
return found_count;
|
||||
}
|
||||
|
||||
static char yacy_base_url[BUFFER_SIZE_LARGE];
|
||||
|
||||
void configure_yacy_engine(const char *instance) {
|
||||
if (!instance || instance[0] == '\0')
|
||||
instance = DEFAULT_YACY_INSTANCE;
|
||||
|
||||
snprintf(yacy_base_url, sizeof(yacy_base_url),
|
||||
"%s/"
|
||||
"yacysearch.rss?resource=global&urlmaskfilter=.*&prefermaskfilter=&"
|
||||
"nav=all&maximumRecords=%d&query=",
|
||||
instance, MAX_RESULTS_PER_ENGINE);
|
||||
|
||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||
if (strcmp(ENGINE_REGISTRY[i].id, "yacy") == 0) {
|
||||
ENGINE_REGISTRY[i].base_url = yacy_base_url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SearchEngine ENGINE_REGISTRY[] = {
|
||||
{.id = "ddg",
|
||||
.name = "DuckDuckGo Lite",
|
||||
@@ -350,7 +433,18 @@ SearchEngine ENGINE_REGISTRY[] = {
|
||||
.page_multiplier = 10,
|
||||
.page_base = 1,
|
||||
.parser = parse_mojeek,
|
||||
.enabled = 1}};
|
||||
.enabled = 1},
|
||||
{.id = "yacy",
|
||||
.name = "YaCy",
|
||||
.base_url = "",
|
||||
.host_header = NULL,
|
||||
.referer = NULL,
|
||||
.page_param = "startRecord",
|
||||
.page_multiplier = 10,
|
||||
.page_base = 0,
|
||||
.parser = parse_yacy,
|
||||
.enabled = 0,
|
||||
.is_xml = 1}};
|
||||
|
||||
const int ENGINE_COUNT = sizeof(ENGINE_REGISTRY) / sizeof(SearchEngine);
|
||||
|
||||
@@ -373,6 +467,8 @@ static int engine_id_compare(const char *engine_id, const char *config_id) {
|
||||
void apply_engines_config(const char *engines_str) {
|
||||
if (!engines_str || engines_str[0] == '\0') {
|
||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||
if (engine_id_compare(ENGINE_REGISTRY[i].id, "yacy"))
|
||||
continue;
|
||||
ENGINE_REGISTRY[i].enabled = 1;
|
||||
}
|
||||
return;
|
||||
@@ -395,6 +491,8 @@ void apply_engines_config(const char *engines_str) {
|
||||
|
||||
if (strcmp(token, "*") == 0) {
|
||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||
if (engine_id_compare(ENGINE_REGISTRY[i].id, "yacy"))
|
||||
continue;
|
||||
ENGINE_REGISTRY[i].enabled = 1;
|
||||
}
|
||||
} else if (token[0] == '-' && token[1] != '\0') {
|
||||
|
||||
@@ -25,6 +25,12 @@ char *pretty_display_url(const char *input) {
|
||||
strncpy(temp, start, sizeof(temp) - 1);
|
||||
temp[sizeof(temp) - 1] = '\0';
|
||||
|
||||
char *query = strchr(temp, '?');
|
||||
if (query) {
|
||||
*query = '\0';
|
||||
input_len = strlen(temp);
|
||||
}
|
||||
|
||||
if (input_len > 0 && temp[input_len - 1] == '/') {
|
||||
temp[input_len - 1] = '\0';
|
||||
}
|
||||
|
||||
@@ -31,6 +31,17 @@ static size_t write_callback(void *contents, size_t size, size_t nmemb,
|
||||
return realsize;
|
||||
}
|
||||
|
||||
static struct curl_slist *build_http_headers(void) {
|
||||
struct curl_slist *headers = NULL;
|
||||
headers = curl_slist_append(
|
||||
headers,
|
||||
"Accept: "
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
||||
headers = curl_slist_append(headers, "Accept-Language: en-US,en;q=0.5");
|
||||
headers = curl_slist_append(headers, "DNT: 1");
|
||||
return headers;
|
||||
}
|
||||
|
||||
HttpResponse http_get(const char *url, const char *user_agent) {
|
||||
HttpResponse resp = {.memory = NULL, .size = 0, .capacity = 0};
|
||||
|
||||
@@ -51,16 +62,24 @@ HttpResponse http_get(const char *url, const char *user_agent) {
|
||||
return resp;
|
||||
}
|
||||
|
||||
struct curl_slist *headers = build_http_headers();
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resp);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT,
|
||||
user_agent ? user_agent : "libcurl-agent/1.0");
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 15L);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, CURL_TIMEOUT_SECS);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
|
||||
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
|
||||
curl_easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, CURL_DNS_TIMEOUT_SECS);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
||||
apply_proxy_settings(curl);
|
||||
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
curl_slist_free_all(headers);
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
if (res != CURLE_OK) {
|
||||
|
||||
@@ -3,6 +3,143 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static unsigned int hexval(char c) {
|
||||
if (c >= '0' && c <= '9')
|
||||
return c - '0';
|
||||
if (c >= 'a' && c <= 'f')
|
||||
return c - 'a' + 10;
|
||||
if (c >= 'A' && c <= 'F')
|
||||
return c - 'A' + 10;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned int hex4(const char *s) {
|
||||
return (hexval(s[0]) << 12) | (hexval(s[1]) << 8) | (hexval(s[2]) << 4) |
|
||||
hexval(s[3]);
|
||||
}
|
||||
|
||||
static size_t utf8_len(unsigned int cp) {
|
||||
if (cp < 0x80)
|
||||
return 1;
|
||||
if (cp < 0x800)
|
||||
return 2;
|
||||
if (cp < 0x10000)
|
||||
return 3;
|
||||
return 4;
|
||||
}
|
||||
|
||||
static void utf8_write(char *buf, size_t *i, unsigned int cp) {
|
||||
if (cp < 0x80) {
|
||||
buf[(*i)++] = (char)cp;
|
||||
} else if (cp < 0x800) {
|
||||
buf[(*i)++] = (char)(0xC0 | (cp >> 6));
|
||||
buf[(*i)++] = (char)(0x80 | (cp & 0x3F));
|
||||
} else if (cp < 0x10000) {
|
||||
buf[(*i)++] = (char)(0xE0 | (cp >> 12));
|
||||
buf[(*i)++] = (char)(0x80 | ((cp >> 6) & 0x3F));
|
||||
buf[(*i)++] = (char)(0x80 | (cp & 0x3F));
|
||||
} else {
|
||||
buf[(*i)++] = (char)(0xF0 | (cp >> 18));
|
||||
buf[(*i)++] = (char)(0x80 | ((cp >> 12) & 0x3F));
|
||||
buf[(*i)++] = (char)(0x80 | ((cp >> 6) & 0x3F));
|
||||
buf[(*i)++] = (char)(0x80 | (cp & 0x3F));
|
||||
}
|
||||
}
|
||||
|
||||
char *json_string_unescape(const char *s, const char *end) {
|
||||
if (!s || !end || end < s)
|
||||
return NULL;
|
||||
|
||||
size_t len = 0;
|
||||
const char *p = s;
|
||||
while (p < end) {
|
||||
if (*p == '\\' && p + 1 < end) {
|
||||
if (p[1] == 'u' && p + 5 < end) {
|
||||
unsigned int cp = hex4(p + 2);
|
||||
if (cp >= 0xD800 && cp <= 0xDBFF && p + 11 < end && p[6] == '\\' &&
|
||||
p[7] == 'u') {
|
||||
unsigned int cp2 = hex4(p + 8);
|
||||
if (cp2 >= 0xDC00 && cp2 <= 0xDFFF) {
|
||||
len += 4;
|
||||
p += 12;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
len += utf8_len(cp);
|
||||
p += 6;
|
||||
continue;
|
||||
}
|
||||
len += 1;
|
||||
p += 2;
|
||||
continue;
|
||||
}
|
||||
len += 1;
|
||||
p += 1;
|
||||
}
|
||||
|
||||
char *out = malloc(len + 1);
|
||||
if (!out)
|
||||
return NULL;
|
||||
size_t i = 0;
|
||||
p = s;
|
||||
while (p < end) {
|
||||
if (*p == '\\' && p + 1 < end) {
|
||||
if (p[1] == 'u' && p + 5 < end) {
|
||||
unsigned int cp = hex4(p + 2);
|
||||
if (cp >= 0xD800 && cp <= 0xDBFF && p + 11 < end && p[6] == '\\' &&
|
||||
p[7] == 'u') {
|
||||
unsigned int cp2 = hex4(p + 8);
|
||||
if (cp2 >= 0xDC00 && cp2 <= 0xDFFF) {
|
||||
utf8_write(out, &i,
|
||||
0x10000 + ((cp - 0xD800) << 10) + (cp2 - 0xDC00));
|
||||
p += 12;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (cp < 0xD800 || cp > 0xDFFF)
|
||||
utf8_write(out, &i, cp);
|
||||
p += 6;
|
||||
continue;
|
||||
}
|
||||
if (p[1] == 'n') {
|
||||
out[i++] = '\n';
|
||||
p += 2;
|
||||
continue;
|
||||
}
|
||||
if (p[1] == 'r') {
|
||||
out[i++] = '\r';
|
||||
p += 2;
|
||||
continue;
|
||||
}
|
||||
if (p[1] == 't') {
|
||||
out[i++] = '\t';
|
||||
p += 2;
|
||||
continue;
|
||||
}
|
||||
if (p[1] == 'b') {
|
||||
out[i++] = '\b';
|
||||
p += 2;
|
||||
continue;
|
||||
}
|
||||
if (p[1] == 'f') {
|
||||
out[i++] = '\f';
|
||||
p += 2;
|
||||
continue;
|
||||
}
|
||||
if (p[1] == '"' || p[1] == '\\' || p[1] == '/') {
|
||||
out[i++] = p[1];
|
||||
p += 2;
|
||||
continue;
|
||||
}
|
||||
p += 2;
|
||||
continue;
|
||||
}
|
||||
out[i++] = *p++;
|
||||
}
|
||||
out[i] = '\0';
|
||||
return out;
|
||||
}
|
||||
|
||||
char *unescape_search_url(const char *input) {
|
||||
if (!input)
|
||||
return NULL;
|
||||
|
||||
@@ -5,5 +5,6 @@
|
||||
|
||||
char *unescape_search_url(const char *input);
|
||||
char *url_decode_query(const char *src);
|
||||
char *json_string_unescape(const char *s, const char *end);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,98 @@
|
||||
#include "Utility.h"
|
||||
#include "../Scraping/Scraping.h"
|
||||
#include <beaker.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static char global_default_locale[32] = "en_gb";
|
||||
static char **themes_list = NULL;
|
||||
static int themes_count = 0;
|
||||
static int themes_initialized = 0;
|
||||
|
||||
void init_themes(const char *static_path) {
|
||||
if (themes_initialized)
|
||||
return;
|
||||
|
||||
char themes_dir[512];
|
||||
snprintf(themes_dir, sizeof(themes_dir), "%s/themes", static_path);
|
||||
|
||||
DIR *dir = opendir(themes_dir);
|
||||
if (!dir)
|
||||
return;
|
||||
|
||||
struct dirent *entry;
|
||||
int capacity = 4;
|
||||
themes_list = malloc(sizeof(char *) * capacity);
|
||||
if (!themes_list) {
|
||||
closedir(dir);
|
||||
return;
|
||||
}
|
||||
themes_count = 0;
|
||||
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
size_t len = strlen(entry->d_name);
|
||||
if (len > 4 && strcmp(entry->d_name + len - 4, ".css") == 0) {
|
||||
if (themes_count >= capacity) {
|
||||
int new_capacity = capacity * 2;
|
||||
char **new_list = realloc(themes_list, sizeof(char *) * new_capacity);
|
||||
if (!new_list)
|
||||
break;
|
||||
themes_list = new_list;
|
||||
capacity = new_capacity;
|
||||
}
|
||||
char *theme = strndup(entry->d_name, len - 4);
|
||||
if (!theme)
|
||||
break;
|
||||
themes_list[themes_count] = theme;
|
||||
themes_count++;
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
themes_initialized = 1;
|
||||
|
||||
for (int i = 0; i < themes_count; i++) {
|
||||
for (int j = i + 1; j < themes_count; j++) {
|
||||
int priority_i = 0, priority_j = 0;
|
||||
if (strcmp(themes_list[i], "system") == 0)
|
||||
priority_i = 0;
|
||||
else if (strcmp(themes_list[i], "light") == 0)
|
||||
priority_i = 1;
|
||||
else if (strcmp(themes_list[i], "dark") == 0)
|
||||
priority_i = 2;
|
||||
else
|
||||
priority_i = 3;
|
||||
if (strcmp(themes_list[j], "system") == 0)
|
||||
priority_j = 0;
|
||||
else if (strcmp(themes_list[j], "light") == 0)
|
||||
priority_j = 1;
|
||||
else if (strcmp(themes_list[j], "dark") == 0)
|
||||
priority_j = 2;
|
||||
else
|
||||
priority_j = 3;
|
||||
if (priority_i > priority_j ||
|
||||
(priority_i == priority_j &&
|
||||
strcmp(themes_list[i], themes_list[j]) > 0)) {
|
||||
char *tmp = themes_list[i];
|
||||
themes_list[i] = themes_list[j];
|
||||
themes_list[j] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void get_available_themes(char ***out_themes, int *out_count) {
|
||||
*out_themes = themes_list;
|
||||
*out_count = themes_count;
|
||||
}
|
||||
|
||||
void set_default_locale(const char *locale) {
|
||||
if (locale && strlen(locale) > 0) {
|
||||
snprintf(global_default_locale, sizeof(global_default_locale), "%s",
|
||||
locale);
|
||||
}
|
||||
}
|
||||
|
||||
int hex_to_int(char c) {
|
||||
if (c >= '0' && c <= '9')
|
||||
@@ -9,3 +103,265 @@ int hex_to_int(char c) {
|
||||
return c - 'A' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *get_theme(const char *default_theme) {
|
||||
char *cookie = get_cookie("theme");
|
||||
if (cookie && strlen(cookie) > 0) {
|
||||
for (int i = 0; i < themes_count; i++) {
|
||||
if (strcmp(cookie, themes_list[i]) == 0) {
|
||||
return cookie;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(cookie);
|
||||
return strdup(default_theme && strlen(default_theme) > 0 ? default_theme
|
||||
: "system");
|
||||
}
|
||||
|
||||
char *get_locale(const char *default_locale) {
|
||||
char *cookie = get_cookie("locale");
|
||||
if (cookie && beaker_get_locale_meta(cookie) != NULL) {
|
||||
return cookie;
|
||||
}
|
||||
free(cookie);
|
||||
const char *fallback =
|
||||
default_locale ? default_locale : global_default_locale;
|
||||
return strdup(fallback);
|
||||
}
|
||||
|
||||
static int engine_id_casecmp(const char *a, const char *b) {
|
||||
while (*a && *b) {
|
||||
char la = *a;
|
||||
char lb = *b;
|
||||
if (la >= 'A' && la <= 'Z')
|
||||
la = la - 'A' + 'a';
|
||||
if (lb >= 'A' && lb <= 'Z')
|
||||
lb = lb - 'A' + 'a';
|
||||
if (la != lb)
|
||||
return 0;
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
return *a == *b;
|
||||
}
|
||||
|
||||
int is_engine_id_enabled(const char *engine_id) {
|
||||
if (!engine_id)
|
||||
return 0;
|
||||
for (int i = 0; i < ENGINE_COUNT; i++) {
|
||||
if (ENGINE_REGISTRY[i].enabled &&
|
||||
engine_id_casecmp(ENGINE_REGISTRY[i].id, engine_id)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_user_engines(char ***out_ids, int *out_count) {
|
||||
*out_ids = NULL;
|
||||
*out_count = 0;
|
||||
|
||||
char *cookie = get_cookie("engines");
|
||||
if (!cookie || cookie[0] == '\0') {
|
||||
free(cookie);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char **ids = NULL;
|
||||
int count = 0;
|
||||
|
||||
char *copy = strdup(cookie);
|
||||
if (!copy) {
|
||||
free(cookie);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *saveptr;
|
||||
char *token = strtok_r(copy, "+", &saveptr);
|
||||
while (token) {
|
||||
while (*token == ' ' || *token == '\t')
|
||||
token++;
|
||||
|
||||
if (token[0] != '\0' && is_engine_id_enabled(token)) {
|
||||
char **new_ids = realloc(ids, sizeof(char *) * (count + 1));
|
||||
if (new_ids) {
|
||||
ids = new_ids;
|
||||
ids[count] = strdup(token);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
token = strtok_r(NULL, "+", &saveptr);
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
char *copy2 = strdup(cookie);
|
||||
if (copy2) {
|
||||
char *saveptr2 = NULL;
|
||||
char *token2 = strtok_r(copy2, ",", &saveptr2);
|
||||
while (token2) {
|
||||
while (*token2 == ' ' || *token2 == '\t')
|
||||
token2++;
|
||||
if (token2[0] != '\0' && is_engine_id_enabled(token2)) {
|
||||
char **new_ids = realloc(ids, sizeof(char *) * (count + 1));
|
||||
if (new_ids) {
|
||||
ids = new_ids;
|
||||
ids[count] = strdup(token2);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
token2 = strtok_r(NULL, ",", &saveptr2);
|
||||
}
|
||||
free(copy2);
|
||||
}
|
||||
}
|
||||
free(copy);
|
||||
free(cookie);
|
||||
|
||||
if (count == 0) {
|
||||
free(ids);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*out_ids = ids;
|
||||
*out_count = count;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int user_engines_contains(const char *engine_id, char **ids, int count) {
|
||||
if (!engine_id || !ids)
|
||||
return 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (engine_id_casecmp(ids[i], engine_id))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *get_default_search_engine(void) {
|
||||
char *cookie = get_cookie("default_engine");
|
||||
if (cookie && (strcmp(cookie, "all") == 0 || is_engine_id_enabled(cookie)))
|
||||
return cookie;
|
||||
|
||||
free(cookie);
|
||||
return strdup("all");
|
||||
}
|
||||
|
||||
void free_string_matrix(char ***matrix, int *inner_counts, int row_count) {
|
||||
if (matrix) {
|
||||
for (int i = 0; i < row_count; i++) {
|
||||
int field_count = inner_counts ? inner_counts[i] : 0;
|
||||
for (int j = 0; j < field_count; j++)
|
||||
free(matrix[i][j]);
|
||||
free(matrix[i]);
|
||||
}
|
||||
}
|
||||
free(matrix);
|
||||
free(inner_counts);
|
||||
}
|
||||
|
||||
void string_matrix_init(StringMatrix *matrix) {
|
||||
if (matrix)
|
||||
*matrix = (StringMatrix){0};
|
||||
}
|
||||
|
||||
int string_matrix_append(StringMatrix *matrix, const char *const *values,
|
||||
int field_count) {
|
||||
if (!matrix || !values || field_count <= 0)
|
||||
return -1;
|
||||
|
||||
char **row = calloc((size_t)field_count, sizeof(*row));
|
||||
if (!row)
|
||||
return -1;
|
||||
|
||||
for (int i = 0; i < field_count; i++) {
|
||||
row[i] = strdup(values[i] ? values[i] : "");
|
||||
if (!row[i]) {
|
||||
for (int j = 0; j < i; j++)
|
||||
free(row[j]);
|
||||
free(row);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (matrix->count == matrix->capacity) {
|
||||
int new_capacity = matrix->capacity ? matrix->capacity * 2 : 8;
|
||||
char ***new_rows = malloc(sizeof(*new_rows) * (size_t)new_capacity);
|
||||
int *new_counts = malloc(sizeof(*new_counts) * (size_t)new_capacity);
|
||||
if (!new_rows || !new_counts) {
|
||||
free(new_rows);
|
||||
free(new_counts);
|
||||
for (int i = 0; i < field_count; i++)
|
||||
free(row[i]);
|
||||
free(row);
|
||||
return -1;
|
||||
}
|
||||
if (matrix->count > 0) {
|
||||
memcpy(new_rows, matrix->rows, sizeof(*new_rows) * matrix->count);
|
||||
memcpy(new_counts, matrix->field_counts,
|
||||
sizeof(*new_counts) * matrix->count);
|
||||
}
|
||||
free(matrix->rows);
|
||||
free(matrix->field_counts);
|
||||
matrix->rows = new_rows;
|
||||
matrix->field_counts = new_counts;
|
||||
matrix->capacity = new_capacity;
|
||||
}
|
||||
|
||||
matrix->rows[matrix->count] = row;
|
||||
matrix->field_counts[matrix->count] = field_count;
|
||||
matrix->count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void string_matrix_free(StringMatrix *matrix) {
|
||||
if (!matrix)
|
||||
return;
|
||||
free_string_matrix(matrix->rows, matrix->field_counts, matrix->count);
|
||||
*matrix = (StringMatrix){0};
|
||||
}
|
||||
|
||||
int string_matrix_build_pagination(int page,
|
||||
char *(*href_builder)(int page, void *data),
|
||||
void *data, StringMatrix *out_matrix) {
|
||||
enum { PAGER_WINDOW_SIZE = 5 };
|
||||
if (!out_matrix || !href_builder)
|
||||
return -1;
|
||||
|
||||
string_matrix_init(out_matrix);
|
||||
int pager_start = page <= 3 ? 1 : page - 2;
|
||||
int pager_end = pager_start + PAGER_WINDOW_SIZE - 1;
|
||||
|
||||
for (int i = page > 1 ? pager_start - 1 : pager_start; i <= pager_end + 1;
|
||||
i++) {
|
||||
const char *label = NULL;
|
||||
const char *class_name = "pagination-btn";
|
||||
char page_label[16];
|
||||
int target_page = i;
|
||||
|
||||
if (page > 1 && i == pager_start - 1) {
|
||||
label = "←";
|
||||
class_name = "pagination-btn prev";
|
||||
target_page = page - 1;
|
||||
} else if (i == pager_end + 1) {
|
||||
label = "→";
|
||||
class_name = "pagination-btn next";
|
||||
target_page = page + 1;
|
||||
} else {
|
||||
snprintf(page_label, sizeof(page_label), "%d", i);
|
||||
label = page_label;
|
||||
if (i == page)
|
||||
class_name = "pagination-btn pagination-current";
|
||||
}
|
||||
|
||||
char *href = href_builder(target_page, data);
|
||||
const char *values[LINK_FIELD_COUNT] = {href, label, class_name};
|
||||
int result = string_matrix_append(out_matrix, values, LINK_FIELD_COUNT);
|
||||
free(href);
|
||||
if (result != 0) {
|
||||
string_matrix_free(out_matrix);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,46 @@
|
||||
#ifndef UTILITY_H
|
||||
#define UTILITY_H
|
||||
|
||||
#include <beaker.h>
|
||||
|
||||
#ifndef VERSION
|
||||
#define VERSION "unknown"
|
||||
#endif
|
||||
|
||||
#ifndef GIT_REMOTE
|
||||
#define GIT_REMOTE "https://git.bwaaa.space/omnisearch"
|
||||
#endif
|
||||
|
||||
#define LINK_FIELD_COUNT 3
|
||||
|
||||
typedef struct {
|
||||
char ***rows;
|
||||
int *field_counts;
|
||||
int count;
|
||||
int capacity;
|
||||
} StringMatrix;
|
||||
|
||||
int hex_to_int(char c);
|
||||
char *get_theme(const char *default_theme);
|
||||
void init_themes(const char *static_path);
|
||||
void get_available_themes(char ***out_themes, int *out_count);
|
||||
void set_default_locale(const char *locale);
|
||||
char *get_locale(const char *default_locale);
|
||||
|
||||
int is_engine_id_enabled(const char *engine_id);
|
||||
int get_user_engines(char ***out_ids, int *out_count);
|
||||
int user_engines_contains(const char *engine_id, char **ids, int count);
|
||||
char *get_default_search_engine(void);
|
||||
|
||||
void free_string_matrix(char ***matrix, int *inner_counts, int row_count);
|
||||
|
||||
void string_matrix_init(StringMatrix *matrix);
|
||||
int string_matrix_append(StringMatrix *matrix, const char *const *values,
|
||||
int field_count);
|
||||
void string_matrix_free(StringMatrix *matrix);
|
||||
|
||||
int string_matrix_build_pagination(int page,
|
||||
char *(*href_builder)(int page, void *data),
|
||||
void *data, StringMatrix *out_matrix);
|
||||
|
||||
#endif
|
||||
|
||||
461
static/main.css
461
static/main.css
@@ -1,36 +1,26 @@
|
||||
:root {
|
||||
--bg-main: #ffffff;
|
||||
--bg-card: #f8f9fa;
|
||||
--border: #e0e0e0;
|
||||
--text-primary: #1a1a1a;
|
||||
--text-secondary: #5f6368;
|
||||
--text-muted: #757575;
|
||||
--accent: #202124;
|
||||
--accent-glow: rgba(0,0,0,0.05);
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg-main: #121212;
|
||||
--bg-card: #1e1e1e;
|
||||
--border: #333333;
|
||||
--text-primary: #ffffff;
|
||||
--text-secondary: #a0a0a0;
|
||||
--text-muted: #d1d1d1;
|
||||
--accent: #e2e2e2;
|
||||
--accent-glow: rgba(255,255,255,0.1);
|
||||
}
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
font-family: system-ui;
|
||||
}
|
||||
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
html {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--bg-main);
|
||||
background-image: radial-gradient(
|
||||
circle at top end,
|
||||
var(--bg-card) 0%,
|
||||
var(--bg-main) 100%
|
||||
);
|
||||
background-attachment: fixed;
|
||||
color: var(--text-primary);
|
||||
font-family:system-ui,-apple-system,sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
min-height: 100%;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
@@ -38,13 +28,17 @@ img[src=""] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#header-icon {
|
||||
text-decoration: none;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.view-home {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
background: radial-gradient(circle at top right, var(--bg-card) 0%, var(--bg-main) 100%);
|
||||
}
|
||||
|
||||
.view-home .container {
|
||||
@@ -70,7 +64,9 @@ img[src=""] {
|
||||
.view-home .search-box {
|
||||
font-size: 1.1rem;
|
||||
padding: 16px 28px;
|
||||
box-shadow:0 4px 6px -1px rgba(0,0,0,0.1),0 2px 4px -1px rgba(0,0,0,0.06);
|
||||
box-shadow:
|
||||
0 4px 6px -1px rgba(0, 0, 0, 0.1),
|
||||
0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.view-home .buttons {
|
||||
@@ -100,18 +96,82 @@ img[src=""] {
|
||||
background: var(--bg-card);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--border);
|
||||
text-decoration: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 10px 24px;
|
||||
border-radius: 8px;
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
.view-home .btn-secondary:hover {
|
||||
background: var(--border);
|
||||
border-color: var(--text-secondary);
|
||||
}
|
||||
.home-settings-btn {
|
||||
position: fixed;
|
||||
top: 27px;
|
||||
inset-inline-end: 60px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
background-color: var(--text-primary);
|
||||
-webkit-mask-image: url("/static/settings.svg");
|
||||
mask-image: url("/static/settings.svg");
|
||||
mask-size: contain;
|
||||
mask-repeat: no-repeat;
|
||||
mask-position: center;
|
||||
text-decoration: none;
|
||||
}
|
||||
.home-footer {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 8px 24px;
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
text-align: center;
|
||||
}
|
||||
.version-link {
|
||||
color: var(--text-muted);
|
||||
text-decoration: underline;
|
||||
}
|
||||
.version-link:hover {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
.nav-settings-icon {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
flex-shrink: 0;
|
||||
margin-inline-start: auto;
|
||||
margin-top: 3px;
|
||||
background-color: var(--text-secondary);
|
||||
-webkit-mask-image: url("/static/settings.svg");
|
||||
mask-image: url("/static/settings.svg");
|
||||
mask-size: 100% 100%;
|
||||
transition: background-color 0.2s;
|
||||
text-decoration: none;
|
||||
}
|
||||
.nav-settings-icon:hover,
|
||||
.nav-settings-icon.active {
|
||||
background-color: var(--text-primary);
|
||||
}
|
||||
.nav-settings-link {
|
||||
display: none;
|
||||
margin-inline-start: auto;
|
||||
}
|
||||
header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
padding:15px 60px;
|
||||
padding-block: 15px;
|
||||
padding-inline: 60px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--bg-main);
|
||||
width: 100%;
|
||||
}
|
||||
.search-form {
|
||||
flex-grow: 1;
|
||||
@@ -126,6 +186,16 @@ h1 {
|
||||
h1 span {
|
||||
color: var(--accent);
|
||||
}
|
||||
.logo-link {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
header .logo-link {
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
header .logo-link:hover {
|
||||
transform: scale(1.03);
|
||||
}
|
||||
.search-box {
|
||||
width: 100%;
|
||||
padding: 12px 24px;
|
||||
@@ -134,7 +204,9 @@ h1 span {
|
||||
background: var(--bg-card);
|
||||
color: var(--text-primary);
|
||||
outline: none;
|
||||
transition: border-color 0.2s, box-shadow 0.2s;
|
||||
transition:
|
||||
border-color 0.2s,
|
||||
box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.search-box:focus {
|
||||
@@ -142,14 +214,14 @@ h1 span {
|
||||
box-shadow: 0 0 0 4px var(--accent-glow);
|
||||
}
|
||||
.nav-tabs {
|
||||
padding:0 60px;
|
||||
padding-inline: 60px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--bg-main);
|
||||
width: 100%;
|
||||
}
|
||||
.nav-container {
|
||||
display: flex;
|
||||
gap: 30px;
|
||||
max-width:1200px;
|
||||
}
|
||||
.nav-tabs a {
|
||||
padding: 14px 0;
|
||||
@@ -168,6 +240,9 @@ h1 span {
|
||||
color: var(--accent);
|
||||
border-bottom-color: var(--accent);
|
||||
}
|
||||
.nav-right {
|
||||
margin-inline-start: auto;
|
||||
}
|
||||
.image-results-container {
|
||||
padding: 30px 60px;
|
||||
}
|
||||
@@ -183,7 +258,9 @@ h1 span {
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--border);
|
||||
transition:transform 0.2s ease,border-color 0.2s;
|
||||
transition:
|
||||
transform 0.2s ease,
|
||||
border-color 0.2s;
|
||||
}
|
||||
.image-card:hover {
|
||||
transform: translateY(-4px);
|
||||
@@ -270,7 +347,8 @@ h1 span {
|
||||
display: grid;
|
||||
grid-template-columns: 140px minmax(0, 700px) 450px;
|
||||
gap: 60px;
|
||||
padding:30px 60px;
|
||||
padding-block: 30px;
|
||||
padding-inline: 60px;
|
||||
}
|
||||
.result-header {
|
||||
display: flex;
|
||||
@@ -286,7 +364,7 @@ h1 span {
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
position: absolute;
|
||||
left: -24px;
|
||||
inset-inline-start: -24px;
|
||||
}
|
||||
.url {
|
||||
color: var(--text-secondary);
|
||||
@@ -294,18 +372,12 @@ h1 span {
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.result-sources {
|
||||
color:var(--text-secondary);
|
||||
display:block;
|
||||
font-size:0.78rem;
|
||||
margin-bottom:8px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.result-favicon {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
left: -20px;
|
||||
inset-inline-start: -20px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +385,7 @@ h1 span {
|
||||
.result-favicon {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
left: -16px;
|
||||
inset-inline-start: -16px;
|
||||
}
|
||||
}
|
||||
.results-container {
|
||||
@@ -368,10 +440,15 @@ h1 span {
|
||||
}
|
||||
.result > a {
|
||||
color: var(--accent);
|
||||
text-decoration:none;
|
||||
text-decoration: underline;
|
||||
text-decoration-color: transparent;
|
||||
font-size: 1.25rem;
|
||||
display: inline-block;
|
||||
margin-bottom: 4px;
|
||||
transition: text-decoration-color 0.1s;
|
||||
}
|
||||
.result > a:hover {
|
||||
text-decoration-color: var(--accent);
|
||||
}
|
||||
.desc {
|
||||
color: var(--text-muted);
|
||||
@@ -400,7 +477,8 @@ h1 span {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
} .infobox-content {
|
||||
}
|
||||
.infobox-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
@@ -416,7 +494,8 @@ h1 span {
|
||||
|
||||
.read-more:hover {
|
||||
text-decoration: underline;
|
||||
} .infobox-main {
|
||||
}
|
||||
.infobox-main {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
padding: 20px;
|
||||
@@ -464,7 +543,6 @@ h1 span {
|
||||
border-color: var(--text-secondary);
|
||||
}
|
||||
|
||||
|
||||
.pagination-current {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
@@ -476,41 +554,60 @@ h1 span {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
[dir="rtl"] .pagination-btn.prev {
|
||||
transform: scaleX(-1);
|
||||
}
|
||||
|
||||
[dir="rtl"] .pagination-btn.next {
|
||||
transform: scaleX(-1);
|
||||
}
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
body {
|
||||
padding-left: 16px;
|
||||
padding-right: 16px;
|
||||
}
|
||||
.content-layout {
|
||||
grid-template-columns: 1fr;
|
||||
padding:20px 30px;
|
||||
padding-block: 20px;
|
||||
padding-inline: 30px;
|
||||
gap: 20px;
|
||||
}
|
||||
.results-container,.infobox-sidebar {
|
||||
header {
|
||||
gap: 20px;
|
||||
}
|
||||
.results-container,
|
||||
.infobox-sidebar {
|
||||
grid-column: 1;
|
||||
max-width: 100%;
|
||||
}
|
||||
.settings-layout {
|
||||
padding-block: 20px;
|
||||
padding-inline: 30px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.infobox-sidebar {
|
||||
order: -1;
|
||||
}
|
||||
.nav-tabs,.image-results-container {
|
||||
padding:0 30px;
|
||||
.nav-tabs,
|
||||
.image-results-container {
|
||||
padding-inline: 30px;
|
||||
}
|
||||
header {
|
||||
padding:15px 30px;
|
||||
padding-block: 15px;
|
||||
padding-inline: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
body {
|
||||
padding-left: 16px;
|
||||
padding-right: 16px;
|
||||
.nav-settings-icon {
|
||||
display: none;
|
||||
}
|
||||
.nav-settings-link {
|
||||
display: inline;
|
||||
}
|
||||
header {
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding:12px 16px;
|
||||
padding-block: 12px;
|
||||
padding-inline: 16px;
|
||||
text-align: center;
|
||||
}
|
||||
h1 {
|
||||
@@ -526,7 +623,7 @@ h1 span {
|
||||
.nav-tabs {
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
padding:0 16px;
|
||||
padding-inline: 16px;
|
||||
}
|
||||
.nav-container {
|
||||
gap: 24px;
|
||||
@@ -537,7 +634,9 @@ h1 span {
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
.content-layout {
|
||||
padding:16px;
|
||||
padding-inline-start: 40px;
|
||||
padding-inline-end: 16px;
|
||||
padding-block: 16px;
|
||||
gap: 16px;
|
||||
}
|
||||
.result {
|
||||
@@ -581,7 +680,7 @@ h1 span {
|
||||
max-width: 200px;
|
||||
}
|
||||
.image-results-container {
|
||||
padding:16px;
|
||||
padding-inline: 16px;
|
||||
}
|
||||
.pagination {
|
||||
flex-wrap: wrap;
|
||||
@@ -596,7 +695,6 @@ h1 span {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
transform: translateY(-5vh);
|
||||
padding: 20px 16px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
@@ -626,8 +724,17 @@ h1 span {
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.content-layout {
|
||||
padding-inline-start: 28px;
|
||||
padding-inline-end: 16px;
|
||||
padding-block: 16px;
|
||||
}
|
||||
.settings-layout {
|
||||
padding: 0;
|
||||
}
|
||||
header {
|
||||
padding:12px 12px;
|
||||
padding-inline: 12px;
|
||||
padding-block: 12px;
|
||||
}
|
||||
.search-box {
|
||||
font-size: 0.95rem;
|
||||
@@ -662,3 +769,231 @@ h1 span {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-layout {
|
||||
padding-block: 30px;
|
||||
padding-inline-start: 260px;
|
||||
padding-inline-end: 60px;
|
||||
}
|
||||
|
||||
.settings-container {
|
||||
max-width: 700px;
|
||||
}
|
||||
|
||||
.settings-title {
|
||||
font-size: 1.8rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 32px 0;
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
|
||||
.settings-section {
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 24px;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.settings-section-title {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 4px 0;
|
||||
}
|
||||
|
||||
.settings-section-desc {
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.9rem;
|
||||
margin: 0 0 20px 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.settings-field {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.settings-field + .settings-field {
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.settings-label {
|
||||
font-size: 0.95rem;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.settings-select {
|
||||
padding: 8px 12px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--bg-main);
|
||||
color: var(--text-primary);
|
||||
font-size: 0.9rem;
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.settings-select:focus {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.settings-checkbox {
|
||||
width:18px;
|
||||
height:18px;
|
||||
accent-color:var(--accent);
|
||||
cursor:pointer;
|
||||
flex-shrink:0;
|
||||
margin:0;
|
||||
}
|
||||
|
||||
.settings-engine-list {
|
||||
margin:0;
|
||||
}
|
||||
|
||||
.settings-engine-options {
|
||||
display:grid;
|
||||
gap:8px;
|
||||
margin-inline:-3px;
|
||||
}
|
||||
|
||||
.settings-engine-option {
|
||||
display:flex;
|
||||
align-items:center;
|
||||
justify-content:space-between;
|
||||
gap:16px;
|
||||
padding:12px 14px;
|
||||
border:1px solid var(--border);
|
||||
border-radius:8px;
|
||||
background:var(--bg-main);
|
||||
color:var(--text-primary);
|
||||
font-size:0.95rem;
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
.settings-default-engine-field {
|
||||
margin-top:12px;
|
||||
padding-top:12px;
|
||||
border-top:1px solid var(--border);
|
||||
}
|
||||
|
||||
.settings-actions {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-top: 8px;
|
||||
padding-bottom: 40px;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.settings-actions .btn-primary {
|
||||
background: var(--accent);
|
||||
color: var(--bg-main);
|
||||
border: 1px solid transparent;
|
||||
padding: 10px 24px;
|
||||
border-radius: 8px;
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
.settings-actions .btn-primary:hover {
|
||||
filter: brightness(1.1);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.settings-actions .btn-secondary {
|
||||
background: var(--bg-card);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border);
|
||||
padding: 10px 24px;
|
||||
border-radius: 8px;
|
||||
font-weight: 600;
|
||||
font-size: 0.9rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
.settings-actions .btn-secondary:hover {
|
||||
background:var(--border);
|
||||
border-color:var(--text-secondary);
|
||||
}
|
||||
|
||||
@media (max-width:768px) {
|
||||
.settings-layout {
|
||||
padding:12px;
|
||||
display:block;
|
||||
}
|
||||
.settings-container {
|
||||
max-width:100%;
|
||||
}
|
||||
.settings-title {
|
||||
font-size:1.4rem;
|
||||
margin-bottom:24px;
|
||||
}
|
||||
.settings-section {
|
||||
padding:16px;
|
||||
}
|
||||
.settings-field {
|
||||
flex-direction:column;
|
||||
align-items:stretch;
|
||||
gap:8px;
|
||||
}
|
||||
.settings-engine-options {
|
||||
margin-inline:0;
|
||||
}
|
||||
.settings-engine-option {
|
||||
padding-inline:7px;
|
||||
}
|
||||
.settings-actions {
|
||||
flex-direction:column;
|
||||
}
|
||||
.settings-actions .btn-primary,
|
||||
.settings-actions .btn-secondary {
|
||||
width:100%;
|
||||
text-align:center;
|
||||
}
|
||||
}
|
||||
|
||||
[dir="rtl"] {
|
||||
direction: rtl;
|
||||
unicode-bidi: embed;
|
||||
}
|
||||
|
||||
[dir="rtl"] header {
|
||||
flex-direction: row-reverse;
|
||||
direction: ltr;
|
||||
}
|
||||
|
||||
[dir="rtl"] .nav-container {
|
||||
flex-direction: row-reverse;
|
||||
direction: ltr;
|
||||
}
|
||||
|
||||
[dir="rtl"] .search-box {
|
||||
text-align: right;
|
||||
direction: rtl;
|
||||
}
|
||||
|
||||
[dir="rtl"] .url {
|
||||
text-align: end;
|
||||
}
|
||||
|
||||
[dir="rtl"] .nav-settings-icon {
|
||||
margin-inline-start: unset;
|
||||
margin-inline-end: auto;
|
||||
}
|
||||
|
||||
[dir="rtl"] .settings-actions .btn-primary {
|
||||
margin-inline-end: auto;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
[dir="rtl"] header {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
4
static/settings.svg
Normal file
4
static/settings.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="3"/>
|
||||
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 829 B |
10
static/themes/catppuccin-frappe.css
Normal file
10
static/themes/catppuccin-frappe.css
Normal file
@@ -0,0 +1,10 @@
|
||||
:root {
|
||||
--bg-main: #292c2c;
|
||||
--bg-card: #303446;
|
||||
--border: #414559;
|
||||
--text-primary: #c6d0f5;
|
||||
--text-secondary: #a5adce;
|
||||
--text-muted: #737994;
|
||||
--accent: #ca9ee6;
|
||||
--accent-glow: rgba(255,255,255,0.1);
|
||||
}
|
||||
10
static/themes/catppuccin-latte.css
Normal file
10
static/themes/catppuccin-latte.css
Normal file
@@ -0,0 +1,10 @@
|
||||
:root {
|
||||
--bg-main: #e6e9ef;
|
||||
--bg-card: #eff1f5;
|
||||
--border: #cdd0da;
|
||||
--text-primary: #4c4f69;
|
||||
--text-secondary: #6c6f85;
|
||||
--text-muted: #9ca0b0;
|
||||
--accent: #8839ef;
|
||||
--accent-glow: rgba(255,255,255,0.1);
|
||||
}
|
||||
10
static/themes/catppuccin-macchiato.css
Normal file
10
static/themes/catppuccin-macchiato.css
Normal file
@@ -0,0 +1,10 @@
|
||||
:root {
|
||||
--bg-main: #1e2030;
|
||||
--bg-card: #24273a;
|
||||
--border: #363a4f;
|
||||
--text-primary: #cad3f5;
|
||||
--text-secondary: #a5adcb;
|
||||
--text-muted: #6e738d;
|
||||
--accent: #c6a0f6;
|
||||
--accent-glow: rgba(255,255,255,0.1);
|
||||
}
|
||||
10
static/themes/catppuccin-mocha.css
Normal file
10
static/themes/catppuccin-mocha.css
Normal file
@@ -0,0 +1,10 @@
|
||||
:root {
|
||||
--bg-main: #1e1e2e;
|
||||
--bg-card: #313244;
|
||||
--border: #6c7086;
|
||||
--text-primary: #cdd6f4;
|
||||
--text-secondary: #a6adc8;
|
||||
--text-muted: #6c7086;
|
||||
--accent: #cba6f7;
|
||||
--accent-glow: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
10
static/themes/dark.css
Normal file
10
static/themes/dark.css
Normal file
@@ -0,0 +1,10 @@
|
||||
:root {
|
||||
--bg-main: #121212;
|
||||
--bg-card: #1e1e1e;
|
||||
--border: #333333;
|
||||
--text-primary: #ffffff;
|
||||
--text-secondary: #a0a0a0;
|
||||
--text-muted: #d1d1d1;
|
||||
--accent: #e2e2e2;
|
||||
--accent-glow: rgba(255,255,255,0.1);
|
||||
}
|
||||
10
static/themes/light.css
Normal file
10
static/themes/light.css
Normal file
@@ -0,0 +1,10 @@
|
||||
:root {
|
||||
--bg-main: #ffffff;
|
||||
--bg-card: #f8f9fa;
|
||||
--border: #e0e0e0;
|
||||
--text-primary: #1a1a1a;
|
||||
--text-secondary: #5f6368;
|
||||
--text-muted: #757575;
|
||||
--accent: #202124;
|
||||
--accent-glow: rgba(0,0,0,0.05);
|
||||
}
|
||||
22
static/themes/system.css
Normal file
22
static/themes/system.css
Normal file
@@ -0,0 +1,22 @@
|
||||
:root {
|
||||
--bg-main: #ffffff;
|
||||
--bg-card: #f8f9fa;
|
||||
--border: #e0e0e0;
|
||||
--text-primary: #1a1a1a;
|
||||
--text-secondary: #5f6368;
|
||||
--text-muted: #757575;
|
||||
--accent: #202124;
|
||||
--accent-glow: rgba(0,0,0,0.05);
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg-main: #121212;
|
||||
--bg-card: #1e1e1e;
|
||||
--border: #333333;
|
||||
--text-primary: #ffffff;
|
||||
--text-secondary: #a0a0a0;
|
||||
--text-muted: #d1d1d1;
|
||||
--accent: #e2e2e2;
|
||||
--accent-glow: rgba(255,255,255,0.1);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="{{__locale_id}}" dir="{{__locale_direction}}">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@@ -8,6 +8,7 @@
|
||||
OmniSearch
|
||||
</title>
|
||||
<link rel="stylesheet" href="static/main.css">
|
||||
<link rel="stylesheet" href="static/themes/{{theme}}.css">
|
||||
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
|
||||
<link rel="search"
|
||||
type="application/opensearchdescription+xml"
|
||||
@@ -18,23 +19,28 @@
|
||||
<div class="view-home">
|
||||
<div class="container">
|
||||
<h1 class="hero-logo">
|
||||
Omni<span>Search</span>
|
||||
<span>Void</span>arc
|
||||
</h1>
|
||||
<form action="/search" class="home-search-form">
|
||||
<div class="search-input-wrapper">
|
||||
<input name="q" type="text" class="search-box" placeholder="Search the web..."
|
||||
<input name="q" type="text" class="search-box" placeholder="{{l("search_placeholder")}}"
|
||||
autofocus autocomplete="off">
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<button type="submit" class="btn-primary">
|
||||
Search
|
||||
{{l("search_button")}}
|
||||
</button>
|
||||
<button type="submit" name="btnI" value="1" class="btn-secondary">
|
||||
Surprise me
|
||||
{{l("surprise_me_button")}}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<a href="/settings" class="home-settings-btn" title="{{l("settings_tab")}}"></a>
|
||||
<footer class="home-footer">
|
||||
<a href="{{git_remote}}" class="version-link" target="_blank" rel="noopener noreferrer">{{version}}</a>
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="{{__locale_id}}" dir="{{__locale_direction}}">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@@ -9,25 +9,30 @@
|
||||
</title>
|
||||
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
|
||||
<link rel="stylesheet" href="static/main.css">
|
||||
<link rel="stylesheet" href="static/themes/{{theme}}.css">
|
||||
</head>
|
||||
|
||||
<body class="images-view">
|
||||
<header>
|
||||
<h1>
|
||||
<a href="/" class="logo-link"><h1>
|
||||
Omni<span>Search</span>
|
||||
</h1>
|
||||
</h1></a>
|
||||
<form action="/images" method="GET" class="search-form">
|
||||
<input name="q" autocomplete="off"="text" class="search-box" placeholder="Search for images..."
|
||||
<input name="q" autocomplete="off"="text" class="search-box" placeholder="{{l("search_placeholder")}}"
|
||||
value="{{query}}">
|
||||
</form>
|
||||
<a href="/settings?q={{query}}" class="nav-settings-icon" title="{{l("settings_tab")}}"></a>
|
||||
</header>
|
||||
<nav class="nav-tabs">
|
||||
<div class="nav-container">
|
||||
<a href="/search?q={{query}}">
|
||||
All
|
||||
{{l("all_tab")}}
|
||||
</a>
|
||||
<a href="/images?q={{query}}" class="active">
|
||||
Images
|
||||
{{l("images_tab")}}
|
||||
</a>
|
||||
<a href="/settings?q={{query}}" class="nav-settings-link">
|
||||
{{l("settings_tab")}}
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -40,10 +45,10 @@
|
||||
<div class="image-overlay">
|
||||
<div class="overlay-buttons">
|
||||
<a href="{{img[3]}}" target="_blank" class="overlay-btn primary">
|
||||
View Image
|
||||
{{l("view_image")}}
|
||||
</a>
|
||||
<a href="{{img[2]}}" target="_blank" class="overlay-btn secondary">
|
||||
Visit Site
|
||||
{{l("visit_site")}}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -59,48 +64,15 @@
|
||||
</div>
|
||||
{{endfor}}
|
||||
</div>
|
||||
{{if exists pagination_links}}
|
||||
<nav class="pagination">
|
||||
<a class="pagination-btn prev" href="/images?q={{query}}&p={{prev_page}}">
|
||||
←
|
||||
</a>
|
||||
|
||||
{{if two_prev_page != 0}}
|
||||
<a class="pagination-btn prev" href="/images?q={{query}}&p={{two_prev_page}}">
|
||||
{{two_prev_page}}
|
||||
</a>
|
||||
{{endif}}
|
||||
|
||||
{{if prev_page != 0}}
|
||||
<a class="pagination-btn prev" href="/images?q={{query}}&p={{prev_page}}">
|
||||
{{prev_page}}
|
||||
</a>
|
||||
{{endif}}
|
||||
|
||||
<a class="pagination-current" href="/images?q={{query}}&p={{page}}">
|
||||
{{page}}
|
||||
</a>
|
||||
<a class="pagination-btn next" href="/images?q={{query}}&p={{next_page}}">
|
||||
{{next_page}}
|
||||
</a>
|
||||
<a class="pagination-btn next" href="/images?q={{query}}&p={{two_next_page}}">
|
||||
{{two_next_page}}
|
||||
</a>
|
||||
|
||||
{{if prev_page == 0}}
|
||||
<a class="pagination-btn prev" href="/images?q={{query}}&p=4">
|
||||
4
|
||||
</a>
|
||||
{{endif}}
|
||||
|
||||
{{if two_prev_page == 0}}
|
||||
<a class="pagination-btn prev" href="/images?q={{query}}&p=5">
|
||||
5
|
||||
</a>
|
||||
{{endif}}
|
||||
<a class="pagination-btn next" href="/images?q={{query}}&p={{next_page}}">
|
||||
→
|
||||
{{for link in pagination_links}}
|
||||
<a class="{{link[2]}}" href="{{link[0]}}">
|
||||
{{link[1]}}
|
||||
</a>
|
||||
{{endfor}}
|
||||
</nav>
|
||||
{{endif}}
|
||||
</main>
|
||||
</body>
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
|
||||
<ShortName>OmniSearch</ShortName>
|
||||
<Description>Lightweight metasearch engine</Description>
|
||||
<Url type="text/html" method="get" template="{{domain}}/search?q={searchTerms}"/>
|
||||
<Url type="text/html" method="get" template="{{scheme}}://{{domain}}/search?q={searchTerms}"/>
|
||||
<InputEncoding>UTF-8</InputEncoding>
|
||||
<OutputEncoding>UTF-8</OutputEncoding>
|
||||
<moz:SearchForm>{{domain}}/</moz:SearchForm>
|
||||
<moz:SearchForm>{{scheme}}://{{domain}}/</moz:SearchForm>
|
||||
</OpenSearchDescription>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="{{__locale_id}}" dir="{{__locale_direction}}">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@@ -8,6 +8,7 @@
|
||||
OmniSearch - {{query}}
|
||||
</title>
|
||||
<link rel="stylesheet" href="static/main.css">
|
||||
<link rel="stylesheet" href="static/themes/{{theme}}.css">
|
||||
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
|
||||
<link rel="search"
|
||||
type="application/opensearchdescription+xml"
|
||||
@@ -16,22 +17,26 @@
|
||||
|
||||
<body class="results-view">
|
||||
<header>
|
||||
<h1>
|
||||
Omni<span>Search</span>
|
||||
</h1>
|
||||
<a href="/" class="logo-link"><h1>
|
||||
VOID<span>ARC</span>
|
||||
</h1></a>
|
||||
<form action="/search" method="GET" class="search-form">
|
||||
<input name="engine" type="hidden" value="{{selected_engine}}">
|
||||
<input name="q" type="text" class="search-box" autocomplete="off" placeholder="Search the web..."
|
||||
<input name="q" type="text" class="search-box" autocomplete="off" placeholder="{{l("search_placeholder")}}"
|
||||
value="{{query}}">
|
||||
</form>
|
||||
<a href="/settings?q={{query}}" class="nav-settings-icon" title="{{l("settings_tab")}}"></a>
|
||||
</header>
|
||||
<nav class="nav-tabs">
|
||||
<div class="nav-container">
|
||||
<a href="{{search_href}}" class="active">
|
||||
All
|
||||
{{l("all_tab")}}
|
||||
</a>
|
||||
<a href="/images?q={{query}}">
|
||||
Images
|
||||
{{l("images_tab")}}
|
||||
</a>
|
||||
<a href="/settings?q={{query}}" class="nav-settings-link">
|
||||
{{l("settings_tab")}}
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -68,13 +73,11 @@
|
||||
<div class="result">
|
||||
<div class="result-header">
|
||||
<div class="result-favicon"
|
||||
style="background-image: url('https://{{result[4]}}/favicon.ico'), url('https://{{result[4]}}/favicon.png');">
|
||||
style="background-image: url('/proxy?url=https://{{result[4]}}/favicon.ico'), url('/proxy?url=https://{{result[4]}}/favicon.png');">
|
||||
</div>
|
||||
<span class="url">
|
||||
{{result[1]}}
|
||||
</span>
|
||||
<span class="result-sources">
|
||||
{{result[5]}}
|
||||
</span>
|
||||
</div>
|
||||
<a href="{{result[0]}}">
|
||||
@@ -84,7 +87,7 @@
|
||||
{{result[3]}}
|
||||
</p>
|
||||
<span>
|
||||
<a class="cached" href="https://web.archive.org/web/{{result[0]|safe}}">View Cached</a>
|
||||
<a class="cached" href="https://web.archive.org/web/{{result[0]|safe}}">{{l("view_cached")}}</a>
|
||||
</span>
|
||||
</div>
|
||||
{{endfor}}
|
||||
@@ -113,9 +116,11 @@
|
||||
<div class="infobox-content"> <p class="infobox-summary">
|
||||
{{info[2]|safe}}
|
||||
</p>
|
||||
{{if info[3] != "#"}}
|
||||
<a class="read-more" href="{{info[3]}}">
|
||||
Read More
|
||||
{{l("read_more")}}
|
||||
</a>
|
||||
{{endif}}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
116
templates/settings.html
Normal file
116
templates/settings.html
Normal file
@@ -0,0 +1,116 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{__locale_id}}" dir="{{__locale_direction}}">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0">
|
||||
<title>
|
||||
OmniSearch - {{l("settings_title")}}
|
||||
</title>
|
||||
<link rel="stylesheet" href="static/main.css">
|
||||
<link rel="stylesheet" href="static/themes/{{theme}}.css">
|
||||
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
|
||||
<link rel="search"
|
||||
type="application/opensearchdescription+xml"
|
||||
title="OmniSearch" href="/opensearch.xml">
|
||||
</head>
|
||||
|
||||
<body class="settings-view">
|
||||
<header>
|
||||
<a href="/" class="logo-link"><h1>
|
||||
Omni<span>Search</span>
|
||||
</h1></a>
|
||||
{{if query != ""}}
|
||||
<form action="/search" method="GET" class="search-form">
|
||||
<input name="q" type="text" class="search-box" autocomplete="off" placeholder="{{l("search_placeholder")}}"
|
||||
value="{{query}}">
|
||||
</form>
|
||||
{{endif}}
|
||||
{{if query != ""}}
|
||||
<a href="/search?q={{query}}" class="nav-settings-icon active" title="{{l("settings_tab")}}"></a>
|
||||
{{else}}
|
||||
<a href="/" class="nav-settings-icon active" title="{{l("settings_tab")}}"></a>
|
||||
{{endif}}
|
||||
</header>
|
||||
{{if query != ""}}
|
||||
<nav class="nav-tabs">
|
||||
<div class="nav-container">
|
||||
<a href="/search?q={{query}}">
|
||||
{{l("all_tab")}}
|
||||
</a>
|
||||
<a href="/images?q={{query}}">
|
||||
{{l("images_tab")}}
|
||||
</a>
|
||||
<a href="/settings" class="active nav-settings-link">
|
||||
{{l("settings_tab")}}
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
{{endif}}
|
||||
<div class="settings-layout">
|
||||
<main class="settings-container">
|
||||
<form action="/save_settings" method="GET">
|
||||
<input type="hidden" name="q" value="{{query}}">
|
||||
<section class="settings-section">
|
||||
<h3 class="settings-section-title">{{l("theme_label")}}</h3>
|
||||
<p class="settings-section-desc">{{l("theme_desc")}}</p>
|
||||
<div class="settings-field">
|
||||
<label class="settings-label" for="theme">{{l("theme_label")}}</label>
|
||||
<select id="theme" name="theme" class="settings-select">
|
||||
{{for t in themes}}
|
||||
<option value="{{t[0]}}" {{if theme == t[0]}}selected{{endif}}>{{t[1]}}</option>
|
||||
{{endfor}}
|
||||
</select>
|
||||
</div>
|
||||
</section>
|
||||
<section class="settings-section">
|
||||
<h3 class="settings-section-title">{{l("language_label")}}</h3>
|
||||
<p class="settings-section-desc">{{l("language_desc")}}</p>
|
||||
<div class="settings-field">
|
||||
<label class="settings-label" for="locale">{{l("display_language_label")}}</label>
|
||||
<select id="locale" name="locale" class="settings-select">
|
||||
{{for loc in locales}}
|
||||
<option value="{{loc[0]}}" {{if __locale_id == loc[0]}}selected{{endif}}>{{loc[1]}}</option>
|
||||
{{endfor}}
|
||||
</select>
|
||||
</div>
|
||||
</section>
|
||||
{{if has_enabled_engines}}
|
||||
<section class="settings-section settings-engines-section">
|
||||
<h3 class="settings-section-title">{{l("engines_label")}}</h3>
|
||||
<p class="settings-section-desc">{{l("engines_desc")}}</p>
|
||||
<input type="hidden" name="engines_present" value="1">
|
||||
|
||||
<div class="settings-engine-list">
|
||||
<div class="settings-engine-options">
|
||||
{{for eng in enabled_engines}}
|
||||
<label class="settings-engine-option" for="engine_{{eng[0]}}">
|
||||
<span>{{eng[1]}}</span>
|
||||
<input type="checkbox" id="engine_{{eng[0]}}" name="engine_{{eng[0]}}" value="1" class="settings-checkbox" {{eng[2]}}>
|
||||
</label>
|
||||
{{endfor}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings-field settings-default-engine-field">
|
||||
<label class="settings-label" for="default_engine">{{l("default_engine_label")}}</label>
|
||||
<select id="default_engine" name="default_engine" class="settings-select">
|
||||
<option value="all" {{if default_engine == "all"}}selected{{endif}}>{{l("all_engines_option")}}</option>
|
||||
{{for eng in enabled_engines}}
|
||||
{{if eng[2] != ""}}
|
||||
<option value="{{eng[0]}}" {{eng[3]}}>{{eng[1]}}</option>
|
||||
{{endif}}
|
||||
{{endfor}}
|
||||
</select>
|
||||
</div>
|
||||
</section>
|
||||
{{endif}}
|
||||
<div class="settings-actions">
|
||||
<button type="submit" class="btn-primary">{{l("save_settings_button")}}</button>
|
||||
</div>
|
||||
</form>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user