<?php 
 
// ----------------------------------------------------------------------
 
// Usermanage - Web authentication suite.
 
// Copyright (C) 2002-2003 The CGI Open Source Federation.
 
// http://cosf.sf.net
 
// ----------------------------------------------------------------------
 
// LICENSE
 
// This program is free software; you can redistribute it and/or
 
// modify it under the terms of the GNU General Public License (GPL)
 
// as published by the Free Software Foundation; either version 2
 
// 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 General Public License for more details.
 
// You should have recieved the lincence included with the disribution.
 
// If not visit http://www.gnu.org/copyleft/gpl.html
 
// ----------------------------------------------------------------------
 
// You do not need to modify this file.
 
// ----------------------------------------------------------------------
 
// Include the header.inc.php and LEMP
 
if (file_exists('LEMP/lemp.php')) {
 
    require ('LEMP/lemp.php');
 
} elseif (file_exists('../LEMP/lemp.php')) {
 
    require ('../LEMP/lemp.php');
 
} 
 
// Create LEMP object
 
$lemp = &create_obj('LEMP');
 
// --------
 
// Initiate variables
 
// --------
 
$edit_tables = array ();
 
$table_inserts = array ();
 
 
$self = basename (__FILE__); // Find file name (usually either index.php or setup.php)
 
$path = dirname (__FILE__); // Find the current directory
 
 
$setup_dir = (is_dir ('setup'))? './setup': '.'; // Find/Set the setup folder
 
$action = (empty ($_REQUEST['action']))? 'menu' : $_REQUEST['action']; // Retrieve current action from input
 
$screen = (empty ($_REQUEST['screen']))? 'main_menu' : $_REQUEST['screen']; // Retrieve current screen from input
 
$url = (empty ($_REQUEST['url']))? '' : $_REQUEST['url']; // Retrieve current screen from input
 
// Load table schema into memory
 
$tables = get_config('tables');
 
// --------
 
// Load headers + extensions
 
// --------
 
// Begin UserManage header extension
 
$menus['main_menu'][0]['name'] = 'Install';
 
$menus['main_menu'][0]['screen'] = 'usermanage';
 
$menus['main_menu'][0]['action'] = 'create';
 
 
$menus['main_menu'][1]['name'] = 'Uninstall';
 
$menus['main_menu'][1]['screen'] = 'usermanage';
 
$menus['main_menu'][1]['action'] = 'drop';
 
$menus['main_menu'][1]['confirm'] = true;
 
 
$menus['main_menu'][2]['name'] = 'Run UserManage!';
 
$menus['main_menu'][2]['url'] = ($setup_dir == './setup')? '../index.php' : 'index.php';
 
// End UserManage header extension
 
// Include optional extensions
 
if (file_exists("$setup_dir/header.inc.php")) {
 
    include ("$setup_dir/header.inc.php");
 
} 
 
if (file_exists("$setup_dir/setup_config.php")) {
 
    include ("$setup_dir/setup_config.php");
 
} 
 
// Initiate variables from input or from an extension
 
$menu = (!empty($_REQUEST['menu']))? $_REQUEST['menu'] : (!empty ($screens[$screen]['menu']))? $screens[$screen]['menu'] : 'on'; // Determine if the menu should be displayed
 
$next_screen = (!empty($_REQUEST['next_screen']))? $_REQUEST['next_screen'] : (!empty ($screens["$screen:$action"]['next_screen']))? $screens["$screen:$action"]['next_screen'] : ''; // Determine the following screen (Used only in "continue" links)
 
 
// Display header
 
if (!empty ($url)) {
 
    header ("Location: $url");
 
    exit ();
 
} elseif (isset($header)) {
 
    echo $header;
 
} else {
 
 
    ?>
 
<html>
 
 
<head>
 
<title>Installation</title>
 
<script type = "text/javascript">
 
function confirm_action (action) {
 
    return confirm("Are you sure you wish to '" + action + "'?");
 
}
 
function confirm_link (action, link) {
 
    if (confirm("Are you sure you wish to '" + action + "'?")) {
 
        window.location.href = link;
 
    }
 
}
 
</script>
 
</head>
 
 
<body>
 
<?php
 
} 
 
// --------
 
// Load current screen
 
// --------
 
// Include the screen
 
// Begin Usermanage Screen
 
if ($screen == 'usermanage') {
 
    switch ($action) {
 
        case 'create':
 
            $table = $tables['auth_user_info'];
 
            $edit_tables[] = <<<EOL
 
CREATE TABLE IF NOT EXISTS `{$table['_name']}` (
 
    `{$table['uid']}` INT( 11 ) NOT NULL ,
 
    `{$table['uname']}` VARCHAR( 128 ) NOT NULL ,
 
    `{$table['pass']}` VARCHAR( 128 ) NOT NULL ,
 
    `{$table['sid']}` VARCHAR( 128 ) NOT NULL ,
 
    UNIQUE (`{$table['uid']}`)
 
);
 
EOL;
 
            break;
 
        case 'drop':
 
            $edit_tables[] = "DROP TABLE IF EXISTS `{$tables['auth_user_info']['_name']}`;";
 
            break;
 
    } 
 
} else { // End Usermanage Screen
 
    if (file_exists("$setup_dir/$screen.inc.php")) {
 
        include ("$setup_dir/$screen.inc.php");
 
    } 
 
} 
 
