Commit graph

478 commits

Author SHA1 Message Date
TomZ 743d1e34ac
[BRANDING] cosmetic s/Gitea/Forgejo/ in logs, messages, etc.
As the docs of codeberg refer to the strings printed by the Forgejo
ssh servers, this is user-facing and is nice to update to the new
product name.

(cherry picked from commit 103991d73f0f78f31a5f1dae47824c2fe481bcc6)
(cherry picked from commit 2a0d3f85f199d28a4180becdebcb90af0d6f3504)
(cherry picked from commit eb2b4ce388810dc145dd90d3358d4d4373e31b80)
(cherry picked from commit 0998b51716ef5d3c25e139886aa8b7bfde703b20)

[BRANDING] forgejo log message

(cherry picked from commit d51a046ebe774236f8b902c45486dc8cbd041e0e)
(cherry picked from commit d66e1c7b6e2fbfefb976103805b18eb29b6406af)
(cherry picked from commit b5bffe4ce8a8353c9e5529350a7932d4a2d9e53e)
(cherry picked from commit 3fa776d8566c42ce31540024ce5bf5a6cb5cd4e4)
(cherry picked from commit 18d064f47214327dc5b6c55c2d02a3da53358dbc)
(cherry picked from commit c95094e355212d4baf607f3778152ceb455d4f82)
(cherry picked from commit 5784290bc46afffca9b93e0faa3bd88944e54919)
(cherry picked from commit aee336886b2606beaf8c27a2992c21aa2a574966)
(cherry picked from commit ec2f60b516b1ee11b5e7c52ecb02fdf8e5bbcaec)
(cherry picked from commit 7af742a28469d6725248d5519e69217b844ed792)
(cherry picked from commit f279e2a264ae028ab511ba61a71e00739dc5020a)
(cherry picked from commit fd38cfb14eebe34dc72b8358479e53d27fe01180)
(cherry picked from commit 64c82266183943f062016479c2d1868ccdee2cec)
(cherry picked from commit b546fb23042c6d231ce29241d1991c9cb1bf1bba)
(cherry picked from commit ad102021776a8dd407ef19cbfadc42b3ca7fabd5)
(cherry picked from commit c89cab9c2b019a592dffe4b6de29482feca1bb33)
(cherry picked from commit 9579322ec2eec40cb8f113458c1d5669f5d4b818)
(cherry picked from commit 16b44ad18de82b0429a8b0a05ed93445d1524241)
(cherry picked from commit 2571ff703b77cc8527f37f82c36e9260a80ac673)
(cherry picked from commit ad61d9ce9b93503b04deb9ecdb5f214566caf820)
(cherry picked from commit 9b2c45d4d3b1c6401a3d7d0a5544213e1486ab9e)
(cherry picked from commit ed01b79a598a0698324392dab66a2cd3d41c628c)
(cherry picked from commit d040b664279292f9f7304f96db0d172672c1e904)
(cherry picked from commit ffe0bbea48d036c26149d98856add938bb08a475)
(cherry picked from commit 4c1b2c409bb90a0c2876f3a7323cf162a7e58765)
(cherry picked from commit 3d8338ed106cb6260a4dae249ddef71489c47357)
(cherry picked from commit a92f044ea96bbe9c47689455a417e4f1bc3cd648)

[BRANDING] link to forgejo.org/docs instead of docs.gitea.io

(cherry picked from commit 3efafd0e083eb331ce06681351a40c4f46d7c96f)
(cherry picked from commit 148185e34b2be36fa46e8630928ee64a73768883)
(cherry picked from commit 834e264698f710049f20491b91b3c39b853de867)
(cherry picked from commit e72fa6eb1ef8f4355197ced3c619d8ff6d9c1c9f)

[BRANDING] link to forgejo.org/docs instead of docs.gitea.io

Fix the link that was 404.

(cherry picked from commit ae515d7258602a0fe4bb4471f2017e4ccc7dd0e7)
(cherry picked from commit facc2367f0e5fc1e1162cc2478a658f050c07718)
(cherry picked from commit 25784b9f21a37d9161b050503b0d45d87cd8863d)
(cherry picked from commit 2efc6138d92e958ee6a6091e579fa269aea45ce4)
(cherry picked from commit b9d0871631ef70abe88de64ccbabcfc94a49274b)
(cherry picked from commit f0446e51b9c2268f274a1c4b8c25abfcf417975c)
(cherry picked from commit 1638aa67fb384bdcd97386861054447a8d53e832)
(cherry picked from commit 290db6a018d4f82173446799b8726a320c209bb4)
(cherry picked from commit 89b87cf5426b7407ba0e23912fbbd3c521a8bae4)
(cherry picked from commit 656ed949625652a3a0e8d0b1381e76f75688e461)
(cherry picked from commit 036f879f96d606af691326474cefe77441c8c4ed)
(cherry picked from commit 69eea35f813d03f578ca143e45292289b0ad92a8)
(cherry picked from commit b72e3f4a92a04ac065b5b72ca25f7eb0c96ba69d)
(cherry picked from commit af606b8574d67c8c7a3699cf41d6a96fc3852547)
(cherry picked from commit 7e47f8135c08be3f48ccad6b8d8a940bc5713e53)
(cherry picked from commit 0e5218cc5374a0e16a273298f862dd3d6cebe020)
(cherry picked from commit 7c2a20a528a6911412986ff8eb479f3a19d7f226)
(cherry picked from commit 4e94006363227435b53769b92882b51a6109ba52)
(cherry picked from commit e47cdfc43fb693dfd0507bb1fe943da41fd2ebb4)
(cherry picked from commit 1dcb3e1da4ab4d8dbb659e87c4f542245b066409)
(cherry picked from commit 67367c4e0f4b755879350e9311e44deff95c137c)
(cherry picked from commit 252087d1ffcae00dfa7e8edc7face8775412d4cc)
(cherry picked from commit f5977a43e5cb2c869af0cd8c993cd0d3eeccb622)

