mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-15 05:00:49 +08:00
Refactoring user permissions
This commit is contained in:
@@ -149,7 +149,6 @@ $emailnotify_smtp = $SMTP['emailnotify'];
|
||||
$smtptype = $SMTP['smtptype'];
|
||||
$smtp_host = $SMTP['smtp_host'];
|
||||
$smtp_port = $SMTP['smtp_port'];
|
||||
if (strtoupper(substr(PHP_OS,0,3)=='WIN'))
|
||||
$smtp_from = $SMTP['smtp_from'];
|
||||
$smtpaddress = $SMTP['smtpaddress'] ?? '';
|
||||
$smtpport = $SMTP['smtpport'] ?? '';
|
||||
@@ -167,7 +166,7 @@ $disableemailchange = $SECURITY['changeemail'];
|
||||
$cheaterdet_security = $SECURITY['cheaterdet'];
|
||||
$nodetect_security = $SECURITY['nodetect'];
|
||||
|
||||
$defaultclass_class = $AUTHORITY['defaultclass'];
|
||||
$defaultclass_class = isset(\App\Models\User::$classes[$AUTHORITY['defaultclass']]) ? $AUTHORITY['defaultclass'] : \App\Models\User::CLASS_USER;
|
||||
$staffmem_class = $AUTHORITY['staffmem'];
|
||||
$newsmanage_class = $AUTHORITY['newsmanage'];
|
||||
$newfunitem_class = $AUTHORITY['newfunitem'];
|
||||
|
||||
@@ -2238,14 +2238,18 @@ function tr($x,$y,$noesc=0,$relation='', $return = false) {
|
||||
print $result;
|
||||
}
|
||||
|
||||
function tr_small($x,$y,$noesc=0,$relation='') {
|
||||
function tr_small($x,$y,$noesc=0,$relation='',$return = false) {
|
||||
if ($noesc)
|
||||
$a = $y;
|
||||
else {
|
||||
$a = htmlspecialchars($y);
|
||||
//$a = str_replace("\n", "<br />\n", $a);
|
||||
}
|
||||
print("<tr".( $relation ? " relation = \"$relation\"" : "")."><td width=\"1%\" class=\"rowhead nowrap\" valign=\"top\" align=\"right\">".$x."</td><td width=\"99%\" class=\"rowfollow\" valign=\"top\" align=\"left\">".$a."</td></tr>\n");
|
||||
$result = "<tr".( $relation ? " relation = \"$relation\"" : "")."><td width=\"1%\" class=\"rowhead nowrap\" valign=\"top\" align=\"right\">".$x."</td><td width=\"99%\" class=\"rowfollow\" valign=\"top\" align=\"left\">".$a."</td></tr>";
|
||||
if ($return) {
|
||||
return $result;
|
||||
}
|
||||
print($result);
|
||||
}
|
||||
|
||||
function twotd($x,$y,$nosec=0){
|
||||
@@ -2683,7 +2687,7 @@ else {
|
||||
</td>
|
||||
<td class="bottom" align="right"><span class="medium"><?php echo $lang_functions['text_the_time_is_now'] ?><?php echo $datum['hours'].":".$datum['minutes']?><br />
|
||||
<?php
|
||||
if (get_user_class() >= $staffmem_class) {
|
||||
if (user_can('staffmem')) {
|
||||
$totalreports = $Cache->get_value('staff_report_count');
|
||||
if ($totalreports == ""){
|
||||
$totalreports = get_row_count("reports");
|
||||
@@ -2791,7 +2795,7 @@ if ($msgalert)
|
||||
}
|
||||
}
|
||||
|
||||
if (get_user_class() >= $staffmem_class)
|
||||
if (user_can('staffmem'))
|
||||
{
|
||||
//torrent approval
|
||||
if (get_setting('torrent.approval_status_none_visible') == 'no') {
|
||||
@@ -3182,7 +3186,7 @@ function commenttable($rows, $type, $parent_id, $review = false)
|
||||
print("<div style=\"margin-top: 8pt; margin-bottom: 8pt;\"><table id=\"cid".$row["id"]."\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\"><tr><td class=\"embedded\" width=\"99%\">#" . $row["id"] . " <font color=\"gray\">".$lang_functions['text_by']."</font>");
|
||||
print(get_username($row["user"],false,true,true,false,false,true));
|
||||
print(" <font color=\"gray\">".$lang_functions['text_at']."</font>".gettime($row["added"]).
|
||||
($row["editedby"] && get_user_class() >= $commanage_class ? " - [<a href=\"comment.php?action=vieworiginal&cid=".$row['id']."&type=".$type."\">".$lang_functions['text_view_original']."</a>]" : "") . "</td><td class=\"embedded nowrap\" width=\"1%\"><a href=\"#top\"><img class=\"top\" src=\"pic/trans.gif\" alt=\"Top\" title=\"Top\" /></a> </td></tr></table></div>");
|
||||
($row["editedby"] && user_can('commanage') ? " - [<a href=\"comment.php?action=vieworiginal&cid=".$row['id']."&type=".$type."\">".$lang_functions['text_view_original']."</a>]" : "") . "</td><td class=\"embedded nowrap\" width=\"1%\"><a href=\"#top\"><img class=\"top\" src=\"pic/trans.gif\" alt=\"Top\" title=\"Top\" /></a> </td></tr></table></div>");
|
||||
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars(trim($userRow["avatar"])) : "");
|
||||
if (!$avatar)
|
||||
$avatar = "pic/default_avatar.png";
|
||||
@@ -3201,7 +3205,7 @@ function commenttable($rows, $type, $parent_id, $review = false)
|
||||
print("<td class=\"rowfollow\" valign=\"top\"><br />".$text.$text_editby."</td>\n");
|
||||
print("</tr>\n");
|
||||
$actionbar = "<a href=\"comment.php?action=add&sub=quote&cid=".$row['id']."&pid=".$parent_id."&type=".$type."\"><img class=\"f_quote\" src=\"pic/trans.gif\" alt=\"Quote\" title=\"".$lang_functions['title_reply_with_quote']."\" /></a>".
|
||||
"<a href=\"comment.php?action=add&pid=".$parent_id."&type=".$type."\"><img class=\"f_reply\" src=\"pic/trans.gif\" alt=\"Add Reply\" title=\"".$lang_functions['title_add_reply']."\" /></a>".(get_user_class() >= $commanage_class ? "<a href=\"comment.php?action=delete&cid=".$row['id']."&type=".$type."\"><img class=\"f_delete\" src=\"pic/trans.gif\" alt=\"Delete\" title=\"".$lang_functions['title_delete']."\" /></a>" : "").($row["user"] == $CURUSER["id"] || get_user_class() >= $commanage_class ? "<a href=\"comment.php?action=edit&cid=".$row['id']."&type=".$type."\"><img class=\"f_edit\" src=\"pic/trans.gif\" alt=\"Edit\" title=\"".$lang_functions['title_edit']."\" />"."</a>" : "");
|
||||
"<a href=\"comment.php?action=add&pid=".$parent_id."&type=".$type."\"><img class=\"f_reply\" src=\"pic/trans.gif\" alt=\"Add Reply\" title=\"".$lang_functions['title_add_reply']."\" /></a>".(user_can('commanage') ? "<a href=\"comment.php?action=delete&cid=".$row['id']."&type=".$type."\"><img class=\"f_delete\" src=\"pic/trans.gif\" alt=\"Delete\" title=\"".$lang_functions['title_delete']."\" /></a>" : "").($row["user"] == $CURUSER["id"] || get_user_class() >= $commanage_class ? "<a href=\"comment.php?action=edit&cid=".$row['id']."&type=".$type."\"><img class=\"f_edit\" src=\"pic/trans.gif\" alt=\"Edit\" title=\"".$lang_functions['title_edit']."\" />"."</a>" : "");
|
||||
print("<tr><td class=\"toolbox\"> ".("'".$userRow['last_access']."'"> $dt ? "<img class=\"f_online\" src=\"pic/trans.gif\" alt=\"Online\" title=\"".$lang_functions['title_online']."\" />":"<img class=\"f_offline\" src=\"pic/trans.gif\" alt=\"Offline\" title=\"".$lang_functions['title_offline']."\" />" )."<a href=\"sendmessage.php?receiver=".htmlspecialchars(trim($row["user"]))."\"><img class=\"f_pm\" src=\"pic/trans.gif\" alt=\"PM\" title=\"".$lang_functions['title_send_message_to'].htmlspecialchars($userRow["username"])."\" /></a><a href=\"report.php?commentid=".htmlspecialchars(trim($row["id"]))."\"><img class=\"f_report\" src=\"pic/trans.gif\" alt=\"Report\" title=\"".$lang_functions['title_report_this_comment']."\" /></a></td><td class=\"toolbox\" align=\"right\">".$actionbar."</td>");
|
||||
|
||||
print("</tr></table>\n");
|
||||
@@ -3415,7 +3419,7 @@ if ($CURUSER['showcomnum'] != 'no') { ?>
|
||||
<td class="colhead"><a href="?<?php echo $oldlink?>sort=6&type=<?php echo $link[6]?>"><img class="snatched" src="pic/trans.gif" alt="snatched" title="<?php echo $lang_functions['title_number_of_snatched']?>" /></a></td>
|
||||
<td class="colhead"><a href="?<?php echo $oldlink?>sort=9&type=<?php echo $link[9]?>"><?php echo $lang_functions['col_uploader']?></a></td>
|
||||
<?php
|
||||
if (get_user_class() >= $torrentmanage_class) { ?>
|
||||
if (user_can('torrentmanage')) { ?>
|
||||
<td class="colhead"><?php echo $lang_functions['col_action'] ?></td>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
@@ -3653,7 +3657,7 @@ foreach ($rows as $row)
|
||||
else
|
||||
print("<td class=\"rowfollow\">" . number_format($row["times_completed"]) . "</td>\n");
|
||||
|
||||
if ($row["anonymous"] == "yes" && get_user_class() >= $torrentmanage_class)
|
||||
if ($row["anonymous"] == "yes" && user_can('torrentmanage'))
|
||||
{
|
||||
print("<td class=\"rowfollow\" align=\"center\"><i>".$lang_functions['text_anonymous']."</i><br />".(isset($row["owner"]) ? "(" . get_username($row["owner"]) .")" : "<i>".$lang_functions['text_orphaned']."</i>") . "</td>\n");
|
||||
}
|
||||
@@ -3666,7 +3670,7 @@ foreach ($rows as $row)
|
||||
print("<td class=\"rowfollow\">" . (isset($row["owner"]) ? get_username($row["owner"]) : "<i>".$lang_functions['text_orphaned']."</i>") . "</td>\n");
|
||||
}
|
||||
|
||||
if (get_user_class() >= $torrentmanage_class)
|
||||
if (user_can('torrentmanage'))
|
||||
{
|
||||
print("<td class=\"rowfollow\"><a href=\"".htmlspecialchars("fastdelete.php?id=".$row['id'])."\"><img class=\"staff_delete\" src=\"pic/trans.gif\" alt=\"D\" title=\"".$lang_functions['text_delete']."\" /></a>");
|
||||
print("<br /><a href=\"edit.php?returnto=" . rawurlencode($_SERVER["REQUEST_URI"]) . "&id=" . $row["id"] . "\"><img class=\"staff_edit\" src=\"pic/trans.gif\" alt=\"E\" title=\"".$lang_functions['text_edit']."\" /></a></td>\n");
|
||||
@@ -4113,8 +4117,12 @@ function getSmileIt($formname, $taname, $smilyNumber) {
|
||||
return "<a href=\"javascript: SmileIT('[em$smilyNumber]','".$formname."','".$taname."')\" onmouseover=\"domTT_activate(this, event, 'content', '".htmlspecialchars("<table><tr><td><img src=\'pic/smilies/$smilyNumber.gif\' alt=\'\' /></td></tr></table>")."', 'trail', false, 'delay', 0,'lifetime',10000,'styleClass','smilies','maxWidth', 400);\"><img style=\"max-width: 25px;\" src=\"pic/smilies/$smilyNumber.gif\" alt=\"\" /></a>";
|
||||
}
|
||||
|
||||
function classlist($selectname,$maxclass, $selected, $minClass = 0){
|
||||
function classlist($selectname,$maxclass, $selected, $minClass = 0, $includeNoClass = false){
|
||||
global $lang_functions;
|
||||
$list = "<select name=\"".$selectname."\">";
|
||||
if ($includeNoClass) {
|
||||
$list .= sprintf('<option value="%s">%s</option>', \App\Models\Setting::PERMISSION_NO_CLASS, $lang_functions['select_an_user_class']);
|
||||
}
|
||||
for ($i = $minClass; $i <= $maxclass; $i++)
|
||||
$list .= "<option value=\"".$i."\"" . ($selected == $i ? " selected=\"selected\"" : "") . ">" . get_user_class_name($i,false,false,true) . "</option>\n";
|
||||
$list .= "</select>";
|
||||
@@ -4802,14 +4810,14 @@ function user_can_upload($where = "torrents"){
|
||||
return false;
|
||||
if ($where == "torrents")
|
||||
{
|
||||
if (get_user_class() >= $upload_class)
|
||||
if (user_can('upload'))
|
||||
return true;
|
||||
if (get_if_restricted_is_open())
|
||||
return true;
|
||||
}
|
||||
if ($where == "music")
|
||||
{
|
||||
if ($enablespecial == 'yes' && get_user_class() >= $uploadspecial_class)
|
||||
if ($enablespecial == 'yes' && user_can('uploadspecial'))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
function get_global_sp_state()
|
||||
{
|
||||
static $global_promotion_state;
|
||||
@@ -735,7 +737,7 @@ function add_filter($name, $function, $priority = 10, $argc = 1)
|
||||
function apply_filter($name, ...$args)
|
||||
{
|
||||
global $hook;
|
||||
do_log("[APPLY_FILTER]: $name");
|
||||
// do_log("[APPLY_FILTER]: $name");
|
||||
return $hook->applyFilter(...func_get_args());
|
||||
}
|
||||
|
||||
@@ -748,7 +750,7 @@ function add_action($name, $function, $priority = 10, $argc = 1)
|
||||
function do_action($name, ...$args)
|
||||
{
|
||||
global $hook;
|
||||
do_log("[DO_ACTION]: $name");
|
||||
// do_log("[DO_ACTION]: $name");
|
||||
return $hook->doAction(...func_get_args());
|
||||
}
|
||||
|
||||
@@ -902,7 +904,7 @@ function clear_setting_cache()
|
||||
\Nexus\Database\NexusDB::cache_del('nexus_settings_in_nexus');
|
||||
}
|
||||
|
||||
function user_can($permission, $uid = 0): bool
|
||||
function user_can($permission, $fail = false, $uid = 0): bool
|
||||
{
|
||||
if ($uid == 0) {
|
||||
$uid = get_user_id();
|
||||
@@ -910,13 +912,28 @@ function user_can($permission, $uid = 0): bool
|
||||
if ($uid <= 0) {
|
||||
return false;
|
||||
}
|
||||
$userInfo = get_user_row($uid);
|
||||
$log = "permission: $permission, user: $uid, userClass: {$userInfo['class']}";
|
||||
if ($userInfo['class'] == User::CLASS_STAFF_LEADER) {
|
||||
do_log("$log, CLASS_STAFF_LEADER, true");
|
||||
return true;
|
||||
}
|
||||
$result = apply_filter('nexus_user_can', null, $permission, $uid);
|
||||
if (is_bool($result)) {
|
||||
$requireClass = get_setting("authority.$permission");
|
||||
if (!is_bool($result)) {
|
||||
$result = is_numeric($requireClass) && $requireClass >= 0 && $requireClass < $userInfo['class'];
|
||||
do_log("$log, requireClass: $requireClass, result: $result");
|
||||
}
|
||||
if (!$fail || $result) {
|
||||
return $result;
|
||||
}
|
||||
if (isset(\App\Models\Setting::$permissionDegeneration[$permission])) {
|
||||
$permission = \App\Models\Setting::$permissionDegeneration[$permission];
|
||||
if (IN_NEXUS && !IN_TRACKER) {
|
||||
global $lang_functions;
|
||||
if (isset(User::$classes[$requireClass])) {
|
||||
stderr($lang_functions['std_sorry'],$lang_functions['std_permission_denied_only'].get_user_class_name($requireClass,false,true,true).$lang_functions['std_or_above_can_view'],false);
|
||||
} else {
|
||||
stderr($lang_functions['std_error'], $lang_functions['std_permission_denied']);
|
||||
}
|
||||
}
|
||||
$requireClass = get_setting("authority.$permission");
|
||||
return is_numeric($requireClass) && $requireClass < get_user_class();
|
||||
throw new \Illuminate\Auth\Access\AuthorizationException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user