base64 isn't needed for ssh key

This commit is contained in:
Arya Kiran 2023-01-17 20:39:46 +05:30
parent 992a11d35f
commit a4435a2247
Signed by: arya
GPG Key ID: 842D12BDA50DF120
2 changed files with 2 additions and 8 deletions

View File

@ -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.|

View File

@ -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" +