Browse Source

v6.3.1.0

Changelog: https://roxy-wi.org/changelog#6_3_1
pull/355/head
Pavel Loginov 2 years ago
parent
commit
16f8893a51
  1. 10
      app/modules/alerting/alerting.py
  2. 5
      app/modules/roxywi/common.py
  3. 79
      app/modules/roxywi/user.py
  4. 90
      app/options.py

10
app/modules/alerting/alerting.py

@ -262,3 +262,13 @@ def delete_slack_channel(channel_id) -> None:
if sql.delete_slack(channel_id):
print("Ok")
roxywi_common.logging('Roxy-WI server', f'The Slack channel {slack_name} has been deleted ', roxywi=1, login=1)
def update_telegram(token: str, channel: str, group: str, user_id: int) -> None:
sql.update_telegram(token, channel, group, user_id)
roxywi_common.logging('group ' + group, f'The Telegram token has been updated for channel: {channel}', roxywi=1, login=1)
def update_slack(token: str, channel: str, group: str, user_id: int) -> None:
sql.update_slack(token, channel, group, user_id)
roxywi_common.logging(f'group {group}', f'The Slack token has been updated for channel: {channel}', roxywi=1, login=1)

5
app/modules/roxywi/common.py

@ -181,7 +181,10 @@ def logging(server_ip: str, action: str, **kwargs) -> None:
log_file = f"{log_path}/config_edit-{cur_date}.log"
if kwargs.get('keep_history'):
keep_action_history(kwargs.get('service'), action, server_ip, login, ip)
try:
keep_action_history(kwargs.get('service'), action, server_ip, login, ip)
except Exception:
pass
try:
with open(log_file, 'a') as log:

79
app/modules/roxywi/user.py

@ -94,3 +94,82 @@ def update_user_password():
sql.update_user_password(password, user_id)
roxywi_common.logging('user ' + username, ' has changed password ', roxywi=1, login=1)
print("Ok")
def get_user_services() -> None:
user_id = common.checkAjaxInput(form.getvalue('getuserservices'))
groups = []
u_g = sql.select_user_groups(user_id)
services = sql.select_services()
for g in u_g:
groups.append(g.user_group_id)
env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True)
template = env.get_template('/show_user_services.html')
template = template.render(user_services=sql.select_user_services(user_id), id=user_id, services=services)
print(template)
def change_user_services() -> None:
user_id = common.checkAjaxInput(form.getvalue('changeUserServicesId'))
services = common.checkAjaxInput(form.getvalue('changeUserServices'))
user = common.checkAjaxInput(form.getvalue('changeUserServicesUser'))
try:
if sql.update_user_services(services=services, user_id=user_id):
roxywi_common.logging('Roxy-WI server', f'Access to the services has been updated for user: {user}',
roxywi=1, login=1)
except Exception as e:
print(e)
def get_user_groups() -> None:
user_id = common.checkAjaxInput(form.getvalue('getusergroups'))
groups = []
u_g = sql.select_user_groups(user_id)
for g in u_g:
groups.append(g.user_group_id)
env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True)
template = env.get_template('/show_user_groups.html')
template = template.render(groups=sql.select_groups(), user_groups=groups, id=user_id)
print(template)
def change_user_group() -> None:
group_id = common.checkAjaxInput(form.getvalue('changeUserGroupId'))
groups = common.checkAjaxInput(form.getvalue('changeUserGroups'))
user = common.checkAjaxInput(form.getvalue('changeUserGroupsUser'))
if sql.delete_user_groups(group_id):
for group in groups:
if group[0] == ',':
continue
try:
sql.update_user_groups(groups=group[0], user_group_id=group_id)
except Exception as e:
print(e)
roxywi_common.logging('Roxy-WI server', f'Groups has been updated for user: {user}', roxywi=1, login=1)
def change_user_active_group() -> None:
group_id = common.checkAjaxInput(form.getvalue('changeUserCurrentGroupId'))
user_uuid = common.checkAjaxInput(form.getvalue('changeUserGroupsUser'))
try:
if sql.update_user_current_groups(group_id, user_uuid):
print('Ok')
else:
print('error: Cannot change group')
except Exception as e:
print(e)
def get_user_active_group(user_id: str, group: str) -> None:
group_id = sql.get_user_id_by_uuid(user_id.value)
groups = sql.select_user_groups_with_names(group_id)
env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True)
template = env.get_template('/show_user_current_group.html')
template = template.render(groups=groups, group=group.value, id=group_id)
print(template)

90
app/options.py

