Skip to content

Commit 30dc0bd

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix-ssh-server
2 parents c01ea7c + 2448c5a commit 30dc0bd

File tree

43 files changed

+1282
-338
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1282
-338
lines changed

cmd/admin.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var (
5656
microcmdUserList,
5757
microcmdUserChangePassword,
5858
microcmdUserDelete,
59+
microcmdUserGenerateAccessToken,
5960
},
6061
}
6162

@@ -154,6 +155,27 @@ var (
154155
Action: runDeleteUser,
155156
}
156157

158+
microcmdUserGenerateAccessToken = cli.Command{
159+
Name: "generate-access-token",
160+
Usage: "Generate a access token for a specific user",
161+
Flags: []cli.Flag{
162+
cli.StringFlag{
163+
Name: "username,u",
164+
Usage: "Username",
165+
},
166+
cli.StringFlag{
167+
Name: "token-name,t",
168+
Usage: "Token name",
169+
Value: "gitea-admin",
170+
},
171+
cli.BoolFlag{
172+
Name: "raw",
173+
Usage: "Display only the token value",
174+
},
175+
},
176+
Action: runGenerateAccessToken,
177+
}
178+
157179
subcmdRepoSyncReleases = cli.Command{
158180
Name: "repo-sync-releases",
159181
Usage: "Synchronize repository releases with tags",
@@ -641,6 +663,41 @@ func runDeleteUser(c *cli.Context) error {
641663
return user_service.DeleteUser(user)
642664
}
643665

666+
func runGenerateAccessToken(c *cli.Context) error {
667+
if !c.IsSet("username") {
668+
return fmt.Errorf("You must provide the username to generate a token for them")
669+
}
670+
671+
ctx, cancel := installSignals()
672+
defer cancel()
673+
674+
if err := initDB(ctx); err != nil {
675+
return err
676+
}
677+
678+
user, err := user_model.GetUserByName(c.String("username"))
679+
if err != nil {
680+
return err
681+
}
682+
683+
t := &models.AccessToken{
684+
Name: c.String("token-name"),
685+
UID: user.ID,
686+
}
687+
688+
if err := models.NewAccessToken(t); err != nil {
689+
return err
690+
}
691+
692+
if c.Bool("raw") {
693+
fmt.Printf("%s\n", t.Token)
694+
} else {
695+
fmt.Printf("Access token was successfully created: %s\n", t.Token)
696+
}
697+
698+
return nil
699+
}
700+
644701
func runRepoSyncReleases(_ *cli.Context) error {
645702
ctx, cancel := installSignals()
646703
defer cancel()

contrib/init/openwrt/gitea

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh /etc/rc.common
2+
3+
USE_PROCD=1
4+
5+
# PROCD_DEBUG=1
6+
7+
START=90
8+
STOP=10
9+
10+
PROG=/opt/gitea/gitea
11+
GITEA_WORK_DIR=/opt/gitea
12+
CONF_FILE=$GITEA_WORK_DIR/app.ini
13+
14+
start_service(){
15+
procd_open_instance gitea
16+
procd_set_param env GITEA_WORK_DIR=$GITEA_WORK_DIR
17+
procd_set_param env HOME=$GITEA_WORK_DIR
18+
procd_set_param command $PROG web -c $CONF_FILE
19+
procd_set_param file $CONF_FILE
20+
procd_set_param user git
21+
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} # respawn automatically if something died, be careful if you have an alternative process supervisor
22+
procd_close_instance
23+
}
24+
25+
start(){
26+
service_start $PROG
27+
}
28+
29+
stop(){
30+
service_stop $PROG
31+
}
32+
33+
reload(){
34+
service_reload $PROG
35+
}

contrib/update_dependencies.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ grep 'git' go.mod | grep '\.com' | grep -v indirect | grep -v replace | cut -f 2
44
go get -u "$line"
55
make vendor
66
git add .
7-
git commit -S -m "update $line"
7+
git commit -m "update $line"
88
done

contrib/upgrade.sh

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/usr/bin/env bash
2-
set -euo pipefail
3-
42
# This is an update script for gitea installed via the binary distribution
53
# from dl.gitea.io on linux as systemd service. It performs a backup and updates
64
# Gitea in place.
@@ -13,41 +11,83 @@ set -euo pipefail
1311
# upgrade.sh 1.15.10
1412
# giteahome=/opt/gitea giteaconf=$giteahome/app.ini upgrade.sh
1513

14+
while true; do
15+
case "$1" in
16+
-v | --version ) ver="$2"; shift 2 ;;
17+
-y | --yes ) no_confirm="yes"; shift ;;
18+
--ignore-gpg) ignore_gpg="yes"; shift ;;
19+
-- ) shift; break ;;
20+
* ) break ;;
21+
esac
22+
done
23+
24+
set -euo pipefail
25+
26+
27+
function require {
28+
for exe in "$@"; do
29+
command -v "$exe" &>/dev/null || (echo "missing dependency '$exe'"; exit 1)
30+
done
31+
}
32+
33+
34+
require curl xz sha256sum gpg
35+
36+
if [[ -f /etc/os-release ]]; then
37+
os_release=$(cat /etc/os-release)
38+
39+
if [[ "$os_release" =~ "OpenWrt" ]]; then
40+
sudocmd="su"
41+
service_start="/etc/init.d/gitea start"
42+
service_stop="/etc/init.d/gitea stop"
43+
service_status="/etc/init.d/gitea status"
44+
else
45+
require systemctl
46+
fi
47+
fi
48+
49+
1650
# apply variables from environment
1751
: "${giteabin:="/usr/local/bin/gitea"}"
1852
: "${giteahome:="/var/lib/gitea"}"
1953
: "${giteaconf:="/etc/gitea/app.ini"}"
2054
: "${giteauser:="git"}"
2155
: "${sudocmd:="sudo"}"
2256
: "${arch:="linux-amd64"}"
57+
: "${service_start:="$sudocmd systemctl start gitea"}"
58+
: "${service_stop:="$sudocmd systemctl stop gitea"}"
59+
: "${service_status:="$sudocmd systemctl status gitea"}"
2360
: "${backupopts:=""}" # see `gitea dump --help` for available options
2461