Conflicts:
	templates/base/head_navbar.tmpl
	https://codeberg.org/forgejo/forgejo/pulls/1351
(cherry picked from commit 594938eb1505f6d81d8c0cce84a34c20a18b5c7a)
(cherry picked from commit 0257d038a7416fd208571d8be0a14a9ea6ac4d95)
(cherry picked from commit 72821dd14052505814df556e09a500981256f709)

[BRANDING] s/gitea/forgejo/ in HTML placeholders

Replaced Gitea branding with Forgejo for input placeholders

Closes: #686
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/752

(cherry picked from commit 6160d37ca972566017aee46b2ef42f398f969dca)
(cherry picked from commit df61138c7eaa25068fe0012644fd15b407a4816e)
(cherry picked from commit 1f30566c3f63925ca56eaa21b4fa580b4bb1ffaf)
(cherry picked from commit 539bb825f555585f0a52ea4c8747c5b589254633)
(cherry picked from commit bee0f66c869d2632a1ad3cda731caaba74c3634c)
(cherry picked from commit 60ad005c95a6d53f615a720445eef77e4bc499ef)
(cherry picked from commit 282e26222ef4aea1720b4b121ac29264876069c7)
(cherry picked from commit f9ca551f3dbc0f75250445b4e731396dc34fc041)
(cherry picked from commit b2e04b04c381549557873b1956065dc5a5132a97)
(cherry picked from commit c8f395a03c688bcc1413c6ed6b6f820aab7851d5)
(cherry picked from commit 0d58ce49aeefd43b3316c0238dcd04e019b6be25)
(cherry picked from commit c602ddf91efd95347de433cfad8ac20995d12283)
(cherry picked from commit 029e37271ead5405daa11945bd64104f12c8ba77)
(cherry picked from commit fdaa96b3ccca76cba877f8f5dafcf4cf9d160af8)
(cherry picked from commit 515d99e27d5db12c5495e31e104ccb6b7ad0ce7a)
(cherry picked from commit da73274ba1cb55d1c425b95890a55aecee2bb246)
(cherry picked from commit ce90b696a01619d86ac7dac7b0cd78be8f06e4b1)
(cherry picked from commit b6bf98763be1855b5613dc8db627fd889bff8308)
(cherry picked from commit 5b380d22d78568c2c4f26a3e8aa90a42006969e9)

[BRANDING] How to start a runner: URL to Actions admin documentation

(cherry picked from commit da91799e6f06ac3c91c1cfc763f4ec0b5cc3cf21)
(cherry picked from commit 28231663b634f6d877173ba4956f6c0a5d128b2b)
(cherry picked from commit 533a90345bb0236c8fc088f2ab1b92535f8a4269)
(cherry picked from commit 6a0e4e55dd02beff179b8503259d1cc774e8e81b)
(cherry picked from commit f47cd611c68f9da2df9b0e5e0a8332f6fcc17932)
(cherry picked from commit 001264b7840aaad6aa25e0b06a927300751ef20e)
(cherry picked from commit e4099e9bb9f557e99bb0117eaf6ad88467684527)
(cherry picked from commit 3a1885649ff1dcaf5acdb1bb237c477a92aeb01f)
(cherry picked from commit c42802c710c0fce2eea06a93a7f4373557515616)
(cherry picked from commit a611ce8d6d293573534d4ce1efde81d32129723a)
(cherry picked from commit a3d7d10a80ba6104ee6f260290518936b210c16b)
(cherry picked from commit 52adde671f8dcb309235506a3c39a38db87e9537)
(cherry picked from commit c9a3820fef10ef0b20e52f5f70d7794dde0974b3)
(cherry picked from commit dce40997c956244742325b5b10d13e8ec918082c)
(cherry picked from commit 312a6b92f384fdb09fc26e5da5a4acf0680ff698)

[BRANDING] package templates & links

- Change Gitea to Forgejo where necessary.
- Point all documentation to Forgejo's documentation.
- Resolves #992

(cherry picked from commit d0b78a6edea0abba54ef537781234d8f778e0ad8)
(cherry picked from commit e2382f30ba07586fd3ea4c8a535ab550ecc33408)
(cherry picked from commit c41cf05a334944a66129425c4a9abb973fbb4687)
(cherry picked from commit 797e598ae73441c66f25849bf643e0c11a737c41)
(cherry picked from commit 970031a1c2974cf0c6ce057ad82afdd6380f6882)
(cherry picked from commit 0c1180e2e142852248787185e2c01582413de8c3)

