Skip to content

Commit

Permalink
🔒 Now API calls about led changes & geting stats requires user to be …
Browse files Browse the repository at this point in the history
…logged in
  • Loading branch information
keelus committed Jul 28, 2023
1 parent b6952bc commit 0031f07
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions server/handlers/apiHandler/ledHandler/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ func SetBrightness(c *gin.Context) {
}

func SetCooldown(c *gin.Context) {
if !internal.IsLogged(c) {
c.JSON(http.StatusForbidden, gin.H{"details": "User not logged in."})
return
}

amountStr := c.Param("amount")
mode := c.Param("mode")
amount, err := strconv.Atoi(amountStr)
Expand Down Expand Up @@ -350,6 +355,11 @@ func SetCooldown(c *gin.Context) {
}

func SetLedAmount(c *gin.Context) {
if !internal.IsLogged(c) {
c.JSON(http.StatusForbidden, gin.H{"details": "User not logged in."})
return
}

ledAmountStr := c.Param("amount")

ledAmount, err := strconv.Atoi(ledAmountStr)
Expand Down
8 changes: 7 additions & 1 deletion server/handlers/apiHandler/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,20 @@ func HandleLogout(c *gin.Context) {
logger.Log(c, logger.LOGIN, "User logout.")
c.Redirect(http.StatusTemporaryRedirect, "/")
}

func HandleGetStats(c *gin.Context) {
if !internal.IsLogged(c) {
c.JSON(http.StatusForbidden, gin.H{"details": "User not logged in."})
return
}

var temperature float64
var cpuUsage float64
var ramUsage float64
var diskUsage [2]float64
var sysUptime float64

if CUR_RASP {
if CUR_RASP { // TODO: Move functions to a single file dedicated for that only.
temperature, _ = getTemp()
cpuUsage, _ = getCpuUsage()
ramUsage, _ = getRamUsage()
Expand Down

0 comments on commit 0031f07

Please sign in to comment.