Added search by user in virtualhosts

This commit is contained in:
Antonio de la Rosa 2025-10-17 19:13:38 +02:00
parent 8da559b6ec
commit 2ae159623f
2 changed files with 38 additions and 8 deletions

View file

@ -40,6 +40,8 @@ system_path='./ssh/'
if hasattr(config, 'pastafari_system_path'):
system_path=config.pastafari_system_path
config_task.pastafari_paths.append('modules/apache/tasks')
@admin_app.route('/webservers/servers/')
def webservers():
@ -278,8 +280,13 @@ def virtualhost(webserver_id):
arr_webserver=cursor.fetchone()
if arr_webserver:
usernames=[]
with db.query('select DISTINCT username from virtualhost WHERE webserver_id=%s', [webserver_id]) as cursor:
usernames=cursor.fetchall()
return t.load_template('virtualhosts.phtml', title=_('Virtual Hosts'), path_module='admin_app.webservers', webserver_id=webserver_id, hostname=arr_webserver['hostname'])
return t.load_template('virtualhosts.phtml', title=_('Virtual Hosts'), path_module='admin_app.webservers', webserver_id=webserver_id, hostname=arr_webserver['hostname'], usernames=usernames)
else:
@ -305,25 +312,34 @@ def get_virtualhosts():
db=g.connection
user_id=request.args.get('webserver_id', '0')
webserver_id=request.args.get('webserver_id', '0')
username=request.args.get('username', '').strip()
group_sql=''
count_data=[]
sql_data=[user_id]
count_data=[webserver_id]
sql_data=[webserver_id]
extra_sql=''
if username!='':
count_data.append(username)
sql_data.append(username)
extra_sql=' AND username=%s'
fields=[[_('Domain'), True], [_('User'), True], [_('Options'), False]]
arr_order_fields=['domain']
count_query=['select count(virtualhost.id) as num_elements from virtualhost', count_data]
count_query=['select count(virtualhost.id) as num_elements from virtualhost WHERE webserver_id=%s'+extra_sql, count_data]
# server.id as select_id,
# select hostname, ip, date, num_updates, id from serverofuser where user_id=%s;
# select hostname, ip, date, num_updates, id from serverofuser where webserver_id=%s;
#str_query=['select webserver.hostname, webserver.ip, webserver.id from webserver,serverdbtask', sql_data]
str_query=['select domain, username, id from virtualhost WHERE webserver_id=%s', sql_data]
str_query=['select domain, username, id from virtualhost WHERE webserver_id=%s'+extra_sql, sql_data]
ajax=AjaxList(db, fields, arr_order_fields, count_query, str_query)