// cd34, v0.1, 2002-02-05 // http://daviesinc.com/modules/ // int thread_safe=1; #include inherit "module"; inherit "caudiumlib"; constant module_type = MODULE_FIRST; constant module_name = "Skimmer Module"; constant module_doc = ""; constant module_unique = 1; object incl=0,excl=0; int redirected=0,passed=0; void create() { defvar("skim", 5, "Skim %", TYPE_INT, "This will take x% of the incoming requests for an .html doc and redirect them to a different URL"); defvar("topdir", 0, "Skim Top Directory?", TYPE_FLAG, "Do you want to skim traffic from the top directory?"); defvar("redirecturl", "NONE/", "Where are we sending the traffic?", TYPE_STRING, ""); defvar("regexpinclude", "\.(htm|html|shtml|rxml)$|/$", "Regexp Include Specification", TYPE_STRING, "An expression here will include processing for anything that matches this Pike Syntax Regexp
" "For Example:
.*
will include processing for all files. id->not_query is automatically " "lowercased." "
" "\\.(htm|html|shtml|rxml)$|/$"); defvar("regexpexclude", "\.(jpg|jpeg|gif|png)$|^/_internal", "Regexp Exclude Specification", TYPE_STRING, "An expression here will exclude processing for anything that matches this Pike Syntax Regexp
" "For Example:
\\.(jpg|jpeg|gif|png)$|^/_internal
will exclude processing for jpg, gif and png files " "id->not_query is automatically lowercased"); } void start(int num, object conf) { catch { if (strlen(query("regexpinclude"))) incl = Regexp(query("regexpinclude")); if (strlen(query("regexpexclude"))) excl = Regexp(query("regexpexclude")); }; } string status() { return (sprintf("%d redirected, %d passed. %3.2f%% of the traffic is being redirected", redirected,passed,(passed>0)?(float)redirected/((float)passed+(float)redirected)*100.0:0.0)); } mapping first_try(object id) { if (QUERY(topdir)==0 && String.count(id->not_query,"/")<2) return 0; //perror("match: "+id->not_query+" "+incl->match(lower_case(id->not_query))+"\n"); //perror("exclude: "+excl->match(lower_case(id->not_query))+"\n"); if (id->not_query && (incl && !incl->match(lower_case(id->not_query))) || (excl && excl->match(lower_case(id->not_query)))) return(0); if (random(100) < QUERY(skim)) { redirected++; return http_redirect(QUERY(redirecturl)); } passed++; return 0; }