@ -1559,28 +1559,25 @@ if form.getvalue('slackdel') is not None:
alerting.delete_slack_channel(channel_id)
if form.getvalue('updatetoken') is not None:
import modules.alerting.alerting as alerting
token = common.checkAjaxInput(form.getvalue('updatetoken'))
channel = common.checkAjaxInput(form.getvalue('updategchanel'))
group = common.checkAjaxInput(form.getvalue('updatetelegramgroup'))
user_id = common.checkAjaxInput(form.getvalue('id'))
if token is None or channel is None or group is None:
print(error_mess)
else:
sql.update_telegram(token, channel, group, user_id)
roxywi_common.logging('group ' + group, f'The Telegram token has been updated for channel: {channel}', roxywi=1,
login=1)
alerting.update_telegram(token, channel, group, user_id)
if form.getvalue('update_slack_token') is not None:
import modules.alerting.alerting as alerting
token = common.checkAjaxInput(form.getvalue('update_slack_token'))
channel = common.checkAjaxInput(form.getvalue('updategchanel'))
group = common.checkAjaxInput(form.getvalue('updateslackgroup'))
user_id = common.checkAjaxInput(form.getvalue('id'))
if token is None or channel is None or group is None:
print(error_mess)
else:
sql.update_slack(token, channel, group, user_id)
roxywi_common.logging(f'group {group}', f'The Slack token has been updated for channel: {channel}', roxywi=1,
login=1)
alerting.update_slack()
if form.getvalue('updatesettings') is not None:
settings = common.checkAjaxInput(form.getvalue('updatesettings'))
@ -1592,78 +1589,39 @@ if form.getvalue('updatesettings') is not None:
print("Ok")
if form.getvalue('getuserservices'):
user_id = common.checkAjaxInput(form.getvalue('getuserservices'))
groups = []
u_g = sql.select_user_groups(user_id)
services = sql.select_services()
for g in u_g:
groups.append(g.user_group_id)
import modules.roxywi.user as roxy_user
roxy_user.get_user_services()
env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True)
template = env.get_template('/show_user_services.html')
template = template.render(user_services=sql.select_user_services(user_id), id=user_id, services=services)
print(template)
if form.getvalue('getusergroups'):
user_id = common.checkAjaxInput(form.getvalue('getusergroups'))
groups = []
u_g = sql.select_user_groups(user_id)
for g in u_g:
groups.append(g.user_group_id)
import modules.roxywi.user as roxy_user
env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True)
template = env.get_template('/show_user_groups.html')
template = template.render(groups=sql.select_groups(), user_groups=groups, id=user_id)
print(template)
roxy_user.get_user_groups()
if form.getvalue('changeUserGroupId') is not None:
group_id = common.checkAjaxInput(form.getvalue('changeUserGroupId'))
groups = common.checkAjaxInput(form.getvalue('changeUserGroups'))
user = common.checkAjaxInput(form.getvalue('changeUserGroupsUser'))
if sql.delete_user_groups(group_id):
for group in groups:
if group[0] == ',':
continue
try:
sql.update_user_groups(groups=group[0], user_group_id=group_id)
except Exception as e:
print(e)
import modules.roxywi.user as roxy_user
roxywi_common.logging('Roxy-WI server', f'Groups has been updated for user: {user}', roxywi=1, login=1)
roxy_user.change_user_group()
if form.getvalue('changeUserServicesId') is not None:
user_id = common.checkAjaxInput(form.getvalue('changeUserServicesId'))
services = common.checkAjaxInput(form.getvalue('changeUserServices'))
user = common.checkAjaxInput(form.getvalue('changeUserServicesUser'))
import modules.roxywi.user as roxy_user
try:
if sql.update_user_services(services=services, user_id=user_id):
roxywi_common.logging('Roxy-WI server', f'Access to the services has been updated for user: {user}', roxywi=1, login=1)
except Exception as e:
print(e)
roxy_user.change_user_services()
if form.getvalue('changeUserCurrentGroupId') is not None:
group_id = common.checkAjaxInput(form.getvalue('changeUserCurrentGroupId'))
user_uuid = common.checkAjaxInput(form.getvalue('changeUserGroupsUser'))
import modules.roxywi.user as roxy_user
try:
if sql.update_user_current_groups(group_id, user_uuid):
print('Ok')
else:
print('error: Cannot change group')
except Exception as e:
print(e)
roxy_user.change_user_active_group()
if form.getvalue('getcurrentusergroup') is not None:
import modules.roxywi.user as roxy_user
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_id = cookie.get('uuid')
group = cookie.get('group')
group_id = sql.get_user_id_by_uuid(user_id.value)
groups = sql.select_user_groups_with_names(group_id)
env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True)
template = env.get_template('/show_user_current_group.html')
template = template.render(groups=groups, group=group.value, id=group_id)
print(template)
roxy_user.get_user_active_group(user_id, group)
if form.getvalue('newsmon') is not None:
user_group = roxywi_common.get_user_group(id=1)

Loading…
Cancel
Save