<?
/*
PhpMyPrepaid is developped under GPL Licence 2.0 :
http://www.gnu.org/licenses/gpl.txt or read LICENSE file.
Developed by : Toni de la Fuente (blyx) from Madrid and Alfacar (Granada), Spain
For information : hide@address.com http://blyx.com
We are using Oreon for base code: http://www.oreon-project.org
We are using Dialup Admin for user management
and many more things: http://www.freeradius.org
We are using PHPKI for Certificates management: http://phpki.sourceforge.org/
Thanks very much!!
*/
// configuration
include_once ("../class/Session.class.php");
Session::start();
$DEBUG = 0;
function Connexion ($pName, $pPassword, $pServer)
{
$connexion = @mysql_pconnect($pServer, $pName, $pPassword) or die("<center><span class='stop'>Error : ".mysql_error() . "</span></center><br><br>");
return $connexion;
}
function aff_header($str, $str2, $nb){
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title><? print $str; ?></title>
<link rel="shortcut icon" href="../images/favicon.ico">
<link rel="stylesheet" href="../style/install.css" type="text/css">
<SCRIPT language='javascript' src='../include/javascript/functions.js'></SCRIPT>
<SCRIPT language='javascript'>
function LicenceAccepted(){
var theForm = document.forms[0];
var nextButton = document.getElementById("button_next");
if( theForm.setup_license_accept.checked ){
nextButton.disabled = '';
nextButton.focus();
}
else {
nextButton.disabled = "disabled";
}
}
</SCRIPT>
</head>
<body rightmargin="O" topmargin="0" leftmargin="0">
<table cellspacing="0" cellpadding="0" border="0" align="center" class="shell">
<tr>
<th width="400"><? print $nb . ". " . $str2; ?></th>
<th width="100" height="30" style="text-align: right;"><img src="../images/banner.png"></th>
</tr>
<tr>
<td colspan="2" width="600" style="background-position : right; background-color: #DDDDDD; background-repeat : no-repeat;">
<form action="setup.php" method="post" name="theForm" id="theForm">
<input type="hidden" name="step" value="<? print $nb; ?>">
<?
}
function aff_middle(){
?>
<tr>
<td align="right" colspan="2" height="20">
<hr>
<table cellspacing="0" cellpadding="0" border="0" class="stdTable">
<tr>
<td>
<?
}
function aff_footer(){
?> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
<?
}
if (isset($_POST["Recheck"]))
$_POST["step"] = 3;
if (isset($_POST["goto"]) && !strcmp($_POST["goto"], "Back"))
$_POST["step"] -= 2;
//ENVIRONNEMENT CONFIGURATION
if (isset($_POST["mysqlclient"])) $_SESSION["mysqlclient"] = $_POST["mysqlclient"];
if (isset($_POST["phpmyprepaid_path"])) $_SESSION["phpmyprepaid_path"] = $_POST["phpmyprepaid_path"];
if (isset($_POST["snmpwalk"])) $_SESSION["snmpwalk"] = $_POST["snmpwalk"];
if (isset($_POST["snmpget"])) $_SESSION["snmpget"] = $_POST["snmpget"];
if (isset($_POST["rrdtool_bin"])) $_SESSION["rrdtool_bin"] = $_POST["rrdtool_bin"];
if (isset($_POST["sudo_bin"])) $_SESSION["sudo_bin"] = $_POST["sudo_bin"];
if (isset($_POST["system_log_path"])) $_SESSION["system_log_path"] = $_POST["system_log_path"];
if (isset($_POST["cron_bin"])) $_SESSION["cron_bin"] = $_POST["cron_bin"];
if (isset($_POST["cron_path"])) $_SESSION["cron_path"] = $_POST["cron_path"];
if (isset($_POST["apache_site_path"])) $_SESSION["apache_site_path"] = $_POST["apache_site_path"];
if (isset($_POST["apache_bin"])) $_SESSION["apache_bin"] = $_POST["apache_bin"];
if (isset($_POST["apache_ssl_dir"])) $_SESSION["apache_ssl_dir"] = $_POST["apache_ssl_dir"];
//RADIUS CONFIGURATION
if (isset($_POST["radius_log"])) $_SESSION["radius_log"] = $_POST["radius_log"];
if (isset($_POST["radclient"])) $_SESSION["radclient"] = $_POST["radclient"];
if (isset($_POST["radius_bin"]))$_SESSION["radius_bin"] = $_POST["radius_bin"];
if (isset($_POST["radius_conf"]))$_SESSION["radius_conf"] = $_POST["radius_conf"];
if (isset($_POST["radius_dictionary"])) $_SESSION["radius_dictionary"] = $_POST["radius_dictionary"];
if (isset($_POST["radius_startscript"]))$_SESSION["radius_startscript"] = $_POST["radius_startscript"];
if (isset($_POST["radius_secret"]))$_SESSION["radius_secret"] = $_POST["radius_secret"];
if (isset($_POST["radius_port"]))$_SESSION["radius_port"] = $_POST["radius_port"];
if (isset($_POST["radius_version"])) $_SESSION["radius_version"] = $_POST["radius_version"];
if (isset($_POST["radius_server"]) && strcmp($_POST["radius_server"], "")) $_SESSION["radius_server"] = $_POST["radius_server"];
if (isset($_POST["radius_server_sec"]) && strcmp($_POST["radius_server_sec"], "")) $_SESSION["radius_server_sec"] = $_POST["radius_server_sec"];
//ADMIN CONFIGURATION
if (isset($_POST["pralogin"])) $_SESSION["pralogin"] = $_POST["pralogin"];
if (isset($_POST["phpmyprepaidpassword"])) $_SESSION["phpmyprepaidpassword"] = $_POST["phpmyprepaidpassword"];
if (isset($_POST["prafirstname"])) $_SESSION["prafirstname"] = $_POST["prafirstname"];
if (isset($_POST["pralastname"])) $_SESSION["pralastname"] = $_POST["pralastname"];
if (isset($_POST["praemail"])) $_SESSION["praemail"] = $_POST["praemail"];
if (isset($_POST["pralang"])) $_SESSION["pralang"] = $_POST["pralang"];
if (isset($_POST["step"]) && $_POST["step"] == 6 ){
if ($_POST["goto"] != "Back" and strcmp($_POST["phpmyprepaidpassword"], $_POST["phpmyprepaidpassword2"])) {
$_POST["step"] = 5;
$passwd_error = "Password not confimed correctly.";
}
if ($_POST["goto"] != "Back" and $_POST["pralogin"]=="") {
$_POST["step"] = 5;
$passwd_error = "Login can't be blank.";
}
}
//DATABASE CREATION
if (isset($_POST["pwdPraDB"])) $_SESSION["pwdPraDB"] = $_POST["pwdPraDB"];
if (isset($_POST["pwdPraDB2"])) $_SESSION["pwdPraDB2"] = $_POST["pwdPraDB2"];
if (isset($_POST["pwdroot"])) $_SESSION["pwdroot"] = $_POST["pwdroot"];
if (isset($_POST["namePraDB"])) $_SESSION["namePraDB"] = $_POST["namePraDB"];
if (isset($_POST["dbPort"])) $_SESSION["dbPort"] = $_POST["dbPort"];
if (isset($_POST["step"]) && $_POST["step"] == 7 ){
if ($_POST["goto"] != "Back" and strcmp($_POST["pwdPraDB"], $_POST["pwdPraDB2"])) {
$_POST["step"] = 6;
$passwd_error = "Password not confimed correctly.";
}
if ($_POST["goto"] != "Back" and $_POST["namePraDB"]=="") {
$_POST["step"] = 6;
$passwd_error = "Database name can't be blank.";
}
if ($_POST["goto"] != "Back" and $_POST["dbPort"]=="") {
$_POST["step"] = 6;
$passwd_error = "Port can't be blank.";
}
}
if (isset($_POST["dbLocation"]) && strcmp($_POST["dbLocation"], ""))
$_SESSION["dbLocation"] = $_POST["dbLocation"];
else if (!isset( $_SESSION["dbLocation"] ))
$_SESSION["dbLocation"] = "localhost";
//LOCATION
if ($_POST["goto"] != "Back" and isset($_POST["step"]) && $_POST["step"] == 9) {
include('../include/divers/functions.php');
$location_error='';
if ($_POST["domain"]=="" or $_POST["location"]=="")
{
$_POST["step"] = 8;
$location_error = "Location or domain name can't be blank.";
}
if (hasSpace($input)){
$location_error=$error." No spaces allowed location name.<br>"; $count=$count+1;
$_POST["step"] = 8;
}
else if (hasPeriod($input)){
$location_error=$error." No periods allowed location name.<br>"; $count=$count+1;
$_POST["step"] = 8;
}
else if ($_POST['location']=="" or $_POST['isocode']=="" or $_POST['domain']=="" or $_POST['city']=="" )
{
$_POST["step"] = 8;
$location_error = "You got to fill all field to create a location";
}
if ($debug) {
echo "LOC ".$_POST['location']."\n<br>";
echo "DOM ".$_POST['domain']."\n<br>";
echo "CITY ".$_POST['city']."\n<br>";
echo "ISO ".$_POST['isocode']."\n<br>";
echo "ARE ".$_POST['areacode']."\n<br>";
}
$_SESSION["location"] = $_POST["location"];
$_SESSION["domain"] = $_POST["domain"];
$_SESSION["isocode"] = $_POST["isocode"];
$_SESSION["areacode"] = $_POST["areacode"];
if ($location_error=='') {
if (!$_SESSION["pwdroot"])
$res = connexion('root', '', $_SESSION["dbLocation"]) or die ("Can't connect to Mysql Server : ".mysql_error());
else
$res = connexion('root', $_SESSION["pwdroot"], $_SESSION["dbLocation"]) or die ("Can't connect to Mysql Server : ".mysql_error()); //$_SESSION["pwdroot"]
@mysql_select_db($_SESSION["namePraDB"], $res) or die("Error : ".mysql_error());
$areacode=$_SESSION["areacode"] ;
$query="select area_code from areacode where area_short_name='".$areacode."'";
$result=mysql_query($query) or die(mysql_error());
$row = mysql_fetch_object($result);
$areacode=$row->area_code;
$country=$_POST['isocode'];
$query="select iso_code from isocode where iso_name='".$country."'";
$result=mysql_query($query) or die(mysql_error());
$row = mysql_fetch_object($result);
$countrycode=$row->iso_code;
$country=$countrycode;
$location=$_POST['location'];
$domain= $_POST['domain'];
$city=$_POST['city'];
$state=$areacode;
$query="SELECT iso_name FROM isocode WHERE iso_code='$country'";
$result = mysql_query($query) or die("Query database error !");
$row = mysql_fetch_object($result);
$ctrly=$row->iso_name;
if ($ctrly!="") {
$query="SELECT country_code FROM countrycode WHERE country_name REGEXP('$ctrly')";
$result = mysql_query($query) or die("Query database error !");
$row = mysql_fetch_object($result);
}
if (isset($row->country_code))
$ct=$row->country_code;
$query = "insert into locations (LocationName, LocationDomain, LocationState, LocationCity, LocationCountry,locationE164Country ) values ('$location', '$domain', '$state', '$city', '$country','$ct')";
mysql_query ($query) or die("Query database error !");
// we don't know the ID of the location we just added so we query for it
$query="select ID from locations where LocationName='$location'";
$result= mysql_query ($query) or die("Query database error !");
while ($row = mysql_fetch_object($result)) {
$array[] = $row;
$ID = ($row->ID);
}
$query = "insert into user_location (locationid, userid) values ('$ID', '1')";
mysql_query ($query) or die("Query database error !");
//
//
}
if ($location_error!='') $step=8;
}
if (isset($_POST["client_name"])) $_SESSION["client_name"] = $_POST["client_name"];
if (isset($_POST["acct_display"])) $_SESSION["acct_display"] = $_POST["acct_display"];
if (isset($_POST["use_domain_name"])) $_SESSION["use_domain_name"] = $_POST["use_domain_name"];
if (isset($_POST["octet_type"])) $_SESSION["octet_type"] = $_POST["octet_type"];
if (isset($_POST["gatewayTypef"])) $_SESSION["gateway_type_f"] = $_POST["gatewayTypef"];
if (isset($_POST["default_currency"])) $_SESSION["default_currency_f"] = $_POST["default_currency"];
if ($DEBUG) print $_POST["client_name"];
if ($DEBUG) print $_POST["client_name"];
//GENERAL CONFIG
if ($_POST["goto"] != "Back" and isset($_POST["step"]) && $_POST["step"] == 10) {
if (!$_SESSION["pwdroot"])
$res = connexion('root', '', $_SESSION["dbLocation"]) or die ("Can't connect to Mysql Server : ".mysql_error());
else
$res = connexion('root', $_SESSION["pwdroot"], $_SESSION["dbLocation"]) or die ("Can't connect to Mysql Server : ".mysql_error()); //$_SESSION["pwdroot"]
$requete = "UPDATE `phpmyprepaid` SET `client_name` = '".$_SESSION["client_name"]."',`use_domain_name` = '".$_SESSION["use_domain_name"]."',`gateway_type` = '".$_SESSION["gateway_type_f"]."',`default_currency` = '".$_SESSION['default_currency_f']."' WHERE `location_id` =1 LIMIT 1 ;";
$result = @mysql_query($requete, $res);
$err.=mysql_error($res);
$requete = "UPDATE `BillingPlan` SET `CurrencyBp` = '".$_SESSION["default_currency_f"]."' WHERE `ID` >0 ;";
if ($DEBUG) print $requete;
$result = @mysql_query($requete, $res);
$err.=mysql_error($res);
print $err;
}
if (!isset($_POST["step"])){ //STEP 0//////////////////////////////////////////////////
aff_header("PhpMyPrepaid Setup Wizard", "Welcome to PhpMyPrepaid Setup", 1);
$str = "<p>This installer creates the PhpMyPrepaid database tables and sets the
configuration variables that you need to start. The entire process
should take about ten minutes.</p><p>Before start you must be sure your system is <b>PhpMyPrepaid Ready!</b>. </p>
<p>For more information go to <b><a href=\"http://sourcefore.net/projects/phpmyprepaid/\">PhpMyPrepaid project page</a>.</p>
<br><br><br><center><p><b>Arrikitaun!!!</b></p></center>";
print $str;
aff_middle();
$str = "<input class='button' type='submit' name='goto' value='Start' id='defaultFocus' /></td>";
print $str;
aff_footer();
}
else if (isset($_POST["step"]))
include ('step'.$_POST["step"].".php");
?>