Location: PHPKode > projects > phlyMail Lite > phlymail/installer.php
<?php
/* ------------------------------------------------------------------------- */
/* phlyMail 3.7 (Yokohama2 engine) Installation Script                       */
/* (c) 2002-2009 phlyLabs, Berlin (http://phlylabs.de)                       */
/* All rights reserved                                                       */
/* v4.0.7mod1                                                                */
/* ------------------------------------------------------------------------- */

/* ---- MAKE SURE TO DELETE THIS SCRIPT IMMEDIATELY AFTER INSTALLATION! ---- */
// Which PHP version do we use?
if (!version_compare(phpversion(), '5.2.0', '>=')) {
    header('Content-Type: text/plain; charset=utf-8');
    die('phlyMail requires PHP 5.2.0 or higher, you are running '.phpversion().'.'.LF.'Please upgrade your PHP');
}
define('CRLF', "\r\n");
define('LF', "\n");
define('_IN_PHM_', true);
if (isset($_SERVER['SCRIPT_NAME']) && $_SERVER['SCRIPT_NAME']) {
	define('PHP_SELF', $_SERVER['SCRIPT_NAME']);
} else {
	define('PHP_SELF', $_SERVER['PHP_SELF']);
}
@set_include_path(dirname(__FILE__));
// Do not use cookies for session management
@ini_set('session.use_cookies', 'Off');
@ini_set('url_rewriter.tags', '');
session_start();
$old_umask = umask(0);
// Spracheinstellung vermerken
if (isset($_REQUEST['WPInstLang'])) {
    $_SESSION['WPInstLang'] = ('en' == $_REQUEST['WPInstLang']) ? $_REQUEST['WPInstLang'] : 'de';
} elseif (!isset($_SESSION['WPInstLang']) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
    $_SESSION['WPInstLang'] = (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) == 'de') ? 'de' : 'en';
} elseif (!isset($_SESSION['WPInstLang'])) {
    $_SESSION['WPInstLang'] = 'de';
}
$WPInstLang = $_SESSION['WPInstLang'];
$page = (isset($_REQUEST['page'])) ? intval($_REQUEST['page']) : 0;
$do = (isset($_REQUEST['do'])) ? $_REQUEST['do'] : false;
$error = false;
$metainfo = '<meta http-equiv="content-type" content="text/html; charset=UTF-8"></meta>'.LF;
// Load required files
$_PM_ = parse_ini_file(dirname(__FILE__).'/choices.ini.php', true);
$_PM_['core']['file_umask'] = octdec($_PM_['core']['file_umask']);
$_PM_['core']['dir_umask']  = octdec($_PM_['core']['dir_umask']);
error_reporting((isset($_PM_['core']['debugging_level']) && 'disabled' != $_PM_['core']['debugging_level']) ? E_STRICT : 0);
require_once($_PM_['path']['lib'].'/fxl_template.inc.php');
require_once($_PM_['path']['lib'].'/basemethods.php');
require_once(dirname(__FILE__).'/install/messages.'.$WPInstLang.'.php');
//
if ('save' == $do) {
    if (1 == $page) {
        $tokens = array
                ('language' => 'language'
                ,'theme_name' => 'skin'
                ,'database' => 'database'
                ,'send_method' => 'send_method'
                ,'sendmail' => 'sendmail'
                );
        $tokval['core'] = array();
        foreach ($tokens as $k => $v) {
            if (!isset($_REQUEST[$v])) continue;
            $tokval['core'][$k] = $_REQUEST[$v];
        }
        $res = basics::save_config('choices.ini.php', $tokval);
        if (!$res) {
            $error .= $WP_msg['NotUpdateConfF'];
        }
        $suf = fopen($_PM_['path']['conf'].'/config.choices.ini.php', 'w');
        $GlChFile = ';<?php die(); ?>'.LF.'language = "'.$_REQUEST['language_conf'].'"'.LF;
        if ($suf) {
            fputs($suf, $GlChFile);
            fclose($suf);
            chmod($_PM_['path']['conf'].'/config.choices.ini.php', 0755);
        } else {
            $error .= $WP_msg['NotUpdateConfF'];
        }
    }
    if (2 == $page) {
        require_once($_PM_['path']['driver'].'/'.$_PM_['core']['database'].'/driver.php');
        $DB = new driver($_PM_['path']['conf'].'/driver.'.$_PM_['core']['database'].'.ini.php');
        if (!$DB) { $error .= $WP_msg['NoOpenDB']; } else { $DB->close(); }
    }
    if (!$error) {
        ++$page;
        $urladd = '';
    } else {
        $urladd = '&WP_return='.urlencode($error);
    }
    header('Location: '.PHP_SELF.'?page='.$page.'&WPInstLang='.$WPInstLang.$urladd);
    exit;
}

