Bläddra i källkod

updated with cleverdialer files

Tobias von Dewitz 6 år sedan
förälder
incheckning
5a5cab597a
4 ändrade filer med 56 tillägg och 60 borttagningar
  1. 23 4
      Dockerfile
  2. 11 6
      default
  3. 8 13
      httpd-lua.conf
  4. 14 37
      lua/scw.lua

+ 23 - 4
Dockerfile

@@ -1,8 +1,27 @@
-FROM php:7.2-apache-stretch
+FROM centos/httpd
 
-RUN apt-get -y update
-RUN apt-get -y install lua5.3 lua-redis lua-socket lua-cjson lua-rex-pcre lua-luaossl
-RUN a2enmod lua slotmem_shm info proxy proxy_http rewrite
+RUN yum install -y lua-devel epel-release
+RUN yum update -y
+RUN yum install -y luarocks lua-socket pcre-devel openssl-devel
+RUN yum groupinstall -y 'Development Tools'
+RUN luarocks install redis-lua 
+RUN luarocks install lua-cjson 
+RUN luarocks install lrexlib-pcre 
+
+ADD ./lua-openssl /lua-openssl
+RUN ls -l /lua-openssl
+RUN cd /lua-openssl && make && make install
+
+RUN rm -rf /lua-openssl
+RUN yum clean all
+
+# RUN luarocks install openssl --server=https://rocks.moonscript.org/dev
+
+#FROM php:7.2-apache-stretch
+
+#RUN apt-get -y update
+#RUN apt-get -y install lua5.3 lua-redis lua-socket lua-cjson lua-rex-pcre lua-luaossl
+#RUN a2enmod lua slotmem_shm info proxy proxy_http rewrite
 
 
 #FROM httpd:2.4-alpine

+ 11 - 6
default

@@ -1,6 +1,11 @@
-SCW_IGNORE='(^/(captcha|assets).*|\.(png|jpe?g|svg|gif|js|css)$)'
-SCW_KEY='eilghEj25/ku+l5bFOlIDJxWmfKGxoP1po/PxQi6Tb8='
-SCW_COOKIE='tbscw'
-SCW_CAPTCHA_URL='http://docker.scw.systems:8001/captcha?src=%s&r=%s'
-SCW_REDIS_HOST='127.0.0.1'
-SCW_REDIS_PORT='6379'
+
+# Configuration for ScraperWall Apache mod_lua script
+# /usr/local/apache2/lua/scw.lua
+#
+SCW_KEY=DOukLQmiCiYoGdRJ7RhfqrwrX8Ut4w0AKcc6MsxmX1Y=
+SCW_IGNORE=(captcha|\.(png|jpe?g|svg|gif|js|css|ttf|woff))
+SCW_COOKIE=scw_cookie
+SCW_CAPTCHA_URL=https://www.scwcaptcha.de/captcha/?src=%s&r=%s
+SCW_REDIS_HOST=127.0.0.1
+SCW_REDIS_PORT=6479
+

+ 8 - 13
httpd-lua.conf

@@ -3,22 +3,17 @@ LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
 
 # these modules are not necessary for the ScraperWall-Lua module to work
 # and are only here to setup the test server
-LoadModule info_module modules/mod_info.so
-LoadModule proxy_module modules/mod_proxy.so
-LoadModule proxy_http_module modules/mod_proxy_http.so
+#LoadModule info_module modules/mod_info.so
+#LoadModule proxy_module modules/mod_proxy.so
+#LoadModule proxy_http_module modules/mod_proxy_http.so
 #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
-#LoadModule ssl_module modules/mod_ssl.so
+LoadModule ssl_module modules/mod_ssl.so
 
-#SSLPRoxyEngine on
+SSLPRoxyEngine on
 
 <Location /server-info>
-SetHandler server-info
-Require all granted
-</Location>
-
-<Location /captcha>
-ProxyPass http://captcha:8080/captcha
-ProxyPassReverse http://captcha:8080/captcha
+  SetHandler server-info
+  Require ip 10.0.0.1
 </Location>
 
 PassEnv SCW_IGNORE
@@ -28,7 +23,7 @@ PassEnv SCW_CAPTCHA_URL
 PassEnv SCW_REDIS_HOST
 PassEnv SCW_REDIS_PORT
 
