listidle2.awk 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #! /bin/gawk -f
  2. # LISTIDLE2 by tittof
  3. #
  4. # List users that haven't logged in for a given number of days
  5. #
  6. # This AWK Program is a clean room implementation of
  7. # Jehsom's listidle v1.0 shell script.
  8. #
  9. # we want gawk so maybe
  10. #
  11. # sudo apt-get install gawk
  12. # cp /usr/bin/gawk $GLROOT/bin/
  13. #
  14. # You can use it as a site_cmd this way:
  15. # site_cmd LISTIDLE EXEC /bin/listidle.awk
  16. # custom-listidle 1
  17. #
  18. BEGIN {
  19. #
  20. # Where are the userfiles (chrooted)?
  21. USERFILESPATH="/ftp-data/users/"
  22. #
  23. # you can modify the output of the program
  24. #
  25. # Do not show Users in the following groups (space seperated)
  26. # Example BG="HiDDENGROUP ANOTHERHiDDENGROUP"
  27. #
  28. BG=""
  29. #
  30. # Do not show Users with following usernames (space seperated)
  31. # Example UB="sitebot default.user"
  32. #
  33. UB="default.user sitebot"
  34. #
  35. # Do not show Users with following flags (NO SEPERATION)
  36. # Example BF="16"
  37. #
  38. BF="6"
  39. #
  40. # DO NOT EDIT BELOW THIS LINE!
  41. #
  42. #
  43. # Save the DAYS Variable from getting overwritten
  44. if ( ARGC == 2 ) DAYS=ARGV[1];
  45. else {
  46. if ( ARGC == 1 ) {
  47. DAYS=0;
  48. show_error("No Parameter? Assuming 0! ");
  49. }
  50. else {
  51. show_error("Only one parameter please!");
  52. exit 0;
  53. }
  54. }
  55. # DAYS has to be positive numeric up to 10000
  56. if ( DAYS ~ /^[0-9]+$/ ) {
  57. if ( DAYS > 10000 ) DAYS=0
  58. } else {
  59. show_error("Give a valid number! ");
  60. exit 0;
  61. }
  62. #
  63. # retrieve the list of files we want to process
  64. #
  65. OLDRS=RS
  66. RS = "/"
  67. cmd = "cd \""USERFILESPATH"\" && printf '%s/' *"
  68. while (cmd | getline > 0) if ($0) files[n++] = $0
  69. close(cmd)
  70. i=1
  71. for (f in files) {
  72. #printf(USERFILESPATH"%s\n", files[f]);
  73. ARGV[i]=sprintf(USERFILESPATH"%s", files[f]);
  74. i++
  75. }
  76. ARGC=i;
  77. RS=OLDRS
  78. #
  79. # Now we have all the filenames
  80. #
  81. split(BG,BGA," ");
  82. split(UB,UBA," ");
  83. split(BF,BFA,"");
  84. B=0;
  85. IDLE=0;
  86. BN="";
  87. print "USER@GROUP DAYS"
  88. }
  89. function show_error(error_text) {
  90. print ".-=--------------------------------------------=-."
  91. print "| "error_text" |"
  92. print "| |"
  93. print "| site listidle [days of idle] |"
  94. print "| where [days of idle] is 0..10000 |"
  95. print ".-=--------------------------------------------=-."
  96. }
  97. $1 ~ "^TIME$|^GROUP$|^FLAGS$" {
  98. if ($1=="FLAGS") {
  99. for ( FLAGSB in BFA ) {
  100. if (index($2,BFA[FLAGSB]) !=0) nextfile;
  101. }
  102. }
  103. if ($1=="TIME") {
  104. # Show Users that are not BANNED from showing
  105. # and have not logged in since DAYS
  106. if (BN != "") {
  107. for ( USERB in UBA ) {
  108. if (UBA[USERB] == BN) {
  109. B=1;
  110. }
  111. }
  112. }
  113. if (B==0 && BN != "" && IDLE >= DAYS) {
  114. GL != "" ? BNGL=BN"@"GL : BNGL=BN;
  115. printf BNGL" "IDLE"\n"
  116. }
  117. # extract basename of FILENAME and store that to BN
  118. BN=FILENAME;
  119. sub(/^.*\//, "", BN);
  120. # determine idle days of user
  121. IDLE=int((strftime("%s") - $3 )/86400);
  122. # init variables to default values
  123. GL="";
  124. B=0;
  125. }
  126. if ($1=="GROUP") {
  127. for (BGROUP in BGA) {
  128. if (BGA[BGROUP] == $2) {
  129. B=1;
  130. break;
  131. }
  132. }
  133. GL=="" ? GL=$2 : GL=GL","$2;
  134. }
  135. }