25-
function giteacmd {
26-
"$sudocmd" --user "$giteauser" "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@"
27-
}
2862

29-
function require {
30-
for exe in "$@"; do
31-
command -v "$exe" &>/dev/null || (echo "missing dependency '$exe'"; exit 1)
32-
done
63+
function giteacmd {
64+
if [[ $sudocmd = "su" ]]; then
65+
"$sudocmd" - "$giteauser" -c "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@"
66+
else
67+
"$sudocmd" --user "$giteauser" "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@"
68+
fi
3369
}
34-
require systemctl curl xz sha256sum gpg "$sudocmd"
3570

3671
# select version to install
37-
if [[ -z "${1:-}" ]]; then
72+
if [[ -z "${ver:-}" ]]; then
3873
require jq
3974
giteaversion=$(curl --connect-timeout 10 -sL https://dl.gitea.io/gitea/version.json | jq -r .latest.version)
4075
else
41-
giteaversion="$1"
76+
giteaversion="$ver"
4277
fi
4378

79+
4480
# confirm update
45-
current=$(giteacmd --version | cut --delimiter=' ' --fields=3)
81+
current=$(giteacmd --version | cut -d ' ' -f 3)
4682
[[ "$current" == "$giteaversion" ]] && echo "$current is already installed, stopping." && exit 1
47-
echo "Make sure to read the changelog first: https://github.com/go-gitea/gitea/blob/main/CHANGELOG.md"
48-
echo "Are you ready to update Gitea from ${current} to ${giteaversion}? (y/N)"
49-
read -r confirm
50-
[[ "$confirm" == "y" ]] || [[ "$confirm" == "Y" ]] || exit 1
83+
if [[ -z "${no_confirm:-}" ]]; then
84+
echo "Make sure to read the changelog first: https://github.com/go-gitea/gitea/blob/main/CHANGELOG.md"
85+
echo "Are you ready to update Gitea from ${current} to ${giteaversion}? (y/N)"
86+
read -r confirm
87+
[[ "$confirm" == "y" ]] || [[ "$confirm" == "Y" ]] || exit 1
88+
fi
89+
90+
echo "Upgrading gitea from $current to $giteaversion ..."
5191

5292
pushd "$(pwd)" &>/dev/null
5393
cd "$giteahome" # needed for gitea dump later
@@ -59,9 +99,11 @@ echo "Downloading $binurl..."
5999
curl --connect-timeout 10 --silent --show-error --fail --location -O "$binurl{,.sha256,.asc}"
60100

61101
# validate checksum & gpg signature (exit script if error)
62-
sha256sum --check "${binname}.xz.sha256"
63-
gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
64-
gpg --verify "${binname}.xz.asc" "${binname}.xz" || { echo 'Signature does not match'; exit 1; }
102+
sha256sum -c "${binname}.xz.sha256"
103+
if [[ -z "${ignore_gpg:-}" ]]; then
104+
gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
105+
gpg --verify "${binname}.xz.asc" "${binname}.xz" || { echo 'Signature does not match'; exit 1; }
106+
fi
65107
rm "${binname}".xz.{sha256,asc}
66108

67109
# unpack binary + make executable
@@ -72,12 +114,14 @@ chmod +x "$binname"
72114
# stop gitea, create backup, replace binary, restart gitea
73115
echo "Stopping gitea at $(date)"
74116
giteacmd manager flush-queues
75-
$sudocmd systemctl stop gitea
117+
$service_stop
76118
echo "Creating backup in $giteahome"
77119
giteacmd dump $backupopts
78120
echo "Updating binary at $giteabin"
79-
mv --force --backup "$binname" "$giteabin"
80-
$sudocmd systemctl start gitea
81-
$sudocmd systemctl status gitea
121+
cp -f "$giteabin" "$giteabin.bak" && mv -f "$binname" "$giteabin"
122+
$service_start
123+
$service_status
124+
125+
echo "Upgrade to $giteaversion successful!"
82126

83127
popd

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,8 @@ PATH =
21252125
;RENDER_COMMAND = "asciidoc --out-file=- -"
21262126
;; Don't pass the file on STDIN, pass the filename as argument instead.
21272127
;IS_INPUT_FILE = false
2128+
; Don't filter html tags and attributes if true
2129+
;DISABLE_SANITIZER = false
21282130

21292131
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21302132
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ params:
1818
description: Git with a cup of tea
1919
author: The Gitea Authors
2020
website: https://docs.gitea.io
21-
version: 1.16.0
21+
version: 1.16.3
2222
minGoVersion: 1.16
2323
goVersion: 1.17
2424
minNodeVersion: 12.17

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,13 +1003,13 @@ IS_INPUT_FILE = false
10031003
command. Multiple extensions needs a comma as splitter.
10041004
- RENDER\_COMMAND: External command to render all matching extensions.
10051005
- IS\_INPUT\_FILE: **false** Input is not a standard input but a file param followed `RENDER_COMMAND`.
1006+
- DISABLE_SANITIZER: **false** Don't filter html tags and attributes if true. Don't change this to true except you know what that means.
10061007

10071008
Two special environment variables are passed to the render command:
10081009
- `GITEA_PREFIX_SRC`, which contains the current URL prefix in the `src` path tree. To be used as prefix for links.
10091010
- `GITEA_PREFIX_RAW`, which contains the current URL prefix in the `raw` path tree. To be used as prefix for image paths.
10101011

1011-
1012-
Gitea supports customizing the sanitization policy for rendered HTML. The example below will support KaTeX output from pandoc.
1012+
If `DISABLE_SANITIZER` is false, Gitea supports customizing the sanitization policy for rendered HTML. The example below will support KaTeX output from pandoc.
10131013

10141014
```ini
10151015
[markup.sanitizer.TeX]

docs/content/doc/advanced/config-cheat-sheet.zh-cn.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,33 @@ IS_INPUT_FILE = false
318318
- FILE_EXTENSIONS: 关联的文档的扩展名,多个扩展名用都好分隔。
319319
- RENDER_COMMAND: 工具的命令行命令及参数。
320320
- IS_INPUT_FILE: 输入方式是最后一个参数为文件路径还是从标准输入读取。
321+
- DISABLE_SANITIZER: **false** 如果为 true 则不过滤 HTML 标签和属性。除非你知道这意味着什么,否则不要设置为 true。
322+
323+
以下两个环境变量将会被传递给渲染命令:
324+
325+
- `GITEA_PREFIX_SRC`:包含当前的`src`路径的URL前缀,可以被用于链接的前缀。
326+
- `GITEA_PREFIX_RAW`:包含当前的`raw`路径的URL前缀,可以被用于图片的前缀。
327+
328+
如果 `DISABLE_SANITIZER` 为 false,则 Gitea 支持自定义渲染 HTML 的净化策略。以下例子将用 pandoc 支持 KaTeX 输出。
329+
330+
```ini
331+
[markup.sanitizer.TeX]
332+
; Pandoc renders TeX segments as <span>s with the "math" class, optionally
333+
; with "inline" or "display" classes depending on context.
334+
ELEMENT = span
335+
ALLOW_ATTR = class
336+
REGEXP = ^\s*((math(\s+|$)|inline(\s+|$)|display(\s+|$)))+
337+
ALLOW_DATA_URI_IMAGES = true
338+
```
339+
340+
- `ELEMENT`: 将要被应用到该策略的 HTML 元素,不能为空。
341+
- `ALLOW_ATTR`: 将要被应用到该策略的属性,不能为空。
342+
- `REGEXP`: 正则表达式,用来匹配属性的内容。如果为空,则跟属性内容无关。
343+
- `ALLOW_DATA_URI_IMAGES`: **false** 允许 data uri 图片 (`<img src="data:image/png;base64,..."/>`)。
344+
345+
多个净化规则可以被同时定义,只要section名称最后一位不重复即可。如: `[markup.sanitizer.TeX-2]`
346+
为了针对一种渲染类型进行一个特殊的净化策略,必须使用形如 `[markup.sanitizer.asciidoc.rule-1]` 的方式来命名 seciton。
347+
如果此规则没有匹配到任何渲染类型,它将会被应用到所有的渲染类型。
321348

322349
## Time (`time`)
323350

0 commit comments

Comments
 (0)