-LuaHookTranslateName /usr/local/apache2/lua/scw.lua scw
+LuaHookTranslateName /usr/local/apache2/lua/scw.lua scw early
 LuaScope server
 
 LogLevel info

+ 14 - 37
lua/scw.lua

@@ -1,10 +1,8 @@
 require "apache2"
--- local redis = require "redis"
-local hiredis = require "hiredis"
+local redis = require "redis"
 local regex = require "rex_pcre"
 local mime = require "mime"
-local cipher = require "openssl".cipher
-local pretty = require 'pl.pretty'
+local cipher = require "openssl.cipher"
 
 
 -- --------------------------------------------------------------------------
@@ -40,7 +38,8 @@ function scw(r)
     r:err("SCW_IGNORE is not set!")
   end
 
-	local uri = string.match(r.the_request, "^%w+%s+(.+)%s+HTTP")
+
+  uri = string.match(r.the_request, "^%w+%s+(.+)%s+HTTP")
   if ignore ~= nil and regex.match(uri, ignore) then
     return apache2.DECLINED
   end
@@ -53,7 +52,6 @@ function scw(r)
     r:err("SCW_COOKIE is not set!")
   end
 
-
   local cookie_key = r:base64_decode(os.getenv("SCW_KEY"))
   if cookie_key == nil or cookie_key == "" then
     r:err("SCW_KEY is not set!")
@@ -62,12 +60,12 @@ function scw(r)
   local xff = tostring(r.headers_in["X-Forwarded-For"])
   local rip = tostring(r.headers_in["X-Real-IP"])
 
+
   if human_cookie then
     human_cookie = r:base64_decode(r:unescape(human_cookie))
   end
   local is_human = false
 
-
   if human_cookie ~= nil and cookie_key:len() == 32 then
     local cookie_data = _decrypt(human_cookie, cookie_key)
 
@@ -86,20 +84,7 @@ function scw(r)
   -- --------------------------------------------------------------------------
   -- check for blacklist status
   --
-  
-	
-  local sucess = false
-	local err = ""
-  
-  if redis_conn ~= nil then
-    success, err = pcall(function() redis_conn:command("PING") end)
-    if redis_conn == nil then
-      r:info("redis_conn turned nil after ping")
-    end
-  end
-
-  if success then
-    r:info("redis ping was successful")
+  if pcall(function() redis_conn:ping() end) then
     has_redis = true
   else
     -- io.stderr:write("reconnecting to redis\n")
@@ -111,10 +96,7 @@ function scw(r)
     if redis_port == nil or redis_port == "" then
       r:err("SCW_REDIS_PORT is not set!")
     end
-    r:info(string.format("connecting to redis %s:%s", redis_host, redis_port))
-    success, err = pcall(function() redis_conn = hiredis.connect(redis_host, redis_port) end)
-    if success then
-      r:info("created redis connection to " .. redis_host .. ":" .. redis_port)
+    if pcall(function() redis_conn = redis.connect(redis_host, redis_port) end) then
       has_redis = true
     end
   end
@@ -126,25 +108,19 @@ function scw(r)
 
   if has_redis and captcha_url ~= "" then
     -- the client ip
-    if redis_conn == nil then
-      r:info("redis is suddenly nil!")
-    end
-    local v = redis_conn:command("GET", "bl:" .. r.useragent_ip)
+    local v = redis_conn:get("bl:" .. r.useragent_ip)
 
-    -- if v == nil then
-    --   r:info("v is nil!")
-    -- end
     -- the X-Forwarded-For IP
-    if v == nil and xff ~= "" then
-      v = redis_conn:command("GET", "bl:" .. xff)
+    if v == nil then
+      v = redis_conn:get("bl:" .. xff)
     end
 
     -- the X-Real-IP IP
-    if v == nil and rip ~= "" then
-      v = redis_conn:command("GET", "bl:" .. rip)
+    if v == nil then
+      v = redis_conn:get("bl:" .. rip)
     end
 
-    if tostring(v) ~= "" and tostring(v) ~= "NIL" then -- and h == nil then
+    if v ~= nil then -- and h == nil then
       local rprotocol = "http"
       if r.is_https then
         rprotocol = "https"
@@ -169,3 +145,4 @@ function scw(r)
 
   return apache2.DECLINED
 end
+