dodanie zabezpieczenia złego ip dla vpn

This commit is contained in:
Mateusz779 2023-04-21 10:05:58 +02:00
parent 2ebacf8563
commit 7297474469
3 changed files with 15 additions and 5 deletions

4
app.py
View File

@ -137,7 +137,7 @@ def delete(image_id):
return jsonify(message="409")
filename = db.get_conf_image_id(image_id)
squashfs = os.path.join(app.config['UPLOAD_FOLDER'], filename)
pubkey = os.path.join(app.config['UPLOAD_FOLDER'], filename.split(".")[0])
pubkey = os.path.join(app.config['UPLOAD_FOLDER'], filename.split(".")[0]+".pub")
if os.path.exists(squashfs):
os.remove(squashfs)
if os.path.exists(pubkey):
@ -238,6 +238,8 @@ def add_ip():
try:
token = request.headers['token']
ip = request.form['ip']
if utils.is_valid_ip_address(ip) is False:
return jsonify(message="400")
except:
return jsonify(message="400")
if db.update_image_allocation_ip_vpn(token, ip) is not None:

View File

@ -78,7 +78,7 @@
<td>{{ machine.start_time }}</td>
<td>{{ machine.ipvpn }}</td>
<td>{{ machine.iplocal }}</td>
<td><button class="btn btn-primary" onclick="ssh('{{ machine.ipvpn }}', '{{ machine.username }}', '{{ machine.password }}')">SSH</button></td>
<td><button class="btn btn-primary" onclick="ssh('{{ machine.ipvpn }}','{{machine.iplocal}}', '{{ machine.username }}', '{{ machine.password }}')">SSH</button></td>
</tr>
{% endfor %}
</tbody>
@ -86,9 +86,10 @@
</div>
<script>
function ssh(ipvpn, username, password) {
function ssh(ipvpn, iplocal username, password) {
const currentLocation = window.location;
const newUrl = currentLocation.protocol + '//' + currentLocation.hostname + ':' + {{ ssh_port }} + "/?hostname="+ipvpn+"&username="+username+"&password="+btoa(password);
let ip = ipvpn != null ? ipvpn : iplocal;
const newUrl = currentLocation.protocol + '//' + currentLocation.hostname + ':' + {{ ssh_port }} + "/?hostname="+ip+"&username="+username+"&password="+btoa(password);
window.open(newUrl,"_blank");
}
</script>

View File

@ -9,7 +9,7 @@ import threading
from time import sleep
import db
import config
import ipaddress
def generate_random_string(length):
letters = string.ascii_letters
@ -76,3 +76,10 @@ def init_threads():
allocation_thread = threading.Thread(
target=check_allocation_thread_function)
allocation_thread.start()
def is_valid_ip_address(ip: str) -> bool:
try:
ipaddress.IPv4Address(ip)
return True
except ipaddress.AddressValueError:
return False