Changeset 67 in code for trunk


Ignore:
Timestamp:
Feb 7, 2024, 12:26:14 AM (16 months ago)
Author:
yakumo.izuru
Message:

Fix bugs, many other changes

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

Location:
trunk
Files:
4 added
1 deleted
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/README.md

    r60 r67  
    22A privacy friendly frontend to multiple translation engines.
    33
    4 ### History
    5 1. SimplyTranslate was founded by [metalune and fattalion](https://codeberg.org/SimpleWeb/SimplyTranslate-Web). It was written in Python.
    6 2. Fattalion created a Go implementation.
    7 3. Both metalune and fattalion retired, and they handed SimplyTranslate over to ManeraKai.
    8 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)
    9 
    10 ### Instances
    11 | URL | Location | Cloudflare? |
    12 |-----|----------|-------------|
    13 | [tr.chaotic.ninja](https://tr.chaotic.ninja) | DE | No |
    14 
    15 ### Installation
    16 
    17 ```shell
    18 % git clone https://git.chaotic.ninja/yakumo.izuru/mai
    19 % cd mai
    20 % make
    21 # make install
    22 ```
    23 
    24 ### Setup
    25 For [nginx](https://www.nginx.com) you can use this snippet, this also serves the static resources.
    26 
    27 ```nginx
    28 location / {
    29     proxy_set_header Host $host;
    30     proxy_pass http://localhost:5000;
    31 }
    32 ```
    33 
    34 ### Legal notice
    35 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)
    36 
    37 Mai is not affiliated with none of the above, which this program relays.
    38 
    39 Trademarks belong to their respective owners.
    40 Google Translate is a trademark of [Google LLC](https://www.google.com). Reverso is a trademark of Reverso, et cetera.
    41 
    42 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.
     4* [How to install](INSTALL.md)
     5* [List of instances](INSTANCES.md)
     6* [Legal notice](LEGAL.md)
    437
    448### Other projects
  • trunk/cmd/mai/main.go

    r66 r67  
    2222var (
    2323        configfile string
     24        groupname string
     25        username string
    2426)
    2527var conf struct {
    26         group string
    2728        listen string
    2829        staticpath string
    2930        tmplpath string
    30         user string
    3131}
    3232func main() {
     
    4242        conf.tmplpath = "./views"
    4343
    44         if conf.user != "" {
    45                 uid, gid, err := usergroupids(conf.user, conf.group)
     44        if username != "" {
     45                uid, gid, err := usergroupids(username, groupname)
    4646                if err != nil {
    4747                        fmt.Println(err)
     
    259259                }
    260260        })
     261        app.Get("/robots.txt", func(c *fiber.Ctx) error {
     262                return c.SendString("User-Agent: *\nDisallow: /\n")
     263        })
    261264        app.Get("/version", func(c *fiber.Ctx) error {
    262265                return c.JSON(fiber.Map{
  • trunk/cmd/mai/parseflags.go

    r66 r67  
    88func parseFlags() {
    99        flag.StringVar(&configfile, "f", "", "Configuration file")
     10        flag.StringVar(&username, "u", "", "Sets the user to which privilege dropping is done")
     11        flag.StringVar(&groupname, "g", "", "Sets the group to which privilege dropping is done")
    1012        flag.Parse()
    1113}
  • trunk/cmd/mai/readconf.go

    r66 r67  
    1111                return err                                             
    1212        }
    13         conf.group = cfg.Section("mai").Key("group").String()
    1413        conf.listen = cfg.Section("mai").Key("listen").String()
    1514        conf.staticpath = cfg.Section("mai").Key("static").String()
    1615        conf.tmplpath = cfg.Section("mai").Key("templates").String()
    17         conf.user = cfg.Section("mai").Key("user").String()
    1816
    1917        return nil
  • trunk/cmd/mai/usergroupids.go

    r63 r67  
    1515        gid, _ := strconv.Atoi(u.Gid)
    1616
    17         if conf.group != "" {
     17        if groupname != "" {
    1818                g, err := user.LookupGroup(groupname)
    1919                if err != nil {
  • trunk/docs/api/index.html

    r66 r67  
    88        </head>
    99        <body id="body">
    10                 <h1 id="header">API Documentation</h1>
    11                 <br><hr>
    12                 <h2 class="get">[GET] /api/translate</h2>
    13                 <h2 class="post">[POST] /api/translate</h2>
    14                 <h3>Description</h3>
    15                 <p>Translation endpoint, input must be URL-encoded (e.g. multi-byte characters, words separated by space)</p>
    16                 <h3>Arguments</h3>
    17                 <ul>
    18                         <li>engine</li>
    19                         <li>from</li>
    20                         <li>text</li>
    21                         <li>to</li>
    22                 </ul>
    23                 <h3>Examples</h3>
    24                 <p><pre><code>GET /api/translate?engine=google&amp;from=auto&amp;to=en&amp;text="sonrisa"</code></pre></p>
    25                 <hr>
    26                 <h2 class="get">[GET] /api/source_languages</h2>
    27                 <h2 class="get">[GET] /api/target_languages</h2>
    28                 <h3>Description</h3>
    29                 <p>Get a JSON array of supported source and target languages for a particular engine</p>
    30                 <h3>Arguments</h3>
    31                 <ul>
    32                         <li>engine</li>
    33                 </ul>
    34                 <h3>Examples</h3>
    35                 <p><pre><code>GET /api/source_languages?engine=google</code></pre></p>
    36                 <p><pre><code>GET /api/target_languages?engine=google</code></pre></p>
    37                 <hr>
    38                 <h2 class="get">[GET] /api/tts</h2>
    39                 <h3>Description</h3>
    40                 <p>Obtain text-to-speech audio files from an engine, provided said engine supports them</p>
    41                 <h3>Arguments</h3>
    42                 <ul>
    43                         <li>engine</li>
    44                         <li>lang</li>
    45                         <li>text</li>
    46                 </ul>
    47                 <h3>Examples</h3>
    48                 <p><pre><code>GET /api/tts?engine=google&amp;lang=en&amp;text="hi"</code></pre></p>
    49                 <hr>
    50                 <h2 class="post">[POST] /switchlanguages</h2>
    51                 <h3>Description</h3>
    52                 <p>Switch between source and target languages, as long as the source language isn't "auto"</p>
    53                 <hr>
     10                <h1>API documentation</h1>
     11                <table border="1" align="center">
     12                        <tr>
     13                                <td>
     14                                        <h2 class="get">[GET] /api/translate</h2>
     15                                        <h2 class="post">[POST] /api/translate</h2>
     16                                        <h3>Description</h3>
     17                                        <p>Translation endpoint, input must be URL-encoded (e.g. multi-byte characters, words separated by space)</p>
     18                                        <h3>Arguments</h3>
     19                                        <ul>
     20                                                <li>engine</li>
     21                                                <li>from</li>
     22                                                <li>text</li>
     23                                                <li>to</li>
     24                                        </ul>
     25                                </td>
     26                        </tr>
     27                        <tr>
     28                                <td>
     29                                        <h2 class="get">[GET] /api/source_languages</h2>
     30                                        <h2 class="get">[GET] /api/target_languages</h2>
     31                                        <h3>Description</h3>
     32                                        <p>Get a JSON array of supported source and target languages for a particular engine</p>
     33                                        <h3>Arguments</h3>
     34                                        <ul>
     35                                                <li>engine</li>
     36                                        </ul>
     37                                </td>
     38                        </tr>
     39                        <tr>
     40                                <td>
     41                                        <h2 class="get">[GET] /api/tts</h2>
     42                                        <h3>Description</h3>
     43                                        <p>Obtain text-to-speech audio files from an engine, provided said engine supports them</p>
     44                                        <h3>Arguments</h3>
     45                                        <ul>
     46                                                <li>engine</li>
     47                                                <li>lang</li>
     48                                                <li>text</li>
     49                                        </ul>
     50                                </td>
     51                        </tr>
     52                        <tr>
     53                                <td>
     54                                        <h2 class="get">[GET] /robots.txt</h2>
     55                                </td>
     56                        </tr>
     57                        <tr>
     58                                <td>
     59                                        <h2 class="post">[POST] /switchlanguages</h2>
     60                                        <h3>Description</h3>
     61                                        <p>Switch between source and target languages, as long as the source language isn't "auto"</p>
     62                                        <p>Must only be called inside the form interface</p>
     63                                </td>
     64                        </tr>
     65                        <tr>
     66                                <td>
     67                                        <h2 class="get">[GET] /version</h2>
     68                                        <h3>Description</h3>
     69                                        <p>Return the software version as a JSON array</p>
     70                                </td>
     71                        </tr>
     72                </table>
    5473        </body>
    5574</html>
  • trunk/docs/index.html

    r66 r67  
    77                <title>Mai | Documentation</title>
    88        </head>
    9         <body id="body">
    10                 <img src="/static/favicon128x128.png" style="text-align: center;">
    11                 <h1 id="header">Documentation</h1>
    12                 <ul id="nav">
    13                         <li><a href="/docs/api">API</a></li>
    14                 </ul>
     9        <body>
     10                <table>
     11                        <tr><td>
     12                                        <table border="1" align="left">
     13                                                <tr>
     14                                                        <td><a href="/docs/api">API</a></td>
     15                                                </tr>
     16                                        </table>
     17                        </tr></td>
     18                        <tr><td>
     19                                        <table border="1" align="center">
     20                                                <tr>
     21                                                        <td>
     22                                                                <p>Welcome to Mai's documentation!<p>
     23                                                                <p>See the menu for the available entries</p>
     24                                                                <p>Anything else is covered by the man pages</p>
     25                                                        </td>
     26                                                </tr>
     27                                        </table>
     28                                </td></tr>
     29                </table>
    1530        </body>
    1631</html>
  • trunk/docs/style.css

    r66 r67  
    1 /*
    2  * Taken from vnpower
    3  */
    4 
    5 * {
    6   box-sizing: border-box; }
    7 
    81body {
    9   top: 0;
    10   margin: 0;
    11   background-color: #1d1f21;
    12   color: white;
    13   font-family: "Open Sans", "Roboto", "Noto Sans", "Noto Sans CJK JP", sans-serif;
    14   line-height: 1.618;
     2        background-color: #f8cfd2;
     3        color: rgb(206, 147, 191);
    154}
    165
    17 h2.get {
    18         color: orange;
     6a, a:visited {
     7        color: rgb(206, 147, 191);
    198}
    209
    21 h2.post {
    22         color: green;
     10@media screen and (prefers-color-scheme: dark) {
     11        body {
     12                background-color: #700000;
     13                color: #ffffff;
     14        }
     15        a, a:visited {
     16                color: #18c018;
     17        }
    2318}
    2419
    25 @media (max-width: 684px) {
    26   body {
    27     font-size: 1rem; } }
    28 
    29 @media (max-width: 382px) {
    30   body {
    31     font-size: 1rem; } }
    32 
    33 a {
    34   color: #81a2be;
    35   text-decoration-color: #81a2be; }
    36 
    37 #header {
    38   width: 100%;
    39   min-width: 320px;
    40   background-color: #282a2e; }
    41 
    42 #header img {
    43   width: 280px; }
    44 
    45 #header-content {
    46   margin: 0 auto;
    47   width: min-content; }
    48 
    49 #nav {
    50   display: flex;
    51   justify-content: center;
    52   background-color: #373b41; }
    53 
    54 #footer {
    55   margin-top: 0.5rem;
    56   text-align: center; }
    57 
    58 #body {
    59   min-height: 75vh;
    60   max-width: 800px;
    61   margin: 1rem auto;
    62   padding: 0 0.6rem; }
    63   #body h1,
    64   #body h2,
    65   #body h3,
    66   #body h4,
    67   #body h5,
    68   #body h6 {
    69     line-height: 1.1;
    70     font-family: sans-serif;
    71     font-weight: 700;
    72     margin-top: 1rem;
    73     margin-bottom: 1rem;
    74     overflow-wrap: break-word;
    75     word-wrap: break-word;
    76     -ms-word-break: break-all;
    77     word-break: break-word; }
    78   #body h1 {
    79     border-bottom: 1px solid #b5bd68;
    80     display: block; }
    81   #body p {
    82     margin-top: 0px;
    83     margin-bottom: 0.5rem; }
    84   #body li > p {
    85     padding: 0;
    86     margin: 0; }
    87   #body small,
    88   #body sub,
    89   #body sup {
    90     font-size: 75%; }
    91   #body img,
    92   #body video {
    93     height: auto;
    94     max-width: 100%;
    95     margin-top: 0.5rem;
    96     margin-bottom: 0.5rem;
    97     box-shadow: 0px 1px 1px 0px rgba(0, 0, 0, 0.12), 0px 2px 2px 0px rgba(0, 0, 0, 0.12), 0px 4px 4px 0px rgba(0, 0, 0, 0.12), 0px 8px 8px 0px rgba(0, 0, 0, 0.12), 0px 16px 16px 0px rgba(0, 0, 0, 0.12); }
    98   #body pre {
    99     background-color: #373b41;
    100     display: block;
    101     padding: 1em;
    102     overflow-x: auto;
    103     margin-top: 0px;
    104     margin-bottom: 0.5rem; }
    105   #body code, #body kbd, #body samp {
    106     padding: 0 0.5em;
    107     background-color: #373b41;
    108     white-space: pre-wrap; }
    109   #body pre > code {
    110     padding: 0;
    111     background-color: transparent;
    112     white-space: pre;
    113     font-size: 1em; }
    114 
     20table {
     21        border-color: white;
     22}
  • trunk/engines/engine.go

    r60 r67  
    2525        "google": &GoogleTranslate{},
    2626        "reverso": &Reverso{},
    27         "iciba": &ICIBA{},
    2827        "libretranslate": &LibreTranslate{
    2928                InstanceURL: os.Getenv("MAI_LIBRETRANSLATE_INSTANCE"),
  • trunk/example/mai.ini

    r66 r67  
    33rootdir = "./static"
    44tmplpath = "./views"
    5 user = "www"
  • trunk/mai.1

    r65 r67  
    88.Nm
    99.Op Fl f Ar config-file
     10.Op Fl u Ar user
     11.Op Fl g Ar group
    1012.Sh DESCRIPTION
    1113This project has been forked from the remains of the
     
    1517Much to anyone's dismay, this was named after
    1618.Lk https://en.touhouwiki.net/wiki/Mai Mai from Mystic Square
     19.Sh FEATURES
     20.Bl -tag -width 11n -compact
     21.It Command-line tool
     22See
     23.Xr suwako 1
     24.It Privilege dropping
     25Stolen from
     26.Xr partage 1
     27just so you do not run this as root
     28.El
    1729.Sh AUTHORS
    1830.An fattalion
     
    2133.Sh MAINTAINERS
    2234.An Izuru Yakumo Aq Mt yakumo.izuru@chaotic.ninja
    23 .Sh BUGS
    24 iCIBA engine doesn't work, throws HTTP 500
  • trunk/mai.ini.5

    r63 r67  
    88.Ss [mai] section
    99.Bl -tag -width 11n
    10 .It group
    11 Group ID for dropping privileges to.
    12 If unset, assume the GID of user
    1310.It listen
    1411HTTP port for the server to listen.
     
    2017Directory where the templates are located.
    2118Default is "./views"
    22 .It user
    23 User ID for dropping privileges to.
    2419.El
    2520.Sh ENVIRONMENT
  • trunk/rc.d/FreeBSD

    r66 r67  
    2121command="/usr/sbin/daemon"
    2222procname="/usr/local/bin/${name}"
    23 mai_args="-f ${mai_config}"
     23mai_args="-f ${mai_config} -u www -g www"
    2424command_args="-S -m 3 -s info -l daemon -p ${pidfile} /usr/bin/env ${procname} ${mai_args}"
    2525
  • trunk/rc.d/NetBSD

    r66 r67  
    1212rcvar=$name
    1313command="/usr/pkg/bin/mai"
    14 command_args="-f /usr/pkg/etc/mai/mai.ini"
     14command_args="-f /usr/pkg/etc/mai/mai.ini -u www -g www"
    1515pidfile="/var/run/${name}.pid"
    1616start_cmd="mai_start"
  • trunk/rc.d/OpenBSD

    r56 r67  
    33
    44daemon="/usr/local/bin/mai"
    5 daemon_flags="-f /usr/local/etc/mai/mai.ini"
     5daemon_flags="-f /usr/local/etc/mai/mai.ini -u www -g www"
    66
    77. /etc/rc.d/rc.subr
  • trunk/rc.d/immortal.yml

    r66 r67  
    1 cmd: /usr/local/bin/mai -f /usr/local/etc/mai/mai.ini
     1cmd: /usr/local/bin/mai -f /usr/local/etc/mai/mai.ini -g www -u www
     2cwd: /usr/local/share/mai
  • trunk/views/index.html

    r56 r67  
    128128    <footer class="center">
    129129            <p>
    130             <a href="https://git.chaotic.ninja/yakumo.izuru/mai">Source code</a><br>
    131             a <em>Mirage AIB</em> project | Favicon source is <a href="https://pixiv.net/en/artworks/97787072">ユキマイ</a>
     130            <a href="https://git.chaotic.ninja/yakumo.izuru/mai">Source code</a>
     131            </p>
     132            <p>
     133            A <a href="https://mirage.h0stname.net">Mirage AIB</a> project
    132134            </p>
    133135    </footer>
Note: See TracChangeset for help on using the changeset viewer.