// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . define('PATH', dirname(__FILE__) . '/'); define('JISKO_VERSION', '3.0'); require PATH.'includes/gettext.php'; require PATH.'includes/streams.php'; //Avoiding to show notices in the page. error_reporting(E_ALL ^ E_NOTICE); global $gettext_tables; $langExplode = explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']); $langExplode = explode(',', $langExplode[0]); $file = PATH.'includes/languages/'.$langExplode[1].'/LC_MESSAGES/messages.mo'; if (!file_exists($file)) { $file = PATH.'includes/languages/'.$langExplode[1].'/LC_MESSAGES/messages.mo'; if (file_exists($file)) { $gettext_tables = new gettext_reader( new CachedFileReader($file) ); $gettext_tables->load_tables(); } } else { $gettext_tables = new gettext_reader( new CachedFileReader($file) ); $gettext_tables->load_tables(); } function __($string) { global $gettext_tables; if (!$gettext_tables) return $string; else return $gettext_tables->translate($string); } function validUsername($username, $str = false) { global $jk; global $db; $username = trim($username); $forbidden = array('home', 'login', 'register', 'logout', 'notes', 'drop', 'forgot', 'avatar', 'invite', 'preferences', 'follow', 'favorites', 'public', 'profile', 'rss', 'followers', 'following', 'search', 'cron', 'download', 'post', 'ajax', 'mobile', 'report', 'group', 'groups', 'direct_messages', 'account', 'trouble_login', 'resend_mail', 'tos', 'faq', 'admin'); if (in_array($username, $forbidden)) return 'busy'; elseif ((strlen($username) > 20) || (!preg_match('/^[a-z_\-0-9]{3,15}$/i', $username))) return 'invalid'; else return 'valid'; } function checkSession() { if (isset($_SESSION['host']) && isset($_SESSION['port']) && isset($_SESSION['username']) && isset($_SESSION['password']) && $_SESSION['name'] && isset($_SESSION['type'])) return true; else return false; } function do_header($title) { echo ' '.__('Installing Jisko').'
Jisko

'.$title.'

'; } function do_footer() { echo '
'; } session_start(); $step = (isset($_GET['step']) ? (int)$_GET['step'] : 0); switch ($step) { case 4: if (checkSession()) { do_header(__('Thank you for using Jisko')); if ($_SESSION['type'] == 'new') { $fd = fopen('config.php', 'w+'); if ($fd) { fwrite($fd, ""); echo '
'.__('The file config.php was created without any problems').'
'; } else echo '
'.__('There was a problem while creating the config.php file, please rename config.sample.php to config.php, and then edit it with your database credentials').'
'; echo '
'.__('Congratulations! You have now installed Jisko in your host.').'

'.__('Now please remove the install.php file in order to test your Jisko installation').'

'.sprintf(__('Remember to visit %s to see the latest updates'), 'http://jisko.org').'
'; } else { echo '
'.sprintf(__('Congratulations! You have now updated to Jisko %s.'), JISKO_VERSION).'

'.__('Now please remove the install.php file in order to test your new version of Jisko').'

