#!/usr/bin/perl -w # # mt-perm-fix.cgi # Written by Eric Tribou : 2005.08.08 # # ABOUT: # This is a simple, hack-job script used to set full control of a blog # to an existing author in the system. It was written because there was # no obvious means to achieve this. (Although maybe there is and I'm # just very blind.) # # TO USE: # Copy this into your mt scrips folder. This is the same location where # mt.cgi resides (where you login). Make sure execute and read permissions # are set, then call it from a web browser. # # Do not leave this up, and change the name to something else when you # use it. There is not authority control and any user, authorized or # otherwise, will be able to access this script while it is active! # # !NOTE!NOTE!NOTE!NOTE! # This script was written for MT 2.661 and may not work on any other version #Get the MT directory (copied from stock MT scripts) my($MT_DIR); BEGIN { if ($0 =~ m!(.*[/\\])!) { $MT_DIR = $1; } else { $MT_DIR = './'; } unshift @INC, $MT_DIR . 'lib'; unshift @INC, $MT_DIR . 'extlib'; } #Process any existing FORM data #NOTE: this includes GET information. this is very basic form handling read(STDIN, $FormData, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $FormData); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } #Output the content-type for HTML print "Content-type: text/html\n\n"; #Print out the HTML header print < MT Fun
ENDHTML #Load application config use MT; my $mt = MT->new( Config => $MT_DIR . 'mt.cfg' ); #Check FORM data and see if we have something to act upon if ( $FORM{'blog_id'} && int( $FORM{'blog_id'} > 0 ) && $FORM{'author_id'} && int( $FORM{'author_id'} ) > 0 ) { #Sort out the author and blog IDs. Sanitization via int() my $blog_id = int( $FORM{'blog_id'} ); my $author_id = int( $FORM{'author_id'} ); #Start up the permissions library use MT::Permission; #Get existing permissions for this user on this blog my $perms = MT::Permission->load({ blog_id => $blog_id , author_id => $author_id }); #If no permissions exist, we need to create them first if ( !$perms ) { $perms = MT::Permission->new; $perms->author_id($author_id); $perms->blog_id($blog_id); print "Created new permissions.\n"; } else { print "Updated existing permissions.\n"; } #Set full permissions $perms->set_full_permissions; #Save permission changes $perms->save or die $perms->errstr; print "
\n"; } #Begin output of FORM that lets users select a blog and author. print "

\nBlog: "; print "\n

\n"; print "

\nAuthor: "; print "\n

\n"; #Output the rest of the HTML print <

ENDHTML #And we're done.