Skip to content

Commit 94cda02

Browse files
committed
feat: switches for turning on/off git http clone protocols
1 parent e12e2d7 commit 94cda02

11 files changed

Lines changed: 113 additions & 24 deletions

File tree

COUNT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.1.6-alpha,93
1+
v0.1.6-alpha,104

cmd/aegis/webinstaller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type WebInstallerRoutingContext struct {
4343
// step 3 - session config
4444
// step 4 - mailer config
4545
// step 5 - receipt system config
46-
// step 6 - git root & git user
46+
// step 6 - git-related config
4747
// step 7 - ignored namespaces & repositories
4848
// step 8 - web front setup:
4949
// depot name
@@ -244,7 +244,6 @@ func bindAllWebInstallerRoutes(ctx *WebInstallerRoutingContext) {
244244
}))
245245

246246
http.HandleFunc("GET /step6", withLog(func(w http.ResponseWriter, r *http.Request) {
247-
fmt.Println(ctx.Config.GitUser, ctx.Config.GitRoot)
248247
logTemplateError(ctx.loadTemplate("webinstaller/step6").Execute(w, &templates.WebInstallerTemplateModel{
249248
Config: ctx.Config,
250249
ConfirmStageReached: ctx.ConfirmStageReached,
@@ -259,6 +258,8 @@ func bindAllWebInstallerRoutes(ctx *WebInstallerRoutingContext) {
259258
ctx.Config.GitRoot = strings.TrimSpace(r.Form.Get("git-root"))
260259
ctx.Config.GitUser = strings.TrimSpace(r.Form.Get("git-user"))
261260
ctx.Config.SnippetRoot = strings.TrimSpace(r.Form.Get("snippet-root"))
261+
ctx.Config.GitConfig.HTTPCloneProtocol.V1Dumb = len(strings.TrimSpace(r.Form.Get("git-http-clone-enable-v1-dumb"))) > 0
262+
ctx.Config.GitConfig.HTTPCloneProtocol.V2 = len(strings.TrimSpace(r.Form.Get("git-http-clone-enable-v2"))) > 0
262263
next := ""
263264
if ctx.Config.IsInPlainMode() {
264265
next = "/step7"

pkg/aegis/config.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ type AegisConfig struct {
6565
// when set to true, all registration must be screened by the webmaster.
6666
ManualApproval bool `json:"requireManualApproval"`
6767

68+
// git-related config.
69+
// NOTE(2025.12.30): we'll gradually move certain config options into here.
70+
GitConfig AegisGitConfig `json:"gitConfig"`
71+
6872
// cosmetic things...
6973

7074
// the name of the depot (i.e. the top level of the site)
@@ -188,6 +192,15 @@ type AegisDatabaseConfig struct {
188192
TablePrefix string `json:"tablePrefix"`
189193
}
190194

195+
type AegisGitHTTPTransferProtocolDescriptor struct {
196+
// true if enabled.
197+
V1Dumb bool `json:"v1dumb"`
198+
V2 bool `json:"v2"`
199+
}
200+
type AegisGitConfig struct {
201+
HTTPCloneProtocol AegisGitHTTPTransferProtocolDescriptor `json:"httpCloneProtocol"`
202+
}
203+
191204
type AegisSessionConfig struct {
192205
// session type. currently only support:
193206
// + "sqlite"
@@ -364,6 +377,12 @@ func CreateConfigFile(p string) error {
364377
IgnoreRepository: nil,
365378
GlobalVisibility: "public",
366379
FullAccessUser: []string{"admin"},
380+
GitConfig: AegisGitConfig{
381+
HTTPCloneProtocol: AegisGitHTTPTransferProtocolDescriptor{
382+
V1Dumb: true,
383+
V2: true,
384+
},
385+
},
367386
Database: AegisDatabaseConfig{
368387
Type: "sqlite",
369388
Path: "",

routes/controller/admin/site-config.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ func bindAdminSiteConfigController(ctx *RouterContext) {
6060
rc.ReportRedirect("/admin/site-config", 3, "Updated", "Your specifie config has been updated.", w, r)
6161
case "basic":
6262
rc.Config.DepotName = r.Form.Get("depot-name")
63-
rc.Config.GitRoot = r.Form.Get("root")
64-
rc.Config.GitUser = r.Form.Get("git-user")
6563
rc.Config.UseNamespace = false
6664
if r.Form.Has("use-namespace") && r.Form.Get("use-namespace") == "on" {
6765
rc.Config.UseNamespace = true
@@ -89,6 +87,21 @@ func bindAdminSiteConfigController(ctx *RouterContext) {
8987
return
9088
}
9189
rc.ReportRedirect("/admin/site-config", 3, "Updated", "Your specifie config has been updated.", w, r)
90+
case "git":
91+
rc.Config.GitRoot = r.Form.Get("root")
92+
rc.Config.GitUser = r.Form.Get("git-user")
93+
rc.Config.GitConfig.HTTPCloneProtocol.V1Dumb = len(strings.TrimSpace(r.Form.Get("git-http-enable-v1dumb"))) > 0
94+
rc.Config.GitConfig.HTTPCloneProtocol.V2 = len(strings.TrimSpace(r.Form.Get("git-http-enable-v2"))) > 0
95+
err := rc.Config.Sync()
96+
if err != nil {
97+
LogTemplateError(rc.LoadTemplate("admin/site-config").Execute(w, &templates.AdminConfigTemplateModel{
98+
Config: rc.Config,
99+
LoginInfo: rc.LoginInfo,
100+
ErrorMsg: fmt.Sprintf("Error while saving config: %s. Please contact site owner for this...", err.Error()),
101+
}))
102+
return
103+
}
104+
rc.ReportRedirect("/admin/site-config", 3, "Updated", "Your specifie config has been updated.", w, r)
92105
case "theme-config":
93106
rc.Config.Theme.ForegroundColor = strings.TrimSpace(r.Form.Get("foreground-color"))
94107
rc.Config.Theme.BackgroundColor = strings.TrimSpace(r.Form.Get("background-color"))

routes/controller/http-clone.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ func bindHttpCloneController(ctx *RouterContext) {
3333
http.HandleFunc("GET /repo/{repoName}/info/{p...}", UseMiddleware(
3434
[]Middleware{ Logged }, ctx,
3535
func(ctx *routes.RouterContext, w http.ResponseWriter, r *http.Request) {
36+
allowV2 := ctx.Config.GitConfig.HTTPCloneProtocol.V2
37+
allowV1Dumb := ctx.Config.GitConfig.HTTPCloneProtocol.V1Dumb
38+
if !allowV1Dumb && !allowV2 {
39+
w.WriteHeader(403)
40+
fmt.Fprint(w, "HTTP clone not supported on this instance")
41+
return
42+
}
3643
if ctx.Config.GlobalVisibility != aegis.GLOBAL_VISIBILITY_PUBLIC {
3744
ctx.ReportForbidden("", w, r)
3845
return
@@ -60,11 +67,11 @@ func bindHttpCloneController(ctx *RouterContext) {
6067
isRepoArchived := repo.Status == model.REPO_ARCHIVED
6168
if !isNamespacePublic || !(isRepoPublic || isRepoArchived) {
6269
w.WriteHeader(404)
63-
w.Write([]byte("404 Not Found"))
70+
fmt.Fprint(w, "404 Not Found")
6471
return
6572
}
6673
// see docs/http-clone.org.
67-
if (r.URL.Query().Has("service")) {
74+
if (r.URL.Query().Has("service") && allowV2) {
6875
switch r.URL.Query().Get("service") {
6976
case "git-upload-pack":
7077
cmd := exec.Command("git", "upload-pack", repo.LocalPath, "--http-backend-info-refs")
@@ -93,6 +100,11 @@ func bindHttpCloneController(ctx *RouterContext) {
93100
return
94101
}
95102
// v1-dumb
103+
if !allowV1Dumb {
104+
w.WriteHeader(403)
105+
fmt.Fprint(w, "v1-dumb protocl not supported on this instance.")
106+
return
107+
}
96108
rr := repo.Repository.(*gitlib.LocalGitRepository)
97109
p := path.Join(rr.GitDirectoryPath, "info", r.PathValue("p"))
98110
s, err := os.ReadFile(p)
@@ -105,6 +117,11 @@ func bindHttpCloneController(ctx *RouterContext) {
105117
http.HandleFunc("POST /repo/{repoName}/git-upload-pack", UseMiddleware(
106118
[]Middleware{ Logged }, ctx,
107119
func(ctx *RouterContext, w http.ResponseWriter, r *http.Request) {
120+
if !ctx.Config.GitConfig.HTTPCloneProtocol.V2 {
121+
w.WriteHeader(403)
122+
fmt.Fprint(w, "v2 protocl not supported on this instance.")
123+
return
124+
}
108125
if ctx.Config.GlobalVisibility != aegis.GLOBAL_VISIBILITY_PUBLIC {
109126
w.WriteHeader(403)
110127
w.Write([]byte("Service not available right now."))

templates/_comparison-notice.template.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{{define "_comparison-notice"}}
22
<span class="comparison-notice"><b>Fork Notice:</b>
3-
{{if gt (len .BRevList) 0}}
3+
{{if . }}
4+
{{if and .BRevList (gt (len .BRevList)) 0}}
45
This repository is {{len .BRevList}} commits beyond {{if gt (len .ARevList) 0}} and {{len .ARevList}} commits behind {{end}}upstream.
5-
{{else if gt (len .ARevList) 0}}
6+
{{else if and .ARevList (gt (len .ARevList)) 0}}
67
This repository is {{len .ARevList}} commits behind upstream.
7-
{{else if .}}
8+
{{else}}
89
This repository is in sync with upstream.
10+
{{end}}
911
{{else}}
1012
This repository seems to be empty.
1113
{{end}}

templates/_footer.template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
{{define "_footer"}}
33
<div class="footer-message">
4-
Powered by <a href="https://github.com/AegisCodeForge/aegis">Aegis</a>, version v0.1.6-alpha (v0.1.6-alpha.build_93)
4+
Powered by <a href="https://github.com/AegisCodeForge/aegis">Aegis</a>, version v0.1.6-alpha (v0.1.6-alpha.build_104)
55
</div>
66
{{end}}

templates/admin/site-config.template.html

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ <h1 class="header-name" style="margin-bottom: 0">Admin</h1>
3131
<td><label class="field-label" for="tf-depot-name">Depot name:</label></td>
3232
<td><input name="depot-name" id="tf-depot-name" class="field-tf" value="{{.Config.DepotName}}" /></td>
3333
</tr>
34-
<tr class="field">
35-
<td><label class="field-label" for="tf-root">Root:</label></td>
36-
<td><input name="root" id="tf-root" required class="field-tf" value="{{.Config.GitRoot}}" /></td>
37-
</tr>
38-
<tr class="field">
39-
<td><label class="field-label" for="tf-git-user">Git User:</label></td>
40-
<td><input name="git-user" id="tf-git-user" required class="field-tf" value="{{.Config.GitUser}}" /></td>
41-
</tr>
4234
<tr class="field">
4335
<td><label class="field-label field-chkbox-label" for="chkbox-use-namespace">Use Namespace:</label></td>
4436
<td><input type="checkbox" name="use-namespace" id="chkbox-use-namespace" class="field-chkbox" {{if .Config.UseNamespace}}checked{{end}}/></td>
@@ -62,6 +54,35 @@ <h1 class="header-name" style="margin-bottom: 0">Admin</h1>
6254
</table>
6355
</form>
6456
</fieldset>
57+
58+
<fieldset class="git-section">
59+
<legend>Git Settings</legend>
60+
<form action="" method="POST">
61+
<input type="hidden" name="section" value="git" />
62+
<table class="field-table">
63+
<tr class="field">
64+
<td><label class="field-label" for="tf-root">Root:</label></td>
65+
<td><input name="root" id="tf-root" required class="field-tf" value="{{.Config.GitRoot}}" /></td>
66+
</tr>
67+
<tr class="field">
68+
<td><label class="field-label" for="tf-git-user">Git User:</label></td>
69+
<td><input name="git-user" id="tf-git-user" required class="field-tf" value="{{.Config.GitUser}}" /></td>
70+
</tr>
71+
<tr class="field">
72+
<td><label class="field-label" for="chk-http-enable-v1dumb">Enable v1-dumb protocol for HTTP clone</label></td>
73+
<td><input type="checkbox" id="chk-http-enable-v1dumb" name="git-http-enable-v1dumb" class="field-checkbox" {{if .Config.GitConfig.HTTPCloneProtocol.V1Dumb}}checked{{end}}/ ></td>
74+
</tr>
75+
<tr class="field">
76+
<td><label class="field-label" for="chk-http-enable-v2">Enable v2 protocol for HTTP clone</label></td>
77+
<td><input type="checkbox" id="chk-http-enable-v2" name="git-http-enable-v2" class="field-checkbox" {{if .Config.GitConfig.HTTPCloneProtocol.V2}}checked{{end}}/></td>
78+
</tr>
79+
<tr class="field">
80+
<td></td>
81+
<td><input class="field-submit" type="submit" value="Save Config" /></td>
82+
</tr>
83+
</table>
84+
</form>
85+
</fieldset>
6586

6687
<fieldset class="setting-section">
6788
<legend>Web Setting</legend>

templates/shouldShowSynchronizeLink.func.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "github.com/bctnry/aegis/pkg/gitlib"
66
func(s *LoginInfoModel, ci *gitlib.BranchComparisonInfo) bool {
77
if !s.LoggedIn { return false }
88
if !s.IsOwner { return false }
9+
if ci == nil { return true }
910
if len(ci.ARevList) > 0 && len(ci.BRevList) <= 0 { return true }
1011
return false
1112
}

templates/webinstaller/step1.template.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ <h2>Step 1</h2>
3131
<tr><td><label for="operation-mode">operationMode</label></td>
3232
<td>
3333
<select name="operation-mode" id="operation-mode">
34-
<option value="plain" {{if eq .Config.OperationMode "plain"}}selected{{end}}>Plain Mode</option>
35-
<option value="simple" {{if eq .Config.OperationMode "simple"}}selected{{end}}>Simple Mode</option>
36-
<option value="normal" {{if eq .Config.OperationMode "normal"}}selected{{end}}>Normal Mode</option>
34+
<option value="plain" {{if eq .Config.OperationMode "plain"}}selected{{end}}>Read-only web frontend (Plain Mode)</option>
35+
<option value="simple" {{if eq .Config.OperationMode "simple"}}selected{{end}}>Simple managed SSH-enabled instance (Simple Mode)</option>
36+
<option value="normal" {{if eq .Config.OperationMode "normal"}}selected{{end}}>Full functionalities enabled (Normal Mode)</option>
3737
</select>
3838
</td>
3939
</tr>

0 commit comments

Comments
 (0)