0byt3m1n1
Path:
/
data
/
0
/
0
/
6
/
46
/
6861
/
user
/
7034
/
cgi-bin
/
mt
/
[
Home
]
File: mt-load.cgi
#!/usr/local/bin/perl -w # Copyright 2001-2004 Six Apart. This code cannot be redistributed without # permission from www.movabletype.org. # # $Id: mt-load.cgi.pre,v 1.1.2.1.2.1 2004/12/17 03:36:59 ezra Exp $ use strict; my($MT_DIR); BEGIN { if ($0 =~ m!(.*[/\\])!) { $MT_DIR = $1; } else { $MT_DIR = './'; } unshift @INC, $MT_DIR . 'lib'; unshift @INC, $MT_DIR . 'extlib'; } local $| = 1; use MT::L10N; my $LH = MT::L10N->get_handle('en_US'); sub trans_templ { my($text) = @_; $text =~ s!<MT_TRANS((\s\w+=(["'])[^"]*\3)+)>! my($msg, %args) = ($1); #print $msg; while ($msg =~ /(\w+)\s*=\s*(["'])(.*?)\2/g) { #" $args{$1} = $3; } $args{params} = '' unless defined $args{params}; my @p = map MT::Util::decode_html($_), split /\s*%%\s*/, $args{params}; @p = ('') unless @p; $LH->maketext($args{phrase}, @p); !ge; $text; } print "Content-Type: text/html\n\n"; print trans_templ(<<HTML) unless (grep {$_ eq '--nostyle' } @ARGV); <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="content-language" content="en" /> <title>Movable Type System Loader [mt-load.cgi]</title> <style type=\"text/css\"> <!-- body { font-family : Trebuchet MS, Tahoma, Verdana, Arial, Helvetica, Sans Serif; font-size : smaller; padding-top : 0px; padding-left : 0px; margin : 0px; padding-bottom : 40px; width : 80%; border-right : 1px dotted #8faebe; } h1 { background : #8faebe; font-size: large; color : white; padding : 10px; margin-top : 0px; margin-bottom : 20px; text-align : center; } h2 { color: #fff; font-size: small; background : #8faebe; padding : 5px 10px 5px 10px; margin-top : 30px; margin-left : 40px; margin-right : 40px; } h3 { color: #333; font-size: small; margin-left : 40px; margin-bottom : 0px; padding-left : 20px; } p { padding-left : 20px; margin-left : 40px; margin-right : 60px; color : #666; } ul { padding-left : 40px; margin-left : 40px; } code { font-size : small; } .info { margin-left : 60px; margin-right : 60px; padding : 20px; border : 1px solid #666; background : #eaf2ff; color : black; } .alert { margin-left : 60px; margin-right : 60px; padding : 20px; border : 1px solid #666; background : #ff9; color : black; } .ready { color: #fff; background-color: #9C6; } .bad { padding-top : 0px; margin-top : 4px; border-left : 1px solid red; padding-left : 10px; margin-left : 60px; } .good { color: #93b06b; padding-top : 0px; margin-top : 0px; } //--> </style> </head> <body> <h1><MT_TRANS phrase="Movable Type System Loader"> [mt-load.cgi]</h1> <p class="info"><MT_TRANS phrase="This page configures Movable Type to run on your system. If all of the tasks needed to set up Movable Type complete succesfully on your server, you will see a notice to that effect at the bottom of this page. If there are any problems during setup, you will see them display on this page so that you can make the appropriate corrections."></p> <h2><MT_TRANS phrase="Movable Type System Setup"></h2> HTML use File::Spec; eval { my $tmpl_list; eval { $tmpl_list = require 'MT/default-templates.pl' }; die "Can't find default template list; where is 'default-templates.pl'?\n" . "Error: $@\n" if $@ || !$tmpl_list || ref($tmpl_list) ne 'ARRAY' || !@$tmpl_list; print trans_templ("<h3><MT_TRANS phrase='Loading initial data into system...'></h3>\n"); require MT; my $mt = MT->new( Config => $MT_DIR . 'mt.cfg', Directory => $MT_DIR ) or die MT->errstr; if ($mt->{cfg}->ObjectDriver =~ /^DBI::(.*)$/) { my $type = $1; my $dbh = MT::Object->driver->{dbh}; my $schema = File::Spec->catfile($MT_DIR, 'schemas', $type . '.dump'); open FH, $schema or die "<p class=\"bad\">Can't open schema file '$schema': $!</p>"; my $ddl; { local $/; $ddl = <FH> } close FH; my @stmts = split /;/, $ddl; print trans_templ("<h3><MT_TRANS phrase='Loading database schema...'></h3>\n\n"); for my $stmt (@stmts) { $stmt =~ s!^\s*!!; $stmt =~ s!\s*$!!; next unless $stmt =~ /\S/; $dbh->do($stmt) or die $dbh->errstr; } } use MT::Author qw(AUTHOR COMMENTER); require MT::Blog; ## First check if there are any authors or blogs currently--if there ## are, don't run the rest of the script, because we don't want to add ## the default author back in (hack). if (MT::Author->count || MT::Blog->count) { print trans_templ(<<MSG), security_notice(); <h2><MT_TRANS phrase="System Already Initialized"></h2> <p class="bad"><MT_TRANS phrase="It looks like your database has already been initialized by mt-load.cgi. Re-running this script will create a security hole, so this script has been prevented from running."></p> MSG exit; } print trans_templ("<h3><MT_TRANS phrase='Loading weblog'>...</h3>\n"); my $blog = MT::Blog->new; $blog->name($LH->maketext('First Weblog')); $blog->archive_type('Individual,Monthly,Category'); $blog->archive_type_preferred('Individual'); $blog->days_on_index(7); $blog->words_in_excerpt(40); $blog->file_extension('html'); $blog->convert_paras(1); $blog->convert_paras_comments(1); $blog->sanitize_spec(0); $blog->allow_unreg_comments(1); $blog->moderate_unreg_comments(1); $blog->ping_weblogs(0); $blog->ping_blogs(0); $blog->ping_technorati(0); $blog->server_offset(0); $blog->allow_reg_comments(1); $blog->allow_comments_default(1); $blog->language('en_US'); $blog->sort_order_posts('descend'); $blog->sort_order_comments('ascend'); $blog->status_default(1); $blog->custom_dynamic_templates('none'); $blog->children_modified_on('20040101000000'); $blog->save or die $blog->errstr; print trans_templ("<h3><MT_TRANS phrase='Loading author...'></h3>"); my $author = MT::Author->new; $author->name('Melody'); $author->type(AUTHOR); $author->set_password('Nelson'); $author->email(''); $author->can_create_blog(1); $author->can_view_log(1); $author->preferred_language('en_US'); $author->save or die $author->errstr; print "<h3><MT_TRANS phrase='Loading permissions...'></h3>\n"; require MT::Permission; my $perms = MT::Permission->new; $perms->author_id($author->id); $perms->blog_id($blog->id); $perms->set_full_permissions; $perms->save or die $perms->errstr; print trans_templ("<h3><MT_TRANS phrase='Loading templates'>...</h3>\n"); require MT::Template; my @arch_tmpl; for my $val (@$tmpl_list) { $val->{text} = $mt->translate_templatized($val->{text}); my $obj = MT::Template->new; $obj->build_dynamic(0); $obj->set_values($val); $obj->blog_id($blog->id); $obj->save or die $obj->errstr; if ($val->{type} eq 'archive' || $val->{type} eq 'individual' || $val->{type} eq 'category') { push @arch_tmpl, $obj; } } print trans_templ("<h3><MT_TRANS phrase='Mapping templates to blog archive types...'></h3>\n"); require MT::TemplateMap; for my $tmpl (@arch_tmpl) { my(@at); if ($tmpl->type eq 'archive') { @at = qw( Daily Weekly Monthly ); } elsif ($tmpl->type eq 'category') { @at = qw( Category ); } elsif ($tmpl->type eq 'individual') { @at = qw( Individual ); } for my $at (@at) { # print trans_templ("<p class=\"good\"><MT_TRANS phrase='Mapping template ID [_1] to \"[_2]\"'> '"), $tmpl->id, "' to '$at'</p>\n"; my $map = MT::TemplateMap->new; $map->archive_type($at); $map->is_preferred(1); $map->template_id($tmpl->id); $map->blog_id($tmpl->blog_id); $map->save or die "Save failed: ", $map->errstr; } } }; if ($@) { print <<HTML; <p class="bad">An error occurred while loading data:</p> <p class="alert">$@</p> HTML } else { print trans_templ(<<HTML), security_notice(); <h2 class="ready"><MT_TRANS phrase="System Initialization Complete"></h2> <p><MT_TRANS phrase="Done loading initial data! All went well. You can now continue with setup of the Movable Type system as described in the installation instructions."></p> HTML } sub security_notice { return trans_templ(<<TEXT); <h2><MT_TRANS phrase="Very Important:"></h2> <p class="info"><MT_TRANS phrase="Now that you have run mt-load.cgi, you will never need to run it again. You should now <strong>delete [_1]</strong> from your webserver." params="<code>mt-load.cgi</code>"></p> <p class="alert"><strong><MT_TRANS phrase="Failure to delete [_1] introduces a MAJOR SECURITY RISK." params="<code>mt-load.cgi</code>"></strong></p>. TEXT } print "</body>\n\n</html>\n";