From b860f0610b3f8dd232c70051c66e2728532f7edd Mon Sep 17 00:00:00 2001
From: "yakumo.izuru"
Date: Wed, 7 Feb 2024 00:26:14 +0000
Subject: [PATCH] Fix bugs, many other changes
Signed-off-by: Izuru Yakumo
git-svn-id: file:///srv/svn/repo/mai/trunk@67 e410bdd4-646f-c54f-a7ce-fffcc4f439ae
---
HISTORY.md | 13 ++
INSTALL.md | 11 ++
INSTANCES.md | 6 +
LEGAL.md | 9 ++
README.md | 42 +-----
cmd/mai/main.go | 11 +-
cmd/mai/parseflags.go | 2 +
cmd/mai/readconf.go | 2 -
cmd/mai/usergroupids.go | 2 +-
docs/api/index.html | 107 ++++++++-------
docs/index.html | 27 +++-
docs/style.css | 122 +++--------------
engines/engine.go | 1 -
engines/iciba.go | 283 ----------------------------------------
example/mai.ini | 1 -
mai.1 | 14 +-
mai.ini.5 | 5 -
rc.d/FreeBSD | 2 +-
rc.d/NetBSD | 2 +-
rc.d/OpenBSD | 2 +-
rc.d/immortal.yml | 3 +-
views/index.html | 6 +-
22 files changed, 172 insertions(+), 501 deletions(-)
create mode 100644 HISTORY.md
create mode 100644 INSTALL.md
create mode 100644 INSTANCES.md
create mode 100644 LEGAL.md
delete mode 100644 engines/iciba.go
diff --git a/HISTORY.md b/HISTORY.md
new file mode 100644
index 0000000..1b03492
--- /dev/null
+++ b/HISTORY.md
@@ -0,0 +1,13 @@
+## 2021
+[SimplyTranslate](https://codeberg.org/SimpleWeb/SimplyTranslate-Web) was founded by metalune and fattalion.
+It was written in Python and used the Quart framework.
+
+## 2022
+fattalion created a Go implementation.
+
+## 2023
+* Both metalune and fattalion retired, and they handed SimplyTranslate over to [ManeraKai](https://manerakai.com).
+* Arya K. from [~vern](https://vern.cc) made a hard-fork named [Mozhi](https://codeberg.org/aryak/mozhi) and has vastly refactored it.
+
+## 2024
+Izuru Yakumo took interest in SimplyTranslate and decided to fork it in October 2023, and in January he turned it into a hard-fork, eventually renaming it to "Mai", after a character from the fifth [Touhou Project](https://en.touhouwiki.net/wiki/Touhou_Project) game, [Mai](https://en.touhouwiki.net/wiki/Mai).
diff --git a/INSTALL.md b/INSTALL.md
new file mode 100644
index 0000000..f3ca296
--- /dev/null
+++ b/INSTALL.md
@@ -0,0 +1,11 @@
+# Installation
+
+```shell
+$ git clone https://git.chaotic.ninja/yakumo.izuru/mai
+$ cd mai
+$ make
+# make PREFIX=/usr/local install
+```
+* Read the [mai.ini(5)](mai.ini.5) manual page
+* Use any web server than is able to reverse proxy, like Apache, h2o, or NGINX.
+
diff --git a/INSTANCES.md b/INSTANCES.md
new file mode 100644
index 0000000..0e9f011
--- /dev/null
+++ b/INSTANCES.md
@@ -0,0 +1,6 @@
+# List of known instances
+
+* [tr.chaotic.ninja](https://tr.chaotic.ninja)
+ * Location: Germany
+ * Cloudflare: No
+
diff --git a/LEGAL.md b/LEGAL.md
new file mode 100644
index 0000000..4c35c76
--- /dev/null
+++ b/LEGAL.md
@@ -0,0 +1,9 @@
+Mai does not host any content. All content shown on any Mai instances is from [Google Translate](https://translate.google.com), [Reverso](https://www.reverso.net/), and [LibreTranslate](https://libretranslate.com)
+
+Mai is not affiliated with none of the above, which this program relays.
+
+Trademarks belong to their respective owners.
+Google Translate is a trademark of [Google LLC](https://www.google.com). Reverso is a trademark of Reverso, et cetera.
+
+The creators and maintainers of this repository assume no liability for the accuracy and timeliness of any information provided above. Trademark owner information was researched to the best of the author's knowledge at the time of curation and may be outdated or incorrect.
+
diff --git a/README.md b/README.md
index 29b1f5a..f2bf040 100644
--- a/README.md
+++ b/README.md
@@ -1,45 +1,9 @@
## Mai
A privacy friendly frontend to multiple translation engines.
-### History
-1. SimplyTranslate was founded by [metalune and fattalion](https://codeberg.org/SimpleWeb/SimplyTranslate-Web). It was written in Python.
-2. Fattalion created a Go implementation.
-3. Both metalune and fattalion retired, and they handed SimplyTranslate over to ManeraKai.
-4. [Izuru Yakumo The Violet Hermit](https://geidontei.chaotic.ninja/usr/yakumo_izuru) stole it, and renamed it after [Mai](https://en.touhouwiki.net/wiki/Mai) from [Mystic Square](https://en.touhouwiki.net/wiki/Mystic_Square)
-
-### Instances
-| URL | Location | Cloudflare? |
-|-----|----------|-------------|
-| [tr.chaotic.ninja](https://tr.chaotic.ninja) | DE | No |
-
-### Installation
-
-```shell
-% git clone https://git.chaotic.ninja/yakumo.izuru/mai
-% cd mai
-% make
-# make install
-```
-
-### Setup
-For [nginx](https://www.nginx.com) you can use this snippet, this also serves the static resources.
-
-```nginx
-location / {
- proxy_set_header Host $host;
- proxy_pass http://localhost:5000;
-}
-```
-
-### Legal notice
-Mai does not host any content. All content shown on any Mai instances is from [Google Translate](https://translate.google.com), [Reverso](https://www.reverso.net/), [iCIBA](https://www.iciba.net) and [LibreTranslate](https://libretranslate.com)
-
-Mai is not affiliated with none of the above, which this program relays.
-
-Trademarks belong to their respective owners.
-Google Translate is a trademark of [Google LLC](https://www.google.com). Reverso is a trademark of Reverso, et cetera.
-
-The creators and maintainers of this repository assume no liability for the accuracy and timeliness of any information provided above. Trademark owner information was researched to the best of the author's knowledge at the time of curation and may be outdated or incorrect.
+* [How to install](INSTALL.md)
+* [List of instances](INSTANCES.md)
+* [Legal notice](LEGAL.md)
### Other projects
* [Mozhi](https://codeberg.org/aryak/mozhi), also a fork of SimplyTranslate
diff --git a/cmd/mai/main.go b/cmd/mai/main.go
index bd17042..65922bf 100644
--- a/cmd/mai/main.go
+++ b/cmd/mai/main.go
@@ -21,13 +21,13 @@ import (
)
var (
configfile string
+ groupname string
+ username string
)
var conf struct {
- group string
listen string
staticpath string
tmplpath string
- user string
}
func main() {
parseFlags()
@@ -41,8 +41,8 @@ func main() {
conf.staticpath = "./static"
conf.tmplpath = "./views"
- if conf.user != "" {
- uid, gid, err := usergroupids(conf.user, conf.group)
+ if username != "" {
+ uid, gid, err := usergroupids(username, groupname)
if err != nil {
fmt.Println(err)
os.Exit(1)
@@ -258,6 +258,9 @@ func main() {
}
}
})
+ app.Get("/robots.txt", func(c *fiber.Ctx) error {
+ return c.SendString("User-Agent: *\nDisallow: /\n")
+ })
app.Get("/version", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"fiberversion": fiber.Version,
diff --git a/cmd/mai/parseflags.go b/cmd/mai/parseflags.go
index dda2529..4969f9e 100644
--- a/cmd/mai/parseflags.go
+++ b/cmd/mai/parseflags.go
@@ -7,5 +7,7 @@ import (
func parseFlags() {
flag.StringVar(&configfile, "f", "", "Configuration file")
+ flag.StringVar(&username, "u", "", "Sets the user to which privilege dropping is done")
+ flag.StringVar(&groupname, "g", "", "Sets the group to which privilege dropping is done")
flag.Parse()
}
diff --git a/cmd/mai/readconf.go b/cmd/mai/readconf.go
index 9e86bb3..c184797 100644
--- a/cmd/mai/readconf.go
+++ b/cmd/mai/readconf.go
@@ -10,11 +10,9 @@ func readConf(file string) error {
if err != nil {
return err
}
- conf.group = cfg.Section("mai").Key("group").String()
conf.listen = cfg.Section("mai").Key("listen").String()
conf.staticpath = cfg.Section("mai").Key("static").String()
conf.tmplpath = cfg.Section("mai").Key("templates").String()
- conf.user = cfg.Section("mai").Key("user").String()
return nil
}
diff --git a/cmd/mai/usergroupids.go b/cmd/mai/usergroupids.go
index dd4b609..e3d7ced 100644
--- a/cmd/mai/usergroupids.go
+++ b/cmd/mai/usergroupids.go
@@ -14,7 +14,7 @@ func usergroupids(username string, groupname string) (int, int, error) {
uid, _ := strconv.Atoi(u.Uid)
gid, _ := strconv.Atoi(u.Gid)
- if conf.group != "" {
+ if groupname != "" {
g, err := user.LookupGroup(groupname)
if err != nil {
return uid, -1, err
diff --git a/docs/api/index.html b/docs/api/index.html
index ef9b03e..4a96142 100644
--- a/docs/api/index.html
+++ b/docs/api/index.html
@@ -7,49 +7,68 @@
API Documentation | Mai
-
-
- [GET] /api/translate
- [POST] /api/translate
- Description
- Translation endpoint, input must be URL-encoded (e.g. multi-byte characters, words separated by space)
- Arguments
-
- - engine
- - from
- - text
- - to
-
- Examples
- GET /api/translate?engine=google&from=auto&to=en&text="sonrisa"
-
- [GET] /api/source_languages
- [GET] /api/target_languages
- Description
- Get a JSON array of supported source and target languages for a particular engine
- Arguments
-
- Examples
- GET /api/source_languages?engine=google
- GET /api/target_languages?engine=google
-
- [GET] /api/tts
- Description
- Obtain text-to-speech audio files from an engine, provided said engine supports them
- Arguments
-
- Examples
- GET /api/tts?engine=google&lang=en&text="hi"
-
- [POST] /switchlanguages
- Description
- Switch between source and target languages, as long as the source language isn't "auto"
-
+ API documentation
+
+
+
+ [GET] /api/translate
+ [POST] /api/translate
+ Description
+ Translation endpoint, input must be URL-encoded (e.g. multi-byte characters, words separated by space)
+ Arguments
+
+ - engine
+ - from
+ - text
+ - to
+
+ |
+
+
+
+ [GET] /api/source_languages
+ [GET] /api/target_languages
+ Description
+ Get a JSON array of supported source and target languages for a particular engine
+ Arguments
+
+ |
+
+
+
+ [GET] /api/tts
+ Description
+ Obtain text-to-speech audio files from an engine, provided said engine supports them
+ Arguments
+
+ |
+
+
+
+ [GET] /robots.txt
+ |
+
+
+
+ [POST] /switchlanguages
+ Description
+ Switch between source and target languages, as long as the source language isn't "auto"
+ Must only be called inside the form interface
+ |
+
+
+
+ [GET] /version
+ Description
+ Return the software version as a JSON array
+ |
+
+