Security Update #6

Merged
raul merged 25 commits from testing into main 2024-05-17 08:00:14 +02:00
1 changed files with 12 additions and 5 deletions
Showing only changes of commit 5bb37a53fe - Show all commits

View File

@ -14,6 +14,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"time"
) )
var ( var (
@ -69,6 +70,12 @@ func startSecureServer() (net.Listener, error) {
return ln, err return ln, err
} }
func getTime() string {
t := time.Now()
currentTime := fmt.Sprintf("%d-%02d-%02d | %02d:%02d:%02d", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
return currentTime
}
func Server() { func Server() {
var ln net.Listener var ln net.Listener
var err error var err error
@ -188,8 +195,8 @@ func handleConn(conn net.Conn, chatChan chan string) {
newUserTemplate := new(User) newUserTemplate := new(User)
newUser := newUserTemplate.CreateUser(userName, userIP) newUser := newUserTemplate.CreateUser(userName, userIP)
joinMessage := fmt.Sprintf("%v has joined the chat!", newUser.Username) joinMessage := fmt.Sprintf("[%v] %v has joined the chat!", getTime(), newUser.Username)
fmt.Println(joinMessage) fmt.Println(joinMessage + " [" + newUser.IP + "]")
addToLog(fmt.Sprintln(joinMessage)) addToLog(fmt.Sprintln(joinMessage))
//conn.Write([]byte(joinMessage)) //conn.Write([]byte(joinMessage))
sendMessage(joinMessage) sendMessage(joinMessage)
@ -198,8 +205,8 @@ func handleConn(conn net.Conn, chatChan chan string) {
for { for {
message, err := getUserInput(conn) message, err := getUserInput(conn)
if err != nil { if err != nil {
quitMessage := fmt.Sprintf("%v has disconnected!", newUser.Username) quitMessage := fmt.Sprintf("[%v] %v has disconnected!", getTime(), newUser.Username)
fmt.Println(quitMessage) fmt.Println(quitMessage + " [" + newUser.IP + "]")
addToLog(fmt.Sprintln(quitMessage)) addToLog(fmt.Sprintln(quitMessage))
sendMessage(quitMessage) sendMessage(quitMessage)
//removeFromList(chatChan) //removeFromList(chatChan)
@ -208,7 +215,7 @@ func handleConn(conn net.Conn, chatChan chan string) {
// } // }
return return
} }
finalMessage := fmt.Sprintf("[%v] %v: %v", newUser.IP, newUser.Username, strings.TrimRight(message, "\n")) finalMessage := fmt.Sprintf("[%v] %v: %v", getTime(), newUser.Username, strings.TrimRight(message, "\n"))
fm := fmt.Sprintf("%v\n", finalMessage) fm := fmt.Sprintf("%v\n", finalMessage)
fmt.Print(fm) fmt.Print(fm)
addToLog(fm) addToLog(fm)