User:Inge Hoonte/operating system detector: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "<source lang="bash"> #!/usr/bin/python import os print "Content-type: image/jpg" print if "Linux" in os.environ['HTTP_USER_AGENT']: f=open("linux.jpg") print f...")
 
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
===CGI JOE===
'''WHAT'''
CGI Joe detects what operating system the visitor to the website is using, and adjusts the background image accordingly. It displays a soft green meadow for Windows users, purple explosion for Mac users, and an army of penguins for Linux users.
I searched for a variety of wallpapers, ones from the 90s were really nice... But then decided to go with the iconic contemporary graphics. I cleaned up the code I did earlier today (see below). Trying to enter the CGI script as a wikiwar competitor on the main page... not working. Looking into how to operate code from within the wiki, don't know :)
<source lang="bash">
<source lang="bash">
#!/usr/bin/python
#!/usr/bin/python


Line 19: Line 24:
         print f.read()
         print f.read()
</source>
</source>
<source lang="bash">
#!/usr/bin/python
print "Content-type: text/html"
print
import os
#print os.environ
#for key in os.environ:
#      print key,":", os.environ[key], "<br>"
if "Linux" in os.environ['HTTP_USER_AGENT']:
        print """
<html>
<head>
<title>Index</title>
</head>
<body>
<img src="http://linuxnov.com/wp-content/uploads/2011/01/Screenshot-16.png">
<br>
<b style="font family: Arial;font-size: 12px">Welcome home, Linux User</$
<br>
"""
elif "Mac" in os.environ['HTTP_USER_AGENT']:
        print """
<html>
<head>
<title>Index</title>
</head>
<body>
<img src="http://emulators.com/images/GemX_After_Drag.gif">
<br>
<b style="font family: Arial;font size:12px">Welcome, Mac User :)<br/>
<br>
"""
elif "Windows" in os.environ['HTTP_USER_AGENT']:
        print """
<html>
<head>
<body>
<img src="http://www.plig.org/xwinman/screenshots/olwm.gif">
<br>
<b style="font family: Arial; font-size:12px">Welcome home, Windows User<
</body>
</head>
</html>
"""
print """
<ul>
<li><a href="../Lesson One.html">Lesson One</a></li>
<li><a href="../Lesson two.html">Lesson Two</a></li>
<li><a href="../Lesson_03.html">Lesson Three</a></li>
<li><a href="../Lesson_04.html">Lesson Four</a></li>
</ul>
</body>
</html>
"
</source>
[[File:cgi-script_welcome.png]]

Latest revision as of 01:08, 4 November 2011

CGI JOE

WHAT CGI Joe detects what operating system the visitor to the website is using, and adjusts the background image accordingly. It displays a soft green meadow for Windows users, purple explosion for Mac users, and an army of penguins for Linux users.

I searched for a variety of wallpapers, ones from the 90s were really nice... But then decided to go with the iconic contemporary graphics. I cleaned up the code I did earlier today (see below). Trying to enter the CGI script as a wikiwar competitor on the main page... not working. Looking into how to operate code from within the wiki, don't know :)

#!/usr/bin/python

import os
print "Content-type: image/jpg"
print

if "Linux" in os.environ['HTTP_USER_AGENT']:
        f=open("linux.jpg")
        print f.read()

elif "Mac" in os.environ['HTTP_USER_AGENT']:
        f=open("mac.jpg")
        print f.read()

elif "Windows" in os.environ['HTTP_USER_AGENT']:
        f=open("windows.jpg")
        print f.read()


#!/usr/bin/python

print "Content-type: text/html"
print

import os
#print os.environ

#for key in os.environ:
#       print key,":", os.environ[key], "<br>"

if "Linux" in os.environ['HTTP_USER_AGENT']:
        print """
<html>
<head>
<title>Index</title>
</head>
<body>
<img src="http://linuxnov.com/wp-content/uploads/2011/01/Screenshot-16.png">
<br>
<b style="font family: Arial;font-size: 12px">Welcome home, Linux User</$
<br>
"""
elif "Mac" in os.environ['HTTP_USER_AGENT']:
        print """
<html>
<head>
<title>Index</title>
</head>
<body>
<img src="http://emulators.com/images/GemX_After_Drag.gif">
<br>

<b style="font family: Arial;font size:12px">Welcome, Mac User :)<br/>
<br>
"""
elif "Windows" in os.environ['HTTP_USER_AGENT']:
        print """
<html>
<head>
<body>
<img src="http://www.plig.org/xwinman/screenshots/olwm.gif">
<br>
<b style="font family: Arial; font-size:12px">Welcome home, Windows User<
</body>
</head>
</html>

"""

print """
<ul>
<li><a href="../Lesson One.html">Lesson One</a></li>
<li><a href="../Lesson two.html">Lesson Two</a></li>
<li><a href="../Lesson_03.html">Lesson Three</a></li>
<li><a href="../Lesson_04.html">Lesson Four</a></li>
</ul>
</body>
</html>
"

Cgi-script welcome.png