token-validator: save ping state (0: ping ok, 1: arping only)
This commit is contained in:
parent
22a3d75645
commit
c35a8f5e6b
@ -31,7 +31,7 @@ do
|
|||||||
1)
|
1)
|
||||||
PAT=baaaaaad;;
|
PAT=baaaaaad;;
|
||||||
2)
|
2)
|
||||||
PAT=baadfood;;
|
PAT=baadf00d;;
|
||||||
3)
|
3)
|
||||||
PAT=baddcafe;;
|
PAT=baddcafe;;
|
||||||
4)
|
4)
|
||||||
@ -41,8 +41,9 @@ do
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
arping -I br-ext -c 1 -w 1 "${IP}" && {
|
arping -I br-ext -c 1 -w 1 "${IP}" && {
|
||||||
ping -c 1 -w 1 -p "${PAT}" "${IP}" &
|
ping -c 1 -w 1 -p "${PAT}" "${IP}"
|
||||||
curl -k -X POST -d '{"token": "'${SECRET_KEY}'"}' "https://172.23.200.1/api/students/$sid/pong"
|
STATE=$?
|
||||||
|
curl -k -X POST -d '{"challenge": '${STATE}', "token": "'${SECRET_KEY}'"}' "https://172.23.200.1/api/students/$sid/pong"
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -100,6 +100,7 @@ CREATE TABLE IF NOT EXISTS student_challenges(
|
|||||||
CREATE TABLE IF NOT EXISTS student_pong(
|
CREATE TABLE IF NOT EXISTS student_pong(
|
||||||
id_student INTEGER NOT NULL,
|
id_student INTEGER NOT NULL,
|
||||||
time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
state BOOLEAN NOT NULL DEFAULT 0,
|
||||||
FOREIGN KEY(id_student) REFERENCES students(id_student)
|
FOREIGN KEY(id_student) REFERENCES students(id_student)
|
||||||
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
|
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
|
@ -26,18 +26,23 @@ func lastPing(student Student, body []byte) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Student) lastPongs() (pongs []time.Time, err error) {
|
type Pong struct {
|
||||||
if rows, errr := DBQuery("SELECT time FROM student_pong WHERE id_student = ? ORDER BY time DESC", s.Id); errr != nil {
|
Date time.Time
|
||||||
|
State bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Student) lastPongs() (pongs []Pong, err error) {
|
||||||
|
if rows, errr := DBQuery("SELECT time, state FROM student_pong WHERE id_student = ? ORDER BY time DESC", s.Id); errr != nil {
|
||||||
return nil, errr
|
return nil, errr
|
||||||
} else {
|
} else {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var t time.Time
|
var p Pong
|
||||||
if err = rows.Scan(&t); err != nil {
|
if err = rows.Scan(&p.Date, &p.State); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pongs = append(pongs, t)
|
pongs = append(pongs, p)
|
||||||
}
|
}
|
||||||
if err = rows.Err(); err != nil {
|
if err = rows.Err(); err != nil {
|
||||||
return
|
return
|
||||||
@ -58,7 +63,7 @@ func stdPong(student Student, body []byte) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if res, err := DBExec("INSERT INTO student_pong (id_student, time) VALUES (?, ?)", student.Id, time.Now()); err != nil {
|
if res, err := DBExec("INSERT INTO student_pong (id_student, time, state) VALUES (?, ?, ?)", student.Id, time.Now(), gt.Challenge == 0); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
} else if _, err := res.LastInsertId(); err != nil {
|
} else if _, err := res.LastInsertId(); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
Reference in New Issue
Block a user