Repository navigation
Expand file tree
/
Copy pathovlc
More file actions
168 lines (139 loc) · 4.89 KB
/
Copy pathovlc
File metadata and controls
168 lines (139 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# OVLC by Ravikumar Paghdal
# Check if the user is root
if [ "$(id -u)" -ne "0" ]; then
echo "ovlc must be run as root."
exit 1 # Exit with an error code
fi
TEXT_CONTENT=$(cat <<'EOF'
.d88888b. 888 888 888 .d8888b.
d88P" "Y88b 888 888 888 d88P Y88b
888 888 888 888 888 888 888
888 888 Y88b d88P 888 888
888 888 Y88b d88P 888 888
888 888 Y88o88P 888 888 888
Y88b. .d88P Y888P 888 Y88b d88P
"Y88888P" Y8P 88888888 "Y8888P"
Developed by @_RaviRamesh
EOF
)
# Function to center text
center_text() {
local text="$1"
local terminal_width=$(tput cols)
local text_width=${#text}
local padding=$(( (terminal_width - text_width) / 2 ))
printf "%${padding}s" "" # Add leading spaces
echo "$text"
}
# Clear the screen
clear
# Animate the text content with a delay
while IFS= read -r line; do
centered_line=$(center_text "$line")
echo "$centered_line"
sleep 0.5 # Delay in seconds (500ms)
done <<< "$TEXT_CONTENT"
# Reset terminal to default
clear
source utils
source parseimages
# Define the dialog exit status codes
: ${DIALOG_START=0}
: ${DIALOG_STOP=3}
: ${DIALOG_EXIT=1}
fundialog=${fundialog=dialog}
trap ctrl_c INT
declare -a choices
ipaddr=$(ip -4 addr show | grep -v "127.0.0.1" | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n 1)
os_clear_cache
show_progress() {
local docker_command="$1" # The command to run
local max=100 # Maximum value for progress bar
local total_time=2 # Target time for full progress in seconds (2 seconds)
local dialog_title="$2" # Title for the dialog box
local dialog_gauge_message="$3" # Message for the gauge
# Start the timer and record the start time
start_time=$(date +%s)
# Execute the command in the background
eval "$docker_command" > /dev/null 2>&1 &
docker_pid=$!
# Open the progress bar dialog
(
progress=0
while [ -d /proc/$docker_pid ]; do
# Calculate elapsed time and calculate progress proportionally
elapsed_time=$(($(date +%s) - $start_time))
# Calculate progress as a percentage (keep it in bounds between 0 and 100)
progress=$(( (elapsed_time * max) / total_time ))
if [ $progress -gt $max ]; then
progress=$max
fi
# Output current progress to the dialog (show the percentage of completion)
echo $progress
sleep 0.1 # Update the progress every 0.1 seconds
done
) | dialog --title "$dialog_title" --gauge "$dialog_gauge_message" 10 70 0
# Wait for the Docker process to complete
wait $docker_pid
}
while true
do
upcon=`docker ps`
num_upcon=`echo "$upcon" | wc -l`
free_ram_gb=$(echo "scale=2; $(free -m | grep -i mem | awk '{print $4}') / 1024" | bc)
j=1
for i in $(seq 1 $((count - 1)))
do
choices[$j]=$i
up=`echo "$upcon" | grep ${REPONAME[$i]} | wc -l`
if [ $up -eq 1 ]
then
choices[$((j + 1))]="${descs[$i]} *"
else
choices[$((j + 1))]=${descs[$i]}
fi
j=$((j + 2))
done
x=`$fundialog --stdout --clear \
--backtitle "OVLC (Open Source Vulnerable labs collections) v1.0 IP:${ipaddr}" \
--ok-label "START" --cancel-label "EXIT" \
--extra-button --extra-label "STOP" \
--menu "Applications List [Lab Started :$((num_upcon - 1))*] [Free RAM (GB) :${free_ram_gb}]" 0 0 13 "${choices[@]}" `
status=$?
clear
case $status in
$DIALOG_START)
check_status=`echo "$upcon" | grep "${REPONAME[$x]}" | wc -l`
if [ $check_status -eq 0 ]
then
if [ "$(echo "$free_ram_gb > 0.5" | bc)" -eq 1 ]
then
ports=$(echo "${PORT_ARGS[$x]}" | grep -oP '(-p\s+\d+):' | awk -F'[ :]' '{print $2}')
show_progress "${cmd_start[$x]}" "Starting container" "${APP_NAME[$x]} \nApplication running on IP ${ipaddr} and port ${ports}\n\nWait for this dialog to close."
temp=$(${cmd_post[$x]})
else
dialog --title "Alert" --msgbox "Free RAM is less then 500 MB, please stop nonusable app first and try again." 0 0
fi
else
dialog --title "Status" --msgbox "${APP_NAME[$x]} alrady running.." 0 0
fi ;;
$DIALOG_STOP)
check_status=`echo "$upcon" | grep "${REPONAME[$x]}" | wc -l`
if [ $check_status -eq 0 ]
then
dialog --title "Status" --msgbox "${APP_NAME[$x]} App not running.." 0 0
else
show_progress "${cmd_stop[$x]}" "Stoping container" "${APP_NAME[$x]}"
os_clear_cache
fi ;;
$DIALOG_EXIT)
os_clear_cache
break ;;
esac
done
ctrl_c
exit