From e9192b3d42660a5781101df4357d276318151e8a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 2 Aug 2013 17:14:41 -0500 Subject: cgi-bin & lib --- cgi-bin/profile | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100755 cgi-bin/profile (limited to 'cgi-bin/profile') diff --git a/cgi-bin/profile b/cgi-bin/profile new file mode 100755 index 0000000..93dc089 --- /dev/null +++ b/cgi-bin/profile @@ -0,0 +1,167 @@ +#!/usr/bin/perl +######################################### +# profile +# maintain a user's profile +# or print a form +######################################### + +use localbucky; + +my $pid; + +$dbh = DBI->connect ($dsn); + +our ($USER, $lastlog) = checkin(); +our $loggedin = ($USER != -1); + +sub main + { + $input->{username} ||= $input->{object_from_uri} if defined($input->{object_from_uri}); + my ($keywords) = get_keywords(); + + if (exists($input->{c}) && $input->{c} eq "sticky" && defined($input->{keyword})) + { + logout() unless ($loggedin); + my $keyword = $input->{keyword}; + print "Switching keyword $keyword for $USER->{username} ..." if ($DEBUG); + my $stkcy = check_key($keyword, $USER->{stickies}); + my $newk; + if (exists($input->{chexor})) + { $newk = add_key($USER->{stickies}, $keyword); } + else + { $newk = delete_key($USER->{stickies}, $keyword); } + update_user_sticky($USER->{username}, $newk); + redirect("$BUCKY/index"); + } + elsif (exists($input->{username})) + { + if ($USER->{username} eq $input->{username}) + { + header( { + title => "profile for $input->{username}", + subtitle => qq!edit your profile! + } ); + } + elsif ($input->{username} eq "system") + { + $input->{username} = "marc"; + header("profile for $input->{username}"); + } + elsif (get_uid($input->{username}) == -1) + { nice_redirect(); } + else + { header("profile for $input->{username}"); } + menu(); + show_profile($input->{username}); + } + elsif ($input->{c} eq 'form') + { + logout() unless ($loggedin); + header( { + title => "editing $USER->{username}'s profile", + subtitle => qq!view your profile! + } ); + + menu(); + profile_form($USER->{username}); + } + elsif ($input->{c} eq 'update') + { + logout() unless ($loggedin); + my $messages = ''; + if (exists($input->{rmpic}) && $input->{rmpic} == 1) + { + system("rm", "-f", "$data_path/profile/$USER->{username}.jpg"); + system("rm", "-f", "$data_path/profile/.thumb/$AVATAR_PROFILE_PREFIX$USER->{username}.jpg"); + system("rm", "-f", "$data_path/profile/.thumb/$AVATAR_BIG_PREFIX$USER->{username}.jpg"); + system("rm", "-f", "$data_path/profile/.thumb/$AVATAR_MED_PREFIX$USER->{username}.jpg"); + $messages .= "old profile image deleted
\n"; + } + if (exists($input->{pw1}) && exists($input->{pw2}) && $input->{pw1} && $input->{pw2}) + { + if ($input->{pw1} eq $input->{pw2}) + { + update_password($USER->{username}, crypt($input->{pw1},lc($USER->{username}))); + $messages .= qq(password changed -- please log back in
\n); + } + else + { + $messages .= "passwords don't match!
\n"; + } + } + if (exists($input->{stickies})) + { + my $s; + $input->{stickies} =~ s/[^A-Za-z0-9 ]//; + foreach my $k (split / /, $input->{stickies}) + { + next unless ($keywords->{$k}); + $s = add_key($s, lc($k)); + } + $input->{stickies} = $s; + } + if (exists($input->{sink})) + { + my $s; + $input->{sink} =~ s/[^A-Za-z0-9 ]//g; + foreach my $k (split / /, $input->{sink}) + { + next unless ($keywords->{$k}); + $s = add_key($s, lc($k)); + } + $input->{sink} = $s; + } + + my (@boxes) = qw[welcome bPod radio postform hootbox photostream autoplay showhidden nologout]; + my $newboxes = ' '; + foreach my $key (@boxes) + { + if (exists($input->{$key}) && $input->{$key} == 1) + { $newboxes = add_key($newboxes, $key); } + } + if ($USER->{boxes} ne $newboxes) + { + update_user_boxes($USER->{username}, $newboxes); + $USER->{boxes} = $newboxes; + $messages .= "New box settings: $USER->{boxes}
\n" if ($DEBUG); + } + + if ($loggedin && update_profile($USER->{username}, $input)) + { + $USER->{timezone} = $input->{timezone}; + $dateoffset = -1; + $messages .= "profile updated
" + } + if ($loggedin && update_profile_image($USER->{username})) + { + $messages .= "profile image updated
"; + } + + header( { + title => "updating profile...", + subtitle => qq!edit your profile! + } ); + menu(); + print qq(
$messages); + print qq(

); + show_profile($USER->{username}); + } + else + { + logout() unless ($loggedin); + header( { + title => "profile for $USER->{username}", + subtitle => qq!edit your profile! + } ); + menu(); + show_profile($USER->{username}); + } + + footer(); + } + +main(); + +$dbh->disconnect (); + +print "Profile: " . &report_time() . "\n" if $timer; -- cgit v1.2.3-70-g09d2