Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

Commit

Permalink
added start date functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
thexyno committed Feb 6, 2020
1 parent 3f013e8 commit cc4c863
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
6 changes: 5 additions & 1 deletion frontend-dev/src/leaderboard.ts
Expand Up @@ -60,7 +60,11 @@ constructor() {
}
});

let ws = new WebSocket("wss://" + window.location.host + "/ws");

let protocol = "wss://";
if(document.URL.includes("http://"))
protocol = "ws://";
let ws = new WebSocket(protocol + window.location.host + "/ws");
ws.onopen = function() {
// Web Socket is connected, send data uting send()
console.log("ws connected");
Expand Down
2 changes: 1 addition & 1 deletion frontend-dev/src/main.ts
Expand Up @@ -153,7 +153,7 @@ addChallEventListener(title: string, points: number) {
flagInput.removeEventListener("keypress", this.flaginputeventlistenerfunc);
solutionbutton.removeEventListener("click", this.solutioneventlistenerfunc);

this.flagsubmiteventlistenerfunc = function () {
this.flagsubmiteventlistenerfunc = () => {
const data = new URLSearchParams();
checkLoading.style.display = "block";
data.append("flag", flagInput.value);
Expand Down
14 changes: 9 additions & 5 deletions internal/cfg/config.go
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/gorilla/securecookie"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"
)

const (
Expand Down Expand Up @@ -46,6 +46,7 @@ type DesignConfig struct {
// Config stores settings
type Config struct {
Port int64 `json:"port"`
StartDate string `json:"startdate"`
Key string `json:"key"`
ChallengeInfoDir string `json:"challinfodir"`
SSHHost string `json:"sshhost"`
Expand Down Expand Up @@ -76,9 +77,10 @@ func getConfigYAML() (Config, error) {

//Write default config to disk
config = Config{
Key: base64.StdEncoding.EncodeToString(key),
SSHHost: "ctf.wtfd.tech",
Port: defaultPort,
Key: base64.StdEncoding.EncodeToString(key),
SSHHost: "ctf.wtfd.tech",
Port: defaultPort,
StartDate: time.Now().Format(time.RubyDate),
ChallengeInfoDir: "../challenges/info/",
BugreportConfig: BugreportConfig{
ServiceDeskAddress: "-", // service desk disabled
Expand Down Expand Up @@ -120,7 +122,9 @@ func getConfigYAML() (Config, error) {
return config, err
}
}
fmt.Fprintf(os.Stderr, "a: %v", config)
if _, err := time.Parse(time.RubyDate, config.StartDate); err != nil {
return config, err
}
return config, nil

}
Expand Down
7 changes: 6 additions & 1 deletion internal/liveScoreboard.go
Expand Up @@ -112,7 +112,12 @@ func updateScoreboard() error {
solves := wtfdDB.GetSolvesWithTime(u.Name)
data := make([]chartDataPoint, len(solves)+1)
sum := 0
data[0] = chartDataPoint{T: u.Created.Format(time.RubyDate), Y: sum, Label: "User Created"}
timeChallengeStart, _ := time.Parse(time.RubyDate, config.StartDate)
timecreated := timeChallengeStart
if u.Created.After(timeChallengeStart) {
timecreated = u.Created
}
data[0] = chartDataPoint{T: timecreated.Format(time.RubyDate), Y: sum, Label: "User Created"}
for i, s := range solves {
chall, err := challs.Find(s.ChallengeName)
if err != nil {
Expand Down
27 changes: 16 additions & 11 deletions internal/server.go
Expand Up @@ -266,15 +266,15 @@ func mainpage(w http.ResponseWriter, r *http.Request) {
}
}
data := mainPageData{
PageTitle: "foss-ag O-Phasen CTF",
Config: config,
Challenges: challs,
GeneratedName: genu,
ADC: AllDepsCompleted,
User: user,
IsUser: ok,
RowNums: rnums,
ColNums: cnums,
PageTitle: "foss-ag O-Phasen CTF",
Config: config,
Challenges: challs,
GeneratedName: genu,
ADC: AllDepsCompleted,
User: user,
IsUser: ok,
RowNums: rnums,
ColNums: cnums,
}
err = mainpagetemplate.Execute(w, data)
if err != nil {
Expand Down Expand Up @@ -323,6 +323,12 @@ func submitFlag(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintf(w, "ParseForm() err: %v", err)
return
}
t, _ := time.Parse(time.RubyDate, config.StartDate)
if time.Now().Before(t) {
w.WriteHeader(http.StatusBadRequest)
_, _ = fmt.Fprintf(w, "The challenge has not yet begun")
return
}

user, ok := getUser(r)
if !ok {
Expand Down Expand Up @@ -682,7 +688,6 @@ func authorview(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprint(w, chall.Author)
}


// Server is the main server func, start it with
// log.Fatal(wtfd.Server())
func Server() error {
Expand Down Expand Up @@ -722,7 +727,7 @@ func Server() error {
smtp.Config.Enabled = true
BRServiceDeskEnabled = true
}
BRRateLimitReports = config.BugreportConfig.ServiceDeskRateLimitReports
BRRateLimitReports = config.BugreportConfig.ServiceDeskRateLimitReports
BRRateLimitInterval = config.BugreportConfig.ServiceDeskRateLimitInterval
if BRServiceDeskEnabled {
fmt.Printf("ServiceDesk running at %s (Send via %s@%s:%d) (Max %dR/%.02fs)\n",
Expand Down

0 comments on commit cc4c863

Please sign in to comment.