Skip to content

Commit

Permalink
Merge pull request #682 from aau-network-security/hotfix/add-challeng…
Browse files Browse the repository at this point in the history
…e-issue-#680

Hotfix/add challenge issue #680
  • Loading branch information
mrtrkmn authored Sep 28, 2021
2 parents 1f89c36 + a4d686d commit 8e783e3
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 52 deletions.
24 changes: 13 additions & 11 deletions daemon/exercise.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

pb "github.com/aau-network-security/haaukins/daemon/proto"
eproto "github.com/aau-network-security/haaukins/exercise/ex-proto"
"github.com/aau-network-security/haaukins/lab"
"github.com/aau-network-security/haaukins/store"
storeProto "github.com/aau-network-security/haaukins/store/proto"
"github.com/golang/protobuf/jsonpb"
Expand Down Expand Up @@ -280,17 +279,20 @@ func (d *daemon) AddChallenge(req *pb.AddChallengeRequest, srv pb.Daemon_AddChal
}
}

ev.PauseSignup(true)
var addChalError error
var lb interface{}
sendBackLab := make(chan lab.Lab)
go func() {
lb = <-ev.GetHub().Queue()
if err := lb.(lab.Lab).AddChallenge(ctx, exers...); err != nil {
addChalError = err
}
sendBackLab <- lb.(lab.Lab)
ev.GetHub().Update(sendBackLab)
}()

for _, lb := range ev.GetHub().Labs() {
waitGroup.Add(1)
go func() {
if err := lb.AddChallenge(ctx, exers...); err != nil {
addChalError = err
}
waitGroup.Done()
}()
waitGroup.Wait()
}
ev.PauseSignup(false)

frontendData := ev.GetFrontendData()
for tid, l := range ev.GetAssignedLabs() {
Expand Down
5 changes: 5 additions & 0 deletions lab/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Hub interface {
Suspend(context.Context) error
Resume(context.Context) error
Update(labTag <-chan Lab)
Labs() map[string]Lab
UpdateExercises(exercises []store.Exercise)
}

Expand Down Expand Up @@ -212,3 +213,7 @@ func (h *hub) Resume(ctx context.Context) error {

return resumeError
}

func (h *hub) Labs() map[string]Lab {
return h.labs
}
5 changes: 5 additions & 0 deletions svcs/amigo/amigo.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type siteInfo struct {
Hosts []Hosts
Notification Notification
LabSubnet string
SignupPaused bool // this is used when add challenge is executed in the platform
}

type team struct {
Expand Down Expand Up @@ -134,6 +135,10 @@ func (am *Amigo) SetNotification(n Notification) {
am.globalInfo.Notification = n
}

func (am *Amigo) PauseSignup(pause bool) {
am.globalInfo.SignupPaused = pause
}

func (am *Amigo) getSiteInfo(w http.ResponseWriter, r *http.Request) siteInfo {
info := am.globalInfo

Expand Down
87 changes: 47 additions & 40 deletions svcs/amigo/resources/private/signup.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,63 @@
<div class="row h-100">
<div class="col" style="min-height: 800px!important; height: 100vh">
<div class="login-content h-100">
<form class="login-form" method="post" action="/signup">
<h4>Create a Team</h4>
<div class="input-div">
<div class="input-div-icon">
<i class="fas fa-user"></i>
</div>
<div class="input-div-input">
<h5>Team Name</h5>
<input class="input" name="team-name" type="text" maxlength="15">
</div>
</div>
<div class="input-div">
<div class="input-div-icon">
<i class="fas fa-lock"></i>
</div>
<div class="input-div-input">
<h5>Password</h5>
<input class="input" name="password" type="password">
</div>
</div>
<div class="input-div mb-2">
<div class="input-div-icon">
<i class="fas fa-lock"></i>
{{ if .SignupPaused }}
<h4>
Signup is temporarily paused, new challenges are processing.
Check few minutes later to sign up.
</h4>
{{ else }}
<form class="login-form" method="post" action="/signup">
<h4>Create a Team</h4>
<div class="input-div">
<div class="input-div-icon">
<i class="fas fa-user"></i>
</div>
<div class="input-div-input">
<h5>Team Name</h5>
<input class="input" name="team-name" type="text" maxlength="15">
</div>
</div>
<div class="input-div-input">
<h5>Repeat Password</h5>
<input class="input" name="password-repeat" type="password">
<div class="input-div">
<div class="input-div-icon">
<i class="fas fa-lock"></i>
</div>
<div class="input-div-input">
<h5>Password</h5>
<input class="input" name="password" type="password">
</div>
</div>
</div>
{{ if .IsSecretEvent }}
<div class="input-div mb-2">
<div class="input-div-icon">
<i class="fas fa-user-secret"></i>
<i class="fas fa-lock"></i>
</div>
<div class="input-div-input">
<h5>Secret Key</h5>
<input class="input" name="secret-event-key" type="password" maxlength="20" minlength="1">
<h5>Repeat Password</h5>
<input class="input" name="password-repeat" type="password">
</div>
</div>
{{ end }}
<div class="g-recaptcha ml-0 ml-sm-4" data-sitekey="6LduW74ZAAAAAI9eDk0Btd_fbjegoXOfCSR-kLSo"></div>
<input type="submit" class="btn btn-login mt-3" value="Login">
{{ with .Content }}
{{ if .SignupError }}
<div class="mt-2 text-danger">
{{ .SignupError }}
{{ if .IsSecretEvent }}
<div class="input-div mb-2">
<div class="input-div-icon">
<i class="fas fa-user-secret"></i>
</div>
{{ end }}
<div class="input-div-input">
<h5>Secret Key</h5>
<input class="input" name="secret-event-key" type="password" maxlength="20" minlength="1">
</div>
</div>
{{ end }}
</form>
<div class="g-recaptcha ml-0 ml-sm-4" data-sitekey="6LduW74ZAAAAAI9eDk0Btd_fbjegoXOfCSR-kLSo"></div>
<input type="submit" class="btn btn-login mt-3" value="Login">
{{ with .Content }}
{{ if .SignupError }}
<div class="mt-2 text-danger">
{{ .SignupError }}
</div>
{{ end }}
{{ end }}
</form>
{{ end }}
</div>
</div>
<div class="col myd-none" style="min-height: 800px!important;">
Expand Down
6 changes: 5 additions & 1 deletion svcs/guacamole/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ type Event interface {
Finish(string)
AssignLab(*store.Team, lab.Lab) error
Handler() http.Handler

PauseSignup(bool)
AddNotification(message string, loggedInUsers bool) error
SetStatus(int32)
GetStatus() int32
Expand Down Expand Up @@ -322,6 +322,10 @@ func (ev *event) AddNotification(message string, loggedInUsers bool) error {
return nil
}

func (ev *event) PauseSignup(pause bool) {
ev.amigo.PauseSignup(pause)
}

func (ev *event) GetFrontendData() *amigo.FrontendData {
return ev.amigo.FrontEndData
}
Expand Down

0 comments on commit 8e783e3

Please sign in to comment.