Skip to content

Commit

Permalink
Input validations and parent process checking on Traffic back-end.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Jul 29, 2024
1 parent 7335fa2 commit 1878f19
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions backend/traffic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func failOnUmatchedArgSize(size int, args []string) {
}

func main() {
if !proc.IsParentProcessPHP() {
os.Exit(0)
}

if len(os.Args) != 3 {
proc.ShowFailedResponse("Invalid argument arity.")
os.Exit(0)
Expand All @@ -54,6 +58,16 @@ func main() {
apiKey := os.Args[1]
appId := os.Args[2]

if !validateApiKey(apiKey) {
proc.ShowFailedResponse("Invalid API key string.")
os.Exit(0)
}

if !validateApiId(appId) {
proc.ShowFailedResponse("Invalid API ID string.")
os.Exit(0)
}

DispatchWithCallback(func(db *sql.DB) {
query, err := db.Query("SELECT count FROM traffic WHERE api_key=\"" + apiKey +
"\" AND app_id=\"" + appId + "\" ORDER BY STR_TO_DATE(\"date_time\", \"%d%m%Y\") ASC LIMIT 30")
Expand Down

0 comments on commit 1878f19

Please sign in to comment.