/textpattern/setup/index.php
PHP | 503 lines | 411 code | 65 blank | 27 comment | 29 complexity | 5442577f964289dcc4eb5f9142752925 MD5 | raw file
Possible License(s): AGPL-1.0
- <?php
- /*
- This is Textpattern
- Copyright 2005 by Dean Allen
- www.textpattern.com
- All rights reserved
- Use of this software indicates acceptance of the Textpattern license agreement.
- $HeadURL: http://textpattern.googlecode.com/svn/development/4.0/textpattern/setup/index.php $
- $LastChangedRevision: 2980 $
- */
- if (!defined('txpath'))
- {
- define("txpath", dirname(dirname(__FILE__)));
- define("txpinterface", "admin");
- }
- if (!defined('txpadminfolder'))
- define('txpadminfolder', basename(txpath));
- error_reporting(E_ALL);
- @ini_set("display_errors","1");
- include_once txpath.'/lib/constants.php';
- include_once txpath.'/lib/txplib_html.php';
- include_once txpath.'/lib/txplib_forms.php';
- include_once txpath.'/lib/txplib_misc.php';
- include_once txpath.'/lib/txplib_admin.php';
- header("Content-type: text/html; charset=utf-8");
- $adminfoldername = txpadminfolder;
- $rel_siteurl = preg_replace('#^(.*)/'.txpadminfolder.'.*$#i','\\1',$_SERVER['PHP_SELF']);
- print <<<eod
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <title>Textpattern › setup</title>
- <link rel="stylesheet" href="$rel_siteurl/{$adminfoldername}/textpattern.css" type="text/css" />
- </head>
- <body style="border-top:15px solid #FC3">
- <div align="center">
- eod;
- $step = ps('step');
- switch ($step) {
- case "": chooseLang(); break;
- case "getDbInfo": getDbInfo(); break;
- case "getTxpLogin": getTxpLogin(); break;
- case "printConfig": printConfig(); break;
- case "createTxp": createTxp();
- }
- ?>
- </div>
- </body>
- </html>
- <?php
- // -------------------------------------------------------------
- function chooseLang()
- {
- echo '<form action="'.$GLOBALS['rel_siteurl'].'/'.txpadminfolder.'/setup/index.php" method="post">',
- '<table id="setup" cellpadding="0" cellspacing="0" border="0">',
- tr(
- tda(
- hed('Welcome to Textpattern',3).
- graf('Please choose a language:').
- langs().
- graf(fInput('submit','Submit','Submit','publish')).
- sInput('getDbInfo')
- ,' width="400" height="50" colspan="4" align="left"')
- ),
- '</table></form>';
- }
- // -------------------------------------------------------------
- function getDbInfo()
- {
- $GLOBALS['textarray'] = setup_load_lang(ps('lang'));
- @include txpath.'/config.php';
- if (!empty($txpcfg['db']))
- {
- exit(graf(
- gTxt('already_installed', array('{txpath}' => txpath))
- ));
- }
- if (@$_SERVER['SCRIPT_NAME'] && (@$_SERVER['SERVER_NAME'] || @$_SERVER['HTTP_HOST']))
- {
- $guess_siteurl = (@$_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
- $guess_siteurl .= $GLOBALS['rel_siteurl'];
- }
- else
- {
- $guess_siteurl = 'mysite.com';
- }
- echo '<form action="'.$GLOBALS['rel_siteurl'].'/'.txpadminfolder.'/setup/index.php" method="post">',
- '<table id="setup" cellpadding="0" cellspacing="0" border="0">',
- tr(
- tda(
- hed(gTxt('welcome_to_textpattern'),3).
- graf(gTxt('need_details'),' style="margin-bottom:3em"').
- hed('MySQL',3).
- graf(gTxt('db_must_exist'))
- ,' width="400" height="50" colspan="4" align="left"')
- ),
- tr(
- fLabelCell(gTxt('mysql_login')).fInputCell('duser','',1).
- fLabelCell(gTxt('mysql_password')).fInputCell('dpass','',2)
- ),
- tr(
- fLabelCell(gTxt('mysql_server')).fInputCell('dhost','localhost',3).
- fLabelCell(gTxt('mysql_database')).fInputCell('ddb','',4)
- ),
- tr(
- fLabelCell(gTxt('table_prefix')).fInputCell('dprefix','',5).
- tdcs(small(gTxt('prefix_warning')),2)
- ),
- tr(tdcs(' ',4)),
- tr(
- tdcs(
- hed(gTxt('site_url'),3).
- graf(gTxt('please_enter_url')),4)
- ),
- tr(
- fLabelCell('http://').
- tdcs(fInput('text','siteurl',$guess_siteurl,'edit','','',40).
- popHelp('siteurl'),3)
- );
- if (is_disabled('mail'))
- {
- echo tr(
- tdcs(gTxt('warn_mail_unavailable'),3,null,'" style="color:red;text-align:center')
- );
- }
- echo tr(
- td().td(fInput('submit','Submit',gTxt('next'),'publish')).td().td()
- );
- echo endTable(),
- hInput('lang', LANG),
- sInput('printConfig'),
- '</form>';
- }
- // -------------------------------------------------------------
- function printConfig()
- {
- $carry = psa(array('ddb','duser','dpass','dhost','dprefix','siteurl','lang'));
- extract($carry);
- $GLOBALS['textarray'] = setup_load_lang($lang);
- @include txpath.'/config.php';
- if (!empty($txpcfg['db']))
- {
- exit(graf(
- gTxt('already_installed', array(
- '{txpath}' => txpath
- ))
- ));
- }
- // FIXME, remove when all languages are updated with this string
- if (!isset($GLOBALS['textarray']['prefix_bad_characters']))
- $GLOBALS['textarray']['prefix_bad_characters'] =
- 'The Table prefix {dbprefix} contains characters that are not allowed.<br />'.
- 'The first character must match one of <b>a-zA-Z_</b> and all following
- characters must match one of <b>a-zA-Z0-9_</b>';
- echo graf(gTxt("checking_database"));
- if (($mylink = mysql_connect($dhost, $duser, $dpass)))
- $carry['dclient_flags'] = 0;
- elseif (($mylink = mysql_connect($dhost, $duser, $dpass, false, MYSQL_CLIENT_SSL)))
- $carry['dclient_flags'] = 'MYSQL_CLIENT_SSL';
- else
- exit(graf(gTxt('db_cant_connect')));
- echo graf(gTxt('db_connected'));
- if (! ($dprefix == '' || preg_match('#^[a-zA-Z_][a-zA-Z0-9_]*$#', $dprefix)) )
- {
- exit(graf(
- gTxt('prefix_bad_characters', array(
- '{dbprefix}' => strong($dprefix)
- ))
- ));
- }
- if (!$mydb = mysql_select_db($ddb))
- {
- exit(graf(
- gTxt('db_doesnt_exist', array(
- '{dbname}' => strong($ddb)
- ))
- ));
- }
- // use utf8-tables
- if (mysql_query("SET NAMES utf8"))
- {
- $carry['dbcharset'] = "utf8";
- }
- else
- {
- $carry['dbcharset'] = "latin1";
- }
-
- $config = makeConfig($carry);
- $encoded_carry = postEncode($carry);
- if (!file_put_contents( txpath.'/config.php', $config ))
- {
- echo graf(
- gTxt('using_db', array('{dbname}' => strong($ddb)))
- .' ('. $carry['dbcharset'] .')'
- ),
- graf(
- strong(gTxt('before_you_proceed')).', '.gTxt('create_config', array('{txpath}' => txpath))
- ),
-
- '<textarea name="config" cols="40" rows="5" style="width: 400px; height: 200px">',
- $config,
- '</textarea>',
- '<form action="'.$GLOBALS['rel_siteurl'].'/'.txpadminfolder.'/setup/index.php" method="post">',
- fInput('submit','submit',gTxt('did_it'),'smallbox'),
- sInput('getTxpLogin'),hInput('carry',$encoded_carry),
- '</form>';
- }
- else
- {
- getTxpLogin($carry);
- }
- }
- // -------------------------------------------------------------
- function getTxpLogin($carry=array())
- {
- if (empty($carry))
- {
- $carry = postDecode(ps('carry'));
- }
- extract($carry);
- $GLOBALS['textarray'] = setup_load_lang($lang);
- @include txpath.'/config.php';
- if (!isset($txpcfg) || ($txpcfg['db'] != $ddb) || ($txpcfg['table_prefix'] != $dprefix))
- {
- echo graf(
- strong(gTxt('before_you_proceed')).', '.
- gTxt('create_config', array(
- '{txpath}' => txpath
- ))
- ),
- '<textarea style="width:400px;height:200px" name="config" rows="1" cols="1">',
- makeConfig($carry),
- '</textarea>',
- '<form action="'.$GLOBALS['rel_siteurl'].'/'.txpadminfolder.'/setup/index.php" method="post">',
- fInput('submit','submit',gTxt('did_it'),'smallbox'),
- sInput('getTxpLogin'),hInput('carry',postEncode($carry)),
- '</form>';
- return;
- }
- echo '<form action="'.$GLOBALS['rel_siteurl'].'/'.txpadminfolder.'/setup/index.php" method="post">',
- startTable('edit'),
- tr(
- tda(
- graf(gTxt('thanks')).
- graf(gTxt('about_to_create'))
- ,' width="400" colspan="2" align="center"')
- ),
- tr(
- fLabelCell(gTxt('your_full_name')).fInputCell('RealName')
- ),
- tr(
- fLabelCell(gTxt('setup_login')).fInputCell('name')
- ),
- tr(
- fLabelCell(gTxt('choose_password')).fInputCell('pass')
- ),
- tr(
- fLabelCell(gTxt('your_email')).fInputCell('email')
- ),
- tr(
- td().td(fInput('submit','Submit',gTxt('next'),'publish'))
- ),
- endTable(),
- sInput('createTxp'),
- hInput('lang', htmlspecialchars($lang)),
- hInput('siteurl', htmlspecialchars($siteurl)),
- '</form>';
- }
- // -------------------------------------------------------------
- function createTxp()
- {
- $GLOBALS['textarray'] = setup_load_lang(ps('lang'));
- if (!is_valid_email(ps('email')))
- {
- exit(graf(gTxt('email_required')));
- }
- require txpath.'/config.php';
- $ddb = $txpcfg['db'];
- $duser = $txpcfg['user'];
- $dpass = $txpcfg['pass'];
- $dhost = $txpcfg['host'];
- $dclient_flags = isset($txpcfg['client_flags']) ? $txpcfg['client_flags'] : 0;
- $dprefix = $txpcfg['table_prefix'];
- $dbcharset = $txpcfg['dbcharset'];
- $siteurl = str_replace("http://",'', ps('siteurl'));
- $siteurl = rtrim($siteurl,"/");
- $urlpath = preg_replace('#^[^/]+#', '', $siteurl);
- define("PFX",trim($dprefix));
- define('TXP_INSTALL', 1);
- $def_hash_alg = 'sha256';
- include_once txpath.'/lib/txplib_update.php';
- include txpath.'/setup/txpsql.php';
- // This has to come after txpsql.php, because otherwise we can't call mysql_real_escape_string
- extract(doSlash(psa(array('name','pass','RealName','email'))));
- $nonce = md5( uniqid( rand(), true ) );
- $hashpw = doSlash(xpat_hash($def_hash_alg,$pass));
- $def_hash_alg = doSlash($def_hash_alg);
- mysql_query("INSERT INTO `".PFX."txp_users` VALUES
- (1,'$name','$def_hash_alg','$hashpw','$RealName','$email',1,now(),'$nonce')");
- mysql_query("update `".PFX."txp_prefs` set val = '".doSlash($siteurl)."' where `name`='siteurl'");
- mysql_query("update `".PFX."txp_prefs` set val = '".LANG."' where `name`='language'");
- mysql_query("update `".PFX."txp_prefs` set val = '".getlocale(LANG)."' where `name`='locale'");
- mysql_query("update `".PFX."textpattern` set Body = replace(Body, 'siteurl', '".doSlash($urlpath)."'), Body_html = replace(Body_html, 'siteurl', '".doSlash($urlpath)."') WHERE ID = 1");
- mysql_query("update `".PFX."txp_prefs` set val = '".$email."' where `name`='admin_email'");
- echo fbCreate();
- }
- // -------------------------------------------------------------
- function makeConfig($ar)
- {
- define("nl","';\n");
- define("c",'$txpcfg[\'');
- define("m","'] = '");
- $open = chr(60).'?php';
- $close = '?'.chr(62);
- extract($ar);
- return
- $open."\n"
- .c.'db' .m.$ddb.nl
- .c.'user' .m.$duser.nl
- .c.'pass' .m.$dpass.nl
- .c.'host' .m.$dhost.nl
- .($dclient_flags ? c.'client_flags'."'] = ".$dclient_flags.";\n" : '')
- .c.'table_prefix' .m.$dprefix.nl
- .c.'txpath' .m.txpath.nl // remove in crockery
- .c.'dbcharset' .m.$dbcharset.nl
- .$close;
- }
- // -------------------------------------------------------------
- function fbCreate()
- {
- if ($GLOBALS['txp_install_successful'] === false)
- {
- return '<div width="450" valign="top" style="margin-right: auto; margin-left: auto;">'.
- graf(
- gTxt('errors_during_install', array(
- '{num}' => $GLOBALS['txp_err_count']
- ))
- ,' style="margin-top: 3em;"').
- '</div>';
- }
- else
- {
- return '<div width="450" valign="top" style="margin-right: auto; margin-left: auto;">'.
- graf(
- gTxt('that_went_well')
- ,' style="margin-top:3em"').
- graf(
- gTxt('you_can_access', array(
- 'index.php' => $GLOBALS['rel_siteurl'].'/'.txpadminfolder.'/index.php',
- ))
- ).
- graf(gTxt('thanks_for_interest')).
- '</div>';
- }
- }
- // -------------------------------------------------------------
- function postEncode($thing)
- {
- return base64_encode(serialize($thing));
- }
- // -------------------------------------------------------------
- function postDecode($thing)
- {
- return unserialize(base64_decode($thing));
- }
- // -------------------------------------------------------------
- function langs()
- {
- global $langs;
- $langs = array(
- 'ar-dz' => '?????? ????',
- 'bg-bg' => '?????????',
- 'ca-es' => 'Català',
- 'cs-cz' => '?etina',
- 'da-dk' => 'Dansk',
- 'de-de' => 'Deutsch',
- 'el-gr' => '????????',
- 'en-gb' => 'English (Great Britain)',
- 'en-us' => 'English (United States)',
- 'es-es' => 'Español',
- 'et-ee' => 'Eesti',
- 'fi-fi' => 'Suomi',
- 'fr-fr' => 'Français',
- 'gl-gz' => 'Galego',
- 'he-il' => '?????',
- 'hr-hr' => 'Hrvatski',
- 'hu-hu' => 'Magyar',
- 'id-id' => 'Bahasa Indonesia',
- 'is-is' => 'Íslenska',
- 'it-it' => 'Italiano',
- 'ja-jp' => '???',
- 'ko-kr' => '??? (????)',
- 'lv-lv' => 'Latvieu',
- 'nl-nl' => 'Nederlands',
- 'no-no' => 'Norsk',
- 'pl-pl' => 'Polski',
- 'pt-br' => 'Português (Brasil)',
- 'pt-pt' => 'Português (Portugal)',
- 'ro-ro' => 'Român?',
- 'ru-ru' => '???????',
- 'sk-sk' => 'Sloven?ina',
- 'sp-rs' => 'Srpski',
- 'sr-rs' => '??????',
- 'sv-se' => 'Svenska',
- 'th-th' => '???',
- 'tr-tr' => 'Türkçe',
- 'uk-ua' => '??????????',
- 'vi-vn' => 'Ti?ng Vi?t (Vi?t Nam)',
- 'zh-cn' => '??(??)',
- 'zh-tw' => '??(??)',
- );
- $default = 'en-gb';
- $out = n.'<select name="lang">';
- foreach ($langs as $a => $b)
- {
- $out .= n.t.'<option value="'.$a.'"'.
- ( ($a == $default) ? ' selected="selected"' : '').
- '>'.$b.'</option>';
- }
- $out .= n.'</select>';
- return $out;
- }
- // -------------------------------------------------------------
- function setup_load_lang($lang)
- {
- global $langs;
- require_once txpath.'/setup/setup-langs.php';
- $lang = (isset($langs[$lang]) && !empty($langs[$lang]))? $lang : 'en-gb';
- if (!defined('LANG'))
- define('LANG', $lang);
- return $langs[LANG];
- }
- ?>