Skip to content

Commit ad9b78d

Browse files
committed
moved scripts to separate modules
1 parent bf27af6 commit ad9b78d

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

Dockerfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ RUN go mod download
1212
COPY *.go ./
1313
COPY db ./db
1414
COPY utils ./utils
15-
COPY tcpdump.sh ./
16-
COPY cleanup.sh ./
1715

1816
RUN go build -o /mirroring-api-logging
19-
RUN chmod +x tcpdump.sh;
20-
RUN chmod +x cleanup.sh
21-
22-
EXPOSE 4789/udp
2317

2418
CMD ["/bin/sh", "-c", "mkdir -p /app/files && /mirroring-api-logging"]

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ func readTCPFileAndProcess(file fs.FileInfo) {
615615
}
616616

617617
log.Println("Begin reading file: " + file.Name() + " size (" + strconv.FormatInt(file.Size(), 10) + ")")
618-
start := time.Now().Unix()
618+
start := time.Now().UnixMilli()
619619

620620
assemblerMap = make(map[int]*tcpassembly.Assembler)
621621

@@ -627,6 +627,6 @@ func readTCPFileAndProcess(file fs.FileInfo) {
627627
handle.Close()
628628
}
629629

630-
end := time.Now().Unix()
630+
end := time.Now().UnixMilli()
631631
log.Println("Finished reading file: "+file.Name()+" size ("+strconv.FormatInt(file.Size(), 10)+")"+" in ", end-start, "ms")
632632
}

scripts/cleanup/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Use an official lightweight base image with tcpdump installed
2+
FROM alpine:latest
3+
4+
# Install necessary packages
5+
RUN apk add --no-cache tcpdump
6+
7+
# Copy your script to the container
8+
COPY cleanup.sh /usr/local/bin/cleanup.sh
9+
10+
# Make the script executable
11+
RUN chmod +x /usr/local/bin/cleanup.sh
12+
13+
# Set the default command to run your script
14+
CMD ["/usr/local/bin/cleanup.sh"]

cleanup.sh renamed to scripts/cleanup/cleanup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
max=80
4-
base_dir="/app/files" # Base directory for all files
4+
base_dir="/files" # Base directory for all files
55

66
while true
77
do

scripts/tcpdump/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Use an official lightweight base image with tcpdump installed
2+
FROM alpine:latest
3+
4+
# Install necessary packages
5+
RUN apk add --no-cache tcpdump
6+
7+
# Copy your script to the container
8+
COPY tcpdump.sh /usr/local/bin/tcpdump.sh
9+
10+
# Make the script executable
11+
RUN chmod +x /usr/local/bin/tcpdump.sh
12+
13+
# Set the default command to run your script
14+
CMD ["/usr/local/bin/tcpdump.sh"]

tcpdump.sh renamed to scripts/tcpdump/tcpdump.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ modules=$(echo "$modules" | tr -d -c 0-9)
1515
# Create directories if they don't exist
1616
i=1
1717
while [ $i -le $modules ]; do
18-
dir="/app/files/files_$i"
18+
dir="/files/files_$i"
1919

2020
# Check if the directory exists, and create it only if it doesn't exist
2121
if [ ! -d "$dir" ]; then
@@ -34,7 +34,7 @@ while true; do
3434
index=$((counter % modules + 1))
3535

3636
# Set the directory based on the index
37-
dir="/app/files/files_$index"
37+
dir="/files/files_$index"
3838

3939
# Write to the corresponding directory
4040
tcpdump -i "$interface" port not 22 -w "$dir/%s.pcap" -G 30 -W 1 -K -n

0 commit comments

Comments
 (0)