]>
Commit | Line | Data |
---|---|---|
26a77f06 | 1 | /* |
2 | * mod_msff.c: Microsoft Free Fridays: reject MSIE on Friday. | |
3 | * | |
4 | * Michael Anthony <m@beanpod.net> | |
5 | * You may use this software free for any purpose. | |
6 | * It has no warranty. | |
7 | * | |
8 | * You might find success by trying to build it like this: | |
9 | * | |
10 | * gcc -c -I<apache include dir> -fpic -DSHARED_MODULE mod_msff.c | |
11 | * gcc -shared -o mod_msff.so mod_msff.o | |
12 | * | |
13 | * But you also might not. After you do that, you'll want the | |
14 | * resulting .so file in your Apache installation's libexec directory. | |
15 | * | |
16 | * Enable the module by putting this line right around where the | |
17 | * LoadModule line for mod_auth is: | |
18 | * | |
19 | * LoadModule msff_module libexec/mod_msff.so | |
20 | * | |
21 | * and put this line right around where the AddModule line for | |
22 | * mod_auth is: | |
23 | * | |
24 | * AddModule mod_msff.c | |
25 | * | |
26 | */ | |
27 | ||
28 | #include "httpd.h" | |
29 | #include "http_core.h" | |
30 | #include "http_config.h" | |
31 | #include "http_log.h" | |
32 | #include "http_request.h" | |
33 | #include <string.h> | |
34 | #include <ctype.h> | |
35 | ||
36 | static void dump_message (request_rec *r) | |
37 | { | |
38 | r->content_type = "text/html"; | |
39 | r->status = FORBIDDEN; | |
40 | ap_send_http_header (r); | |
41 | ||
42 | if (! r->header_only) | |
43 | { | |
44 | ap_rprintf ( | |
45 | r, | |
46 | "<html xml:lang=\"en\" lang=\"en\">\n" | |
47 | "<head>\n" | |
48 | "<title>Go home, Billy!</title>\n" | |
49 | "</head>\n" | |
50 | "<body>\n" | |
51 | "<p><h1>Happy " | |
52 | "<a href=\"http://davenet.userland.com/2001/06/13\">" | |
53 | "Microsoft-Free Friday</a>!</h1></p>\n" | |
54 | "<p>In support of freedom of choice in browser software, this" | |
55 | " web site is Microsoft-Free on Fridays. Please use any" | |
56 | " browser except MSIE to access this web site today.</p>\n" | |
57 | "</body>\n" | |
58 | "</html>\n"); | |
59 | } | |
60 | } | |
61 | ||
62 | static int msff (request_rec *r) | |
63 | { | |
64 | int ret = 0; | |
65 | time_t now; | |
66 | struct tm *tmp; | |
67 | char *agent = 0; | |
68 | const char *foo; | |
69 | char *p; | |
70 | ||
71 | foo = ap_table_get (r->headers_in, "User-Agent"); | |
72 | if (foo) | |
73 | { | |
74 | agent = ap_pstrdup (r->pool, foo); | |
75 | for (p = agent; *p; ++p) | |
76 | { | |
77 | if (isupper (*p)) | |
78 | { | |
79 | *p = tolower (*p); | |
80 | } | |
81 | } | |
82 | } | |
83 | ||
84 | if (agent | |
85 | && strstr (agent, "msie") | |
86 | && ! strstr (agent, "opera") | |
87 | && ! strstr (agent, "oregano")) | |
88 | { | |
89 | time (&now); | |
90 | tmp = localtime (&now); | |
91 | if (tmp->tm_wday == 5) | |
92 | { | |
93 | ret = 1; | |
94 | } | |
95 | } | |
96 | ||
97 | return ret; | |
98 | } | |
99 | ||
100 | static int handle_msff (request_rec *r) | |
101 | { | |
102 | if (msff (r)) | |
103 | { | |
104 | dump_message (r); | |
105 | return OK; | |
106 | } | |
107 | else | |
108 | { | |
109 | return DECLINED; | |
110 | } | |
111 | } | |
112 | ||
113 | module MODULE_VAR_EXPORT msff_module; | |
114 | ||
115 | static const command_rec msff_cmds[] = | |
116 | { | |
117 | { NULL } | |
118 | }; | |
119 | ||
120 | static const handler_rec msff_handlers[] = | |
121 | { | |
122 | { "*/*", handle_msff }, | |
123 | { NULL } | |
124 | }; | |
125 | ||
126 | module MODULE_VAR_EXPORT msff_module = | |
127 | { | |
128 | STANDARD_MODULE_STUFF, | |
129 | NULL, /* initializer */ | |
130 | NULL, /* dir config creater */ | |
131 | NULL, /* dir merger --- default is to override */ | |
132 | NULL, /* server config */ | |
133 | NULL, /* merge server config */ | |
134 | msff_cmds, /* command table */ | |
135 | msff_handlers, /* handlers */ | |
136 | NULL, /* filename translation */ | |
137 | NULL, /* check_user_id */ | |
138 | NULL, /* check auth */ | |
139 | NULL, /* check access */ | |
140 | NULL, /* type_checker */ | |
141 | NULL, /* fixups */ | |
142 | NULL, /* logger */ | |
143 | NULL, /* header parser */ | |
144 | NULL, /* child_init */ | |
145 | NULL, /* child_exit */ | |
146 | NULL /* post read-request */ | |
147 | }; |