Guest User

Find inactive user with role

a guest
Aug 23rd, 2026
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 4.26 KB | None | 0 0
  1. -- START QUERY 1: AKUN PRIVILEGED YANG SUDAH LAMA TIDAK AKTIF
  2. SET @stale_login_days := 180;
  3. SET @stale_editorial_days := 365;
  4.  
  5. -- Query 1: enabled privileged accounts with stale login and little recent
  6. -- editorial evidence. OJS core does not retain enough HTTP history here to
  7. -- identify who injected a link, the source IP, or the previous field value.
  8. WITH
  9. privileged_roles AS (
  10.     SELECT
  11.         uug.user_id,
  12.         GROUP_CONCAT(DISTINCT ug.context_id ORDER BY ug.context_id) AS context_ids,
  13.         GROUP_CONCAT(DISTINCT ug.role_id ORDER BY ug.role_id) AS role_ids
  14.     FROM user_user_groups uug
  15.     JOIN user_groups ug ON ug.user_group_id = uug.user_group_id
  16.     WHERE ug.role_id IN (1, 16, 17, 4097, 2097152)
  17.     GROUP BY uug.user_id
  18. ),
  19. stages AS (
  20.     SELECT
  21.         sa.user_id,
  22.         COUNT(*) AS stage_assignments
  23.     FROM stage_assignments sa
  24.     GROUP BY sa.user_id
  25. ),
  26. editorial AS (
  27.     SELECT
  28.         el.user_id,
  29.         COUNT(*) AS editorial_events,
  30.         MAX(el.date_logged) AS last_editorial_event
  31.     FROM event_log el
  32.     GROUP BY el.user_id
  33. )
  34. SELECT
  35.     u.user_id,
  36.     u.username,
  37.     u.date_registered,
  38.     u.date_last_login,
  39.     TIMESTAMPDIFF(DAY, u.date_last_login, CURRENT_DATE) AS days_since_last_login,
  40.     r.context_ids,
  41.     r.role_ids,
  42.     COALESCE(s.stage_assignments, 0) AS stage_assignments,
  43.     COALESCE(e.editorial_events, 0) AS editorial_events,
  44.     e.last_editorial_event
  45. FROM users u
  46. JOIN privileged_roles r ON r.user_id = u.user_id
  47. LEFT JOIN stages s ON s.user_id = u.user_id
  48. LEFT JOIN editorial e ON e.user_id = u.user_id
  49. WHERE u.disabled = 0
  50.   AND u.date_last_login < DATE_SUB(CURRENT_DATE, INTERVAL @stale_login_days DAY)
  51.   AND (
  52.       COALESCE(e.editorial_events, 0) = 0
  53.       OR e.last_editorial_event < DATE_SUB(CURRENT_DATE, INTERVAL @stale_editorial_days DAY)
  54.   )
  55. ORDER BY days_since_last_login DESC, u.user_id;
  56. -- END QUERY 1
  57.  
  58.  
  59. -- Query 2: suspicious markers or multiple links still present in public-facing
  60. -- journal/publication fields. It reports fingerprints, not raw content.
  61. -- START QUERY 2: KONTEN PUBLIK SAAT INI
  62. SET @min_links_current_content := 2;
  63.  
  64. WITH public_content AS (
  65.     SELECT
  66.         'journal' AS content_type,
  67.         js.journal_id AS context_id,
  68.         js.journal_id AS object_id,
  69.         j.path AS journal_path,
  70.         js.setting_name,
  71.         js.locale,
  72.         js.setting_value
  73.     FROM journal_settings js
  74.     JOIN journals j ON j.journal_id = js.journal_id
  75.     WHERE js.setting_name IN (
  76.         'pageFooter',
  77.         'additionalHomeContent',
  78.         'customHeaders',
  79.         'searchDescription',
  80.         'description'
  81.     )
  82.  
  83.     UNION ALL
  84.  
  85.     SELECT
  86.         'publication' AS content_type,
  87.         s.context_id,
  88.         ps.publication_id AS object_id,
  89.         j.path AS journal_path,
  90.         ps.setting_name,
  91.         ps.locale,
  92.         ps.setting_value
  93.     FROM publication_settings ps
  94.     JOIN publications p ON p.publication_id = ps.publication_id
  95.     JOIN submissions s ON s.submission_id = p.submission_id
  96.     JOIN journals j ON j.journal_id = s.context_id
  97.     WHERE ps.setting_name IN ('abstract', 'title', 'subtitle')
  98. ),
  99. signals AS (
  100.     SELECT
  101.         c.*,
  102.         GREATEST(
  103.             0,
  104.             (
  105.                 CHAR_LENGTH(LOWER(COALESCE(c.setting_value, '')))
  106.                 - CHAR_LENGTH(REPLACE(LOWER(COALESCE(c.setting_value, '')), 'http', ''))
  107.             ) DIV 4
  108.         ) AS link_count,
  109.         REGEXP_SUBSTR(
  110.             LOWER(COALESCE(c.setting_value, '')),
  111.             'bermain[[:space:]]+slot|slot[[:space:]]*(gacor|online|deposit|777)|slot[0-9]+|gacor|togel|casino|judi|jackpot|nota[0-9]+|toto[[:space:]]*[0-9a-z]|deposit[[:space:]]*[0-9]+'
  112.         ) AS matched_marker
  113.     FROM public_content c
  114. )
  115. SELECT
  116.     content_type,
  117.     context_id,
  118.     object_id,
  119.     journal_path,
  120.     setting_name,
  121.     locale,
  122.     CHAR_LENGTH(COALESCE(setting_value, '')) AS content_chars,
  123.     link_count,
  124.     matched_marker,
  125.     SHA2(COALESCE(setting_value, ''), 256) AS content_fingerprint
  126. FROM signals
  127. WHERE matched_marker IS NOT NULL
  128.    OR link_count >= @min_links_current_content
  129. ORDER BY
  130.     (matched_marker IS NOT NULL) DESC,
  131.     link_count DESC,
  132.     content_type,
  133.     context_id,
  134.     object_id,
  135.     setting_name,
  136.     locale;
  137. -- END QUERY 2
Advertisement
Add Comment
Please, Sign In to add comment