'.sprintf(__('Remember to visit %s to see the latest updates'), 'http://jisko.org').'
'; } do_footer(); } break; case 3: if ($_POST) { if (checkSession()) { $mysqlfd = mysql_connect($_SESSION['host'].':'.$_SESSION['port'], $_SESSION['username'], $_SESSION['password']); if ($mysqlfd) { $db = mysql_select_db($_SESSION['name']); if ($db) { if (empty($_POST['username']) && empty($_POST['password']) && empty($_POST['email'])) header('Location: install.php?step=3&error=empty'); else { $check = validUsername($_POST['username']); if ($check != 'valid') { if ($check == 'busy') header('Location: install.php?step=3&error=forbid'); elseif ($check == 'invalid') header('Location: install.php?step=3&error=user'); } else { $query = mysql_query('SELECT `ID` FROM `users` WHERE `username`=\''.mysql_real_escape_string($_POST['username']).'\''); if (mysql_num_rows($query)) { $id = mysql_insert_id(); $query = mysql_query('INSERT INTO `permissions` SET `userid`=\''.$id.'\', `can_panel`=\'1\''); if ($query) header('Location: install.php?step=4'); else header('Location: install.php?step=3&error=query'); } else { if (!mkdir(PATH."users_files/".$_POST['username'], 0777) || (!mkdir(PATH."users_files/".$_POST['username']."/img", 0777) || (!mkdir(PATH."users_files/".$_POST['username']."/img/avatar", 0777) || (!mkdir(PATH."users_files/".$_POST['username']."/img/background", 0777) || (!mkdir(PATH."users_files/".$_POST['username']."/files", 0777)))))) header('Location: install.php?step=3&error=dir'); else { $salt = substr(md5(rand()), 0, 5); $query = mysql_query("INSERT INTO `users` (`username`, `password`, `api`, `salt`, `language`, `theme`, `email`, `status`, `since`, `last_seen`, `ip`, `notification_level`) values ('".$_POST['username']."', '".md5(md5($_POST['password']).md5($salt))."', '".substr(md5($_POST['username'].rand()), 0, 16)."', '".$salt."', 'def', 'transparency', '".$_POST['email']."', 'ok', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), '".$_SERVER['REMOTE_ADDR']."', 4)"); $id = mysql_insert_id(); $query = mysql_query('INSERT INTO `permissions` SET `userid`=\''.$id.'\', `can_panel`=\'1\''); if ($query) header('Location: install.php?step=4'); else header('Location: install.php?step=3&error=query'); } } } } } else header('Location: install.php?step=3&error=db'); } else header('Location: install.php?step=3&error=mysql'); } else header('Location: install.php?step=1'); } else { if (checkSession()) { if ($_SESSION['type'] == 'new') do_header(__('Installing Jisko (step 3/3)')); else do_header(__('Updating Jisko (step 3/3)')); $error = (isset($_GET['error']) ? $_GET['error'] : ''); switch ($error) { case 'mysql': $error = "Couldn't connect to the mysql database"; break; case 'db': $error = "Couldn't select the database"; break; case 'query': $error = 'There was a problem while trying to execute a query'; break; case 'forbid': $error = "The username you entered cannot be used"; break; case 'user': $error = 'Username not valid. It has to be less than 20 characters'; break; case 'empty': $error = 'There are empty fields. Fill them and try again'; break; case 'dir': $error = "Couldn't create the upload folders for the admin user"; } if ($error) echo '
'.__($error).'
'; echo '
  • '.__('Username').'
    '.__('Username of the admin user. Less than 20 characters').'
  • '.__('Password').'
    '.__('Password of the admin user').'
  • '.__('Email').'
    '.__('Email of the admin user').'


'; do_footer(); } else header('Location: install.php?step=1'); } break; case 2: if ($_POST) { if (checkSession()) { $mysqlfd = mysql_connect($_SESSION['host'].':'.$_SESSION['port'], $_SESSION['username'], $_SESSION['password']); if ($mysqlfd) { $db = mysql_select_db($_SESSION['name']); if ($db) { if (get_magic_quotes_gpc()) { $_POST['base_url'] = stripslashes($_POST['base_url']); $_POST['name'] = stripslashes($_POST['name']); $_POST['admin_mail'] = stripslashes($_POST['admin_mail']); $_POST['abuse_mail'] = $_POST['admin_mail']; } $queries = array( 'base_url' => mysql_real_escape_string($_POST['base_url']), 'name' => mysql_real_escape_string($_POST['name']), 'admin_mail' => mysql_real_escape_string($_POST['admin_mail']), 'abuse_mail' => mysql_real_escape_string($_POST['admin_mail']) ); foreach ($queries as $cat=>$val) { $query = mysql_query('UPDATE `settings` SET `value`=\''.$val.'\' WHERE `category`=\''.$cat.'\''); if (!$query) header('Location: install.php?step=2&error=query'); } header('Location: install.php?step=3'); } else header('Location: install.php?step=2&error=db'); } else header('Location: install.php?step=2&error=mysql'); } else header('Location: install.php?step=1'); } else { if (checkSession()) { if ($_SESSION['type'] == 'new') do_header(__('Installing Jisko (step 2/3)')); else do_header(__('Updating Jisko (step 2/3)')); $error = (isset($_GET['error']) ? $_GET['error'] : ''); switch ($error) { case 'mysql': $error = "Couldn't connect to the mysql database"; break; case 'db': $error = "Couldn't select the database"; break; case 'query': $error = 'There was a problem while trying to execute a query'; } if ($error) echo '
'.__($error).'
'; echo '
  • '.__('Base URL').'
    '.__('The URL where Jisko is located. Without http://').'
  • '.__('Name').'
    '.__('Name of your Jisko installation').'
  • '.__('Admin mail').'
    '.__('Used for the contact page...').'


'; do_footer(); } else header('Location: install.php?step=1'); } break; case 0: if ($_POST) { $val = array('new', '2.0', '3.0beta1', '3.0beta2'); if (in_array($_POST['opt'], $val)) { $_SESSION['type'] = $_POST['opt']; header('Location: install.php?step=1'); } else header('Location: install.php?step=0'); } else { do_header('Updating/Installing Jisko'); echo '

'.__('If you have a previous version of Jisko installed on your server, then you may upgrade your existing installation. Otherwise you can do a clean installation.').'

  • '.__('Install Jisko').'
    '.__('It will do a new installation of Jisko in your server').'
  • '.__('Upgrade from Jisko 2.0').'
    '.__('It will update your database to the new version').'
  • '.__('Upgrade from Jisko 3.0beta1').'
    '.__('It will update your database to the new version').'
  • '.__('Upgrade from Jisko 3.0beta2').'
    '.__('It will update your database to the new version').'


'; do_footer(); } break; case 1: if ($_POST) { $mysqlfd = mysql_connect($_POST['host'].':'.(int)$_POST['port'], $_POST['username'], $_POST['password']); if ($mysqlfd) { $_SESSION['host'] = $_POST['host']; $_SESSION['port'] = (int) $_POST['port']; $_SESSION['username'] = $_POST['username']; $_SESSION['password'] = $_POST['password']; $_SESSION['name'] = $_POST['name']; mysql_close($mysqlfd); if ($_SESSION['type'] == '3.0beta2') { require dirname(__FILE__).'/sql/upgrade3.0beta2.php'; $upd = new Upgrade30beta2($_POST['host'], $_POST['port'], $_POST['username'], $_POST['password'], $_POST['name']); if ($upd == 'mysql') header('Location: install.php?step=1&error=mysql'); else { $status = $upd->upgrade(); if ($status == 'query') header('Location: install.php?step=1&error=query'); else header('Location: install.php?step=4'); } } if ($_SESSION['type'] == '3.0beta1') { require dirname(__FILE__).'/sql/upgrade3.0beta1.php'; $upd = new Upgrade30beta1($_POST['host'], $_POST['port'], $_POST['username'], $_POST['password'], $_POST['name']); if ($upd == 'mysql') header('Location: install.php?step=1&error=mysql'); else { $status = $upd->upgrade(); if ($status == 'query') header('Location: install.php?step=1&error=query'); else header('Location: install.php?step=4'); } } elseif ($_SESSION['type'] == '2.0') { require dirname(__FILE__).'/sql/upgrade2.0.php'; $upd = new Upgrade20($_POST['host'], $_POST['port'], $_POST['username'], $_POST['password'], $_POST['name']); if ($upd == 'mysql') header('Location: install.php?step=1&error=mysql'); else { $status = $upd->upgrade(); if ($status == 'query') header('Location: install.php?step=1&error=query'); else header('Location: install.php?step=3'); } } elseif ($_SESSION['type'] == 'new') { require dirname(__FILE__).'/sql/install.php'; $upd = new Install($_POST['host'], $_POST['port'], $_POST['username'], $_POST['password'], $_POST['name']); if ($upd == 'mysql') header('Location: install.php?step=1&error=mysql'); else { $status = $upd->upgrade(); if ($status == 'query') header('Location: install.php?step=1&error=query'); else header('Location: install.php?step=2'); } } } else header('Location: install.php?step=1&error=mysql'); } else { if ($_SESSION['type'] == 'new') do_header(__('Installing Jisko (step 1/3)')); else do_header(__('Updating Jisko (step 1/3)')); $error = (isset($_GET['error']) ? $_GET['error'] : ''); switch ($error) { case 'mysql': $error = "Couldn't connect to the mysql database"; break; case 'db': $error = "Couldn't select the database"; break; case 'query': $error = 'There was a problem while trying to execute a query'; } if ($error) echo '
'.__($error).'
'; echo '
  • '.__('Database host').'
    '.__('The host where the mysql server is').'
  • '.__('Database port').'
    '.__('The port of the mysql server').'
  • '.__('Database username').'
    '.__('The username to access the mysql server').'
  • '.__('Database password').'
    '.__('The password of the username').'
  • '.__('Database name').'
    '.__('The name of the database where you want to install Jisko').'


'; do_footer(); } break; } ?>