// --------
 
// Load any screen extensions
 
// --------
 
if (is_array ($screens["$screen:$action"]['extensions']) || is_array ($screens[$screen]['extensions'])) {
 
    $extensions = array ();
 
    if (is_array ($screens["$screen:$action"]['extensions'])) {
 
        $extensions = $screens["$screen:$action"]['extensions'];
 
    } 
 
    if (is_array ($screens[$screen]['extensions'])) {
 
        $extensions = array_merge ($extensions, $screens[$screen]['extensions']);
 
    } 
 
    foreach ($extensions as $extension) {
 
        if (is_file("$setup_dir/$extension")) {
 
            include ("$setup_dir/$extension");
 
        } 
 
    } 
 
} 
 
// --------
 
// Execute and display any SQL quries that have been produced by the screen
 
// --------
 
if (!empty($edit_tables) || !empty($table_inserts)) {
 
    echo "Executed: <p><textarea rows='20' cols='85' wrap='off' id=''>";
 
    if (!empty ($edit_tables)) {
 
        foreach ($edit_tables as $edit_table) {
 
            $result = $lemp->dbquery ($edit_table);
 
            echo $edit_table . "\n\n";
 
        } 
 
    } 
 
 
    if (!empty ($table_inserts)) {
 
        foreach ($table_inserts as $table_insert) {
 
            $result = $lemp->dbquery ($table_insert);
 
            echo $table_insert . "\n\n";
 
        } 
 
    } 
 
    echo "</textarea></pre></p>\n";
 
} 
 
// --------
 
// Create the menu which will be displayed at the bottom of the screen
 
// --------
 
if (isset ($menus[$screen]) || isset ($menus['all'])) {
 
    $menus_screen = (isset ($menus['all']) && isset ($menus[$screen]))? array_merge($menus[$screen], $menus['all']) : (isset ($menus['all']))? $menus['all'] : $menus[$screen];
 
    foreach ($menus_screen as $key => $menu_item_arr) {
 
        $menu_item_params = array();
 
        if (!empty ($menu_item_arr['screen'])) {
 
            $menu_item_params[] = "screen={$menu_item_arr['screen']}";
 
        } 
 
        if (!empty ($menu_item_arr['action'])) {
 
            $menu_item_params[] = "action={$menu_item_arr['action']}";
 
        } 
 
        if (!empty ($menu_item_arr['url'])) {
 
            $menu_item_params[] = "url={$menu_item_arr['url']}";
 
        } 
 
        $menu_item_param = implode('&', $menu_item_params);
 
        if ($menu_item_arr['confirm'] == true) {
 
            $menu_arr[] = "<a href=\"javascript:confirm_link ('{$menu_item_arr['name']}', '$self?$menu_item_param')\">{$menu_item_arr['name']}</a>";
 
        } else {
 
            $menu_arr[] = "<a href='$self?$menu_item_param'>{$menu_item_arr['name']}</a>";
 
        } 
 
    } 
 
} 
 
// Create back link
 
if ($screen != 'main_menu' && $menu != 'off') {
 
    $menu_arr[] = "<a href='{$_SERVER['HTTP_REFERER']}'>Back</a>";
 
} 
 
// Create either "continue" or "finish" links
 
if (isset ($finishes) && in_array ("$screen:$action", $finishes)) {
 
    $menu_arr[] = "<a href=\"$self\">Finish and return to main menu</a>";
 
} elseif ($next_screen != '') {
 
    $menu_item = "<a href=\"$self?screen=$next_screen";
 
    if ($next_action != '') {
 
        $menu_item .= "&action=$next_action";
 
    } 
 
    $menu_arr[] = "$menu_item\">Continue...</a>";
 
} 
 
// Display the menu.
 
echo '<p>[ ' . implode(' | ', $menu_arr) . ' ]</p>';
 
// --------
 
// Display footer
 
// --------
 
if (file_exists("$setup_dir/footer.inc.php")) {
 
    include ("$setup_dir/footer.inc.php");
 
} elseif (!empty($footer)) {
 
    echo $footer;
 
} else {
 
    $messages = error_get_all ();
 
    if ($messages != 'NONE') {
 
        echo "\n      <p>\n        Messages: $messages\n      </p>\n";
 
    } 
 
    echo "\n    </body>\n<html>";
 
} 
 
 
?>
 
 |