mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-15 04:32:42 +00:00
Integrated the sql and standard admin_rank stuff a little. Still needs some work. Permissions Panel has a sexy floating search bar. The scripts and stylesheets are external files which will be sent to every client at connect, so they can be used in any panel you wish with no additional overheads. If there are any bugs with the permissions panel (particularly the search bar) please let me know. thanks. rights2text now has a seperator argument. It defaults to "", but can be any string, for instance "<br>" git-svn-id: http://tgstation13.googlecode.com/svn/trunk@5080 316c924e-a436-60f5-8080-3fe189b3f50e
149 lines
5.6 KiB
Plaintext
149 lines
5.6 KiB
Plaintext
/client/proc/edit_admin_permissions()
|
|
set category = "Admin"
|
|
set name = "Permissions Panel"
|
|
set desc = "Edit admin permissions"
|
|
if(!check_rights(R_PERMISSIONS)) return
|
|
usr.client.holder.edit_admin_permissions()
|
|
|
|
/datum/admins/proc/edit_admin_permissions()
|
|
if(!check_rights(R_PERMISSIONS)) return
|
|
|
|
var/output = {"<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Permissions Panel</title>
|
|
<script type='text/javascript' src='search.js'></script>
|
|
<link rel='stylesheet' type='text/css' href='panels.css'>
|
|
</head>
|
|
<body onload='selectTextField();updateSearch();'>
|
|
<div id='main'><table id='searchable' cellspacing='0'>
|
|
<tr class='title'>
|
|
<th style='width:125px;text-align:right;'>CKEY <a class='small' href='?src=\ref[src];editrights=add'>\[+\]</a></th>
|
|
<th style='width:125px;'>RANK</th><th style='width:100%;'>PERMISSIONS</th>
|
|
</tr>
|
|
"}
|
|
|
|
for(var/adm_ckey in admin_datums)
|
|
var/datum/admins/D = admin_datums[adm_ckey]
|
|
if(!D) continue
|
|
var/rank = D.rank ? D.rank : "*none*"
|
|
var/rights = rights2text(D.rights," ")
|
|
if(!rights) rights = "*none*"
|
|
|
|
output += "<tr>"
|
|
output += "<td style='text-align:right;'>[adm_ckey] <a class='small' href='?src=\ref[src];editrights=remove;ckey=[adm_ckey]'>\[-\]</a></td>"
|
|
output += "<td><a href='?src=\ref[src];editrights=rank;ckey=[adm_ckey]'>[rank]</a></td>"
|
|
output += "<td><a class='small' href='?src=\ref[src];editrights=permissions;ckey=[adm_ckey]'>[rights]</a></font></td>"
|
|
output += "</tr>"
|
|
|
|
output += {"
|
|
</table></div>
|
|
<div id='top'><b>Search:</b> <input type='text' id='filter' value='' style='width:70%;' onkeyup='updateSearch();'></div>
|
|
</body>
|
|
</html>"}
|
|
|
|
usr << browse(output,"window=editrights;size=600x500")
|
|
|
|
/datum/admins/proc/log_admin_rank_modification(var/adm_ckey, var/new_rank)
|
|
if(config.admin_legacy_system) return
|
|
|
|
if(!usr.client)
|
|
return
|
|
|
|
if(!usr.client.holder || !(usr.client.holder.rights & R_PERMISSIONS))
|
|
usr << "\red You do not have permission to do this!"
|
|
return
|
|
|
|
establish_db_connection()
|
|
|
|
if(!dbcon.IsConnected())
|
|
usr << "\red Failed to establish database connection"
|
|
return
|
|
|
|
if(!adm_ckey || !new_rank)
|
|
return
|
|
|
|
adm_ckey = ckey(adm_ckey)
|
|
|
|
if(!adm_ckey)
|
|
return
|
|
|
|
if(!istext(adm_ckey) || !istext(new_rank))
|
|
return
|
|
|
|
var/DBQuery/select_query = dbcon.NewQuery("SELECT id FROM erro_admin WHERE ckey = '[adm_ckey]'")
|
|
select_query.Execute()
|
|
|
|
var/new_admin = 1
|
|
var/admin_id
|
|
while(select_query.NextRow())
|
|
new_admin = 0
|
|
admin_id = text2num(select_query.item[1])
|
|
|
|
if(new_admin)
|
|
var/DBQuery/insert_query = dbcon.NewQuery("INSERT INTO `erro_admin` (`id`, `ckey`, `rank`, `level`, `flags`) VALUES (null, '[adm_ckey]', '[new_rank]', -1, 0)")
|
|
insert_query.Execute()
|
|
var/DBQuery/log_query = dbcon.NewQuery("INSERT INTO `test`.`erro_admin_log` (`id` ,`datetime` ,`adminckey` ,`adminip` ,`log` ) VALUES (NULL , NOW( ) , '[usr.ckey]', '[usr.client.address]', 'Added new admin [adm_ckey] to rank [new_rank]');")
|
|
log_query.Execute()
|
|
usr << "\blue New admin added."
|
|
else
|
|
if(!isnull(admin_id) && isnum(admin_id))
|
|
var/DBQuery/insert_query = dbcon.NewQuery("UPDATE `erro_admin` SET rank = '[new_rank]' WHERE id = [admin_id]")
|
|
insert_query.Execute()
|
|
var/DBQuery/log_query = dbcon.NewQuery("INSERT INTO `test`.`erro_admin_log` (`id` ,`datetime` ,`adminckey` ,`adminip` ,`log` ) VALUES (NULL , NOW( ) , '[usr.ckey]', '[usr.client.address]', 'Edited the rank of [adm_ckey] to [new_rank]');")
|
|
log_query.Execute()
|
|
usr << "\blue Admin rank changed."
|
|
|
|
/datum/admins/proc/log_admin_permission_modification(var/adm_ckey, var/new_permission)
|
|
if(config.admin_legacy_system) return
|
|
|
|
if(!usr.client)
|
|
return
|
|
|
|
if(!usr.client.holder || !(usr.client.holder.rights & R_PERMISSIONS))
|
|
usr << "\red You do not have permission to do this!"
|
|
return
|
|
|
|
establish_db_connection()
|
|
if(!dbcon.IsConnected())
|
|
usr << "\red Failed to establish database connection"
|
|
return
|
|
|
|
if(!adm_ckey || !new_permission)
|
|
return
|
|
|
|
adm_ckey = ckey(adm_ckey)
|
|
|
|
if(!adm_ckey)
|
|
return
|
|
|
|
if(istext(new_permission))
|
|
new_permission = text2num(new_permission)
|
|
|
|
if(!istext(adm_ckey) || !isnum(new_permission))
|
|
return
|
|
|
|
var/DBQuery/select_query = dbcon.NewQuery("SELECT id, flags FROM erro_admin WHERE ckey = '[adm_ckey]'")
|
|
select_query.Execute()
|
|
|
|
var/admin_id
|
|
var/admin_rights
|
|
while(select_query.NextRow())
|
|
admin_id = text2num(select_query.item[1])
|
|
admin_rights = text2num(select_query.item[2])
|
|
|
|
if(!admin_id)
|
|
return
|
|
|
|
if(admin_rights & new_permission) //This admin already has this permission, so we are removing it.
|
|
var/DBQuery/insert_query = dbcon.NewQuery("UPDATE `erro_admin` SET flags = [admin_rights & ~new_permission] WHERE id = [admin_id]")
|
|
insert_query.Execute()
|
|
var/DBQuery/log_query = dbcon.NewQuery("INSERT INTO `test`.`erro_admin_log` (`id` ,`datetime` ,`adminckey` ,`adminip` ,`log` ) VALUES (NULL , NOW( ) , '[usr.ckey]', '[usr.client.address]', 'Removed permission [rights2text(new_permission)] (flag = [new_permission]) to admin [adm_ckey]');")
|
|
log_query.Execute()
|
|
usr << "\blue Permission removed."
|
|
else //This admin doesn't have this permission, so we are adding it.
|
|
var/DBQuery/insert_query = dbcon.NewQuery("UPDATE `erro_admin` SET flags = '[admin_rights | new_permission]' WHERE id = [admin_id]")
|
|
insert_query.Execute()
|
|
var/DBQuery/log_query = dbcon.NewQuery("INSERT INTO `test`.`erro_admin_log` (`id` ,`datetime` ,`adminckey` ,`adminip` ,`log` ) VALUES (NULL , NOW( ) , '[usr.ckey]', '[usr.client.address]', 'Added permission [rights2text(new_permission)] (flag = [new_permission]) to admin [adm_ckey]')")
|
|
log_query.Execute()
|
|
usr << "\blue Permission added." |