$tpl = new fxl_template('install/installer.tpl');
if (isset($_REQUEST['WP_return'])) $error = urldecode($_REQUEST['WP_return']);

if (!$page) {
    $t_c = $tpl->get_block('content0');
    $error = false;
    if (!@touch($_PM_['path']['conf'].'/install.test', 0777) || !@unlink($_PM_['path']['conf'].'/install.test')) $error = true;
    if (!@touch($_PM_['path']['storage'].'/install.test', 0777) || !@unlink($_PM_['path']['storage'].'/install.test')) $error = true;
    if (!@touch('install/install.test', 0777) || !@unlink('install/install.test')) $error = true;
    if ($error) {
        $username = get_current_user();
        $uid = getmyuid();
        $gid = getmygid();
        $dirname = dirname(__FILE__);
        $probs = str_replace('$1', $uid, $WP_msg['AccessBlock']);
        $probs = str_replace('$2', $gid, $probs);
        $probs = str_replace('$3', $dirname, $probs);
        $probs = str_replace('$4', $username, $probs);
        $t_c->fill_block('access', 'Probs', $probs);
    }
    $t_c->assign(array
            ('greeting' => $WP_msg['Greeting']
            ,'link_start' => PHP_SELF.'?'.session_name().'='.session_id().'&amp;page=1'
            ,'link_update' => PHP_SELF.'?'.session_name().'='.session_id().'&amp;page=101'
            ,'msg_start' => $WP_msg['StartInstall']
            ,'msg_english' => $WP_msg['English']
            ,'link_english' => PHP_SELF.'?'.session_name().'='.session_id().'&amp;WPInstLang=en'
            ,'msg_german' => $WP_msg['German']
            ,'link_german' => PHP_SELF.'?'.session_name().'='.session_id().'&amp;WPInstLang=de'
            ));
    $tpl->assign('content0', $t_c);
}
if (1 == $page) {
    $t_c = $tpl->get_block('content1');
    if ($error) {
        $t_e = $t_c->get_block('error');
        $t_e->assign('error', $error);
        $t_c->assign('error', $t_e);
    }
    $d_ = opendir($_PM_['path']['driver']);
    while (false !== ($drivername = readdir($d_))) {
        if ($drivername == '.' || $drivername == '..') continue;
        if (!is_readable($_PM_['path']['driver'].'/'.$drivername.'/driver.php')) continue;
        $drivers[] = $drivername;
    }
    closedir($d_);
    sort($drivers);
    $t_d = $t_c->get_block('driverline');
    foreach ($drivers as $drivername) {
        $t_d->assign('drivername', $drivername);
        if ($drivername == $_PM_['core']['database']) $t_d->assign_block('sel');
        $t_c->assign('driverline', $t_d);
        $t_d->clear();
    }

    $d_ = opendir($_PM_['path']['message']);
    while (false !== ($langname = readdir($d_))) {
        if ($langname == '.' || $langname == '..') continue;
        if(!preg_match('!\.php$!i', trim($langname))) continue;
        $langname = preg_replace('!\.php$!i', '', trim($langname));
        $langs[] = $langname;
    }
    closedir($d_);
    sort($langs);
    $t_d = $t_c->get_block('langline');
    foreach ($langs as $langname) {
        $t_d->assign('langname', $langname);
        if ($langname == $_PM_['core']['language']) $t_d->assign_block('sel');
        $t_c->assign('langline', $t_d);
        $t_d->clear();
    }

    $langs = array();
    $d_ = opendir($_PM_['path']['admin'].'/messages/');
    while (false !== ($langname = readdir($d_))) {
        if ($langname == '.' || $langname == '..') continue;
        if(!preg_match('!\.php$!i', trim($langname))) continue;
        $langname = preg_replace('!\.php$!i', '', trim($langname));
        $langs[] = $langname;
    }
    closedir($d_);
    sort($langs);
    $t_d = $t_c->get_block('langconfline');
    foreach ($langs as $langname) {
        $t_d->assign('langname', $langname);
        if ($langname == $_PM_['core']['language']) $t_d->assign_block('sel');
        $t_c->assign('langconfline', $t_d);
        $t_d->clear();
    }

    $d_ = opendir($_PM_['path']['theme']);
    while (false !== ($skinname = readdir($d_))) {
        if ($skinname == '.' || $skinname == '..') continue;
        if (!file_exists($_PM_['path']['theme'].'/'.$skinname)
                || !is_dir($_PM_['path']['theme'].'/'.$skinname)) continue;
        $skins[]= $skinname;
    }
    closedir($d_);
    sort($skins);
    $t_d = $t_c->get_block('skinline');
    foreach ($skins as $skinname) {
        $t_d->assign('skinname', $skinname);
        if ($skinname == $_PM_['core']['theme_name']) $t_d->assign_block('sel');
        $t_c->assign('skinline', $t_d);
        $t_d->clear();
    }

    if ($woliegts = @exec('which sendmail')) {
        if (!preg_match('!^/!', $woliegts)) unset($woliegts);
    }
    if (isset($woliegts) && !isset($_REQUEST['sendmail'])) $sendmail = $woliegts;
    if (!isset($sendmail) && isset($_REQUEST['sendmail'])) $sendmail = $_REQUEST['sendmail'];
    if (!isset($sendmail)) $sendmail = '';

    $t_c->assign(array
            ('form_target' => PHP_SELF.'?'.session_name().'='.session_id()
            ,'head' => $WP_msg['HeadStep1']
            ,'aboutdriver' => $WP_msg['AboutDriver']
            ,'driver' => $WP_msg['Driver']
            ,'aboutlang' => $WP_msg['AboutLang']
            ,'language' => $WP_msg['Language']
            ,'aboutskin' => $WP_msg['AboutSkin']
            ,'skin' => $WP_msg['Skin']
            ,'aboutsendmethod' => $WP_msg['AboutSendMethod']
            ,'sendmethod' => $WP_msg['SendMethod']
            ,'sendmail' => $sendmail
            ,'path' => $WP_msg['Path']
            ,'continue' => $WP_msg['Continue']
            ,'page' => $page
            ));
    $tpl->assign('content1', $t_c);
}
if (2 == $page) {
    $t_c = $tpl->get_block('content2');
    if (isset($error)) $t_c->fill_block('error', 'error', $error);
    $_PM_['tmp']['driver_dir'] = $_PM_['path']['driver'].'/'.$_PM_['core']['database'];
    require_once($_PM_['tmp']['driver_dir'].'/setup.php');
    $t_c->assign(array
            ('form_target' => PHP_SELF.'?'.session_name().'='.session_id()
            ,'head' => $WP_msg['HeadStep2']
            ,'aboutdriver' => $WP_msg['AboutDriverSetup']
            ,'conf_output' => $conf_output
            ,'continue' => $WP_msg['Continue']
            ,'page' => $page
            ,'done' => $WP_msg['Step2Ahead']
            ));
    $tpl->assign('content2', $t_c);
}
if (3 == $page) {
    header('Location: '.PHP_SELF.'?page=4&WPInstLang='.$WPInstLang);
}

