From a4435a22478b2f1c57d17a17f8a30c7435084e7c Mon Sep 17 00:00:00 2001 From: Arya Kiran Date: Tue, 17 Jan 2023 20:39:46 +0530 Subject: [PATCH] base64 isn't needed for ssh key --- README.md | 2 +- pages/signup.go | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 815d1c8..b098fe1 100644 --- a/README.md +++ b/README.md @@ -21,4 +21,4 @@ Currently, PublAPI has only two routes, /online and /signup. | ROUTE | TYPE | EXTRA ARGS | DESCRIPTION | |---------|------|-----------------|------------------------------------| | /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.| diff --git a/pages/signup.go b/pages/signup.go index 65473ae..e88cfcf 100644 --- a/pages/signup.go +++ b/pages/signup.go @@ -20,12 +20,6 @@ func SignupPage(c *fiber.Ctx) error { log.Error("username, email and ssh must be filled", username, email, ssh) 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 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" + "printf \"%s\\n%s\" \"${pass}\" \"${pass}\" | passwd " + username + "\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 600 /home/" + username + "/.ssh/authorized_keys\n" + "chown -R " + username + ":" + username + " /home/" + username + "/.ssh\n" +