Skip to content

Commit a2520c3

Browse files
committed
Updating timestamp to UTC and updating timestamp format
1 parent d8dfac7 commit a2520c3

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

app/h_terminal.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22

3-
from datetime import datetime
3+
from datetime import datetime, timezone
4+
5+
from app.utility.base_world import BaseWorld
46

57

68
class Handle:
@@ -14,8 +16,8 @@ async def run(socket, path, services):
1416
cmd = await socket.recv()
1517
handler = services.get('term_svc').socket_conn.tcp_handler
1618
paw = next(i.paw for i in handler.sessions if i.id == int(session_id))
17-
services.get('contact_svc').report['websocket'].append(
18-
dict(paw=paw, date=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), cmd=cmd)
19+
services.get('contact_svc').report['WEBSOCKET'].append(
20+
dict(paw=paw, date=datetime.now(timezone.utc).strftime(BaseWorld.TIME_FORMAT), cmd=cmd)
1921
)
2022
status, pwd, reply, response_time = await handler.send(session_id, cmd)
2123
await socket.send(json.dumps(dict(response=reply.strip(), pwd=pwd, status=status, response_time=response_time)))

shells/commands/commands.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ func RunCommand(message string, httpServer string, profile map[string]interface{
2424
} else if (strings.HasPrefix(message, "download")) {
2525
pieces := strings.Split(message, "download")
2626
go download(httpServer, pieces[1])
27-
return []byte("Download initiated\n"), 0, time.Now()
27+
return []byte("Download initiated\n"), 0, getUTCTimeStamp()
2828
} else if (strings.HasPrefix(message, "upload")) {
2929
pieces := strings.Split(message, "upload")
3030
go upload(httpServer, pieces[1])
31-
return []byte("Upload initiated\n"), 0, time.Now()
31+
return []byte("Upload initiated\n"), 0, getUTCTimeStamp()
3232
} else {
3333
bites, status, executionTimestamp := execute(message, strings.Split(reflect.ValueOf(profile["executors"]).String(), ",")[0])
3434
return bites, status, executionTimestamp
@@ -42,26 +42,26 @@ func execute(command string, executor string) ([]byte, int, time.Time) {
4242
var executionTimestamp time.Time
4343
if runtime.GOOS == "windows" {
4444
if executor == "cmd" {
45-
executionTimestamp = time.Now()
45+
executionTimestamp = getUTCTimeStamp()
4646
bites, error = exec.Command("cmd.exe", "/c", command).Output()
4747
} else {
48-
executionTimestamp = time.Now()
48+
executionTimestamp = getUTCTimeStamp()
4949
bites, error = exec.Command("powershell.exe", "-ExecutionPolicy", "Bypass", "-C", command).Output()
5050
}
5151
} else {
52-
executionTimestamp = time.Now()
52+
executionTimestamp = getUTCTimeStamp()
5353
bites, error = exec.Command("sh", "-c", command).Output()
5454
}
5555
if error != nil {
56-
executionTimestamp = time.Now()
56+
executionTimestamp = getUTCTimeStamp()
5757
bites = []byte(string(error.Error()))
5858
status = 1
5959
}
6060
return []byte(fmt.Sprintf("%s%s", bites, "\n")), status, executionTimestamp
6161
}
6262

6363
func changeDirectory(target string) ([]byte, time.Time) {
64-
executionTimestamp := time.Now()
64+
executionTimestamp := getUTCTimeStamp()
6565
os.Chdir(strings.TrimSpace(target))
6666
return []byte(" "), executionTimestamp
6767
}
@@ -120,3 +120,7 @@ func upload(server string, file string) []byte {
120120
resp.Body.Close()
121121
return []byte(" ")
122122
}
123+
124+
func getUTCTimeStamp() time.Time {
125+
return time.Now().UTC()
126+
}

0 commit comments

Comments
 (0)