#!/usr/bin/perl # mono-integration 0.1 # # Copyright (c) 2007 Thomas Thurman # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. use strict; use warnings; use Data::Dumper; use BBS::Monochrome; use CGI; use Storable; my $datastore = '../accounts/'; my $query = new CGI; my %vars = $query->Vars(); my $path_info = $query->path_info(); my %user_details; print "Content-Type: application/xml\n\n"; if (!defined $vars{fb_sig_user}) { not_logged_in(); } elsif (!$vars{fb_sig_in_canvas}) { needs_to_be_a_canvas(); } elsif ($path_info eq "/login") { login_page(); } else { %user_details = fetch_user_details(); if (!%user_details) { dont_know_you(); } elsif ($path_info =~ /\/diary/) { diary_page(); } elsif ($path_info =~ /\/status/) { status_page(); } elsif ($path_info =~ /\/signout/) { signout_page(); } else { main_page(); } } ##################################### sub main_page { write_dashboard(); print "
Hello, $user_details{login}, and welcome to the unofficial Monochrome\n"; print "Facebook application. Please choose from among the options in\n"; print "the dashboard above.
"; } sub not_logged_in { print "Great! You've added the Monochrome Facebook application, but I\n"; print "don't know your Monochrome login name. Care to enlighten me?
\n\n"; print ""; print "If you don't have an account yet, try going to the\n"; print "Mono website.
"; } sub login_page { my $login = $vars{login}; my $password = $vars{password}; if (!$login || !$password) { dont_know_you(); return; } print "Hello, $nameline. Obviously you do have a working\n"; print "Mono account. You don't need to press \"Forget login\" above unless\n"; print "you want the Monochrome Facebook application to forget your\n"; print "password (say, if you change it on Mono and want to re-enter it.)\n"; print "Otherwise, stay logged in here as long as you like; it doesn't\n"; print "time out.
\n"; print ""; my %userinfo = ( login=>$login, password=>$password ); store \%userinfo, persistent(); } else { print "Either you don't really have a Mono account at all, or the\n"; print "password you gave was wrong. You should\n"; print "try again, or\n"; print "else ask the Mono people for support.
\n"; } } sub status_page { write_dashboard(); if ($vars{feeling}) { $vars{feeling} = substr($vars{feeling}, 0, 50); my $mono = reliable_connection(); $mono->goto('MTU'); $mono->put('X'); $mono->waitfor('/Text: /'); $mono->print($vars{feeling}); $mono->waitfor('/to continue/'); $mono->print(''); $mono->logout(); print "Okay, your status has been updated.
"; } print <Simply type in a short line (50 chars) describing your feelings at this moment in time, and the world will know how you feel. Once you've told people that you use this file, they'll get used to looking at how you're feeling before putting their foot in it!
REMINDER: The Status file is NOT Xrated. Any swearing found in the file will be dealt with as a breach of Monochrome's Conditions of Use.
EOT } sub diary_page { write_dashboard(); if ($vars{subject} && $vars{diary}) { $vars{subject} = substr($vars{subject}, 0, 50); $vars{diary} =~ s/\n\./\n \./g; my $mono = reliable_connection(); $mono->goto('MLY'); $mono->put('D'); $mono->put('A'); $mono->waitfor('/Subject: /'); $mono->print($vars{subject}); $mono->print($vars{diary}); $mono->print('.'); $mono->waitfor('/====/'); $mono->print(' '); $mono->logout(); print "Okay, your diary has been updated.
"; } print <Okay, I've forgotten about you.\n"; print "Log back in?
\n"; } ##################################### sub write_dashboard { print "Your Mono credentials seem to have been destroyed.
"; print ""; exit(0); } } sub persistent { die "fb_sig_user is not numeric" unless $vars{fb_sig_user} =~ /^\d*$/; return "$datastore/$vars{fb_sig_user}"; }