Conflicts:
	templates/package/content/alpine.tmpl
	templates/package/content/cargo.tmpl
	templates/package/content/chef.tmpl
	templates/package/content/composer.tmpl
	templates/package/content/conan.tmpl
	templates/package/content/conda.tmpl
	templates/package/content/container.tmpl
	templates/package/content/cran.tmpl
	templates/package/content/debian.tmpl
	templates/package/content/generic.tmpl
	templates/package/content/go.tmpl
	templates/package/content/helm.tmpl
	templates/package/content/maven.tmpl
	templates/package/content/npm.tmpl
	templates/package/content/nuget.tmpl
	templates/package/content/pub.tmpl
	templates/package/content/pypi.tmpl
	templates/package/content/rpm.tmpl
	templates/package/content/rubygems.tmpl
	templates/package/content/swift.tmpl
	templates/package/content/vagrant.tmpl

	https://codeberg.org/forgejo/forgejo/pulls/1351
(cherry picked from commit 42ac9ff2abe55826047c36e041f1bcd70caf7581)
(cherry picked from commit e390000bcee673c2d15c8777c2d2da316967ce62)
(cherry picked from commit 56a437b29b71976b9b0816d0de2ce8169a84f288)

Conflicts:
	templates/package/content/cargo.tmpl
	https://codeberg.org/forgejo/forgejo/pulls/1466

[BRANDING] s/Gitea/Forgejo/ in user visible help & comments

- Modify the README of the docker directory to point to the relevant
docker files and documentation for Forgejo.

(cherry picked from commit aca6371215c1bf95b6c0b19b9fadb797544adc48)
(cherry picked from commit 0ba96b1bc4c4df84ce3dca9875ad4a9ac8f1f759)
(cherry picked from commit 5c8e6b53f164dd16b527c603a3089735ff16df89)

Conflicts:
	docker/README.md
	https://codeberg.org/forgejo/forgejo/pulls/1351
(cherry picked from commit b3121c8004f675b31482cdbd564f9a830be48acd)
(cherry picked from commit 607f8704163bd24bfc7ff1d6a812b5e887746797)
(cherry picked from commit 191d96afe4198d3b6498aa21eaeb7686a59865bc)

[BRANDING] healthcheck/check.go

(cherry picked from commit d703a236cebadc0186b7b2431b3b42a54b3d1f09)
(cherry picked from commit d84ce3ff2098e9ba3c7241605ea25951dcb57ca6)
(cherry picked from commit 2dbb8446069c79017dcc4a9921dffcb73594d02c)
(cherry picked from commit 14d3ae7e3ae67dff3443db17e4373e5947ed6c6c)

[BRANDING] s/Gitea/Forgejo/g in CLI output

(cherry picked from commit 7543c126bbb78d5d29c253a88b56ccd2dd394928)
(cherry picked from commit b66f422fc3b9018aa948a869045cb3684e80f5f2)
(cherry picked from commit a81e4e46f3b0e619cea959de5ffde2e811d6008e)

[BRANDING] Gitea->Forgejo in mailer code

(cherry picked from commit b91afea4ff5e092452b5848900fc426b1c7289d5)
(cherry picked from commit 5d7428167c8ee5f25fb719f32a561472ef1aee68)
(cherry picked from commit ed8101ba6cc87526554a69f58a49507a79eadb35)

[BRANDING] use 'Forgejo' for Discord, Packagist, and Slack webhooks

Refs: https://codeberg.org/forgejo/forgejo/issues/1387

(cherry picked from commit 7dc3a05f5b9013a0696f071ebea4d2403c1c36a8)
(cherry picked from commit 133f2fc6cc2e977a5f7660ca4c214c92ac036421)

[BRANDING] cmd/manager.go

(cherry picked from commit d1dba2c79db63a6fc23e6bbab2b8dcbdaf43b679)

[BRANDING] pyproject.toml

(cherry picked from commit 7e8c868db2d5331778a87b5a1b493a81bf6863a4)
(cherry picked from commit 2395995c8b61c0674278db4321aa7d79e4c0eb91)
(cherry picked from commit dd6fbbf332f7833175634ef6d48eb5ad384aabb9)

Conflicts:
	templates/package/content/cargo.tmpl
	https://codeberg.org/forgejo/forgejo/pulls/1548
(cherry picked from commit 6f9a5d5cabc9bf7b57dc199a332261b8fe53e52d)
(cherry picked from commit d0635c4a07bb080e509f5578a995c7378b995691)
(cherry picked from commit 5f9a8c5744d254099c7ce98f14e1b58ec0a40708)
(cherry picked from commit 10b96c45673ef1d8d9f5364721b6e876a10e6f3b)
(cherry picked from commit 717d52e92863aa44536ed7ad524608aa5f398469)
(cherry picked from commit 5debdb103eb44d40fa9dd7056b48accc3cc185aa)
(cherry picked from commit ded1c1700e3795abf1d95d4d732703b9148f68fd)
(cherry picked from commit 52aa23cf7a3a7960c60ed7b504ea58c147a6c399)
(cherry picked from commit 882c942b061ef6f8e65668c70349522b57893090)
(cherry picked from commit 73fc2d2ea86877f9821a0230aa28114b624251fc)

Conflicts:
	cmd/actions.go
	cmd/doctor.go
	cmd/keys.go
	https://codeberg.org/forgejo/forgejo/pulls/1976
(cherry picked from commit 6180ef24dc0edad0b7471c463715179f29d741b9)
(cherry picked from commit 8970fa2bf872ee544ed9e0c1241fde8755e6acf1)

Conflicts:
	templates/package/content/debian.tmpl
	https://codeberg.org/forgejo/forgejo/pulls/2074

