Skip to content

Commit 12fa983

Browse files
committed
feat: managed no-interactive-login message
1 parent a4899b9 commit 12fa983

7 files changed

Lines changed: 33 additions & 2 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,151
1+
v0.1.6-alpha,157

cmd/gitus/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ func main() {
208208
}
209209
HandleSSHLogin(&context, mainCall[1], mainCall[2])
210210
return
211+
case "no-login":
212+
fmt.Println(context.Config.NoInteractiveShellMessage)
213+
return
211214
case "simple-mode":
212215
if len(mainCall) < 3 {
213216
fmt.Print(gitlib.ToPktLine("Error format for `gitus simple-mode`."))

cmd/gitus/webinstaller.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ func bindAllWebInstallerRoutes(ctx *WebInstallerRoutingContext) {
266266
} else {
267267
next = "/step8"
268268
}
269+
ctx.Config.NoInteractiveShellMessage = strings.TrimSpace(r.Form.Get("no-interactive-shell-message"))
269270
err = templates.UnpackStaticFileTo(ctx.Config.StaticAssetDirectory)
270271
if err != nil {
271272
ctx.reportRedirect(next, 0, "Failed", fmt.Sprintf("Static file unpack is unsuccessful due to reason: %s. You can still move forward but would have to unpack static file yourself.", err.Error()), w)
@@ -542,6 +543,7 @@ func bindAllWebInstallerRoutes(ctx *WebInstallerRoutingContext) {
542543
return false
543544
}
544545
}
546+
545547
err = os.MkdirAll(ctx.Config.GitRoot, os.ModeDir|0755)
546548
if errors.Is(err, os.ErrExist) {
547549
err = os.Chown(ctx.Config.GitRoot, uid, gid)
@@ -566,6 +568,22 @@ func bindAllWebInstallerRoutes(ctx *WebInstallerRoutingContext) {
566568
if err != nil {
567569
fmt.Fprintf(w, "<p>Failed to change config file owner: %s. You should do this after the installation process has completed</p>", err)
568570
}
571+
572+
noInteractiveLoginPath := path.Join(homePath, "git-shell-commands", "no-interactive-login")
573+
f, err := os.OpenFile(noInteractiveLoginPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0754)
574+
if err != nil {
575+
fmt.Fprintf(w, "<p>Failed to write <code>no-interactive-login</code>: %s; interactive shell would still be available. If this is undesirable, you'll have to add it yourself.</p>", err.Error())
576+
} else {
577+
defer f.Close()
578+
fmt.Fprintf(f, `#!/bin/sh
579+
580+
%s -config "%s" no-login
581+
`, path.Join(homePath, "git-shell-commands", "gitus"),
582+
shellparse.Quote(ctx.Config.FilePath),
583+
)
584+
os.Chown(noInteractiveLoginPath, uid, gid)
585+
fmt.Fprint(w, "<p><code>no-interactive-login</code> file has been written successfully.</p>")
586+
}
569587
return true
570588
}() { goto leave }
571589

pkg/gitus/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ type GitusConfig struct {
164164
// could be more in the future.
165165
Theme GitusThemeConfig `json:"theme"`
166166

167+
// "no-interactive-shell" message.
168+
// the message that would get displayed when people try to log in w/
169+
// a configured ssh public key.
170+
NoInteractiveShellMessage string `json:"noSshLoginMessage"`
167171
}
168172

169173
const (
@@ -450,6 +454,7 @@ func CreateConfigFile(p string) error {
450454
ForegroundColor: "black",
451455
BackgroundColor: "white",
452456
},
457+
NoInteractiveShellMessage: "Direct shell access is forbidden on this host.",
453458
}, "", " ")
454459
if err != nil { return err }
455460
f.Write(marshalRes)

routes/controller/admin/site-config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func bindAdminSiteConfigController(ctx *RouterContext) {
9292
rc.Config.GitUser = r.Form.Get("git-user")
9393
rc.Config.GitConfig.HTTPCloneProtocol.V1Dumb = len(strings.TrimSpace(r.Form.Get("git-http-enable-v1dumb"))) > 0
9494
rc.Config.GitConfig.HTTPCloneProtocol.V2 = len(strings.TrimSpace(r.Form.Get("git-http-enable-v2"))) > 0
95+
rc.Config.NoInteractiveShellMessage = strings.TrimSpace(r.Form.Get("no-interactive-shell-message"))
9596
err := rc.Config.Sync()
9697
if err != nil {
9798
LogTemplateError(rc.LoadTemplate("admin/site-config").Execute(w, &templates.AdminConfigTemplateModel{

templates/admin/site-config.template.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ <h1 class="header-name" style="margin-bottom: 0">Admin</h1>
7676
<td><label class="field-label" for="chk-http-enable-v2">Enable v2 protocol for HTTP clone</label></td>
7777
<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>
7878
</tr>
79+
<tr class="field">
80+
<td><label class="field-label" for="tf-no-interactive-shell-message">"No Interactive Shell" message:</label></td>
81+
<td><input name="no-interactive-shell-message" id="tf-no-interactive-shell-message" class="field-tf" value="{{.Config.NoInteractiveShellMessage}}" /></td>
82+
</tr>
7983
<tr class="field">
8084
<td></td>
8185
<td><input class="field-submit" type="submit" value="Save Config" /></td>

templates/webinstaller/_nav.template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<li><a href="/step3">Step 3: Session Config</a></li>
66
<li><a href="/step4">Step 4: Mailer Config</a></li>
77
<li><a href="/step5">Step 5: Receipt System Config</a></li>
8-
<li><a href="/step6">Step 6: Git Root &amp; Git User</a></li>
8+
<li><a href="/step6">Step 6: Git Config</a></li>
99
<li><a href="/step7">Step 7: Ignored Namespace/Repositories</a></li>
1010
<li><a href="/step8">Step 8: Web Setup</a></li>
1111
<li><a href="/step9">Step 9: Confirm Code Manager Setup</a></li>

0 commit comments

Comments
 (0)