2000-11-30 22:25:14 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare - Setup *
|
|
|
|
* http://www.phpgroupware.org *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
// Include to check user authorization against the
|
|
|
|
// password in ../header.inc.php to protect all of the setup
|
|
|
|
// pages from unauthorized use.
|
|
|
|
|
|
|
|
if(file_exists("../version.inc.php") || is_file("../version.inc.php")) {
|
|
|
|
include("../version.inc.php"); // To set the current core version
|
|
|
|
}else{
|
2000-12-21 21:43:26 +01:00
|
|
|
$phpgw_info["server"]["versions"]["phpgwapi"] = "Undetected";
|
2000-11-30 22:25:14 +01:00
|
|
|
}
|
|
|
|
|
2000-12-19 23:40:54 +01:00
|
|
|
$phpgw_info["server"]["app_images"] = "templates/default/images";
|
|
|
|
|
2000-12-04 09:45:30 +01:00
|
|
|
function show_header($title = "",$nologoutbutton = False)
|
|
|
|
{
|
2000-11-30 22:25:14 +01:00
|
|
|
global $phpgw_info, $PHP_SELF;
|
2000-12-04 09:45:30 +01:00
|
|
|
echo '
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>phpGroupWare Setup';
|
|
|
|
if ($title != ""){echo " - ".$title;}
|
|
|
|
echo'</title>
|
|
|
|
<style type="text/css"><!-- .link { color: #FFFFFF; } --></style>
|
|
|
|
</head>
|
|
|
|
<BODY BGCOLOR="FFFFFF" margintop="0" marginleft="0" marginright="0" marginbottom="0">
|
|
|
|
<table border="0" width="100%" cellspacing="0" cellpadding="2">
|
|
|
|
<tr>
|
2000-12-21 21:43:26 +01:00
|
|
|
<td align="left" bgcolor="486591"> <font color="fefefe">phpGroupWare version '.$phpgw_info["server"]["versions"]["phpgwapi"].' setup</font>
|
2000-11-30 22:25:14 +01:00
|
|
|
</td>
|
2000-12-04 09:45:30 +01:00
|
|
|
<td align="right" bgcolor="486591">';
|
|
|
|
if ($nologoutbutton) {
|
|
|
|
echo " ";
|
|
|
|
} else {
|
|
|
|
echo '<a href="' . $PHP_SELF . '?FormLogout=True" class="link">Logout</a> ';
|
|
|
|
}
|
|
|
|
echo "</td></tr></table>";
|
2000-11-30 22:25:14 +01:00
|
|
|
}
|
2000-12-04 09:45:30 +01:00
|
|
|
function loginForm($err="")
|
|
|
|
{
|
2000-11-30 22:25:14 +01:00
|
|
|
global $phpgw_info, $phpgw_domain, $SetupDomain, $SetupPW, $PHP_SELF;
|
|
|
|
echo "<p><body bgcolor='#ffffff'>\n";
|
|
|
|
echo "<table border=\"0\" align=\"center\">\n";
|
|
|
|
echo " <tr bgcolor=\"486591\">\n";
|
|
|
|
echo " <td colspan=\"2\"><font color=\"fefefe\"> <b>Setup Login</b></font></td>\n";
|
|
|
|
echo " </tr>\n";
|
|
|
|
if ($err != "") {
|
|
|
|
echo " <tr bgcolor='#e6e6e6'><td colspan='2'><font color='#ff0000'>".$err."</font></td></tr>\n";
|
|
|
|
}
|
|
|
|
echo " <tr bgcolor=\"e6e6e6\">\n";
|
|
|
|
echo " <td><form action='".$PHP_SELF."' method='POST'>\n";
|
|
|
|
if (count($phpgw_domain) > 1){
|
|
|
|
echo " <table><tr><td>Domain: </td><td><input type='text' name='FormDomain' value=''></td></tr>\n";
|
|
|
|
echo " <tr><td>Password: </td><td><input type='password' name='FormPW' value=''></td></tr></table>\n";
|
|
|
|
}else{
|
2000-12-01 23:05:01 +01:00
|
|
|
reset($phpgw_domain);
|
|
|
|
$default_domain = each($phpgw_domain);
|
2000-11-30 22:25:14 +01:00
|
|
|
echo " <input type='password' name='FormPW' value=''>\n";
|
2000-12-01 23:05:01 +01:00
|
|
|
echo " <input type='hidden' name='FormDomain' value='".$default_domain[0]."'>\n";
|
2000-11-30 22:25:14 +01:00
|
|
|
}
|
|
|
|
echo " <input type='submit' name='Login' value='Login'>\n";
|
|
|
|
echo " </form></td>\n";
|
|
|
|
echo " </tr>\n";
|
|
|
|
echo "</table>\n";
|
|
|
|
echo "</body></html>\n";
|
|
|
|
}
|
2000-12-04 09:45:30 +01:00
|
|
|
|
|
|
|
function check_header()
|
|
|
|
{
|
|
|
|
global $phpgw_domain, $phpgw_info, $stage, $header_msg;
|
|
|
|
if(!file_exists("../header.inc.php") || !is_file("../header.inc.php")) {
|
|
|
|
$stage = 1.1;
|
|
|
|
$header_msg = "Stage One";
|
|
|
|
}else{
|
|
|
|
include("../header.inc.php");
|
2000-12-21 21:43:26 +01:00
|
|
|
if (!isset($phpgw_domain) || $phpgw_info["server"]["versions"]["header"] != $phpgw_info["server"]["versions"]["current_header"]) {
|
2000-12-04 09:45:30 +01:00
|
|
|
$stage = 1.2;
|
|
|
|
$header_msg = "Stage One (Upgrade your header.inc.php)";
|
|
|
|
}else{ /* header.inc.php part settled. Moving to authentication */
|
|
|
|
$stage = 1.3;
|
|
|
|
$header_msg = "Stage One (Completed)";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function generate_header(){
|
|
|
|
Global $SCRIPT_FILENAME, $HTTP_POST_VARS, $k, $v;
|
|
|
|
$ftemplate = fopen(dirname($SCRIPT_FILENAME)."/../header.inc.php.template","r");
|
|
|
|
if($ftemplate){
|
|
|
|
$ftemplate = fopen(dirname($SCRIPT_FILENAME)."/../header.inc.php.template","r");
|
|
|
|
$template = fread($ftemplate,filesize(dirname($SCRIPT_FILENAME)."/../header.inc.php.template"));
|
|
|
|
fclose($ftemplate);
|
|
|
|
while(list($k,$v) = each($HTTP_POST_VARS)) {
|
|
|
|
$template = ereg_replace("__".strtoupper($k)."__",$v,$template);
|
|
|
|
}
|
|
|
|
return $template;
|
|
|
|
}else{
|
|
|
|
echo "Could not open the header template for reading!<br>";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function auth()
|
|
|
|
{
|
2000-11-30 22:25:14 +01:00
|
|
|
global $phpgw_domain, $FormLogout, $FormDomain, $FormPW, $SetupPW, $SetupDomain, $db, $HTTP_POST_VARS, $login_msg;
|
|
|
|
if (isset($FormLogout)) {
|
|
|
|
setcookie("SetupPW"); // scrub the old one
|
|
|
|
setcookie("SetupDomain"); // scrub the old one
|
|
|
|
$login_msg = "You have sucessfully logged out";
|
|
|
|
return False;
|
|
|
|
} elseif (isset($SetupPW)) {
|
|
|
|
if ($SetupPW != $phpgw_domain[$SetupDomain]["config_passwd"]) {
|
|
|
|
setcookie("SetupPW"); // scrub the old one
|
|
|
|
setcookie("SetupDomain"); // scrub the old one
|
|
|
|
$login_msg = "Invalid session cookie (cookies must be enabled)";
|
|
|
|
return False;
|
|
|
|
}else{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
} elseif (isset($FormPW)) {
|
|
|
|
if ($FormPW == $phpgw_domain[$FormDomain]["config_passwd"]) {
|
|
|
|
setcookie("SetupPW",$FormPW);
|
|
|
|
setcookie("SetupDomain",$FormDomain);
|
|
|
|
$SetupDomain = $FormDomain;
|
|
|
|
return True;
|
|
|
|
}else{
|
|
|
|
$login_msg = "Invalid password";
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-04 09:45:30 +01:00
|
|
|
function loaddb()
|
|
|
|
{
|
2000-11-30 22:25:14 +01:00
|
|
|
global $phpgw_info, $phpgw_domain, $SetupDomain, $db;
|
|
|
|
/* Database setup */
|
2000-12-21 10:16:30 +01:00
|
|
|
if (!isset($phpgw_info["server"]["api_inc"])) {
|
|
|
|
$phpgw_info["server"]["api_inc"] = $phpgw_info["server"]["server_root"]."/phpgwapi/inc";
|
2000-12-18 21:41:26 +01:00
|
|
|
}
|
2000-12-21 10:16:30 +01:00
|
|
|
include($phpgw_info["server"]["api_inc"] . "/phpgw_db_".$phpgw_domain[$SetupDomain]["db_type"].".inc.php");
|
2000-11-30 22:25:14 +01:00
|
|
|
$db = new db;
|
|
|
|
$db->Host = $phpgw_domain[$SetupDomain]["db_host"];
|
|
|
|
$db->Type = $phpgw_domain[$SetupDomain]["db_type"];
|
|
|
|
$db->Database = $phpgw_domain[$SetupDomain]["db_name"];
|
|
|
|
$db->User = $phpgw_domain[$SetupDomain]["db_user"];
|
|
|
|
$db->Password = $phpgw_domain[$SetupDomain]["db_pass"];
|
|
|
|
}
|
|
|
|
|
2000-12-04 09:45:30 +01:00
|
|
|
function check_db()
|
|
|
|
{
|
|
|
|
global $phpgw_info, $oldversion, $db, $stage, $header_msg;
|
|
|
|
$db->Halt_On_Error = "no";
|
|
|
|
$tables = $db->table_names();
|
|
|
|
if (is_array($tables) && count($tables) > 0){
|
|
|
|
/* tables exists. checking for post beta version */
|
|
|
|
$db->query("select app_version from applications where app_name='admin'");
|
|
|
|
$db->next_record();
|
|
|
|
$oldversion = $db->f("app_version");
|
|
|
|
if (isset($oldversion)){
|
2000-12-21 21:43:26 +01:00
|
|
|
if ($oldversion == $phpgw_info["server"]["versions"]["phpgwapi"]){
|
2000-12-04 09:45:30 +01:00
|
|
|
$db->query("select config_value from config where config_name='freshinstall'");
|
|
|
|
$db->next_record();
|
|
|
|
$configed = $db->f("config_value");
|
|
|
|
if ($configed){
|
|
|
|
$stage = 3.1;
|
|
|
|
$header_msg = "Stage 3 (Needs Configuration)";
|
|
|
|
}else{
|
|
|
|
$stage = 3.2;
|
|
|
|
$header_msg = "Stage 3 (Configuration OK)";
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$stage = 2.4;
|
|
|
|
$header_msg = "Stage 2 (Tables need upgrading)";
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$stage = 2.2;
|
|
|
|
$header_msg = "Stage 2 (Tables appear to be pre-beta)";
|
2000-11-30 23:29:06 +01:00
|
|
|
}
|
2000-12-04 09:45:30 +01:00
|
|
|
}else{
|
|
|
|
/* no tables, so checking if we can create them */
|
2000-12-01 21:11:30 +01:00
|
|
|
|
2000-12-04 09:45:30 +01:00
|
|
|
/* I cannot get either to work properly
|
|
|
|
$isdb = $db->connect("kljkjh", "localhost", "phpgroupware", "phpgr0upwar3");
|
|
|
|
*/
|
|
|
|
|
|
|
|
$db_rights = $db->query("CREATE TABLE phpgw_testrights ( testfield varchar(5) NOT NULL )");
|
2000-11-30 22:25:14 +01:00
|
|
|
|
2000-12-04 09:45:30 +01:00
|
|
|
if (isset($db_rights)){
|
|
|
|
//if (isset($isdb)){
|
|
|
|
$stage = 2.3;
|
|
|
|
$header_msg = "Stage 2 (Create tables)";
|
|
|
|
}else{
|
|
|
|
$stage = 2.1;
|
|
|
|
$header_msg = "Stage 2 (Create Database)";
|
2000-11-30 22:25:14 +01:00
|
|
|
}
|
2000-12-04 09:45:30 +01:00
|
|
|
$db->query("DROP TABLE phpgw_testrights");
|
2000-11-30 22:25:14 +01:00
|
|
|
}
|
|
|
|
}
|
2000-12-10 00:08:36 +01:00
|
|
|
|
2000-12-19 23:40:54 +01:00
|
|
|
function app_setups($appname = ""){
|
|
|
|
global $phpgw_info;
|
|
|
|
$d = dir($phpgw_info["server"]["server_root"]);
|
|
|
|
while($entry=$d->read()) {
|
|
|
|
if (is_dir ($phpgw_info["server"]["server_root"]."/".$entry."/setup")){
|
|
|
|
echo $entry."<br>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$d->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
function execute_script($script, $appname = ""){
|
|
|
|
global $phpgw_info, $currentver, $oldversion, $phpgw_domain, $db;
|
|
|
|
if ($appname == ""){
|
|
|
|
$d = dir($phpgw_info["server"]["server_root"]);
|
|
|
|
while($entry=$d->read()) {
|
|
|
|
$f = $phpgw_info["server"]["server_root"]."/".$entry."/setup/".$script.".inc.php";
|
|
|
|
if (file_exists ($f)){include($f);}
|
|
|
|
}
|
|
|
|
$d->close();
|
|
|
|
}else{
|
|
|
|
$f = $phpgw_info["server"]["server_root"]."/".$appname."/setup/".$script.".inc.php";
|
|
|
|
if (file_exists ($f)){include($f);}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_app_version($appname, $tableschanged = True){
|
|
|
|
global $currentver, $phpgw_info, $db, $tablechanges;
|
|
|
|
if ($tableschanged == True){$tablechanges = True;}
|
|
|
|
$db->query("update applications set app_version='".$currentver."' where app_name='".$appname."'");
|
|
|
|
}
|
|
|
|
|
|
|
|
function manage_tables(){
|
|
|
|
global $currentver, $tablechanges, $phpgw_domain, $phpgw_info, $db;
|
|
|
|
if ($currentver == "drop"){
|
|
|
|
execute_script("droptables");
|
|
|
|
}
|
|
|
|
if ($currentver == "new") {
|
|
|
|
execute_script("newtables");
|
|
|
|
execute_script("common_default_records");
|
|
|
|
execute_script("lang");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($currentver == "oldversion") {
|
|
|
|
$currentver = $oldversion;
|
|
|
|
execute_script("upgradetables");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not yet implemented
|
|
|
|
if (!$tablechanges == True){
|
|
|
|
echo " <tr bgcolor=\"e6e6e6\">\n";
|
|
|
|
echo " <td>No table changes were needed. The script only updated your version setting.</td>\n";
|
|
|
|
echo " </tr>\n";
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2000-12-10 00:08:36 +01:00
|
|
|
function setup_header($title = "",$nologoutbutton = False) {
|
|
|
|
global $phpgw_info, $PHP_SELF, $dontshowtheheaderagain;
|
|
|
|
|
|
|
|
// Ok, so it isn't the greatest idea, but it works for now. Setup needs to be rewritten.
|
|
|
|
if ($dontshowtheheaderagain) {
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
$dontshowtheheaderagain = True;
|
|
|
|
?>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<title>phpGroupWare setup <?php echo $title; ?></title>
|
|
|
|
<style type="text/css">
|
|
|
|
<!--
|
|
|
|
.link
|
|
|
|
{
|
|
|
|
color: #FFFFFF;
|
|
|
|
}
|
|
|
|
-->
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<BODY BGCOLOR="FFFFFF" margintop="0" marginleft="0" marginright="0" marginbottom="0">
|
|
|
|
<table border="0" width="100%" cellspacing="0" cellpadding="2">
|
|
|
|
<tr>
|
|
|
|
<td align="left" bgcolor="486591"> <font color="fefefe">phpGroupWare version <?php
|
2000-12-21 21:43:26 +01:00
|
|
|
echo $phpgw_info["server"]["versions"]["phpgwapi"]; ?> setup</font>
|
2000-12-10 00:08:36 +01:00
|
|
|
</td>
|
|
|
|
<td align="right" bgcolor="486591">
|
|
|
|
<?php
|
|
|
|
if ($nologoutbutton) {
|
|
|
|
echo " ";
|
|
|
|
} else {
|
|
|
|
echo '<a href="' . $PHP_SELF . '?FormLogout=True" class="link">Logout</a> ';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "</td></tr></table>";
|
|
|
|
}
|
|
|
|
|
2000-12-20 01:02:11 +01:00
|
|
|
include("./inc/phpgw_schema_proc.inc.php");
|
|
|
|
// $phpgw_schema_proc = new phpgw_schema_proc($phpgw_domain[$SetupDomain]["db_type"]);
|
|
|
|
$phpgw_schema_proc = new phpgw_schema_proc("mysql");
|
2000-12-10 00:08:36 +01:00
|
|
|
|
2000-11-30 22:25:14 +01:00
|
|
|
?>
|