Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.84 KB | None | 0 0
  1. #!/bin/bash
  2. VER=1.4.1
  3.  
  4. #--[ Different Case Settings ]----------------------------------------#
  5.  
  6. SKIPSECTIONS="/GROUPS|/REQUESTS|/Archive|/PRE"
  7.  
  8. SKIPUSERS=""
  9. SKIPGROUPS=""
  10. SKIPFLAGS=""
  11.  
  12. #--[ On Site Before Settings ]----------------------------------------#
  13.  
  14. NUKE_PREFIX=""
  15.  
  16. DIRLOGLIST_GL=/glftpd/bin/dirloglist_gl
  17.  
  18. SKIPDIRS="^sample$|^Dis[ck].*|^vobsub.*|^extra.*|^cover.*|^sub.*|^bonus.*|^approved$|^allowed$|^ac3.*|^xvid\.decoder.*|^oggdec.*|^trailer.*|^CD[0-9]"
  19.  
  20. ALLOWFILE=/tmp/tur-predircheck.allow
  21.  
  22. #--[ Other Settings ]-------------------------------------------------#
  23.  
  24. DENYGROUPS="
  25. /site:\-BadGroup$|-othergroup$
  26. /site/SVCD:\-SMB$
  27. /site/DIVX:\-BP$
  28. "
  29.  
  30. DENYDIRS="
  31. /site:^NUKED|^\[INCOMPLETE\]\-
  32. "
  33.  
  34. ALLOWDIRS=""
  35.  
  36. ALLOWDIRS_OVERRULES_DENYGROUPS=FALSE
  37. ALLOWDIRS_OVERRULES_DENYDIRS=TRUE
  38.  
  39. #--[ Error Output ]---------------------------------------------------#
  40.  
  41. ## $1 = CreateDir, $2 = InPath
  42. ERROR1="$1 already exists with a different case structure. Skipping."
  43. ERROR2="$1 is already on site or was nuked. Wanker."
  44. ERROR3="Denying creation of $1. This group is BANNED!"
  45. ERROR4="Denying creation of $1. Watch what you're doing!"
  46. ERROR5="Denying creation of $1. Not allowed group/release."
  47.  
  48. DEBUG=TRUE
  49.  
  50. GLLOG=/ftp-data/logs/glftpd.log
  51. BOLD=""
  52.  
  53. IERROR1="$BOLD-[Wanker]- $USER$BOLD tried to create $BOLD$1$BOLD which already exists with a different case structure."
  54. IERROR2="$BOLD-[Wanker]- $USER$BOLD tried to create $BOLD$1$BOLD which is already on site or was nuked."
  55. IERROR3="$BOLD-[Wanker]- $USER$BOLD tried to create $BOLD$1$BOLD which is from a BANNED GROUP."
  56. IERROR4="$BOLD-[Wanker]- $USER$BOLD tried to create $BOLD$1$BOLD but was denied."
  57. IERROR5="$BOLD-[Wanker]- $USER$BOLD tried to create $BOLD$1$BOLD which isnt an allowed group or release."
  58.  
  59.  
  60. #--[ Script Start ]---------------------------------------------------#
  61.  
  62. proc_debug() {
  63. if [ "$DEBUG" = "TRUE" ]; then
  64. echo "#0PreDirCheck: $@"
  65. fi
  66. }
  67.  
  68. proc_announce() {
  69. if [ "$GLLOG" ]; then
  70. if [ ! -w "$GLLOG" ]; then
  71. proc_debug "Error. Can not write to $GLLOG"
  72. else
  73. proc_debug "Sending to gllog: $OUTPUT"
  74. echo `date "+%a %b %e %T %Y"` TURGEN: \"$OUTPUT\" >> $GLLOG
  75. fi
  76. fi
  77. }
  78.  
  79. if [ -z "$1" -o -z "$2" ]; then
  80. proc_debug "Stop & Allow: Didnt get 2 arguments."
  81. exit 0
  82. fi
  83.  
  84. if [ "$DEBUG" = "TRUE" ]; then
  85. if [ "$DIRLOGLIST_GL" ]; then
  86. if [ ! -x "$DIRLOGLIST_GL" ]; then
  87. proc_debug "ERROR: Cant execute DIRLOGLIST_GL: $DIRLOGLIST_GL"
  88. exit 1
  89. fi
  90. proc_debug "Testing dirloglist_gl binary. Should output 5 last lines in dirlog."
  91. for rawdata in `$DIRLOGLIST_GL | tr -d '\t' | tr ' ' '^' | cut -d '^' -f3 | tail -n5`; do
  92. proc_debug "$rawdata"
  93. done
  94. fi
  95. fi
  96.  
  97. if [ "$SKIPSECTIONS" ]; then
  98. if [ "`echo "$2" | egrep -i "$SKIPSECTIONS"`" ]; then
  99. proc_debug "Stop & Allow: Excluded section in SKIPSECTIONS"
  100. exit 0
  101. fi
  102. fi
  103.  
  104. if [ "$SKIPUSERS" ]; then
  105. if [ "`echo "$USER" | egrep -i "$SKIPUSERS"`" ]; then
  106. proc_debug "Stop & Allow: Excluded user in SKUPUSERS"
  107. exit 0
  108. fi
  109. fi
  110.  
  111. if [ "$SKIPGROUPS" ]; then
  112. if [ "`echo "$GROUP" | egrep -i "$SKIPGROUPS"`" ]; then
  113. proc_debug "Stop & Allow: Excluded group $GROUP in SKUPGROUPS"
  114. exit 0
  115. fi
  116. fi
  117.  
  118. if [ "$SKIPFLAGS" ]; then
  119. if [ "`echo "$FLAGS" | egrep -i "$SKIPFLAGS"`" ]; then
  120. proc_debug "Stop & Allow: Excluded flag on $USER. ($FLAGS) in SKIPFLAGS"
  121. exit 0
  122. fi
  123. fi
  124.  
  125. proc_checkallow() {
  126. if [ "$ALLOWFILE" ]; then
  127. if [ -e "$ALLOWFILE" ]; then
  128. if [ "`grep "^$1$" "$ALLOWFILE" `" ]; then
  129. proc_debug "Stop & Allow: This file has been allowed"
  130. exit 0
  131. fi
  132. fi
  133. fi
  134. }
  135.  
  136. if [ ! -d "$2/$1" ]; then
  137. if [ -d "$2" ]; then
  138. if [ "`ls -al "$2" | grep -i "[0-9] $1$" | cut -c1`" = "d" ]; then
  139. proc_debug "Stop & Deny: This dir exists here with another case structure already."
  140. if [ "$IERROR1" ]; then OUTPUT="$IERROR1"; proc_announce; fi
  141. echo -e "$ERROR1\n"
  142. exit 2
  143. fi
  144. fi
  145.  
  146. if [ "$NUKE_PREFIX" ]; then
  147. if [ -d "$NUKE_PREFIX$1" ]; then
  148. proc_checkallow "$1"
  149. proc_debug "Stop & Deny: This dir has been nuked and found by NUKE_PREFIX."
  150. if [ "$IERROR2" ]; then OUTPUT="$IERROR2"; proc_announce; fi
  151. echo -e "$ERROR2\n"
  152. exit 2
  153. fi
  154. fi
  155.  
  156. if [ "`echo "$1" | egrep -i "$SKIPDIRS"`" ]; then
  157. proc_debug "Stop & Allow: This dirname is excluded in SKIPDIRS"
  158. exit 0
  159. fi
  160.  
  161. if [ "$ALLOWDIRS" ]; then
  162. for rawdata in $ALLOWDIRS; do
  163. section="`echo "$rawdata" | cut -d ':' -f1`"
  164. allowed="`echo "$rawdata" | cut -d ':' -f2`"
  165. if [ "`echo "$2" | egrep "$section"`" ]; then
  166. if [ -z "`echo "$1" | egrep -i "$allowed"`" ]; then
  167. proc_checkallow "$1"
  168. proc_debug "Stop & Deny: This dir/group is not allowed."
  169. if [ "$IERROR5" ]; then OUTPUT="$IERROR5"; proc_announce; fi
  170. echo -e "$ERROR5\n"
  171. exit 2
  172. else
  173. if [ "$ALLOWDIRS_OVERRULES_DENYDIRS" = "TRUE" ]; then
  174. ALLOW_OVERRULE_DIR=TRUE
  175. proc_debug ".. Overruling any DENYDIRS"
  176. fi
  177. if [ "$ALLOWDIRS_OVERRULES_DENYGROUPS" = "TRUE" ]; then
  178. ALLOW_OVERRULE_GROUP=TRUE
  179. proc_debug ".. Overruling any DENYGROUPS"
  180. fi
  181. fi
  182. fi
  183. done
  184. fi
  185.  
  186. if [ "$DENYGROUPS" ] && [ "$ALLOW_OVERRULE_GROUP" != "TRUE" ]; then
  187. for rawdata in $DENYGROUPS; do
  188. section="`echo "$rawdata" | cut -d ':' -f1`"
  189. deniedgroup="`echo "$rawdata" | cut -d ':' -f2`"
  190.  
  191. if [ "`echo "$2" | egrep -i "$section"`" ]; then
  192. if [ "`echo "$1" | egrep -i "$deniedgroup"`" ]; then
  193. proc_checkallow "$1"
  194. proc_debug "Stop & Deny: This group is banned."
  195. if [ "$IERROR3" ]; then OUTPUT="$IERROR3"; proc_announce; fi
  196. echo -e "$ERROR3\n"
  197. exit 2
  198. fi
  199. fi
  200. done
  201. fi
  202.  
  203. if [ "$DENYDIRS" ] && [ "$ALLOW_OVERRULE_DIR" != "TRUE" ]; then
  204. for rawdata in $DENYDIRS; do
  205. section="`echo "$rawdata" | cut -d ':' -f1`"
  206. denied="`echo "$rawdata" | cut -d ':' -f2`"
  207.  
  208. if [ "`echo "$2" | egrep -i "$section"`" ]; then
  209. if [ "`echo "$1" | egrep -i "$denied"`" ]; then
  210. proc_checkallow "$1"
  211. proc_debug "Stop & Deny: This dir seems denied in DENYDIRS"
  212. if [ "$IERROR4" ]; then OUTPUT="$IERROR4"; proc_announce; fi
  213. echo -e "$ERROR4\n"
  214. exit 2
  215. fi
  216. fi
  217. done
  218. fi
  219.  
  220. if [ "$DIRLOGLIST_GL" ]; then
  221. if [ "`$DIRLOGLIST_GL | grep "/$1$"`" ]; then
  222. proc_checkallow "$1"
  223. proc_debug "Stop & Deny: It was found in dirlog, thus already upped before (NOPARENT CHECK)."
  224. if [ "$IERROR2" ]; then OUTPUT="$IERROR2"; proc_announce; fi
  225. echo -e "$ERROR2\n"
  226. exit 2
  227. fi
  228. fi
  229.  
  230. fi
  231.  
  232. proc_debug "Stop & Allow: This dir passed all checks."
  233.  
  234. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement