Skip to content

Commit

Permalink
Merge pull request #669 from aau-network-security/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mrtrkmn authored Aug 18, 2021
2 parents 98a5be0 + 9fae150 commit a8a1bd7
Show file tree
Hide file tree
Showing 34 changed files with 867 additions and 577 deletions.
2 changes: 1 addition & 1 deletion client/cli/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *Client) CmdEventCreate() *cobra.Command {
DisableExercises: disabledExercises,
Available: int32(available),
Capacity: int32(capacity),
OnlyVPN: false,
OnlyVPN: 0,
StartTime: time.Now().AddDate(0, 0, int(startTime)).Format("2006-01-02 15:04:05"),
FinishTime: time.Now().AddDate(0, 0, int(finishTime)).Format("2006-01-02 15:04:05"),
SecretEvent: secretKey,
Expand Down
15 changes: 9 additions & 6 deletions daemon/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import (
const (
charSet = "abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
numSet = "0123456789"
numSet = "0123456789"
NoVPN = 0
VPN = 1
VPNBrowser = 2
)

var (
Expand All @@ -40,7 +43,7 @@ var (
func (d *daemon) startEvent(ev guacamole.Event) {
conf := ev.GetConfig()
var frontendNames []string
if !ev.GetConfig().OnlyVPN {
if ev.GetConfig().OnlyVPN != VPN {
for _, f := range conf.Lab.Frontends {
frontendNames = append(frontendNames, f.Image)
}
Expand Down Expand Up @@ -76,7 +79,7 @@ func (d *daemon) CreateEvent(req *pb.CreateEventRequest, resp pb.Daemon_CreateEv
Str("startTime", req.StartTime).
Str("finishTime", req.FinishTime).
Str("SecretKey", req.SecretEvent).
Bool("VPN", req.OnlyVPN).
Int32("VPN", req.OnlyVPN).
Msg("create event")
// get random subnet for vpn connection
// check from database if subnet is already assigned to an event or not
Expand All @@ -86,7 +89,7 @@ func (d *daemon) CreateEvent(req *pb.CreateEventRequest, resp pb.Daemon_CreateEv
return fmt.Errorf("user credentials could not found on context %v", err)
}

if req.OnlyVPN && req.Capacity > 253 {
if (req.OnlyVPN == VPN || req.OnlyVPN == VPNBrowser) && req.Capacity > 253 {
resp.Send(&pb.LabStatus{ErrorMessage: CapacityExceedsErr.Error()})
return CapacityExceedsErr
}
Expand Down Expand Up @@ -192,7 +195,7 @@ func (d *daemon) CreateEvent(req *pb.CreateEventRequest, resp pb.Daemon_CreateEv
},
Status: Running,
CreatedBy: user.Username,
OnlyVPN: req.OnlyVPN,
OnlyVPN: req.OnlyVPN, // 0 novpn 1 // vpn 2 // browser+vpn
VPNAddress: vpnAddress,
SecretKey: secretKey,
}
Expand Down Expand Up @@ -625,7 +628,7 @@ func (d *daemon) generateEventConfig(event *pbc.GetEventResponse_Events, status
Str("startTime", event.StartedAt).
Str("finishTime", event.ExpectedFinishTime).
Str("SecretKey", event.SecretKey).
Bool("VPN", event.OnlyVPN).Msgf("Generating event config from database !")
Int32("VPN", event.OnlyVPN).Msgf("Generating event config from database !")

eventConfig := store.EventConfig{
Name: event.Name,
Expand Down
44 changes: 44 additions & 0 deletions daemon/exercise.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,50 @@ import (
"github.com/rs/zerolog/log"
)

func (d *daemon) ListCategories(ctx context.Context, req *pb.Empty) (*pb.ListCategoriesResponse, error) {
var categories []*pb.ListCategoriesResponse_Category
_, err := getUserFromIncomingContext(ctx)
if err != nil {
return &pb.ListCategoriesResponse{}, NoUserInformation
}

categs, err := d.exClient.GetCategories(ctx, &eproto.Empty{})
if err != nil {
return &pb.ListCategoriesResponse{}, fmt.Errorf("[exercise-service]: ERR getting categories %v", err)
}
var cats []store.Category

for _, c := range categs.Categories {
category, err := protobufToJson(c)
if err != nil {
return nil, err
}
cstruct := store.Category{}
json.Unmarshal([]byte(category), &cstruct)
cats = append(cats, cstruct)
}

for _, c := range cats {
// Render markdown from orgdescription to html
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.HardLineBreak
parser := parser.NewWithExtensions(extensions)

md := []byte(c.CatDescription)
unsafeHtml := markdown.ToHTML(md, parser, nil)

//Sanitizing unsafe HTML with bluemonday
html := bluemonday.UGCPolicy().SanitizeBytes(unsafeHtml)
c.CatDescription = string(html)

categories = append(categories, &pb.ListCategoriesResponse_Category{
Tag: string(c.Tag),
Name: c.Name,
CatDescription: c.CatDescription,
})
}

return &pb.ListCategoriesResponse{Categories: categories}, nil
}
func (d *daemon) ListExercises(ctx context.Context, req *pb.Empty) (*pb.ListExercisesResponse, error) {
var vboxCount int32
var exercises []*pb.ListExercisesResponse_Exercise
Expand Down
Loading

0 comments on commit a8a1bd7

Please sign in to comment.