if (4 == $page) {
    $t_c = $tpl->get_block('content4');
    if (isset($error)) $t_c->fill_block('error', 'error', $error);
    if (is_readable($_PM_['path']['driver'].'/'.$_PM_['core']['database'].'/install.php')) {
        $_PM_['tmp']['driver_dir'] = $_PM_['path']['driver'].'/'.$_PM_['core']['database'];
        ob_start();
        require_once($_PM_['tmp']['driver_dir'].'/install.php');
        $t_c->fill_block('specific', array
                ('msg_specific' => $WP_msg['SpecificBelow']
                ,'msg_check' => $WP_msg['HappyCheck']
                ,'msg_testit' => $WP_msg['TestIt']
                ,'output' => ob_get_contents()
                ));
        ob_end_clean();
    } else {
        $t_c->fill_block('nospecific', 'nospecific', $WP_msg['NoSpecific']);
    }
    $t_c->assign(array
            ('form_target' => PHP_SELF.'?'.session_name().'='.session_id()
            ,'head' => $WP_msg['HeadStep4']
            ,'continue' => $WP_msg['Continue']
            ,'page' => $page
            ));
    $tpl->assign('content4', $t_c);
}

if (5 == $page) {
    require_once($_PM_['path']['driver'].'/'.$_PM_['core']['database'].'/driver.php');
    $DB = new driver($_PM_['path']['conf'].'/driver.'.$_PM_['core']['database'].'.ini.php');
    if (!$DB) die($WP_msg['NoOpenDB']);
	$_PM_['handlers'] = parse_ini_file($_PM_['path']['conf'].'/active_handlers.ini.php');
	$d_ = opendir($_PM_['path']['handler']);
	// Make sure, all not yet covered handlers get to install themselves
    while (false !== ($handler = readdir($d_))) {
        if ($handler == '.' || $handler == '..') continue;
        if (isset($_PM_['handlers'][$handler]) && $_PM_['handlers'][$handler]) continue;
		if (file_exists($_PM_['path']['handler'].'/'.$handler.'/config_api.php')) {
			require_once($_PM_['path']['handler'].'/'.$handler.'/config_api.php');
			if (in_array('handler_install', get_class_methods('cfgapi_'.$handler))) {
				$call = 'cfgapi_'.$handler;
				$API = new $call($_PM_, 0);
				$state = $API->handler_install();
				unset($API);
			}
		}
		$_PM_['handlers'][$handler] = 1;
    }
    basics::save_config($_PM_['path']['conf'].'/active_handlers.ini.php', $_PM_['handlers']);
    // END handler installation
    $nogo = 0;
    $t_c = $tpl->get_block('content5');
    foreach (array
            ('install/phlymail.png', 'install/messages.de.php', 'install/messages.en.php'
            ,'install/installer.tpl') as $kill) {
         @unlink($kill);
    }
    @rmdir('install');
    if (file_exists('install') && is_dir('install')) {
        $t_c->assign_block('dirfail');
        $nogo = 1;
    } else {
        $t_c->assign_block('dirfine');
    }
    if (!@unlink(basename(__FILE__))) {
        $t_c->assign_block('myfail');
        $nogo = 1;
    } else {
        $t_c->assign_block('myfine');
    }
    if ($nogo != 1) {
        $myfile = basename(PHP_SELF);
        $t_c->fill_block('go', 'file_ext', substr($myfile, strrpos($myfile, '.') + 1));
    } else {
        $t_c->assign_block('nogo');
    }
    $t_c->assign(array
            ('head' => $WP_msg['HeadStep5']
            ,'aboutfinal' => $WP_msg['AboutFinal']
            ,'removedir' => $WP_msg['RemoveDir']
            ,'removeme' => $WP_msg['RemoveMe']
            ,'msg_complete' => $WP_msg['InstComplete']
            ,'complete_manually' => $WP_msg['CompleteManually']
            ,'msg_failed' => $WP_msg['Failed']
            ,'msg_success' => $WP_msg['Success']
            ));
    $tpl->assign('content5', $t_c);
}
foreach (range(0, 5) as $k) {
    if ($page == $k) {
        $tpl->assign_block('step'.$k.'_a');
    } else {
        $tpl->assign_block('step'.$k.'_i');
    }
    $tpl->assign('msg_step'.$k, $WP_msg['Step'].' '.$k);
}
$tpl->assign(array
        ('version' => $WP_msg['HeadInstall']
        ,'metainfo' => $metainfo
        ,'msg_meninst' => 'Installation'
        ));
header('Content-Type: text/html; charset=UTF-8');
$tpl->display();
umask($old_umask);

// Decrypt a string
// Input:   deconfuse(string $data, string $key);
// Returns: decrypted String
function deconfuse($data = '', $key = '')
{
    $data = base64_decode($data);
    $decoded = '';  $DataLen = strlen($data);
    if (strlen($key) < $DataLen) $key = str_repeat($key, ceil($DataLen/strlen($key)));
    for($i = 0; $i < $DataLen; ++$i) {
        $decoded .= chr((256 + ord($data{$i}) - ord($key{$i})) % 256);
    }
    return $decoded;
}

// Since array_merge can only merge flat arrays and array_merge_recursive appends doublettes
// to the father element we have to do the merge "manually"
function init_merge_PM($_PM_, $import)
{
    foreach ($import as $k => $v) {
        if (is_array($v)) {
            foreach ($v as $k2 => $v2) $_PM_[$k][$k2] = $v2;
        } else {
            $_PM_[$k] = $v;
        }
    }
    return $_PM_;
}
?>
Return current item: phlyMail Lite