#!/usr/bin/perl

# ispCP ω (OMEGA) a Virtual Hosting Control Panel
# Copyright (C) 2006-2010 by isp Control Panel - http://ispcp.net
#
# Version: $Id: reset-setup 2505 2010-01-06 20:30:53Z nuxwin $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is "ispCP ω (OMEGA) a Virtual Hosting Control Panel".
#
# The Initial Developer of the Original Code is ispCP Team.
# Portions created by Initial Developer are Copyright (C) 2006-2010 by
# isp Control Panel. All Rights Reserved.
#
# The ispCP ω Home Page is:
#
#    http://isp-control.net
#
########################################################################
#
# This Script only resets the ispCP Setup, it WON'T uninstall ispCP!!
# Afterwards a new install is possible. Use it, if you had an installation
# error during setup.
#
# Keep attention: The ispCP database will be deleted with all its content!
#
########################################################################

use FindBin;
use lib "$FindBin::Bin/..";
require 'ispcp_common_code.pl';
use strict;
use warnings;

## Variables
my ($rs, $sql, $rdata, $delete_cmd ) = (undef, undef, undef,undef );
my $user_prefix = $main::cfg{'APACHE_SUEXEC_USER_PREF'};
my $master_user = $main::cfg{'APACHE_SUEXEC_MIN_UID'};
my $user_delete	= $main::cfg{'CMD_USERDEL'};
my $database	= $main::cfg{'DATABASE_NAME'};

## MAIN
print STDOUT "Re-setting ISPCP Setup!\n";
print STDOUT "========================\n";

if ($main::cfg{'ROOT_GROUP'} eq "wheel") {
	$delete_cmd = "rmuser -y $user_prefix$master_user";
	$rs = sys_command($delete_cmd);
} else {
	$delete_cmd = "$user_delete -r $user_prefix$master_user";
	$rs = sys_command($delete_cmd);
	my $delete_fcgi = "$main::cfg{'CMD_RM'} -r $main::cfg{'PHP_STARTER_DIR'}/master";
	$rs = sys_command($delete_fcgi);
}

$sql = "DROP DATABASE IF EXISTS $database";
($rs, $rdata) = doSQL($sql);

if ($rs != 0) {
	print STDOUT "An error occured!\n";
	print STDOUT "$rdata\n";
} else {
	print STDOUT "done!\n";
}