Fix a typo in docker/README.md

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
(cherry picked from commit 2e5df79dfb45719ff55c4c1f33bb1e753c32533f)
(cherry picked from commit 2bf6ce5b8167da5f5245337de93bf01f8522bd49)
(cherry picked from commit 8ec779277d6fbdbcc0a5f369fa73d47d3f80996f)
(cherry picked from commit 6048fc66e8ed9820ecb84e025efe9affbf124d85)
(cherry picked from commit 162538c722202d13f443b45249f05f3d9abd76f5)
(cherry picked from commit 646bb9965088a028a4469796fa6d62e4499e2b0d)
2024-02-05 16:02:14 +01:00
wxiaoguang c28e29fd94
Refactor tests (#26464)
1. Give the global variable clear names
2. Use generic parameter for `onGiteaRun`
2023-08-12 16:30:16 +00:00
wxiaoguang 4f513474dc
Improve CLI and messages (#26341)
Follow the CLI refactoring

1. Remove the "checkCommandFlags" helper
2. Unify the web startup message, make them have consistent names as `./gitea help`
3. Fine tune some other messages (see the diff)
2023-08-05 13:24:49 +00:00
wxiaoguang 52fb936773
Serve pre-defined files in "public", add "security.txt", add CORS header for ".well-known" (#25974)
Replace #25892

Close  #21942
Close  #25464

Major changes:

1. Serve "robots.txt" and ".well-known/security.txt" in the "public"
custom path
* All files in "public/.well-known" can be served, just like
"public/assets"
3. Add a test for ".well-known/security.txt"
4. Simplify the "FileHandlerFunc" logic, now the paths are consistent so
the code can be simpler
5. Add CORS header for ".well-known" endpoints
6. Add logs to tell users they should move some of their legacy custom
public files

```
2023/07/19 13:00:37 cmd/web.go:178:serveInstalled() [E] Found legacy public asset "img" in CustomPath. Please move it to /work/gitea/custom/public/assets/img
2023/07/19 13:00:37 cmd/web.go:182:serveInstalled() [E] Found legacy public asset "robots.txt" in CustomPath. Please move it to /work/gitea/custom/public/robots.txt
```
This PR is not breaking.

---------

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>
2023-07-21 12:14:20 +00:00
wxiaoguang d0dbe52e76
Refactor to use urfave/cli/v2 (#25959)
Replace #10912

And there are many new tests to cover the CLI behavior

There were some concerns about the "option order in hook scripts"
(https://github.com/go-gitea/gitea/pull/10912#issuecomment-1137543314),
it's not a problem now. Because the hook script uses `/gitea hook
--config=/app.ini pre-receive` format. The "config" is a global option,
it can appear anywhere.

----

## ⚠️ BREAKING ⚠️

This PR does it best to avoid breaking anything. The major changes are:

* `gitea` itself won't accept web's options: `--install-port` / `--pid`
/ `--port` / `--quiet` / `--verbose` .... They are `web` sub-command's
options.
    * Use `./gitea web --pid ....` instead
* `./gitea` can still run the `web` sub-command as shorthand, with
default options
* The sub-command's options must follow the sub-command
* Before: `./gitea --sub-opt subcmd` might equal to `./gitea subcmd
--sub-opt` (well, might not ...)
    * After: only `./gitea subcmd --sub-opt` could be used
    * The global options like `--config` are not affected
2023-07-21 17:28:19 +08:00
wxiaoguang 65d3e1161b
Fix sub-command log level (#25537)
More fix for #24981

* #24981


Close #22361

* #22361

There were many patches for Gitea's sub-commands to satisfy the facts:

* Some sub-commands shouldn't output any log, otherwise the git protocol
would be broken
* Sometimes the users want to see "verbose" or "quiet" outputs

That's a longstanding problem, and very fragile. This PR is only a quick
patch for the problem.

In the future, the sub-command system should be refactored to a clear
solution.

----

Other changes:

* Use `ReplaceAllWriters` to replace
`RemoveAllWriters().AddWriters(writer)`, then it's an atomic operation.
* Remove unnecessary `syncLevelInternal` calls, because
`AddWriters/addWritersInternal` already calls it.

Co-authored-by: Giteabot <teabot@gitea.io>
2023-06-28 08:02:06 +02:00
wxiaoguang 2cdf260f42
Refactor path & config system (#25330)
# The problem

There were many "path tricks":

* By default, Gitea uses its program directory as its work path
* Gitea tries to use the "work path" to guess its "custom path" and
"custom conf (app.ini)"
* Users might want to use other directories as work path
* The non-default work path should be passed to Gitea by GITEA_WORK_DIR
or "--work-path"
* But some Gitea processes are started without these values
    * The "serv" process started by OpenSSH server
    * The CLI sub-commands started by site admin
* The paths are guessed by SetCustomPathAndConf again and again
* The default values of "work path / custom path / custom conf" can be
changed when compiling

# The solution

* Use `InitWorkPathAndCommonConfig` to handle these path tricks, and use
test code to cover its behaviors.
* When Gitea's web server runs, write the WORK_PATH to "app.ini", this
value must be the most correct one, because if this value is not right,
users would find that the web UI doesn't work and then they should be
able to fix it.
* Then all other sub-commands can use the WORK_PATH in app.ini to
initialize their paths.
* By the way, when Gitea starts for git protocol, it shouldn't output
any log, otherwise the git protocol gets broken and client blocks
forever.

The "work path" priority is: WORK_PATH in app.ini > cmd arg --work-path
> env var GITEA_WORK_DIR > builtin default

The "app.ini" searching order is: cmd arg --config > cmd arg "work path
/ custom path" > env var "work path / custom path" > builtin default


## ⚠️ BREAKING

If your instance's "work path / custom path / custom conf" doesn't meet
the requirements (eg: work path must be absolute), Gitea will report a
fatal error and exit. You need to set these values according to the
error log.



----

Close #24818
Close #24222
Close #21606
Close #21498
Close #25107
Close #24981
Maybe close #24503

Replace #23301
Replace #22754

And maybe more
2023-06-21 13:50:26 +08:00
wxiaoguang df5cf5ddbd
Avoid polluting config file when "save" (#25395)
That's a longstanding INI package problem: the "MustXxx" calls change
the option values, and the following "Save" will save a lot of garbage
options into the user's config file.

Ideally we should refactor the INI package to a clear solution, but it's
a huge work.

A clear workaround is what this PR does: when "Save", load a clear INI
instance and save it.

Partially fix #25377, the "install" page needs more fine tunes.
2023-06-21 10:31:40 +08:00
wxiaoguang 4e2f1ee58d
Refactor web package and context package (#25298)
1. The "web" package shouldn't depends on "modules/context" package,
instead, let each "web context" register themselves to the "web"
package.
2. The old Init/Free doesn't make sense, so simplify it
* The ctx in "Init(ctx)" is never used, and shouldn't be used that way
* The "Free" is never called and shouldn't be called because the SSPI
instance is shared

---------

Co-authored-by: Giteabot <teabot@gitea.io>
2023-06-18 09:59:09 +02:00
wxiaoguang abcf5a7b5e
Fix install page context, make the install page tests really test (#24858)
Fix #24856

Rename "context.contextKey" to "context.WebContextKey", this context is
for web context only. But the Context itself is not renamed, otherwise
it would cause a lot of changes (if we really want to rename it, there
could be a separate PR).

The old test code doesn't really test, the "install page" gets broken
not only one time, so use new test code to make sure the "install page"
could work.
2023-05-23 09:29:15 +08:00
wxiaoguang 4647660776
Rewrite logger system (#24726)
## ⚠️ Breaking

The `log.<mode>.<logger>` style config has been dropped. If you used it,
please check the new config manual & app.example.ini to make your
instance output logs as expected.

Although many legacy options still work, it's encouraged to upgrade to
the new options.

The SMTP logger is deleted because SMTP is not suitable to collect logs.

If you have manually configured Gitea log options, please confirm the
logger system works as expected after upgrading.

## Description

Close #12082 and maybe more log-related issues, resolve some related
FIXMEs in old code (which seems unfixable before)

Just like rewriting queue #24505 : make code maintainable, clear legacy
bugs, and add the ability to support more writers (eg: JSON, structured
log)

There is a new document (with examples): `logging-config.en-us.md`

This PR is safer than the queue rewriting, because it's just for
logging, it won't break other logic.

## The old problems

The logging system is quite old and difficult to maintain:
* Unclear concepts: Logger, NamedLogger, MultiChannelledLogger,
SubLogger, EventLogger, WriterLogger etc
* Some code is diffuclt to konw whether it is right:
`log.DelNamedLogger("console")` vs `log.DelNamedLogger(log.DEFAULT)` vs
`log.DelLogger("console")`
* The old system heavily depends on ini config system, it's difficult to
create new logger for different purpose, and it's very fragile.
* The "color" trick is difficult to use and read, many colors are
unnecessary, and in the future structured log could help
* It's difficult to add other log formats, eg: JSON format
* The log outputer doesn't have full control of its goroutine, it's
difficult to make outputer have advanced behaviors
* The logs could be lost in some cases: eg: no Fatal error when using
CLI.
* Config options are passed by JSON, which is quite fragile.
* INI package makes the KEY in `[log]` section visible in `[log.sub1]`
and `[log.sub1.subA]`, this behavior is quite fragile and would cause
more unclear problems, and there is no strong requirement to support
`log.<mode>.<logger>` syntax.


## The new design

See `logger.go` for documents.


## Screenshot

<details>


![image](https://github.com/go-gitea/gitea/assets/2114189/4462d713-ba39-41f5-bb08-de912e67e1ff)


![image](https://github.com/go-gitea/gitea/assets/2114189/b188035e-f691-428b-8b2d-ff7b2199b2f9)


![image](https://github.com/go-gitea/gitea/assets/2114189/132e9745-1c3b-4e00-9e0d-15eaea495dee)

</details>

## TODO

* [x] add some new tests
* [x] fix some tests
* [x] test some sub-commands (manually ....)

---------

Co-authored-by: Jason Song <i@wolfogre.com>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: Giteabot <teabot@gitea.io>
2023-05-21 22:35:11 +00:00
Lunny Xiao 377a0a20f0
Merge setting.InitXXX into one function with options (#24389)
This PR will merge 3 Init functions on setting packages as 1 and
introduce an options struct.
2023-05-04 11:55:35 +08:00
Lunny Xiao 5cf7da63ee
Refactor config provider (#24245)
This PR introduces more abstract about `ConfigProvider` and hides more `ini` references.

---------

Co-authored-by: delvh <dev.lh@web.de>
2023-04-25 23:06:39 +08:00
Lunny Xiao 623a539f23
Move pidfile creation from setting to web cmd package (#23285)
Creating pid file should not belong to setting package and only web
command needs that. So this PR moves pidfile creation from setting
package to web command package to keep setting package more readable.

I marked this as `break` because the PIDFile path moved. For those who
have used the pid build argument, it has to be changed.

---------

Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
2023-03-16 15:22:54 +08:00
Lunny Xiao c53ad052d8
Refactor the setting to make unit test easier (#22405)
Some bugs caused by less unit tests in fundamental packages. This PR
refactor `setting` package so that create a unit test will be easier
than before.

- All `LoadFromXXX` files has been splited as two functions, one is
`InitProviderFromXXX` and `LoadCommonSettings`. The first functions will
only include the code to create or new a ini file. The second function
will load common settings.
- It also renames all functions in setting from `newXXXService` to
`loadXXXSetting` or `loadXXXFrom` to make the function name less
confusing.
- Move `XORMLog` to `SQLLog` because it's a better name for that.

Maybe we should finally move these `loadXXXSetting` into the `XXXInit`
function? Any idea?

---------

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: delvh <dev.lh@web.de>
2023-02-20 00:12:01 +08:00
flynnnnnnnnnn e81ccc406b
Implement FSFE REUSE for golang files (#21840)
Change all license headers to comply with REUSE specification.

Fix #16132

Co-authored-by: flynnnnnnnnnn <flynnnnnnnnnn@github>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
2022-11-27 18:20:29 +00:00
Clar Fon 3d10193be2
Allow specifying SECRET_KEY_URI, similar to INTERNAL_TOKEN_URI (#19663)
Only load SECRET_KEY and INTERNAL_TOKEN if they exist.
Never write the config file if the keys do not exist, which was only a fallback for Gitea upgraded from < 1.5

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2022-10-02 01:26:33 +08:00
zeripath bb0ff77e46
Share HTML template renderers and create a watcher framework (#20218)
The recovery, API, Web and package frameworks all create their own HTML
Renderers. This increases the memory requirements of Gitea
unnecessarily with duplicate templates being kept in memory.

Further the reloading framework in dev mode for these involves locking
and recompiling all of the templates on each load. This will potentially
hide concurrency issues and it is inefficient.

This PR stores the templates renderer in the context and stores this
context in the NormalRoutes, it then creates a fsnotify.Watcher
framework to watch files.

The watching framework is then extended to the mailer templates which
were previously not being reloaded in dev.

Then the locales are simplified to a similar structure.

Fix #20210 
Fix #20211
Fix #20217

Signed-off-by: Andrew Thornton <art27@cantab.net>
2022-08-28 10:43:25 +01:00
zeripath 943753f560
Support Proxy protocol (#12527)
This PR adds functionality to allow Gitea to sit behind an
HAProxy and HAProxy protocolled connections directly.

Fix #7508

Signed-off-by: Andrew Thornton <art27@cantab.net>
2022-08-21 19:20:43 +01:00
wxiaoguang 91f1c285a1
Improve pprof doc (#20463) 2022-07-24 01:33:55 +08:00
zeripath 90f3365d93
Add fgprof pprof profiler (#20005)
fgprof is a sampling Go profiler that allows you to analyze On-CPU as
well as Off-CPU (e.g. I/O) time together.

Go's builtin sampling CPU profiler can only show On-CPU time, but it's
better than fgprof at that. Go also includes tracing profilers that can
analyze I/O, but they can't be combined with the CPU profiler.

fgprof is designed for analyzing applications with mixed I/O and CPU
workloads. This kind of profiling is also known as wall-clock profiling.

Whilst fgprof can cause significant STW latencies in applications with a
lot of goroutines (> 1-10k), these latencies only occur if the profile
is requested - it doesn't cause a delay by simply being available.

The fgprof profile is mounted on
`http://localhost:6060/debug/fgprof?seconds=3`

Signed-off-by: Andrew Thornton <art27@cantab.net>
2022-06-18 11:04:52 +01:00
zeripath c88547ce71
Add Goroutine stack inspector to admin/monitor (#19207)
Continues on from #19202.

Following the addition of pprof labels we can now more easily understand the relationship between a goroutine and the requests that spawn them. 

This PR takes advantage of the labels and adds a few others, then provides a mechanism for the monitoring page to query the pprof goroutine profile.

The binary profile that results from this profile is immediately piped in to the google library for parsing this and then stack traces are formed for the goroutines.

If the goroutine is within a context or has been created from a goroutine within a process context it will acquire the process description labels for that process. 

The goroutines are mapped with there associate pids and any that do not have an associated pid are placed in a group at the bottom as unbound.

In this way we should be able to more easily examine goroutines that have been stuck.

A manager command `gitea manager processes` is also provided that can export the processes (with or without stacktraces) to the command line.

Signed-off-by: Andrew Thornton <art27@cantab.net>
2022-03-31 19:01:43 +02:00
Cristian Le 60f203385e
Support custom ACME provider (#18340)
* Added ACMECAURL option to support custom ACME provider. Closes #18306
* Refactor setting.go https settings, renamed options and variables, and documented app.example.ini
* Refactored runLetsEncrypt to runACME
* Improved documentation
2022-02-08 13:45:35 +08:00
6543 54e9ee37a7
format with gofumpt (#18184)
* gofumpt -w -l .

* gofumpt -w -l -extra .

* Add linter

* manual fix

* change make fmt
2022-01-20 18:46:10 +01:00
wxiaoguang 5bf8d5445e
Refactor Router Logger (#17308)
Make router logger more friendly, show the related function name/file/line.

[BREAKING]
This PR substantially changes the logging format of the router logger. If you use this logging for monitoring e.g. fail2ban you will need to update this to match the new format.
2022-01-20 19:41:25 +08:00
mscherer f49d160447
Replace "unix" by "http+unix" for PROTOCOL (#17771) 2021-12-05 23:46:11 -05:00
wxiaoguang 042cac5fed
Improve install code to avoid low-level mistakes. (#17779)
* Improve install code to avoid low-level mistakes.

If a user tries to do a re-install in a Gitea database, they gets a warning and double check.
When Gitea runs, it never create empty app.ini automatically.

Also some small (related) refactoring:

* Refactor db.InitEngine related logic make it more clean (especially for the install code)
* Move some i18n strings out from setting.go to make the setting.go can be easily maintained.
* Show errors in CLI code if an incorrect app.ini is used.
* APP_DATA_PATH is created when installing, and checked when starting (no empty directory is created any more).
2021-12-01 15:50:01 +08:00
wxiaoguang 750a8465f5
A better go code formatter, and now make fmt can run in Windows (#17684)
* go build / format tools
* re-format imports
2021-11-17 20:34:35 +08:00
zeripath 9d855bd6a1
Simplify Gothic to use our session store instead of creating a different store (#17507)
* Simplify Gothic to use our session store instead of creating a different store

We have been using xormstore to provide a separate session store for our OAuth2 logins
however, this relies on using gorilla context and some doubling of our session storing.
We can however, simplify and simply use our own chi-based session store. Thus removing
a cookie and some of the weirdness with missing contexts.

Signed-off-by: Andrew Thornton <art27@cantab.net>

* as per review

Signed-off-by: Andrew Thornton <art27@cantab.net>

* as per review

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Handle MaxTokenLength

Signed-off-by: Andrew Thornton <art27@cantab.net>

* oops

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: Lauris BH <lauris@nix.lv>
2021-11-03 08:33:54 +08:00
wxiaoguang 599ff1c054
Only allow webhook to send requests to allowed hosts (#17482) 2021-11-01 16:39:52 +08:00
zeripath 73defbbd1c
Ensure that template compilation panics are sent to the logs (#16788)
Although panics within the rendering pipeline are caught and dealt with,
panics that occur before that starts are unprotected and will kill Gitea
without being sent to the logs.

This PR adds a basic recovery handler to catch panics that occur after
the logger is initialised and ensure that they're sent to the logger.

Signed-off-by: Andrew Thornton <art27@cantab.net>
2021-08-23 20:40:59 +01:00
zeripath 35f37a3625
Add --quiet and --verbose to gitea web to control initial logging (#16260)
One of the repeatedly reported issues has been that gitea produces too much console
logging during set up even if the console logger is turned off.

Fundamentally this is due to some otherwise very helpful logging that has to occur
before logging is set up. This has come to a head with the merging of #16243 where
otherwise potentially helpful Trace logging in the git module now appears on the
console.

This PR proposes three things:

1. Change the initial default logger to Info not Trace.
2. Change the logging for the AppPath things to Info in recompense.
3. Add two new command line options to gitea web: --quiet and --verbose

`gitea web -q` or `gitea web --quiet` will only log Fatal level initially.
`gitea web -verbose` will log at Trace.

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2021-06-26 20:56:58 -04:00
Lunny Xiao 1bfb0a24d8
Refactor routers directory (#15800)
* refactor routers directory

* move func used for web and api to common

* make corsHandler a function to prohibit side efects

* rm unused func

Co-authored-by: 6543 <6543@obermui.de>
2021-06-09 01:33:54 +02:00
KN4CK3R efe77eec85
Unified custom config creation (#16012)
* Unified custom config creation.

* Fixed log message.

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2021-05-29 19:44:14 +01:00
Naohisa Murakami 9f19c2b8cc
Fix error message when saving generated LOCAL_ROOT_URL config (#15880) 2021-05-15 11:23:21 +01:00
zeripath c03f530212
Make internal SSH server host key path configurable (#14918)
* Make SSH server host key path configurable

* make it possible to have multiple keys

* Make gitea.rsa the default key

* Add some more logging

Signed-off-by: Andrew Thornton <art27@cantab.net>
2021-03-08 03:43:59 +01:00
Lunny Xiao 6433ba0ec3
Move macaron to chi (#14293)
Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR.

- [x] Define `context.ResponseWriter` interface with an implementation `context.Response`.
- [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before.
- [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic .
- [x] Use https://github.com/unrolled/render instead of macaron's internal render
- [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip
- [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK**
- [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha
- [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache
- [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding
- [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors
- [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation`
- [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle.
- [x] Removed macaron log service because it's not need any more. **BREAK**
- [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition.
- [x] Move Git HTTP protocol implementation to use routers directly.
- [x] Fix the problem that chi routes don't support trailing slash but macaron did.
- [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. 

Notices:
- Chi router don't support request with trailing slash
- Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI.

Co-authored-by: 6543 <6543@obermui.de>
2021-01-26 16:36:53 +01:00
techknowlogick d2ea21d0d8
Use caddy's certmagic library for extensible/robust ACME handling (#14177)
* use certmagic for more extensible/robust ACME cert handling

* accept TOS based on config option

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: Lauris BH <lauris@nix.lv>
2021-01-25 01:37:35 +02:00
zeripath 742e21aeba
Handle and propagate errors when checking if paths are Dirs, Files or Exist (#13186)
* Ensure errors from IsDir propagate

* Handle errors when checking IsFile

* Handle and propagate errors from IsExist

* Update modules/templates/static.go

* Update modules/templates/static.go

* Return after ctx.ServerError

* Apply suggestions from code review

* Fix tests

The previous merge managed to break repo_form.go

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: Lauris BH <lauris@nix.lv>
2020-11-27 21:42:08 -05:00
Lunny Xiao 586bfb9f32
Use mount but not register for chi routes (#13555)
* Use mount but not register for chi routes

* Fix test

* Fix test

* Fix test

* Fix comment

* turn back unnecessary change

* Remove the timout middleware since some operations may spend much time.
2020-11-16 15:33:41 +08:00
Lunny Xiao c296f4fed6
Introduce go chi web framework as frontend of macaron, so that we can move routes from macaron to chi step by step (#7420)
* When route cannot be found on chi, go to macaron

* Stick chi version to 1.5.0

* Follow router log setting
2020-11-13 14:51:07 +02:00
zeripath dd12384f22
Fix --port setting (#13288)
* Fix --port setting

Unfortunately there was an error in #13195 which set the --port
option before the settings were read. This PR fixes this by
moving applying this option to after the the settings are read

However, on looking further into this code I believe that the setPort
code was slightly odd.

Firstly, it may make sense to run the install page on a different
temporary port to the full system and this should be possible with
a --install-port option.

Secondy, if the --port option is provided we should apply it to both
otherwise there will be unusual behaviour on graceful restart

Thirdly, the documentation for --port says that the setting is
temporary - it should therefore not save its result to the configuration

(This however, does mean that authorized_keys and internal links may
not be correct. - I think we need to discuss this option further.)

Fix #13277

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Update cmd/web.go

* Apply suggestions from code review

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2020-10-30 15:26:03 -04:00
zeripath 2f1353a2f3
Move install pages out of main macaron routes (#13195)
* Move install pages out of main macaron loop

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Update templates/post-install.tmpl

Co-authored-by: Lauris BH <lauris@nix.lv>

* remove prefetch

Signed-off-by: Andrew Thornton <art27@cantab.net>
2020-10-19 17:03:08 -04:00
6543 818d921bbb
Refactor use TrimSuffix instead of TrimRight (#12993)
* Refactor use TrimSuffix instead of TrimRight

* TrimRight right

* has #12990
2020-10-01 06:54:34 +01:00
zeripath ac3cfad23d
Make the default PID file compile-time settable (#12485)
#12391 offered to change the default PID file from /var/run/gitea.pid however in discussion it was decided that this could break users of older systems. An alternative was offered that we could make the PID file compile/link time settable.

This PR does this, and changes the name of the setting from CustomPID to simply PIDFile. It also updates the from-source docs to show how to change the compiler settings to do this.

Closes #12391

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Florian Klink <flokli@flokli.de>
2020-08-15 21:15:27 +01:00
Wim 4609eba2e7
Fix ipv6 parsing (#12321)
* Fix ipv6 parsing

* Update modules/setting/setting.go

Co-authored-by: 6543 <6543@obermui.de>

Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2020-07-26 16:31:28 -04:00
zeripath e3c3b33ea7
Graceful: Xorm, RepoIndexer, Cron and Others (#9282)
* Change graceful to use a singleton obtained through GetManager instead of a global.
* Graceful: Make TestPullRequests shutdownable
* Graceful: Make the cron tasks graceful
* Graceful: AddTestPullRequest run in graceful ctx
* Graceful: SyncMirrors shutdown
* Graceful: SetDefaultContext for Xorm to be HammerContext
* Avoid starting graceful for migrate commands and checkout
* Graceful: DeliverHooks now can be shutdown
* Fix multiple syncing errors in modules/sync/UniqueQueue &  Make UniqueQueue closable
* Begin the process of making the repo indexer shutdown gracefully
2019-12-15 09:51:28 +00:00
zeripath 2c83dac5d4 FCGI: Allow FCGI over unix sockets (#9298)
* FCGI: Allow FCGI over unix sockets

* fixup! FCGI: Allow FCGI over unix sockets
2019-12-10 13:23:26 +01:00
zeripath 60c5339042 Graceful: Cancel Process on monitor pages & HammerTime (#9213)
* Graceful: Create callbacks to with contexts

* Graceful: Say when Gitea is completely finished

* Graceful: Git and Process within HammerTime

Force all git commands to terminate at HammerTime
Force all process commands to terminate at HammerTime
Move almost all git processes to run as git Commands

* Graceful: Always Hammer after Shutdown

* ProcessManager: Add cancel functionality

* Fix tests

* Make sure that process.Manager.Kill() cancels

* Make threadsafe access to Processes and remove own unused Kill

* Remove cmd from the process manager as it is no longer used

* the default context is the correct context

* get rid of double till
2019-11-30 16:40:22 +02:00
zeripath 7523314ef8
Graceful: Allow graceful restart for fcgi (#9112)
* Graceful: Allow graceful restart for fcgi

My previous interpretation was incorrect - we do not handle sockets
being passed in over stdin

* Update web.go
2019-11-24 10:39:50 +00:00