mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Check port function
This commit is contained in:
parent
542943e39a
commit
ed2f051fb0
2 changed files with 27 additions and 0 deletions
|
@ -345,6 +345,15 @@ app:
|
|||
full: --value
|
||||
help: Value to set
|
||||
|
||||
### app_checkport()
|
||||
checkport:
|
||||
action_help: Check availability of a local port
|
||||
api: GET /app/checkport
|
||||
arguments:
|
||||
port:
|
||||
help: Port to check
|
||||
pattern: '^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$'
|
||||
|
||||
### app_checkurl()
|
||||
checkurl:
|
||||
action_help: Check availability of a web path
|
||||
|
@ -507,6 +516,7 @@ firewall:
|
|||
arguments:
|
||||
port:
|
||||
help: Port to open
|
||||
pattern: '^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$'
|
||||
protocol:
|
||||
help: Protocol associated with port
|
||||
choices:
|
||||
|
|
|
@ -31,6 +31,7 @@ import stat
|
|||
import yaml
|
||||
import time
|
||||
import re
|
||||
import socket
|
||||
from yunohost import YunoHostError, YunoHostLDAP, win_msg, random_password, is_true, validate
|
||||
from yunohost_domain import domain_list, domain_add
|
||||
from yunohost_user import user_info
|
||||
|
@ -500,6 +501,22 @@ def app_setting(app, key, value=None):
|
|||
yaml.safe_dump(app_settings, f, default_flow_style=False)
|
||||
|
||||
|
||||
def app_checkport(port):
|
||||
"""
|
||||
|
||||
"""
|
||||
try:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.settimeout(1)
|
||||
s.connect(("localhost", int(port)))
|
||||
s.close()
|
||||
except socket.error:
|
||||
win_msg(_("Port available: ")+ str(port))
|
||||
else:
|
||||
raise YunoHostError(22, _("Port not available"))
|
||||
|
||||
|
||||
|
||||
def app_checkurl(url, app=None):
|
||||
"""
|
||||
|
||||
|
|
Loading…
Reference in a new issue