base64 isn't needed for ssh key
This commit is contained in:
parent
992a11d35f
commit
a4435a2247
@ -21,4 +21,4 @@ Currently, PublAPI has only two routes, /online and /signup.
|
|||||||
| ROUTE | TYPE | EXTRA ARGS | DESCRIPTION |
|
| ROUTE | TYPE | EXTRA ARGS | DESCRIPTION |
|
||||||
|---------|------|-----------------|------------------------------------|
|
|---------|------|-----------------|------------------------------------|
|
||||||
| /online | GET | N/A | Returns the number of online users |
|
| /online | GET | N/A | Returns the number of online users |
|
||||||
| /signup | POST | username, email, ssh | Creates a register script and notifies admins that a new registration request was sent. Note: SSH Key must be sent in base64 form |
|
| /signup | POST | username, email, ssh | Creates a register script and notifies admins that a new registration request was sent.|
|
||||||
|
@ -20,12 +20,6 @@ func SignupPage(c *fiber.Ctx) error {
|
|||||||
log.Error("username, email and ssh must be filled", username, email, ssh)
|
log.Error("username, email and ssh must be filled", username, email, ssh)
|
||||||
return c.SendStatus(fiber.StatusBadRequest)
|
return c.SendStatus(fiber.StatusBadRequest)
|
||||||
}
|
}
|
||||||
sshke, err := base64.StdEncoding.DecodeString(ssh)
|
|
||||||
sshkey := string(sshke)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("unable to decode base64 ssh key")
|
|
||||||
return c.SendStatus(fiber.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
// create user file
|
// create user file
|
||||||
f, err := os.Create("/var/publapi/users/" + username + ".sh")
|
f, err := os.Create("/var/publapi/users/" + username + ".sh")
|
||||||
@ -42,7 +36,7 @@ func SignupPage(c *fiber.Ctx) error {
|
|||||||
"useradd -Um -s /bin/bash " + username + "\n" +
|
"useradd -Um -s /bin/bash " + username + "\n" +
|
||||||
"printf \"%s\\n%s\" \"${pass}\" \"${pass}\" | passwd " + username + "\n" +
|
"printf \"%s\\n%s\" \"${pass}\" \"${pass}\" | passwd " + username + "\n" +
|
||||||
"mkdir /home/" + username + "/.ssh\n" +
|
"mkdir /home/" + username + "/.ssh\n" +
|
||||||
"echo '" + sshkey + "' > /home/" + username + "/.ssh/authorized_keys\n" +
|
"echo '" + ssh + "' > /home/" + username + "/.ssh/authorized_keys\n" +
|
||||||
"chmod 700 /home/" + username + "/.ssh\n" +
|
"chmod 700 /home/" + username + "/.ssh\n" +
|
||||||
"chmod 600 /home/" + username + "/.ssh/authorized_keys\n" +
|
"chmod 600 /home/" + username + "/.ssh/authorized_keys\n" +
|
||||||
"chown -R " + username + ":" + username + " /home/" + username + "/.ssh\n" +
|
"chown -R " + username + ":" + username + " /home/" + username + "/.ssh\n" +
|
||||||
|
Loading…
Reference in New Issue
Block a user