Пример #1
0
function drawRenewalTables()
{
    global $pro_mysql_product_table;
    global $pro_mysql_admin_table;
    global $pro_mysql_ssl_ips_table;
    global $pro_mysql_product_table;
    global $pro_mysql_vps_table;
    global $pro_mysql_dedicated_table;
    global $pro_mysql_ssl_ips_table;
    global $pro_mysql_client_table;
    global $pro_mysql_domain_table;
    global $pro_mysql_completedorders_table;
    global $pro_mysql_pay_table;
    global $pro_mysql_spent_type_table;
    global $pro_mysql_spent_providers_table;
    global $pro_mysql_spent_moneyout_table;
    global $pro_mysql_companies_table;
    global $pro_mysql_spent_bank_table;
    global $pro_mysql_client_table;
    global $pro_mysql_new_admin_table;
    global $secpayconf_currency_letters;
    global $rub;
    global $conf_vps_renewal_shutdown;
    get_secpay_conf();
    if (!isset($_REQUEST["sousrub"]) || $_REQUEST["sousrub"] == "") {
        $sousrub = "renewalreport";
    } else {
        $sousrub = $_REQUEST["sousrub"];
    }
    $out = '<ul class="box_wnb_content_nb">';
    if ($sousrub == "renewalreport") {
        $out .= "<li class=\"box_wnb_content_nb_item_select\"><a href=\"?rub={$rub}\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/tabs/p_clientinterface.gif\" align=\"absmiddle\" border=\"0\"> " . _("Renewal report") . "</a></li>";
    } else {
        $out .= "<li class=\"box_wnb_content_nb_item\"><a href=\"?rub={$rub}\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/tabs/p_clientinterface.gif\" align=\"absmiddle\" border=\"0\"> " . _("Renewal repport") . "</a></li>";
    }
    $out .= '<li class="box_wnb_content_nb_item_vsep"></li>';
    if ($sousrub == "spent") {
        $out .= "<li class=\"box_wnb_content_nb_item_select\"><a href=\"?rub={$rub}&sousrub=spent\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/config-icon/box_wnb_nb_picto-payementgateway.gif\" align=\"absmiddle\" border=\"0\">" . _("Money spent") . "</a></li>";
    } else {
        $out .= "<li class=\"box_wnb_content_nb_item\"><a href=\"?rub={$rub}&sousrub=spent\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/config-icon/box_wnb_nb_picto-payementgateway.gif\" align=\"absmiddle\" border=\"0\">" . _("Money spent") . "</a></li>";
    }
    $out .= '<li class="box_wnb_content_nb_item_vsep"></li>';
    if ($sousrub == "bank") {
        $out .= "<li class=\"box_wnb_content_nb_item_select\"><a href=\"?rub={$rub}&sousrub=bank\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/config-icon/box_wnb_nb_picto-payementgateway.gif\" align=\"absmiddle\" border=\"0\">" . _("Bank accounts & payments") . "</a></li>";
    } else {
        $out .= "<li class=\"box_wnb_content_nb_item\"><a href=\"?rub={$rub}&sousrub=bank\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/config-icon/box_wnb_nb_picto-payementgateway.gif\" align=\"absmiddle\" border=\"0\">" . _("Bank accounts & payments") . "</a></li>";
    }
    $out .= '<li class="box_wnb_content_nb_item_vsep"></li>';
    if ($sousrub == "provideredit") {
        $out .= "<li class=\"box_wnb_content_nb_item_select\"><a href=\"?rub={$rub}&sousrub=provideredit\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/tabs/p_admineditor.gif\" align=\"absmiddle\" border=\"0\">" . _("Upstream provider editor") . "</a></li>";
    } else {
        $out .= "<li class=\"box_wnb_content_nb_item\"><a href=\"?rub={$rub}&sousrub=provideredit\"><img width=\"16\" height=\"16\" src=\"gfx/skin/bwoup/gfx/tabs/p_admineditor.gif\" align=\"absmiddle\" border=\"0\">" . _("Upstream provider editor") . "</a></li>";
    }
    $out .= "</ul>";
    switch ($sousrub) {
        case "spent":
            $ret = dateSelector("spent_moneyout", "invoice_date", "date_selector");
            $out .= $ret["text"];
            $where_condition = $ret["where_condition"];
            $q = "SELECT * FROM {$pro_mysql_spent_providers_table} ";
            $r = mysql_query($q) or die("Cannot query {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $prov_popup_id = array();
            $prov_popup_names = array();
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $prov_popup_id[] = $a["id"];
                $prov_popup_names[] = $a["quick_name"];
            }
            $q = "SELECT * FROM {$pro_mysql_spent_type_table} ";
            $r = mysql_query($q) or die("Cannot query {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $spent_type_popup_id = array();
            $spent_type_names = array();
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $spent_type_popup_id[] = $a["id"];
                $spent_type_names[] = $a["label"];
            }
            $q = "SELECT * FROM {$pro_mysql_companies_table} ";
            $r = mysql_query($q) or die("Cannot query {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $company_paying_popup_id = array();
            $company_paying_names = array();
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $company_paying_popup_id[] = $a["id"];
                $company_paying_names[] = $a["name"];
            }
            $q = "SELECT * FROM {$pro_mysql_spent_bank_table} ";
            $r = mysql_query($q) or die("Cannot query {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $bank_popup_id = array();
            $bank_names = array();
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $bank_popup_id[] = $a["id"];
                $bank_names[] = $a["acct_name"];
            }
            $dsc = array("title" => _("List of payments done by your hosting company"), "table_name" => $pro_mysql_spent_moneyout_table, "action" => "money_out_editor", "forward" => array("rub", "sousrub"), "print_where_condition" => $where_condition, "order_by" => "invoice_date", "cols" => array("id" => array("type" => "id", "display" => "no", "legend" => "id"), "label" => array("type" => "text", "size" => "10", "legend" => _("Label")), "id_company_spending" => array("legend" => _("Company paying"), "type" => "popup", "values" => $company_paying_popup_id, "display_replace" => $company_paying_names), "id_provider" => array("legend" => _("Company paid"), "type" => "popup", "values" => $prov_popup_id, "display_replace" => $prov_popup_names), "expenditure_type" => array("legend" => _("Expenditure type"), "type" => "popup", "values" => $spent_type_popup_id, "display_replace" => $spent_type_names), "payment_type" => array("legend" => _("Means of payment"), "type" => "popup", "values" => array("none", "credit_card", "wire_transfer", "paypal", "check", "cash"), "display_replace" => array(_("Unknown"), _("Credit card"), _("Wire transfer"), _("Paypal"), _("Check"), _("Cash"))), "payment_total" => array("type" => "text", "size" => 6, "legend" => _("Total cost")), "vat_rate" => array("type" => "text", "size" => 4, "legend" => _("Tax rate")), "vat_total" => array("type" => "text", "size" => 4, "legend" => _("Total tax")), "currency_type" => array("type" => "text", "size" => 4, "legend" => _("Currency")), "bank_acct_id" => array("type" => "popup", "values" => $bank_popup_id, "display_replace" => $bank_names, "legend" => _("Bank account")), "amount" => array("type" => "text", "size" => 6, "legend" => _("Bank amount")), "invoice_date" => array("type" => "text", "size" => 10, "legend" => _("Invoice date")), "paid_date" => array("type" => "text", "size" => 10, "legend" => _("Payment date"))));
            if (isset($_REQUEST["date_selector"])) {
                $dsc["forward"][] = "date_selector";
            }
            $out .= dtcDatagrid($dsc);
            break;
        case "bank":
            $q = "SELECT * FROM {$pro_mysql_companies_table} ";
            $r = mysql_query($q) or die("Cannot query {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $company_paying_popup_id = array();
            $company_paying_names = array();
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $company_paying_popup_id[] = $a["id"];
                $company_paying_names[] = $a["name"];
            }
            $dsc = array("title" => _("Bank accounts edition"), "table_name" => $pro_mysql_spent_bank_table, "action" => "bank_account_editor", "forward" => array("rub", "sousrub"), "cols" => array("id" => array("type" => "id", "display" => "no", "legend" => "id"), "acct_name" => array("type" => "text", "legend" => _("Account name")), "id_company" => array("legend" => _("Company"), "type" => "popup", "values" => $company_paying_popup_id, "display_replace" => $company_paying_names), "sort_code" => array("legend" => _("Sort code"), "type" => "text", "size" => "8"), "acct_number" => array("legend" => _("Account number"), "type" => "text"), "swift" => array("legend" => _("SWIFT"), "type" => "text", "size" => "8"), "bank_addr" => array("legend" => _("Bank address"), "type" => "text"), "currency_type" => array("legend" => _("Currency"), "type" => "text", "size" => "4")));
            $out .= dtcDatagrid($dsc);
            // Payment type
            $dsc = array("title" => _("Payment type edition"), "table_name" => $pro_mysql_spent_type_table, "action" => "payment_type_editor", "forward" => array("rub", "sousrub"), "cols" => array("id" => array("type" => "id", "display" => "no", "legend" => "id"), "label" => array("legend" => _("Type of payment"), "type" => "text", "size" => "32")));
            $out .= dtcDatagrid($dsc);
            break;
        case "provideredit":
            $dsc = array("title" => _("Upstream provider list edition"), "table_name" => $pro_mysql_spent_providers_table, "action" => "provider_list_editor", "forward" => array("rub", "sousrub"), "id_fld" => "id", "list_fld_show" => "quick_name", "new_item_title" => _("New upstream provider") . ":", "new_item_link" => _("New upsream provider"), "edit_item_title" => _("Edit upstream provider") . ":", "check_unique" => array("quick_name"), "where_list" => array("always_yes" => "yes"), "cols" => array("id" => array("type" => "id", "display" => "no", "legend" => "id"), "quick_name" => array("type" => "text", "disable_edit" => "yes", "check" => "dtc_login_or_email", "legend" => _("Short name:")), "company_name" => array("legend" => _("Company name:"), "type" => "text"), "is_company" => array("type" => "checkbox", "values" => array("yes", "no"), "default" => "yes", "legend" => _("Is it a company:")), "familyname" => array("legend" => _("First name:"), "type" => "text"), "christname" => array("legend" => _("Familly name:"), "type" => "text"), "addr1" => array("legend" => _("Address:"), "type" => "text"), "addr2" => array("legend" => _("Address (line2):"), "type" => "text"), "addr3" => array("legend" => _("Address (line3):"), "type" => "text"), "city" => array("legend" => _("City:"), "type" => "text"), "zipcode" => array("legend" => _("Zipcode:"), "type" => "text"), "state" => array("legend" => _("State:"), "type" => "text"), "country" => array("legend" => _("Country:"), "type" => "text"), "phone" => array("legend" => _("Phone:"), "type" => "text"), "fax" => array("legend" => _("Fax:"), "type" => "text"), "email" => array("legend" => _("Email:"), "type" => "text"), "special_note" => array("legend" => _("Note:"), "type" => "textarea")));
            $out .= dtcListItemsEdit($dsc);
            break;
        default:
        case "renewalreport":
            // Allow shutdown of expired VPS
            if (isset($_REQUEST["action"])) {
                switch ($_REQUEST["action"]) {
                    case "shutdown_expired_vps":
                        // Perform a clean shutdown
                        remoteVPSAction($_REQUEST["server_hostname"], $_REQUEST["vps_name"], "shutdown_vps");
                        break;
                    case "kill_vps_and_owner":
                        // Do a brutal kill of the running instance
                        deleteVPS($_REQUEST["vps_id"]);
                        remoteVPSAction($_REQUEST["server_hostname"], $_REQUEST["vps_name"], "destroy_vps");
                        remoteVPSAction($_REQUEST["server_hostname"], $_REQUEST["vps_name"], "kill_vps_disk");
                        // Delete the admin
                        $q = "DELETE FROM {$pro_mysql_admin_table} WHERE adm_login='******';";
                        $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                        // And the client
                        $q = "DELETE FROM {$pro_mysql_client_table} WHERE id='" . $_REQUEST["client_id"] . "';";
                        $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                        break;
                    default:
                        break;
                }
            }
            // Display of each month payment list
            if (isset($_REQUEST["date"])) {
                $ret = dateSelector($pro_mysql_pay_table, "date", "date");
                $out .= $ret["text"];
                $where_condition = $ret["where_condition"];
                $q = "SELECT id,name FROM {$pro_mysql_product_table} ";
                $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                $n = mysql_num_rows($r);
                $prod_ids = array();
                $prod_names = array();
                for ($i = 0; $i < $n; $i++) {
                    $a = mysql_fetch_array($r);
                    $prod_ids[] = $a["id"];
                    $prod_names[] = $a["name"];
                }
                $out .= "<h3>" . _("Payements for the period: ") . $_REQUEST["date"] . "</h3>";
                $dsc = array("title" => _("Payment history"), "table_name" => $pro_mysql_pay_table, "action" => "payment_history_list_editor", "forward" => array("rub", "sousrub", "date"), "order_by" => "date", "skip_deletion" => "yes", "skip_creation" => "yes", "print_where_condition" => $where_condition, "cols" => array("id" => array("type" => "id", "display" => "no", "legend" => "id"), "date" => array("type" => "text", "size" => "8", "legend" => _("Date")), "id_client" => array("type" => "forkey", "forkey_type" => "info", "table" => $pro_mysql_client_table, "other_table_fld" => "CONCAT(company_name,': ',familyname,', ',christname)", "other_table_key" => "id", "this_table_field" => "id_client", "link" => "?rub=crm&id=", "bk_table" => $pro_mysql_new_admin_table, "bk_other_table_fld" => "CONCAT(comp_name,': ',family_name,', ',first_name)", "bk_other_table_key" => "id", "bk_this_table_field" => "id_client", "legend" => _("Customer name")), "product_id" => array("type" => "popup", "values" => $prod_ids, "display_replace" => $prod_names, "legend" => _("Product")), "refund_amount" => array("type" => "text", "size" => "8", "legend" => _("Refund amount")), "paiement_cost" => array("type" => "text", "size" => "4", "legend" => _("Gate cost")), "vat_rate" => array("type" => "text", "size" => "4", "legend" => _("VAT rate")), "vat_total" => array("type" => "text", "size" => "4", "legend" => _("VAT total")), "paiement_total" => array("type" => "text", "size" => "6", "legend" => _("Grand total")), "paiement_type" => array("type" => "text", "size" => "6", "legend" => _("Type")), "secpay_site" => array("type" => "text", "size" => "4", "legend" => _("Gate type")), "new_account" => array("type" => "popup", "values" => array("no", "yes"), "display_replace" => array(_("New account"), _("Renewal")), "legend" => _("Is renewal")), "valid" => array("type" => "popup", "values" => array("no", "pending", "yes"), "display_replace" => array(_("No"), _("Pending"), _("Yes")), "legend" => _("Validated")), "pending_reason" => array("type" => "text", "size" => "6", "legend" => _("Pending reason"))));
                $out .= dtcDatagrid($dsc);
                return $out;
                $ret = dateSelector($pro_mysql_completedorders_table, "date", "date");
                // Allow nuke of bad payment (hackers?) to have accounting done correctly
                if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "nuke_payment") {
                    $q = "DELETE FROM {$pro_mysql_completedorders_table} WHERE id='" . $_REQUEST["completedorders_id"] . "';";
                    $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                }
                $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                $n = mysql_num_rows($r);
                if ($n < 1) {
                    $out .= _("No past payments for this period") . "<br>";
                } else {
                    $out .= "<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\">\n\t\t\t\t<tr><td>" . _("Product") . "</td><td>" . _("Client ID") . "</td><td>" . _("Client") . "</td><td>" . _("Service country") . "</td>\n\t\t\t\t<td>" . _("Client country") . "</td>\n\t\t\t\t<td>" . _("VAT collected") . "</td><td>" . _("Period") . "</td><td>" . _("Payment date") . "</td><td>" . _("Total") . "</td><td>" . _("Payment method") . "</td>\n\t\t\t\t<td>" . _("Action") . "</td></tr>";
                    for ($i = 0; $i < $n; $i++) {
                        $a = mysql_fetch_array($r);
                        if ($a["id_client"] == 0) {
                            $client_name = _("No client id");
                            $client_id_txt = _("No client id");
                        } else {
                            $q2 = "SELECT * FROM {$pro_mysql_client_table} WHERE id='" . $a["id_client"] . "';";
                            $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                            $n2 = mysql_num_rows($r2);
                            if ($n2 != 1) {
                                $client_name = _("N/A");
                                $client_id_txt = _("N/A");
                                $client_country = _("N/A");
                            } else {
                                $a2 = mysql_fetch_array($r2);
                                $client_name = $a2["company_name"] . ":" . $a2["christname"] . ", " . $a2["familyname"];
                                $client_id_txt = $a["id_client"];
                                $client_country = $a2["country"];
                            }
                        }
                        $q2 = "SELECT * FROM {$pro_mysql_product_table} WHERE id='" . $a["product_id"] . "';";
                        $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                        $n2 = mysql_num_rows($r2);
                        if ($n2 != 1) {
                            $product_txt = _("Product not found");
                        } else {
                            $a2 = mysql_fetch_array($r2);
                            $product_txt = $a2["name"];
                            $product_period_size = $a2["period"];
                        }
                        $q2 = "SELECT * FROM {$pro_mysql_pay_table} WHERE id='" . $a["payment_id"] . "';";
                        $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                        $n2 = mysql_num_rows($r2);
                        if ($n2 != 1) {
                            $payment_txt = _("Payment not found");
                            $payment_type = _("Payment not found");
                            $vat_collected = _("VAT not found");
                        } else {
                            $a2 = mysql_fetch_array($r2);
                            $payment_txt = $a2["paiement_total"] . " " . $a2["currency"];
                            $payment_type = $a2["paiement_type"];
                            if ($payment_type == "online") {
                                $payment_type .= ": " . $a2["secpay_site"];
                            }
                            $vat_collected = $a2["paiement_total"] * $a2["vat_rate"] / 100;
                        }
                        if ($a["last_expiry_date"] == "0000-00-00") {
                            $last_expiry_date = $a["date"];
                        } else {
                            $last_expiry_date = $a["last_expiry_date"];
                        }
                        if ($payment_type == 'wire') {
                            $pay = _("Wire");
                        } else {
                            if ($payment_type == 'cheque') {
                                $pay = _("cheque");
                            } else {
                                if ($payment_type == 'online: none') {
                                    $pay = _("online: none");
                                } else {
                                    $pay = $payment_type;
                                }
                            }
                        }
                        $new_expiry_date = calculateExpirationDate($last_expiry_date, $product_period_size);
                        $out .= "<tr><td>{$product_txt}</td><td>{$client_id_txt}</td><td>{$client_name}</td><td>" . $a["country_code"] . "</td>\n\t\t\t\t\t<td>{$client_country}</td>\n\t\t\t\t\t<td>{$vat_collected}</td><td>{$last_expiry_date} -> {$new_expiry_date}</td><td>" . $a["date"] . "</td><td>{$payment_txt}</td>\n\t\t\t\t\t<td>{$pay}</td>\n\t\t\t\t\t<td><a href=\"" . $_SERVER["PHP_SELF"] . "?rub={$rub}&date=" . $_REQUEST["date"] . "&action=nuke_payment&completedorders_id=" . $a["id"] . "\">" . _("Delete") . "</a></tr>";
                    }
                    $out .= "</table>";
                }
                return $out;
            }
            // Calculation of recuring totals
            $out .= "<h3>" . _("Total recurring incomes per month:") . "</h3>";
            // Monthly recurring for shared hosting:
            $q = "SELECT {$pro_mysql_product_table}.price_dollar,{$pro_mysql_product_table}.period,{$pro_mysql_product_table}.id\n\t\tFROM {$pro_mysql_product_table},{$pro_mysql_admin_table}\n\t\tWHERE {$pro_mysql_product_table}.id = {$pro_mysql_admin_table}.prod_id\n\t\tAND {$pro_mysql_product_table}.heb_type='shared'\n\t\tAND {$pro_mysql_admin_table}.expire != '0000-00-00'";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $total_shared = 0;
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $period = $a["period"];
                $price = $a["price_dollar"];
                $id = $a["id"];
                if ($period == '0001-00-00') {
                    $total_shared += $price / 12;
                } else {
                    $papoum = explode('-', $period);
                    $months = $papoum[1];
                    if ($months == 0) {
                        echo "Product {$id} has zero month.<br>";
                    } else {
                        $total_shared += $price / $months;
                    }
                }
            }
            // Calculate how much SSL IPs have been taken
            $q = "SELECT count(id) as num_ssl FROM {$pro_mysql_ssl_ips_table} WHERE available='no'";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $total_ssl = 0;
            if ($n != 0) {
                $a = mysql_fetch_array($r);
                $q = "SELECT price_dollar FROM {$pro_mysql_product_table} WHERE heb_type='ssl'";
                $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                $n = mysql_num_rows($r);
                if ($n != 0) {
                    $b = mysql_fetch_array($r);
                    $total_ssl = $a["num_ssl"] * $b["price_dollar"] / 12;
                }
            }
            // Monthly recurring for VPS:
            $q = "SELECT {$pro_mysql_product_table}.price_dollar,{$pro_mysql_product_table}.period,{$pro_mysql_product_table}.id\n\t\tFROM {$pro_mysql_product_table},{$pro_mysql_vps_table}\n\t\tWHERE {$pro_mysql_product_table}.id = {$pro_mysql_vps_table}.product_id";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $total_vps = 0;
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $period = $a["period"];
                $price = $a["price_dollar"];
                $id = $a["id"];
                if ($period == '0001-00-00') {
                    $total_shared += $price / 12;
                } else {
                    $papoum = explode('-', $period);
                    $months = $papoum[1];
                    if ($months != 0) {
                        $total_vps += $price / $months;
                    } else {
                        echo "Product {$id} has zero month.<br>";
                    }
                }
            }
            // Monthly recurring for dedicated servers:
            $q = "SELECT {$pro_mysql_product_table}.price_dollar,{$pro_mysql_product_table}.period,{$pro_mysql_product_table}.id\n\t\tFROM {$pro_mysql_product_table},{$pro_mysql_dedicated_table}\n\t\tWHERE {$pro_mysql_product_table}.id = {$pro_mysql_dedicated_table}.product_id";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            $total_dedicated = 0;
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $period = $a["period"];
                $price = $a["price_dollar"];
                $id = $a["id"];
                if ($period == '0001-00-00') {
                    $total_shared += $price / 12;
                } else {
                    $papoum = explode('-', $period);
                    $months = $papoum[1];
                    if ($months == 0) {
                        echo _("Dedicated server product ID {$id} has zero for the number of month to renew") . "<br>";
                    } else {
                        $total_dedicated += $price / $months;
                    }
                }
            }
            $p_renewal = "";
            $p_renewal .= _("Shared hosting: ") . round($total_shared, 2) . " {$secpayconf_currency_letters}<br>";
            $p_renewal .= _("SSL IPs renewals: ") . round($total_ssl, 2) . " {$secpayconf_currency_letters}<br>";
            $p_renewal .= _("VPS: ") . round($total_vps, 2) . " {$secpayconf_currency_letters}<br>";
            $p_renewal .= _("Dedicated servers: ") . round($total_dedicated, 2) . " {$secpayconf_currency_letters}<br>";
            $big_total = $total_shared + $total_vps + $total_dedicated + $total_ssl;
            $p_renewal .= "<b>" . _("Total: ") . round($big_total, 2) . " {$secpayconf_currency_letters}</b>";
            // Show a quick history of payments
            $year = date("Y");
            $month = date("m");
            $cur_year = $year - 2;
            $cur_month = $month;
            $p_history = "";
            $p_history .= "<table cellspacing=\"1\" cellpadding=\"1\" border=\"1\">\n\t\t<tr><td>" . _("Period") . "</td><td>" . _("Amount") . "</td><td>" . _("VAT collected") . "</td><td>" . _("Payment gateway cost") . "</td><td>" . _("Profit") . "</td></tr>";
            for ($i = 0; $i < 25; $i++) {
                $q2 = "SELECT {$pro_mysql_pay_table}.paiement_total,{$pro_mysql_pay_table}.vat_rate,{$pro_mysql_pay_table}.paiement_cost\n\t\t\tFROM {$pro_mysql_pay_table},{$pro_mysql_completedorders_table}\n\t\t\tWHERE {$pro_mysql_pay_table}.vat_rate!='0.00'\n\t\t\tAND {$pro_mysql_completedorders_table}.payment_id = {$pro_mysql_pay_table}.id\n\t\t\tAND {$pro_mysql_completedorders_table}.date LIKE '" . $cur_year . "-" . $cur_month . "-%';";
                $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                $n2 = mysql_num_rows($r2);
                $vat_collected = 0;
                $month_total = 0;
                $cost_total = 0;
                for ($j = 0; $j < $n2; $j++) {
                    $a2 = mysql_fetch_array($r2);
                    $tt = $a2["paiement_total"];
                    $vat = $a2["vat_rate"];
                    $vat_collected += $tt * $vat / 100;
                    $month_total += $tt;
                    $cost_total += $a2["paiement_cost"];
                }
                $q2 = "SELECT sum(paiement_total) as paiement_total, sum(paiement_cost) as paiement_cost FROM {$pro_mysql_completedorders_table},{$pro_mysql_pay_table}\n\t\t\tWHERE {$pro_mysql_completedorders_table}.date LIKE '" . $cur_year . "-" . $cur_month . "%'\n\t\t\tAND {$pro_mysql_completedorders_table}.payment_id = {$pro_mysql_pay_table}.id\n\t\t\tAND {$pro_mysql_pay_table}.vat_rate = '0.00';";
                $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                $n2 = mysql_num_rows($r2);
                if ($n2 > 0) {
                    $a2 = mysql_fetch_array($r2);
                    $cost_total += $a2["paiement_cost"];
                    $month_total += $a2["paiement_total"];
                    $profit = $month_total - $cost_total - $vat_collected;
                    $p_history .= "<tr><td style=\"text-align:right;\"><a href=\"" . $_SERVER["PHP_SELF"] . "?rub={$rub}&date=" . $cur_year . "-" . $cur_month . "\">" . $cur_year . "-" . $cur_month . "</a></td>\n\t\t\t\t<td style=\"text-align:right;\">" . $month_total . " {$secpayconf_currency_letters}</td>\n\t\t\t\t<td style=\"text-align:right;\">" . round($vat_collected, 2) . " {$secpayconf_currency_letters}</td>\n\t\t\t\t<td style=\"text-align:right;\">" . round($cost_total, 2) . " {$secpayconf_currency_letters}</td>\n\t\t\t\t<td style=\"text-align:right;\">" . round($profit, 2) . " {$secpayconf_currency_letters}</td></tr>";
                }
                $cur_month++;
                if ($cur_month > 12) {
                    $cur_month = 1;
                    $cur_year++;
                }
                if ($cur_month < 10) {
                    $cur_month = "0" . $cur_month;
                }
            }
            $p_history .= "</table>";
            $p_active_prods = "<img src=\"active_prods_graph.php?graph=year\"><br>\n<img src=\"active_prods_graph.php?graph=month\">";
            // Layout the recuring stat and the effective payment statistics
            $out .= "<table cellspacing=\"1\" cellpadding=\"4\" border=\"0\" width=\"100%\">\n\t\t<tr valign=\"top\"><td valign=\"top\" width=\"50%\">{$p_history}</td>\n\t\t<td valign=\"top\">{$p_renewal}</td>\n\t\t<td valign=\"top\">{$p_active_prods}</td></tr></table>";
            $out .= "<h3>" . _("Shared hosting renewals:") . "</h3>";
            $q = "SELECT * FROM {$pro_mysql_admin_table} WHERE expire < '" . date("Y-m-d") . "' AND id_client!='0' AND expire !='0000-00-00' ORDER BY expire;";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__);
            $n = mysql_num_rows($r);
            if ($n < 1) {
                $out .= _("No shared account expired.") . "<br>";
            } else {
                $out .= "<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\">\n\t\t\t<tr><td>" . _("Login") . "</td><td>" . _("Client") . "</td><td>" . _("Email") . "</td><td>" . _("Expiration date") . "</td></tr>";
                for ($i = 0; $i < $n; $i++) {
                    $a = mysql_fetch_array($r);
                    $q2 = "SELECT * FROM {$pro_mysql_client_table} WHERE id='" . $a["id_client"] . "';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        $client_name = _("Client name not found!");
                    } else {
                        $a2 = mysql_fetch_array($r2);
                        $client_name = $a2["company_name"] . ":" . $a2["christname"] . ", " . $a2["familyname"];
                    }
                    $q2 = "SELECT * FROM {$pro_mysql_domain_table} WHERE owner='" . $a["adm_login"] . "';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__);
                    $n2 = mysql_num_rows($r2);
                    if ($n2 > 0) {
                        $out .= "<tr><td>" . $a["adm_login"] . "</td><td>{$client_name}</td><td>" . $a2["email"] . "</td><td>" . $a["expire"] . "</td></tr>";
                    }
                }
                $out .= "</table>";
            }
            // List of expired expired SSL IPs
            $out .= "<h3>" . _("SSL IPs renewals") . "</h3>";
            $q = "SELECT * FROM {$pro_mysql_ssl_ips_table} WHERE expire < '" . date("Y-m-d") . "' AND available='no' ORDER BY expire";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            if ($n < 1) {
                $out .= _("No SSL IP expired") . "<br>";
            } else {
                $out .= "<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\">\n\t\t\t<tr><td>" . _("Login") . "</td><td>" . _("Client") . "</td><td>" . _("Email") . "</td><td>" . _("Expiration date") . "</td></tr>";
                for ($i = 0; $i < $n; $i++) {
                    $a = mysql_fetch_array($r);
                    $q2 = "SELECT * FROM {$pro_mysql_admin_table} WHERE adm_login='******';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        die("Cannot find admin name " . $a["adm_login"] . " line " . __LINE__ . " file " . __FILE__);
                    } else {
                        $admin = mysql_fetch_array($r2);
                    }
                    $q2 = "SELECT * FROM {$pro_mysql_client_table} WHERE id='" . $admin["id_client"] . "';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        $client_name = _("Client name not found!");
                    } else {
                        $a2 = mysql_fetch_array($r2);
                        $client_name = $a2["company_name"] . ":" . $a2["christname"] . ", " . $a2["familyname"];
                    }
                    $out .= "<tr><td>" . $a["adm_login"] . "</td><td>{$client_name}</td><td>" . $a2["email"] . "</td><td>" . $a["expire"] . "</td></tr>";
                }
                $out .= "</table>";
            }
            // List if expired VPS
            $out .= "<h3>" . _("VPS renewals:") . "</h3>";
            $q = "SELECT * FROM {$pro_mysql_vps_table} WHERE expire_date < '" . date("Y-m-d") . "' ORDER BY expire_date";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            if ($n < 1) {
                $out .= _("No VPS expired") . "<br>";
            } else {
                $out .= "<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\">\n\t\t\t<tr><td>" . _("Login") . "</td><td>" . _("VPS") . "</td>\n\t\t\t<td>" . _("Client") . "</td>\n\t\t\t<td>" . _("Email") . "</td>\n\t\t\t<td>" . _("Expiration date") . "</td>\n\t\t\t<td>" . _("Days of expiration") . "</td>\n\t\t\t<td>" . _("Action") . "</td>\n\t\t\t</tr>";
                for ($i = 0; $i < $n; $i++) {
                    $a = mysql_fetch_array($r);
                    $q2 = "SELECT * FROM {$pro_mysql_admin_table} WHERE adm_login='******';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        die("Cannot find admin name " . $a["owner"] . " line " . __LINE__ . " file " . __FILE__);
                    } else {
                        $admin = mysql_fetch_array($r2);
                    }
                    $q2 = "SELECT * FROM {$pro_mysql_client_table} WHERE id='" . $admin["id_client"] . "';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        $client_name = _("Client name not found!");
                    } else {
                        $a2 = mysql_fetch_array($r2);
                        $client_name = $a2["company_name"] . ":" . $a2["christname"] . ", " . $a2["familyname"];
                    }
                    $q2 = "SELECT adm_login FROM {$pro_mysql_admin_table} WHERE id_client='" . $admin["id_client"] . "'";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 == 1) {
                        $q2 = "SELECT * FROM {$pro_mysql_vps_table} WHERE owner='" . $admin["adm_login"] . "'";
                        $r2 = mysql_query($q2) or die("Cannot querry " . $q2 . " line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                        $n2 = mysql_num_rows($r2);
                        if ($n2 == 1) {
                            $q2 = "SELECT * FROM {$pro_mysql_dedicated_table} WHERE owner='" . $admin["adm_login"] . "'";
                            $r2 = mysql_query($q2) or die("Cannot querry " . $q2 . " line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                            $n2 = mysql_num_rows($r2);
                            if ($n2 == 0) {
                                $q2 = "SELECT * FROM {$pro_mysql_domain_table} WHERE owner='" . $admin["adm_login"] . "'";
                                $r2 = mysql_query($q2) or die("Cannot querry " . $q2 . " line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                                $n2 = mysql_num_rows($r2);
                                if ($n2 == 0) {
                                    $kill_owner_txt = "<a href=\"" . $_SERVER["PHP_SELF"] . "?action=kill_vps_and_owner&adm_login="******"adm_login"] . "&client_id=" . $admin["id_client"] . "&vps_name=" . $a["vps_xen_name"] . "&server_hostname=" . $a["vps_server_hostname"] . "&vps_id=" . $a["id"] . "\">" . _("Kill VPS and owner") . "</a>";
                                } else {
                                    $kill_owner_txt = _("Has some domains");
                                }
                            } else {
                                $kill_owner_txt = _("Has a dedicated");
                            }
                        } else {
                            $kill_owner_txt = _("More than one VPS");
                        }
                    } else {
                        $kill_owner_txt = _("More than one login");
                    }
                    if (numOfDays($a["expire_date"]) >= $conf_vps_renewal_shutdown) {
                        $bgcolor = " bgcolor=\"#FF8888\" ";
                    } else {
                        $bgcolor = " ";
                    }
                    $out .= "<tr><td>" . $a["owner"] . "</td>\n\t\t\t\t<td>" . $a["vps_xen_name"] . ":" . $a["vps_server_hostname"] . "</td>\n\t\t\t\t<td>{$client_name}</td>\n\t\t\t\t<td>" . $a2["email"] . "</td>\n\t\t\t\t<td {$bgcolor}>" . $a["expire_date"] . "</td>\n\t\t\t\t<td {$bgcolor}>" . calculateAge($a["expire_date"], "00:00:00") . "</td>\n\t\t\t\t<td><a href=\"" . $_SERVER["PHP_SELF"] . "?rub={$rub}&action=shutdown_expired_vps&server_hostname=" . $a["vps_server_hostname"] . "&vps_name=" . $a["vps_xen_name"] . "\">" . _("Shutdown") . "</a> - {$kill_owner_txt}</td></tr>";
                }
                $out .= "</table>";
            }
            // List expired dedicated servers
            $out .= "<h3>" . _("Dedicated servers renewals") . "</h3>";
            $q = "SELECT * FROM {$pro_mysql_dedicated_table} WHERE expire_date < '" . date("Y-m-d") . "' ORDER BY expire_date";
            $r = mysql_query($q) or die("Cannot querry {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            if ($n < 1) {
                $out .= _("No dedicated server expired") . "<br>";
            } else {
                $out .= "<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\">\n\t\t\t<tr><td>" . _("Login") . "</td><td>" . _("Server") . "</td><td>" . _("Client") . "</td><td>" . _("Email") . "</td><td>" . _("Expiration date") . "</td></tr>";
                for ($i = 0; $i < $n; $i++) {
                    $a = mysql_fetch_array($r);
                    $q2 = "SELECT * FROM {$pro_mysql_admin_table} WHERE adm_login='******';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        die("Cannot find admin name " . $a["owner"] . " line " . __LINE__ . " file " . __FILE__);
                    } else {
                        $admin = mysql_fetch_array($r2);
                    }
                    $q2 = "SELECT * FROM {$pro_mysql_client_table} WHERE id='" . $admin["id_client"] . "';";
                    $r2 = mysql_query($q2) or die("Cannot querry {$q2} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                    $n2 = mysql_num_rows($r2);
                    if ($n2 != 1) {
                        $client_name = _("Client name not found!");
                    } else {
                        $a2 = mysql_fetch_array($r2);
                        $client_name = $a2["company_name"] . ":" . $a2["christname"] . ", " . $a2["familyname"];
                    }
                    $out .= "<tr><td>" . $a["owner"] . "</td><td>" . $a["server_hostname"] . "</td><td>{$client_name}</td><td>" . $a2["email"] . "</td><td>" . $a["expire_date"] . "</td></tr>";
                }
                $out .= "</table>";
            }
            break;
    }
    return $out;
}
Пример #2
0
function pro_vhost_generate()
{
    global $pro_mysql_domain_table;
    global $pro_mysql_admin_table;
    global $pro_mysql_subdomain_table;
    global $pro_mysql_ssl_ips_table;
    global $pro_mysql_product_table;
    global $conf_db_version;
    global $conf_unix_type;
    global $conf_apache_vhost_path;
    global $conf_generated_file_path;
    global $conf_dtcshared_path;
    global $conf_dtcadmin_path;
    global $conf_dtcclient_path;
    global $conf_dtcdoc_path;
    global $conf_dtcemail_path;
    global $conf_main_site_ip;
    global $conf_use_multiple_ip;
    global $conf_site_addrs;
    global $conf_php_library_path;
    global $conf_php_additional_library_path;
    global $conf_administrative_site;
    global $conf_administrative_ssl_port;
    global $conf_use_ssl;
    global $conf_shared_renewal_shutdown;
    global $conf_use_nated_vhost;
    global $conf_nated_vhost_ip;
    global $console;
    global $chk_dir_script;
    global $chk_certs_script;
    global $conf_main_domain;
    global $conf_404_subdomain;
    global $conf_mysql_db;
    global $conf_apache_version;
    global $conf_apache_directoryindex;
    global $conf_autogen_webmail_alias;
    global $conf_autogen_webmail_type;
    global $conf_use_shared_ssl;
    $vhost_file = "";
    $logrotate_file = "# Do not edit this file, it's generated\n# edit /etc/dtc/logrotate.template instead!\n";
    $vhost_file .= "# WARNING ! This file is automatically edited by the dtc cron\n# daemon: do not edit. All manual changes to hosts that are configured within\n# the dtc panel will be removed with the next cron job. It's the same for all\n# files in this folder exept the ssl, the 404 and the template folder.\n#\n# If you feel an option is missing, feel free to edit the script that generate\n# this file in dtc/admin/genfiles/gen_pro_vhosts.php. Best is to send us your\n# patch if you feel it's good enough to share.\n#\n# All non dtc hosts should be added in a SEPARATE file that you should include\n# in your httpd.conf or apache.conf See your distribution manual to know where\n# to find this file (somewhere in /etc/httpd or /etc/apache2 or even in\n# /usr/local/etc/apache/httpd.conf ...).\n";
    $vhost_file_listen = "";
    if ($conf_unix_type == "gentoo") {
        $conf_tools_prefix = "/var/www/localhost/htdocs";
    } else {
        if ($conf_unix_type == "bsd") {
            $conf_tools_prefix = "/usr/local/www";
        } else {
            $conf_tools_prefix = "/usr/share";
        }
    }
    // DB version check
    if ($conf_db_version < 10000 || !isset($conf_db_version) || !isset($conf_use_ssl) || !isset($conf_use_nated_vhost)) {
        $vhost_file .= "# WARNING !!! DATABASE SCHEMA IS COMMING FROM AN HOLD DTC VERSION : PLEASE UPGRADE YOUR TABLES TO NEW VERSION !!!\n";
    }
    $num_generated_vhosts = 0;
    $query = "SELECT * FROM {$pro_mysql_domain_table} WHERE 1 ORDER BY name;";
    $result = mysql_query($query) or die("Cannot execute query \"{$query}\"");
    $num_rows = mysql_num_rows($result);
    if ($num_rows < 1) {
        die("No account to generate : database has to contain AT LEAST one domain name");
    }
    $query2 = "SELECT {$pro_mysql_admin_table}.path\nFROM {$pro_mysql_domain_table},{$pro_mysql_admin_table}\nWHERE {$pro_mysql_domain_table}.name='{$conf_main_domain}'\nAND {$pro_mysql_admin_table}.adm_login={$pro_mysql_domain_table}.owner;";
    $result2 = mysql_query($query2) or die("Cannot execute query \"{$query2}\"!");
    $enable404feature = true;
    //echo "Query $query2 resulted in ".mysql_num_rows($result2)."\n";
    if (mysql_num_rows($result2) != 1) {
        $enable404feature = false;
    }
    //don't die here... 	we will try and do things to work around this bug
    //die("Cannot find main domain admin path!!!");
    if ($enable404feature == true) {
        $a = mysql_fetch_array($result2);
        $path_404 = $a["path"] . "/{$conf_main_domain}/subdomains/{$conf_404_subdomain}";
        // make sure the vhost_chk_dir script has the 404 entries
        vhost_chk_dir_sh("{$path_404}/html");
        vhost_chk_dir_sh("{$path_404}/logs");
        vhost_chk_dir_sh("{$path_404}/cgi-bin");
    }
    if ($conf_use_multiple_ip == "yes" && $conf_use_nated_vhost == "no") {
        $all_site_addrs = explode("|", $conf_site_addrs);
        $nbr_addrs = sizeof($all_site_addrs);
        for ($i = 0; $i < $nbr_addrs; $i++) {
            // first write all config'ed IPs with the Listen
            if (test_valid_local_ip($all_site_addrs[$i]) && !preg_match("/Listen " . $all_site_addrs[$i] . ":80/", $vhost_file_listen)) {
                $vhost_file_listen .= "Listen " . $all_site_addrs[$i] . ":80\n";
            } else {
                $vhost_file_listen .= "#Listen " . $all_site_addrs[$i] . ":80\n";
            }
            $query2 = "SELECT * FROM {$pro_mysql_domain_table} WHERE ip_addr='" . $all_site_addrs[$i] . "' LIMIT 1;";
            $result2 = mysql_query($query2) or die("Cannot execute query \"{$query}\"");
            $num_rows2 = mysql_num_rows($result2);
            if ($num_rows2 > 0) {
                $vhost_file .= "NameVirtualHost " . $all_site_addrs[$i] . ":80\n";
                if ($conf_use_shared_ssl == "yes") {
                    $vhost_file .= "NameVirtualHost " . $all_site_addrs[$i] . ":443\n";
                }
                if ($enable404feature == true) {
                    $vhost_file .= "<VirtualHost " . $all_site_addrs[$i] . ":80>\n\tServerName {$conf_404_subdomain}.{$conf_main_domain}\n\tDocumentRoot {$path_404}/html\n\t<Directory {$path_404}/html>\n\t\tAllow from all\n\t</Directory>\n\tScriptAlias /cgi-bin {$path_404}/cgi-bin\n\tErrorLog {$path_404}/logs/error.log\n\tLogSQLTransferLogTable " . str_replace("-", "A", str_replace(".", "_", $conf_main_domain)) . '$' . $conf_404_subdomain . '$' . "xfer\n\tLogSQLScoreDomain {$conf_main_domain}\n\tLogSQLScoreSubdomain {$conf_404_subdomain}\n\tLogSQLScoreTable {$conf_mysql_db}.http_accounting\n\tDirectoryIndex {$conf_apache_directoryindex}\n</VirtualHost>\n";
                    $logrotate_file .= "{$path_404}/logs/error.log ";
                }
            }
        }
    } else {
        $ip_for_404 = $conf_main_site_ip;
        if ($conf_use_nated_vhost == "yes") {
            $ip_for_404 = $conf_nated_vhost_ip;
            if (test_valid_local_ip($conf_nated_vhost_ip) && !preg_match("/Listen " . $conf_nated_vhost_ip . ":80/", $vhost_file_listen)) {
                $vhost_file_listen .= "Listen " . $conf_nated_vhost_ip . ":80\n";
            } else {
                $vhost_file_listen .= "#Listen " . $conf_nated_vhost_ip . ":80\n";
            }
            $vhost_file .= "NameVirtualHost " . $conf_nated_vhost_ip . ":80\n";
        } else {
            if (test_valid_local_ip($conf_main_site_ip) && !preg_match("/Listen " . $conf_main_site_ip . ":80/", $vhost_file_listen)) {
                $vhost_file_listen .= "Listen " . $conf_main_site_ip . ":80\n";
            } else {
                $vhost_file_listen .= "#Listen " . $conf_main_site_ip . ":80\n";
            }
            $vhost_file .= "NameVirtualHost " . $conf_main_site_ip . ":80\n";
            if ($conf_use_shared_ssl == "yes") {
                $vhost_file .= "NameVirtualHost " . $conf_main_site_ip . ":443\n";
            }
        }
        if ($enable404feature == true) {
            $vhost_file .= "<VirtualHost " . $ip_for_404 . ":80>\n        ServerName {$conf_404_subdomain}.{$conf_main_domain}\n        DocumentRoot {$path_404}/html\n        ScriptAlias /cgi-bin {$path_404}/cgi-bin\n        ErrorLog {$path_404}/logs/error.log\n        LogSQLTransferLogTable " . str_replace("-", "A", str_replace(".", "_", $conf_main_domain)) . '$' . $conf_404_subdomain . '$' . "xfer\n        LogSQLScoreDomain {$conf_main_domain}\n        LogSQLScoreSubdomain {$conf_404_subdomain}\n        LogSQLScoreTable {$conf_mysql_db}.http_accounting\n        DirectoryIndex {$conf_apache_directoryindex}\n</VirtualHost>\n";
            if ($conf_use_shared_ssl == "yes") {
                $vhost_file .= "<VirtualHost " . $conf_main_site_ip . ":443>\n        ServerName {$conf_404_subdomain}.{$conf_main_domain}\n        DocumentRoot {$path_404}/html\n        ScriptAlias /cgi-bin {$path_404}/cgi-bin\n        ErrorLog {$path_404}/logs/error.log\n        LogSQLTransferLogTable " . str_replace("-", "A", str_replace(".", "_", $conf_main_domain)) . '$' . $conf_404_subdomain . '$' . "xfer\n        LogSQLScoreDomain {$conf_main_domain}\n        LogSQLScoreSubdomain {$conf_404_subdomain}\n        LogSQLScoreTable {$conf_mysql_db}.http_accounting\n        DirectoryIndex {$conf_apache_directoryindex}\n\tSSLEngine on\n\tSSLCertificateFile " . $conf_generated_file_path . "/ssl/new.cert.cert\n\tSSLCertificateKeyFile " . $conf_generated_file_path . "/ssl/new.cert.key\n</VirtualHost>\n\n";
            }
            $logrotate_file .= "{$path_404}/logs/error.log ";
        }
    }
    $vhost_file .= "<Directory {$conf_dtcadmin_path}>\n\tOptions FollowSymLinks\n\tOrder Deny,Allow\n\tAllow from all\n</Directory>\n<Directory {$conf_dtcclient_path}>\n\tOptions FollowSymLinks\n\tOrder Deny,Allow\n\tAllow from all\n</Directory>\n<Directory {$conf_dtcemail_path}>\n\tOptions FollowSymLinks\n\tOrder Deny,Allow\n\tAllow from all\n</Directory>\n";
    if ($conf_autogen_webmail_alias == "yes") {
        if ($conf_autogen_webmail_type == "squirrelmail") {
            $vhost_file .= "RedirectPermanent /webmail https://{$conf_administrative_site}/squirrelmail\n";
        } else {
            $vhost_file .= "RedirectPermanent /webmail https://{$conf_administrative_site}/roundcube\n";
        }
    }
    #############################
    # mod_cband user generation #
    #############################
    $vhost_file .= "<IfModule mod_cband.c>\n";
    $q = "SELECT DISTINCT adm_login,{$pro_mysql_product_table}.bandwidth FROM {$pro_mysql_domain_table},{$pro_mysql_admin_table},{$pro_mysql_product_table}\nWHERE {$pro_mysql_domain_table}.owner={$pro_mysql_admin_table}.adm_login\nAND {$pro_mysql_product_table}.id={$pro_mysql_admin_table}.prod_id\nAND {$pro_mysql_admin_table}.prod_id != '0'\nAND {$pro_mysql_admin_table}.id_client != '0'";
    $r = mysql_query($q) or die("Cannot query {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
    $n = mysql_num_rows($r);
    for ($i = 0; $i < $n; $i++) {
        $a = mysql_fetch_array($r);
        $vhost_file .= "\n<CBandUser " . $a["adm_login"] . ">\n\tCBandSpeed 10Mbps 10 30\n\tCBandRemoteSpeed 2Mbps 3 3\n\tCBandLimit " . $a["bandwidth"] . "M\n\tCBandPeriod 4W\n\tCBandPeriodSlice 1W\n\tCBandExceededSpeed 32kbps 2 5\n\tCBandUserScoreboard /var/lib/dtc/etc/cband_scores/" . $a["adm_login"] . "\n</CBandUser>\n";
    }
    $vhost_file .= "</IfModule>\n";
    #################################
    # end mod_cband user generation #
    #################################
    for ($i = 0; $i < $num_rows; $i++) {
        $row = mysql_fetch_array($result) or die("Cannot fetch user");
        $web_name = $row["name"];
        if ($web_name == "") {
            print "No name specified for domain, skipping...";
            continue;
        }
        $web_owner = $row["owner"];
        $ip_addr = $row["ip_addr"];
        $domain_safe_mode = $row["safe_mode"];
        $domain_sbox_protect = $row["sbox_protect"];
        $domain_parking = $row["domain_parking"];
        $domain_parking_type = $row["domain_parking_type"];
        $domain_wildcard_dns = $row["wildcard_dns"];
        $domain_default_sub_server_alias = $row["default_sub_server_alias"];
        unset($backup_ip_addr);
        if (isset($row["backup_ip_addr"])) {
            $backup_ip_addr = $row["backup_ip_addr"];
        }
        if (isset($backup_ip_addr) && ($backup_ip_addr == "NULL" || trim($backup_ip_addr) == "")) {
            unset($backup_ip_addr);
        }
        // need to check if we have a NameVirtualHost entry for this backup IP, to support multiple backup sites on one IP
        if (isset($backup_ip_addr)) {
            if (test_valid_local_ip($backup_ip_addr) && !preg_match("/Listen " . $backup_ip_addr . ":80/", $vhost_file_listen)) {
                $vhost_file_listen .= "Listen " . $backup_ip_addr . ":80\n";
            } else {
                $vhost_file_listen .= "#Listen " . $backup_ip_addr . ":80\n";
            }
            if (!preg_match("/NameVirtualHost {$backup_ip_addr}/", $vhost_file)) {
                $vhost_file .= "NameVirtualHost " . $backup_ip_addr . ":80\n";
            }
        }
        if ($conf_use_multiple_ip == "yes") {
            $ip_to_write = $ip_addr;
        } else {
            $ip_to_write = $conf_main_site_ip;
        }
        if ($conf_use_nated_vhost == "yes") {
            $ip_to_write = $conf_nated_vhost_ip;
        }
        $web_default_subdomain = $row["default_subdomain"];
        // Get the owner informations
        $query2 = "SELECT * FROM {$pro_mysql_admin_table} WHERE adm_login='******';";
        $result2 = mysql_query($query2) or die("Cannot execute query \"{$query2}\"");
        $num_rows2 = mysql_num_rows($result2);
        if ($num_rows2 != 1) {
            echo "No user of that name ({$web_owner})!\n";
            continue;
        }
        $webadmin = mysql_fetch_array($result2) or die("Cannot fetch user");
        $web_path = $webadmin["path"];
        $expire_stored = $webadmin["expire"];
        if ($expire_stored == "0000-00-00") {
            $site_expired = "no";
        } else {
            $calc_expire_date = calculateExpirationDate($expire_stored, "0000-00-{$conf_shared_renewal_shutdown}");
            $calc_expire_date_array = explode("-", $calc_expire_date);
            $expire_timestamp = mktime(1, 1, 1, $calc_expire_date_array[1], $calc_expire_date_array[2], $calc_expire_date_array[0]);
            if ($expire_timestamp < mktime()) {
                $site_expired = "yes";
            } else {
                $site_expired = "no";
            }
        }
        if ($domain_parking != "no-parking" && $web_name != $conf_main_domain) {
            $domain_to_get = $domain_parking;
        } else {
            $domain_to_get = $web_name;
        }
        // Grab all subdomains
        if ($web_name == $conf_main_domain) {
            $query2 = "SELECT * FROM {$pro_mysql_subdomain_table} WHERE domain_name='{$web_name}' AND ip='default' AND subdomain_name!='{$conf_404_subdomain}' AND subdomain_name!='{$web_default_subdomain}' ORDER BY subdomain_name;";
        } else {
            $query2 = "SELECT * FROM {$pro_mysql_subdomain_table} WHERE domain_name='{$domain_to_get}' AND ip='default' AND subdomain_name!='{$web_default_subdomain}' ORDER BY subdomain_name;";
        }
        $result2 = mysql_query($query2) or die("Cannot execute query \"{$query2}\"");
        $num_rows2 = mysql_num_rows($result2);
        unset($temp_array_subs);
        $temp_array_subs = array();
        for ($j = 0; $j < $num_rows2; $j++) {
            $temp_array_subs[] = mysql_fetch_array($result2) or die("Cannot fetch user line " . __LINE__ . " file " . __FILE__);
        }
        // We get the default subdomain and we add it at the end of the array. The goal is to have the
        // wildcard subdomain be the last in the list of the vhosts.conf
        $query2 = "SELECT * FROM {$pro_mysql_subdomain_table} WHERE domain_name='{$domain_to_get}' AND ip='default' AND subdomain_name='{$web_default_subdomain}';";
        $result2 = mysql_query($query2) or die("Cannot execute query \"{$query2}\"");
        $my_num_rows = mysql_num_rows($result2);
        if ($my_num_rows == 1) {
            $temp_array_subs[] = mysql_fetch_array($result2) or die("Cannot fetch user" . __LINE__ . " file " . __FILE__);
            $num_rows2++;
        }
        // This is a bad idea to die in this case
        // because it actualy happen if you redirect www ip to something else.
        //		if($num_rows2 < 1){
        //			die("No subdomain for domain $web_name !");
        //		}
        for ($j = 0; $j < $num_rows2; $j++) {
            $subdomain = $temp_array_subs[$j];
            //			$subdomain = mysql_fetch_array($result2) or die ("Cannot fetch user");
            $web_subname = $subdomain["subdomain_name"];
            if ($subdomain["customize_vhost"] == "") {
                $custom_directives = "";
            } else {
                $custom_directives = "\n\t# Start of custom directives\n\t" . $subdomain["customize_vhost"] . "\n\t# End of custom directives";
            }
            //			$console .= "Working on $web_subname.$web_name\n";
            // if we explicitly don't want to generate a vhost entry for this subdomain
            if (isset($subdomain["generate_vhost"]) && $subdomain["generate_vhost"] == "no") {
                continue;
            }
            // ------------------------------------------------
            // --- Start of the conf of the panel subdomain ---
            // ------------------------------------------------
            if ($conf_administrative_site == "{$web_subname}.{$web_name}") {
                // generate SSL and non SSL if we have enabled SSL
                $gen_iterations = 1;
                if ($conf_use_ssl == "yes") {
                    $gen_iterations++;
                }
                // if we want to generate a backup IP (transitional)
                // need to loop through this one
                if (isset($backup_ip_addr)) {
                    $gen_iterations++;
                }
                for ($k = 0; $k < $gen_iterations; $k++) {
                    $log_tablename = str_replace("-", "A", str_replace(".", "_", $web_name)) . '$' . str_replace("-", "A", str_replace(".", "_", $web_subname));
                    if ($conf_use_ssl == "yes" && $k == 0) {
                        # add the directive for SSL here
                        if (test_valid_local_ip($ip_to_write) && !preg_match("/Listen " . $ip_to_write . ":" . $conf_administrative_ssl_port . "/", $vhost_file_listen)) {
                            $vhost_file_listen .= "Listen " . $ip_to_write . ":" . $conf_administrative_ssl_port . "\n";
                        } else {
                            $vhost_file_listen .= "#Listen " . $ip_to_write . ":" . $conf_administrative_ssl_port . "\n";
                        }
                        $vhost_file .= "<VirtualHost " . $ip_to_write . ":" . $conf_administrative_ssl_port . ">\n";
                    } else {
                        if ($k == 1 && isset($backup_ip_addr) || $conf_use_ssl != "yes" && $k == 0 && isset($backup_ip_addr)) {
                            $vhost_file .= "<VirtualHost " . $backup_ip_addr . ":80>\n";
                        } else {
                            $vhost_file .= "<VirtualHost " . $ip_to_write . ":80>\n";
                        }
                    }
                    // Added by Luke
                    // Needed to create an Alias in httpd.conf for non-resolvable domains
                    // This does http://dtc.your-domain.com/unresolved-domain.com
                    // TG: added a flag to say yes/no to that alias for each domains
                    $alias_domain_query = "SELECT * FROM {$pro_mysql_domain_table} WHERE gen_unresolved_domain_alias='yes' ORDER BY name;";
                    $result_alias = mysql_query($alias_domain_query) or die("Cannot execute query \"{$query}\" line " . __LINE__ . " file " . __FILE__ . " mysql said: " . mysql_error());
                    $num_rows_alias = mysql_num_rows($result_alias);
                    for ($x = 0; $x < $num_rows_alias; $x++) {
                        $rowX = mysql_fetch_array($result_alias) or die("Cannot fetch domain for Alias");
                        $web_nameX = $rowX["name"];
                        $web_ownerX = $rowX["owner"];
                        $ip_addrX = $rowX["ip_addr"];
                        $backup_ip_addrX = $rowX["backup_ip_addr"];
                        $alias_user_query = "SELECT * FROM {$pro_mysql_admin_table} WHERE adm_login='******';";
                        $alias_user_result = mysql_query($alias_user_query) or die("Cannot fetch user for Alias");
                        $num_rows_alias_user = mysql_num_rows($alias_user_result);
                        if ($num_rows_alias_user != 1) {
                            echo "No user of that name ({$web_ownerX})!\n";
                            continue;
                        }
                        $alias_path = mysql_fetch_array($alias_user_result) or die("Cannot fetch user");
                        $web_pathX = $alias_path["path"];
                        // TG: Added open_basedir restriction (for obvious security reasons)
                        $qsubdom = "SELECT * FROM {$pro_mysql_subdomain_table} WHERE domain_name='{$web_nameX}' AND ip='default';";
                        $rx = mysql_query($qsubdom) or die("Cannot execute query \"{$qsubdom}\" line " . __LINE__ . " file " . __FILE__ . " mysql said: " . mysql_error());
                        $numx = mysql_num_rows($rx);
                        for ($subx = 0; $subx < $numx; $subx++) {
                            $ax = mysql_fetch_array($rx) or die("Cannot fetch subdomain for Alias");
                            $subdomx = $ax["subdomain_name"];
                            $globalx = $ax["register_globals"];
                            if ($globalx == "yes") {
                                $gblx = "php_admin_value register_globals 1";
                            } else {
                                $gblx = "php_admin_value register_globals 0";
                            }
                            if ($rowX["safe_mode"] == "no" && $ax["safe_mode"] == "no") {
                                $safex = "php_admin_value safe_mode 0";
                            } else {
                                $safex = "php_admin_value safe_mode 1";
                            }
                            $vhost_file .= "\tAlias /{$subdomx}.{$web_nameX} {$web_pathX}/{$web_nameX}/subdomains/{$subdomx}/html\n\t<Location /{$subdomx}.{$web_nameX}>\n\t\t" . $safex . $custom_directives . "\n\t\tphp_admin_value open_basedir \"{$web_pathX}/{$web_nameX}/:{$conf_php_library_path}:{$conf_php_additional_library_path}:\"\n\t\t{$gblx}\n\t</Location>\n";
                        }
                    }
                    // End of Luke's patch
                    $vhost_file .= "\tServerName {$web_subname}.{$web_name}\n";
                    if ($conf_use_ssl == "yes" && $k == 0) {
                        $vhost_file .= "\tSSLEngine on\n\tSSLCertificateFile " . $conf_generated_file_path . "/ssl/new.cert.cert\n\tSSLCertificateKeyFile " . $conf_generated_file_path . "/ssl/new.cert.key\n";
                        if (file_exists($conf_generated_file_path . "/ssl/new.cert.ca")) {
                            $vhost_file .= "\tSSLCertificateChainFile " . $conf_generated_file_path . "/ssl/new.cert.ca\n";
                        }
                    }
                    vhost_chk_dir_sh("{$web_path}/{$web_name}/subdomains/{$web_subname}/html");
                    vhost_chk_dir_sh("{$web_path}/{$web_name}/subdomains/{$web_subname}/logs");
                    vhost_chk_dir_sh("{$web_path}/{$web_name}/subdomains/{$web_subname}/cgi-bin");
                    $vhost_file .= "\tAlias /phpmyadmin " . $conf_tools_prefix . "/phpmyadmin\n\tAlias /dtc {$conf_dtcclient_path}\n\tAlias /dtcdoc {$conf_dtcdoc_path}/html/en\n\tAlias /dtcemail {$conf_dtcemail_path}\n\tAlias /dtcadmin {$conf_dtcadmin_path}/\n\tAlias /stats {$web_path}/{$web_name}/subdomains/{$web_subname}/logs\n\tAlias /awstats-icon {$conf_tools_prefix}/awstats/icon\n\tAlias /squirrelmail " . $conf_tools_prefix . "/squirrelmail\n\tAlias /roundcube /var/lib/roundcube\n\tphp_admin_value sendmail_from webmaster@{$web_name}\n\tDocumentRoot {$web_path}/{$web_name}/subdomains/{$web_subname}/html\n\t<Directory {$web_path}/{$web_name}/subdomains/{$web_subname}/html>\n\t\tAllow from all\n\t</Directory>\n# No ScriptAlias: we want to use system's /usr/lib/cgi-bin !!!\n#\tScriptAlias /cgi-bin {$web_path}/{$web_name}/subdomains/{$web_subname}/cgi-bin\n\tErrorLog {$web_path}/{$web_name}/subdomains/{$web_subname}/logs/error.log\n\tLogSQLTransferLogTable {$log_tablename}\$xfer\n\tLogSQLScoreDomain {$web_name}\n\tLogSQLScoreSubdomain {$web_subname}\n\tLogSQLScoreTable {$conf_mysql_db}.http_accounting\n\tDirectoryIndex {$conf_apache_directoryindex}{$custom_directives}\n\t<IfModule mod_bwshare.c>\n\t\tBW_throttle_off 1\n\t</IfModule>\n\t<IfModule mod_security2.c>\n\t\tSecRuleEngine Off\n        </IfModule>\n</VirtualHost>\n\n";
                    $logrotate_file .= "{$web_path}/{$web_name}/subdomains/{$web_subname}/logs/error.log ";
                }
                // - end of for loop
                // ---------------------------------------------------
                // --- Start of the conf of server users subdomain ---
                // ---------------------------------------------------
            } else {
                // Generate a permanet redirect for all subdomains of target if using a domain parking
                if ($domain_parking != "no-parking" && ($domain_parking_type == "redirect" || $conf_administrative_site == "{$web_subname}.{$domain_to_get}")) {
                    if ($j == 0) {
                        $console .= "Making domain parking for {$web_name}\n";
                        $vhost_file .= "<VirtualHost " . $ip_to_write . ":80>\n\tServerName {$web_name}\n\tRedirect permanent / http://{$domain_parking}/\n</VirtualHost>\n\n";
                    }
                    $console .= "Making domain parking for {$web_subname}.{$web_name}\n";
                    $vhost_file .= "<VirtualHost " . $ip_to_write . ":80>\n\tServerName {$web_subname}.{$web_name}\n\tRedirect permanent / http://{$web_subname}.{$domain_parking}/\n</VirtualHost>\n\n";
                } else {
                    if ($domain_parking != "no-parking" && $domain_parking_type == "serveralias") {
                        // do nothing here, as serveralias parking will be injected throughout the generation of the main domain
                    } else {
                        vhost_chk_dir_sh("{$web_path}/{$domain_to_get}/subdomains/{$web_subname}/logs");
                        vhost_chk_dir_sh("{$web_path}/{$domain_to_get}/subdomains/{$web_subname}/html");
                        vhost_chk_dir_sh("{$web_path}/{$domain_to_get}/subdomains/{$web_subname}/cgi-bin");
                        // We need to make it for both in case of a domain parking
                        if ($domain_to_get != $web_name) {
                            vhost_chk_dir_sh("{$web_path}/{$web_name}/subdomains/{$web_subname}/logs");
                            vhost_chk_dir_sh("{$web_path}/{$web_name}/subdomains/{$web_subname}/html");
                            vhost_chk_dir_sh("{$web_path}/{$web_name}/subdomains/{$web_subname}/cgi-bin");
                        }
                        $iteration_table = array();
                        $iteration_table[] = "normal";
                        $ssl_cert_folder_path = "{$web_path}/{$domain_to_get}/subdomains/{$web_subname}/ssl";
                        if ($subdomain["ssl_ip"] != "none") {
                            $ssl_returns = checkCertificate($ssl_cert_folder_path, $web_subname . "." . $web_name);
                            if ($ssl_returns == "yes") {
                                $iteration_table[] = "ssl";
                                // Start of <*****@*****.**> patch
                                if ($conf_use_nated_vhost == "yes") {
                                    $q = "select port from {$pro_mysql_ssl_ips_table} where ip_addr='{$subdomain["ssl_ip"]}' and available='no';";
                                    $r = mysql_query($q) or die("Cannot query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                                    $n = mysql_num_rows($r);
                                    if ($n > 0) {
                                        $row = mysql_fetch_array($r);
                                        $port = $row["port"];
                                        $ip_vhost = $ip_to_write;
                                        if (empty($port)) {
                                            $port = "443";
                                        }
                                    } else {
                                        $port = "443";
                                        $ip_vhost = $subdomain["ssl_ip"];
                                    }
                                } else {
                                    $port = "443";
                                }
                                // End of <*****@*****.**> patch
                            }
                        }
                        // if we want to generate a backup IP (transitional)
                        // need to loop through this one
                        if (isset($backup_ip_addr)) {
                            $iteration_table[] = "backup";
                        }
                        $log_tablename = str_replace("-", "A", str_replace(".", "_", $web_name)) . '$' . str_replace("-", "A", str_replace(".", "_", $web_subname));
                        $vhost_more_conf = "";
                        if ($subdomain["register_globals"] == "yes") {
                            $vhost_more_conf .= "\tphp_admin_value register_globals 1\n";
                        }
                        if ($subdomain["php_memory_limit"] != "") {
                            $vhost_more_conf .= "\tphp_admin_value memory_limit " . $subdomain["php_memory_limit"] . "M\n";
                        }
                        if ($subdomain["php_max_execution_time"] != "") {
                            $vhost_more_conf .= "\tphp_admin_value max_execution_time " . $subdomain["php_max_execution_time"] . "\n";
                        }
                        if ($subdomain["php_session_auto_start"] == "yes") {
                            $vhost_more_conf .= "\tphp_admin_flag session_autostart " . $subdomain["php_session_auto_start"] . "\n";
                        }
                        if ($subdomain["php_allow_url_fopen"] == "yes") {
                            $vhost_more_conf .= "\tphp_admin_flag allow_url_fopen on\n";
                        }
                        if ($subdomain["php_post_max_size"] != "") {
                            $vhost_more_conf .= "\tphp_admin_value post_max_size " . $subdomain["php_post_max_size"] . "M\n";
                        }
                        if ($subdomain["php_upload_max_filesize"] != "") {
                            $vhost_more_conf .= "\tphp_admin_value upload_max_filesize " . $subdomain["php_upload_max_filesize"] . "M\n";
                        }
                        if ($subdomain["use_shared_ssl"] == "yes" && $conf_use_shared_ssl == "yes") {
                            $iteration_table[] = "shared_ssl";
                        }
                        if (preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $subdomain["redirect_url"])) {
                            $vhost_more_conf .= "Redirect / " . $subdomain["redirect_url"] . "\n";
                        }
                        if ($web_subname == "{$web_default_subdomain}") {
                            if ($domain_parking == "no-parking") {
                                // no domain parking
                                $server_alias_domain = $domain_to_get;
                            } else {
                                // parking: same_docroot
                                $server_alias_domain = $web_name;
                                // parking: redirect doesn't happen in this else branch
                            }
                            if ($domain_default_sub_server_alias == "yes") {
                                $vhost_more_conf .= "\tServerAlias {$server_alias_domain}\n";
                            }
                            if ($domain_wildcard_dns == "yes") {
                                $vhost_more_conf .= "   ServerAlias *.{$server_alias_domain}\n";
                            }
                        }
                        // ServerAlias for parked domains
                        $q_serveralias = "select * from {$pro_mysql_domain_table} where domain_parking_type='serveralias' and domain_parking='{$web_name}'";
                        $r_serveralias = mysql_query($q_serveralias) or die("Cannot query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
                        while ($row_serveralias = mysql_fetch_array($r_serveralias)) {
                            // default subdomain and wildcard subdomain settings are inherited from the main domain, not the parked domain
                            // this is because in the gui these settings are not accessable for a parked domain
                            if ($web_subname == "{$web_default_subdomain}") {
                                $vhost_more_conf .= "        ServerAlias {$row_serveralias["name"]}\n";
                            }
                            $vhost_more_conf .= "        ServerAlias {$web_subname}.{$row_serveralias["name"]}\n";
                            if ($domain_wildcard_dns == "yes") {
                                $vhost_more_conf .= "        ServerAlias *.{$row_serveralias["name"]}\n";
                            }
                        }
                        // Sbox and safe mode protection values
                        if ($domain_safe_mode == "no" && $subdomain["safe_mode"] == "no") {
                            $safe_mode_value = "0";
                        } else {
                            $safe_mode_value = "1";
                        }
                        if ($domain_sbox_protect == "no" && $subdomain["sbox_protect"] == "no") {
                            $cgi_directive = "ScriptAlias /cgi-bin {$web_path}/{$domain_to_get}/subdomains/{$web_subname}/cgi-bin";
                        } else {
                            $cgi_directive = "RewriteEngine on\n\tRewriteRule ^/cgi-bin/(.*) /cgi-bin/sbox/\$1 [PT]";
                        }
                        $gen_iterations = sizeof($iteration_table);
                        for ($k = 0; $k < $gen_iterations; $k++) {
                            switch ($iteration_table[$k]) {
                                case "backup":
                                    $vhost_file .= "<VirtualHost " . $backup_ip_addr . ":80>\n";
                                    break;
                                case "normal":
                                    $vhost_file .= "<VirtualHost " . $ip_to_write . ":80>\n";
                                    break;
                                case "ssl":
                                    //if($conf_use_nated_vhost=="no"){
                                    //	$vhost_file .= "Listen ".$ip_vhost.":$port\n";
                                    //}
                                    $vhost_file .= "Listen " . $subdomain["ssl_ip"] . ":{$port}\n";
                                    $vhost_file .= "<VirtualHost " . $subdomain["ssl_ip"] . ":{$port}>\n";
                                    $vhost_file .= "\tSSLEngine on\n";
                                    $vhost_file .= "\tSSLCertificateFile {$ssl_cert_folder_path}/" . $web_subname . "." . $domain_to_get . ".cert.cert\n";
                                    $vhost_file .= "\tSSLCertificateKeyFile {$ssl_cert_folder_path}/" . $web_subname . "." . $domain_to_get . ".cert.key\n";
                                    if (file_exists("{$ssl_cert_folder_path}/" . $web_subname . "." . $domain_to_get . ".cert.ca")) {
                                        $vhost_file .= "        SSLCertificateChainFile {$ssl_cert_folder_path}/" . $web_subname . "." . $domain_to_get . ".cert.ca\n";
                                    }
                                    break;
                                case "shared_ssl":
                                    $vhost_file .= "<VirtualHost " . $ip_to_write . ":443>\n";
                                    $vhost_file .= "\tSSLEngine on\n";
                                    $vhost_file .= "\tSSLCertificateFile " . $conf_generated_file_path . "/ssl/new.cert.cert\n";
                                    $vhost_file .= "\tSSLCertificateKeyFile " . $conf_generated_file_path . "/ssl/new.cert.key\n";
                                    break;
                            }
                            $vhost_file .= "\tServerName {$web_subname}.{$web_name}\n\tAlias /stats {$web_path}/{$web_name}/subdomains/{$web_subname}/logs\n\tAlias /awstats-icon /usr/share/awstats/icon\n";
                            // Disable the site if expired
                            if ($site_expired == "yes") {
                                $document_root = $conf_generated_file_path . "/expired_site";
                                $vhost_file .= "\tDocumentRoot {$document_root}\n\t<Directory {$document_root}>\n\t\tAllow from all\n\t</Directory>\n";
                            } else {
                                $document_root = "{$web_path}/{$domain_to_get}/subdomains/{$web_subname}/html";
                                $vhost_file .= "\tDocumentRoot {$document_root}\n\t<Directory {$document_root}>\n\t\tAllow from all\n\t</Directory>\n{$vhost_more_conf}\tphp_admin_value safe_mode {$safe_mode_value}\n\tphp_admin_value sendmail_from phpmailfunction{$web_subname}@{$web_name}\n\tphp_admin_value sendmail_path \"/usr/sbin/sendmail -t -i -f phpmailfunction{$web_subname}@{$domain_to_get}\"\n\tphp_value session.save_path {$web_path}/{$domain_to_get}/subdomains/{$web_subname}/tmp\n\t<Location />\n\t\tphp_admin_value open_basedir \"{$web_path}:{$conf_php_library_path}:{$conf_php_additional_library_path}:\"\n\t</Location>\n\t{$cgi_directive}\n" . get_defaultCharsetDirective($subdomain["add_default_charset"]);
                            }
                            $vhost_file .= "\tErrorLog {$web_path}/{$web_name}/subdomains/{$web_subname}/logs/error.log\n\tLogSQLTransferLogTable {$log_tablename}\$xfer\n\tLogSQLScoreDomain {$web_name}\n\tLogSQLScoreSubdomain {$web_subname}\n\tLogSQLScoreTable {$conf_mysql_db}.http_accounting\n\tDirectoryIndex {$conf_apache_directoryindex}{$custom_directives}\n\t<IfModule mod_security.c>\n\t\tSecUploadDir {$web_path}/{$domain_to_get}/subdomains/{$web_subname}/tmp\n\t</IfModule>\n\t<IfModule mod_cband.c>\n\t\tCBandUser {$web_owner}\n\t</IfModule>\n</VirtualHost>\n\n";
                            $logrotate_file .= "{$web_path}/{$web_name}/subdomains/{$web_subname}/logs/error.log ";
                            $num_generated_vhosts += $num_rows2;
                        }
                    }
                }
            }
        }
    }
    // Writting the vhosts.conf file
    $filep = fopen("{$conf_generated_file_path}/{$conf_apache_vhost_path}", "w+");
    if ($filep == NULL) {
        die("Cannot open {$conf_generated_file_path}/{$conf_apache_vhost_path} file for writting");
    }
    fwrite($filep, $vhost_file_listen);
    fwrite($filep, $vhost_file);
    fclose($filep);
    $console .= "{$num_generated_vhosts} vhosts generated !<br>";
    // Writting the vhost_check_dir script
    $filep = fopen("{$conf_generated_file_path}/vhost_check_dir", "w+");
    if ($filep == NULL) {
        echo "Cannot open {$conf_generated_file_path}/vhost_check_dir file for writting";
    } else {
        fwrite($filep, $chk_dir_script);
        fclose($filep);
    }
    $console .= "vhost_check_dir.sh script written !<br>";
    // Writing the vhost_check_ssl_cert script
    $chk_certs_script .= "exit \$EXIT_VAL";
    $filep = fopen("{$conf_generated_file_path}/vhost_check_ssl_cert", "w+");
    if ($filep == NULL) {
        echo "Cannot open {$conf_generated_file_path}/vhost_check_ssl_cert file for writting";
    } else {
        fwrite($filep, $chk_certs_script);
        fclose($filep);
        chmod("{$conf_generated_file_path}/vhost_check_ssl_cert", 0700);
    }
    $console .= "vhost_check_ssl_cert script written !<br>";
    // Writing the logrotate configuration file
    if ($logrotate_file != "") {
        $fname = "";
        if (file_exists("/etc/dtc/logrotate.template")) {
            $fname = "/etc/dtc/logrotate.template";
        } else {
            if (file_exists("/usr/local/etc/dtc/logrotate.template")) {
                $fname = "/usr/local/etc/dtc/logrotate.template";
            }
        }
        if ($fname != "") {
            $fp = fopen($fname, "r");
            if ($fp != NULL) {
                $logrotate_template = fread($fp, filesize($fname));
                fclose($fp);
            } else {
                $logrotate_template = "";
            }
        } else {
            $logrotate_template = "";
        }
        $logrotate_file .= " {\n{$logrotate_template}\n\n\tsharedscripts\n";
        if ($conf_apache_version == "2") {
            $logrotate_file .= "\n\tpostrotate\n\t\tif [ -f /var/run/apache2.pid ]; then\n\t\t\t/etc/init.d/apache2 restart > /dev/null\n\t\tfi\n\tendscript\n}\n";
        } else {
            $logrotate_file .= "\n\tpostrotate\n\t\tif [ -f /var/run/apache.pid ]; then \\\n\t\t\tif [ -x /usr/sbin/invoke-rc.d ]; then \\\n\t\t\t\tinvoke-rc.d apache reload > /dev/null; \\\n\t\t\telse \\\n\t\t\t\tif [ -x /etc/init.d/apache ]; then \\\n\t\t\t\t\t/etc/init.d/apache reload > /dev/null; \\\n\t\t\t\telif [ -x /etc/init.d/httpd ]; then \\\n\t\t\t\t\t/etc/init.d/httpd reload > /dev/null; \\\n\t\t\t\tfi; \\\n\t\t\tfi; \\\n\t\tfi;\n\tendscript\n}\n";
        }
        $filep = fopen("{$conf_generated_file_path}/logrotate", "w+");
        if ($filep == NULL) {
            echo "Cannot open {$conf_generated_file_path}/logrotate for writting";
        } else {
            fwrite($filep, $logrotate_file);
            fclose($filep);
        }
        $console .= "logrotate config file generated!<br>";
    }
    return true;
}
Пример #3
0
function validateWaitingUser($waiting_login_id)
{
    global $conf_administrative_site;
    global $conf_use_ssl;
    global $pro_mysql_admin_table;
    global $pro_mysql_client_table;
    global $pro_mysql_new_admin_table;
    global $pro_mysql_product_table;
    global $pro_mysql_vps_ip_table;
    global $pro_mysql_vps_server_table;
    global $pro_mysql_completedorders_table;
    global $pro_mysql_domain_table;
    global $dtcshared_path;
    global $txt_userwaiting_account_activated_subject;
    global $txt_userwaiting_account_activated_text_header;
    global $conf_site_root_host_path;
    global $conf_demo_version;
    global $conf_use_ssl;
    global $conf_webmaster_email_addr;
    global $conf_this_server_country_code;
    global $conf_message_subject_header;
    global $console;
    //get affiliate cookie
    if (isset($_COOKIE["affiliate"]) && isMailbox($affiliatename)) {
        $affiliatename = $_COOKIE["affiliate"];
    }
    if (isset($affiliatename)) {
        //Step 1: validate that the affiliatename exists
        $q = "SELECT * FROM {$pro_mysql_admin_table} WHERE adm_login='******';";
        $r = mysql_query($q) or die("Cannot execute query \"{$q}\" ! line: " . __LINE__ . " file: " . __FILE__ . " sql said: " . mysql_error());
        if (mysql_num_rows($r) != 1) {
            unset($affiliatename);
        }
        // at this point, we should have an affiliatename
    }
    // Get the informations from the user waiting table
    $q = "SELECT * FROM {$pro_mysql_new_admin_table} WHERE id='{$waiting_login_id}';";
    //	$q = "SELECT * FROM $pro_mysql_new_admin_table WHERE reqadm_login='******';";
    $r = mysql_query($q) or die("Cannot execute query \"{$q}\" ! line: " . __LINE__ . " file: " . __FILE__ . " sql said: " . mysql_error());
    $n = mysql_num_rows($r);
    if ($n != 1) {
        die("I can't find username with id {$waiting_login_id} in the userwaiting table line: " . __LINE__ . " file: " . __FILE__ . "!");
    }
    $a = mysql_fetch_array($r);
    $waiting_login = $a["reqadm_login"];
    $last_used_lang = $a["last_used_lang"];
    // Check if there is a user by that name
    $q = "SELECT * FROM {$pro_mysql_admin_table} WHERE adm_login='******';";
    $r = mysql_query($q) or die("Cannot execute query \"{$q}\" ! line: " . __LINE__ . " file: " . __FILE__ . " sql said: " . mysql_error());
    $n = mysql_num_rows($r);
    if ($a["add_service"] == "yes") {
        if ($n != 1) {
            die("There is no user with name {$waiting_login} in database: I can't add a service to it line: " . __LINE__ . " file: " . __FILE__ . "!");
        }
        $existing_admin = mysql_fetch_array($r);
        $cid = $existing_admin["id_client"];
        $vps_root_pass = $existing_admin["adm_pass"];
    } else {
        if ($n != 0) {
            die("There is already a user with name {$waiting_login} in database: I can't add another one line: " . __LINE__ . " file: " . __FILE__ . "!");
        }
        $vps_root_pass = $a["reqadm_pass"];
    }
    // Calculate user's path with default path
    $newadmin_path = $conf_site_root_host_path . "/" . $waiting_login;
    // Create admin's directory
    if ($conf_demo_version == "no" && $a["add_service"] != "yes") {
        $oldumask = umask(0);
        if (!file_exists($newadmin_path)) {
            mkdir("{$newadmin_path}", 0750);
            $console .= "mkdir {$newadmin_path};<br>";
        }
    }
    // Get the informations from the product table
    $q2 = "SELECT * FROM {$pro_mysql_product_table} WHERE id='" . $a["product_id"] . "'";
    $r2 = mysql_query($q2) or die("Cannot execute query \"{$q2}\" ! line: " . __LINE__ . " file: " . __FILE__ . " sql said: " . mysql_error());
    $n2 = mysql_num_rows($r2);
    if ($n2 != 1) {
        die("I can't find the product in the table line: " . __LINE__ . " file: " . __FILE__ . "!");
    }
    $a2 = mysql_fetch_array($r2);
    // Add customer's info to production table
    if ($a["add_service"] != "yes") {
        $adm_query = "INSERT INTO {$pro_mysql_client_table}\n(id,is_company,company_name,vat_num,familyname,christname,addr1,addr2,addr3,\ncity,zipcode,state,country,phone,fax,email,\ndisk_quota_mb,bw_quota_per_month_gb,\nspecial_note) VALUES ('','" . $a["iscomp"] . "',\n'" . addslashes($a["comp_name"]) . "','" . addslashes($a["vat_num"]) . "','" . addslashes($a["family_name"]) . "','" . addslashes($a["first_name"]) . "',\n'" . addslashes($a["addr1"]) . "','" . addslashes($a["addr2"]) . "','" . addslashes($a["addr3"]) . "','" . addslashes($a["city"]) . "',\n'" . addslashes($a["zipcode"]) . "','" . addslashes($a["state"]) . "','" . addslashes($a["country"]) . "','" . addslashes($a["phone"]) . "',\n'" . addslashes($a["fax"]) . "','" . addslashes($a["email"]) . "','" . $a2["quota_disk"] . "','" . $a2["bandwidth"] / 1024 . "',\n'" . addslashes($a["restricted_ftp_path"]) . "','" . addslashes($a["allow_dns_and_mx_change"]) . "',\n'" . addslashes($a["ftp_login_flag"]) . "','" . addslashes($a["allow_mailing_list_edit"]) . "','" . addslashes($a["allow_subdomain_edit"]) . "',\n'" . addslashes($a["custom_notes"]) . "');";
        $r = mysql_query($adm_query) or die("Cannot execute query \"{$adm_query}\" ! line: " . __LINE__ . " file: " . __FILE__ . " sql said: " . mysql_error());
        $cid = mysql_insert_id();
    }
    // Add user in database
    $expires = calculateExpirationDate(date("Y-m-d"), $a2["period"]);
    if ($a2["heb_type"] == "vps") {
        $admtbl_added1 = ",expire,prod_id";
        $admtbl_added2 = ",'0000-00-00','0'";
    } else {
        if ($a2["heb_type"] == "server") {
            $admtbl_added1 = ",expire,prod_id";
            $admtbl_added2 = ",'0000-00-00','0'";
        } else {
            $admtbl_added1 = ",expire,prod_id";
            $admtbl_added2 = ",'{$expires}','" . $a2["id"] . "'";
            $admtbl_added3 = ", expire='{$expires}', prod_id='" . $a2["id"] . "' ";
        }
    }
    if ($a["add_service"] != "yes") {
        $adm_query = "INSERT INTO {$pro_mysql_admin_table}\n(adm_login        ,adm_pass              ,last_used_lang   ,path            ,id_client,bandwidth_per_month_mb,quota,nbrdb,allow_add_domain,max_domain,restricted_ftp_path,allow_dns_and_mx_change,ftp_login_flag,allow_mailing_list_edit,allow_subdomain_edit,max_email{$admtbl_added1}) VALUES\n('{$waiting_login}','" . $a["reqadm_pass"] . "','{$last_used_lang}','{$newadmin_path}','{$cid}','" . $a2["bandwidth"] . "','" . $a2["quota_disk"] . "','" . $a2["nbr_database"] . "','" . $a2["allow_add_domain"] . "','" . $a2["max_domain"] . "',\n'" . $a2["restricted_ftp_path"] . "','" . $a2["allow_dns_and_mx_change"] . "','" . $a2["ftp_login_flag"] . "','" . $a2["allow_mailing_list_edit"] . "','" . $a2["allow_subdomain_edit"] . "','" . $a2["nbr_email"] . "'{$admtbl_added2});";
        mysql_query($adm_query) or die("Cannot execute query \"{$adm_query}\" ! line: " . __LINE__ . " file: " . __FILE__ . " sql said: " . mysql_error());
    } else {
        if ($a2["heb_type"] == "shared") {
            $adm_query = "UPDATE {$pro_mysql_admin_table}\n\t\t\tSET bandwidth_per_month_mb='" . $a2["bandwidth"] . "', quota='" . $a2["quota_disk"] . "', nbrdb='" . $a2["nbr_database"] . "',\n\t\t\tallow_add_domain='" . $a2["allow_add_domain"] . "', max_domain='" . $a2["max_domain"] . "', restricted_ftp_path='" . $a2["restricted_ftp_path"] . "',\n\t\t\tallow_dns_and_mx_change='" . $a2["allow_dns_and_mx_change"] . "', ftp_login_flag='" . $a2["ftp_login_flag"] . "', allow_mailing_list_edit='" . $a2["allow_mailing_list_edit"] . "',\n\t\t\tallow_subdomain_edit='" . $a2["allow_subdomain_edit"] . "', max_email='" . $a2["nbr_email"] . "' {$admtbl_added3}\n\t\t\tWHERE adm_login='******';";
            mysql_query($adm_query) or die("Cannot execute query \"{$adm_query}\" ! line: " . __LINE__ . " file: " . __FILE__ . " sql said: " . mysql_error());
        }
    }
    if ($a2["heb_type"] == "vps") {
        $vps_xen_name = addVPSToUser($waiting_login, $a["vps_location"], $a2["id"], $a["vps_os"]);
        $soap_client = connectToVPSServer($a["vps_location"]);
        if ($soap_client == false) {
            echo "Could not connect to the VPS server for doing the setup: please contact the administrator!";
        } else {
            $image_type = "lvm";
            if (isVPSNodeLVMEnabled($a["vps_location"]) == "no") {
                $image_type = "vbd";
            }
            $r = $soap_client->call("setupLVMDisks", array("vpsname" => $vps_xen_name, "hddsize" => $a2["quota_disk"], "swapsize" => $a2["memory_size"], "imagetype" => $image_type), "", "", "");
            $qvps = "SELECT * FROM {$pro_mysql_vps_ip_table} WHERE vps_server_hostname='" . $a["vps_location"] . "' AND vps_xen_name='{$vps_xen_name}' LIMIT 1;";
            $rvps = mysql_query($qvps) or die("Cannot execute query \"{$qvps}\" line " . __LINE__ . " file: " . __FILE__ . " sql said: " . mysql_error());
            $nvps = mysql_num_rows($rvps);
            if ($nvps != 1) {
                echo "Cannot find VPS IP: wont be able to setup the os, please get in touch with the administrator!";
            } else {
                $avps = mysql_fetch_array($rvps);
                $r = $soap_client->call("reinstallVPSos", array("vpsname" => $vps_xen_name, "ostype" => $a["vps_os"], "hddsize" => $a2["quota_disk"], "ramsize" => $a2["memory_size"], "ipaddr" => $avps["ip_addr"], "password" => $vps_root_pass), "", "", "");
                $qcountry = "SELECT * FROM {$pro_mysql_vps_server_table} WHERE hostname='" . $a["vps_location"] . "';";
                $rcountry = mysql_query($qcountry) or die("Cannot execute query \"{$qcountry}\" line " . __LINE__ . " file: " . __FILE__ . " sql said: " . mysql_error());
                $ncountry = mysql_num_rows($rcountry);
                if ($ncountry != 1) {
                    echo "Cannot find VPS server country!";
                    $country = 'US';
                } else {
                    $acountry = mysql_fetch_array($rcountry);
                    $country = $acountry["country_code"];
                }
            }
        }
        // Read the (customizable) registration message to send
        $txt_welcome_message = readCustomizedMessage("registration_msg/vps_open", $waiting_login);
    } else {
        if ($a2["heb_type"] == "server") {
            // As there is currently no dedicated server provision system, we just do this:
            $country = $conf_this_server_country_code;
            addDedicatedToUser($waiting_login, $a["domain_name"], $a2["id"]);
            // Read the (customizable) registration message to send
            $txt_welcome_message = readCustomizedMessage("registration_msg/dedicated_open", $waiting_login);
        } else {
            $country = $conf_this_server_country_code;
            addDomainToUser($waiting_login, $a["reqadm_pass"], $a["domain_name"]);
            // Read the (customizable) registration message to send
            $txt_welcome_message = readCustomizedMessage("registration_msg/shared_open", $waiting_login);
            $q = "UPDATE {$pro_mysql_domain_table} SET max_email='" . $a2["nbr_email"] . "',quota='" . $a2["quota_disk"] . "' WHERE name='" . $a["domain_name"] . "';";
            $r = mysql_query($q) or die("Cannot execute query \"{$q}\" ! line: " . __LINE__ . " file: " . __FILE__ . " sql said: " . mysql_error());
        }
    }
    // Send a mail to user with how to login and use interface.
    $txt_userwaiting_account_activated_subject = "{$conf_message_subject_header} Account {$waiting_login} has been activated!";
    // Manage the signature of all registration messages
    $signature = readCustomizedMessage("signature", $waiting_login);
    $msg_2_send = str_replace("%%%SIGNATURE%%%", $signature, $txt_welcome_message);
    // Manage the login info part of the message
    if ($conf_use_ssl == "yes") {
        $surl = "s";
    } else {
        $surl = "";
    }
    $dtc_login_info = "URL: http{$surl}://{$conf_administrative_site}/dtc/\nLogin: {$waiting_login}\nPassword: "******"reqadm_pass"];
    $msg_2_send = str_replace("%%%DTC_LOGIN_INFO%%%", $dtc_login_info, $msg_2_send);
    // Manage the header of the messages
    $head = readCustomizedMessage("messages_header", $waiting_login);
    $msg_2_send = $head . "\n" . $msg_2_send;
    $headers = "From: " . $conf_webmaster_email_addr;
    mail($a["email"], $txt_userwaiting_account_activated_subject, $msg_2_send, $headers);
    // Now add a command to the user so we keep tracks of payments
    $q = "INSERT INTO {$pro_mysql_completedorders_table} (id,id_client,domain_name,quantity,date,product_id,payment_id,country_code,last_expiry_date)\n\tVALUES ('','{$cid}','" . $a["domain_name"] . "','1','" . date("Y-m-d") . "','" . $a["product_id"] . "','" . $a["paiement_id"] . "','{$country}','" . date("Y-d-m") . "');";
    mysql_query($q) or die("Cannot execute query \"{$q}\" ! line: " . __LINE__ . " file: " . __FILE__ . " sql said: " . mysql_error());
    if (isset($affiliatename)) {
        // Step 2) retrieve the kickback from the products table
        $kickback = $a2["affiliate_kickback"];
        $orderid = mysql_insert_id();
        if ($kickback) {
            // Step 3) if a kickback exists, store it in the affiliate transaction table
            $kickback = 1.0 + $kickback - 1.0;
            //cast to float.  I hate PHP.
            $xxs = "INSERT INTO affiliate_payments (adm_login,order_id,kickback) VALUES('{$affiliatename}',{$orderid},{$kickback});";
            mysql_query($q) or die("Cannot execute query \"{$q}\" ! line: " . __LINE__ . " file: " . __FILE__ . " sql said: " . mysql_error());
        }
    }
    // Finaly delete the user from the userwaiting table
    $q = "DELETE FROM {$pro_mysql_new_admin_table} WHERE id='{$waiting_login_id}';";
    mysql_query($q) or die("Cannot execute query \"{$q}\" ! line: " . __LINE__ . " file: " . __FILE__ . " sql said: " . mysql_error());
}
Пример #4
0
 $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
 $n = mysql_num_rows($r);
 if ($n != 1) {
     die("Didn't find the IP address you want to add line " . __LINE__ . " file " . __FILE__);
 }
 $a = mysql_fetch_array($r);
 $q = "UPDATE {$pro_mysql_vps_ip_table} SET available='no' WHERE vps_xen_name='" . $a["vps_xen_name"] . "' AND vps_server_hostname='" . $a["vps_server_hostname"] . "';";
 $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
 $q = "SELECT * FROM {$pro_mysql_product_table} WHERE id='" . $_REQUEST["product_id"] . "';";
 $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
 $n = mysql_num_rows($r);
 if ($n != 1) {
     die("Didn't find the IP address you want to add line " . __LINE__ . " file " . __FILE__);
 }
 $prod = mysql_fetch_array($r);
 $exp_date = calculateExpirationDate(date("Y-m-d"), $prod["period"]);
 $q = "INSERT INTO {$pro_mysql_vps_table} (id,owner,vps_server_hostname,vps_xen_name,start_date,expire_date,hddsize,ramsize,bandwidth_per_month_gb,product_id)\n\tVALUES('','{$adm_login}','" . $a["vps_server_hostname"] . "','" . $a["vps_xen_name"] . "','" . date("Y-m-d") . "','{$exp_date}','" . $prod["quota_disk"] . "','" . $prod["memory_size"] . "','" . $prod["bandwidth"] . "','" . $_REQUEST["product_id"] . "');";
 $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
 // Setup the physical VPS (do the lvcreate remotly)
 if ($_REQUEST["physical_setup"] == "yes") {
     $soap_client = connectToVPSServer($a["vps_server_hostname"]);
     if ($soap_client == false) {
         echo "Could not connect to the VPS server for doing the setup: please contact the administrator!";
     } else {
         $image_type = "lvm";
         if (isVPSNodeLVMEnabled($a["vps_server_hostname"]) == "no") {
             $image_type = "vbd";
         }
         $r = $soap_client->call("setupLVMDisks", array("vpsname" => $a["vps_xen_name"], "hddsize" => $prod["quota_disk"], "swapsize" => $prod["memory_size"], "imagetype" => $image_type), "", "", "");
     }
 }
Пример #5
0
function addVPSToUser($adm_login, $vps_server_hostname, $product_id, $operating_system = "debian")
{
    global $pro_mysql_product_table;
    global $pro_mysql_vps_ip_table;
    global $pro_mysql_vps_table;
    $q = "SELECT * FROM {$pro_mysql_product_table} WHERE id='{$product_id}';";
    $r = mysql_query($q) or die("Cannot query : \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said " . mysql_error());
    $n = mysql_num_rows($r);
    if ($n != 1) {
        die("Cannot find product line " . __LINE__ . " file " . __FILE__);
    }
    $product = mysql_fetch_array($r);
    $q = "SELECT * FROM {$pro_mysql_vps_ip_table} WHERE available='yes' AND vps_server_hostname='{$vps_server_hostname}' LIMIT 1;";
    $r = mysql_query($q) or die("Cannot query : \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said " . mysql_error());
    $n = mysql_num_rows($r);
    if ($n != 1) {
        die("Cannot find available IP and Xen name in {$vps_server_hostname} line " . __LINE__ . " file " . __FILE__);
    }
    $vps_ip = mysql_fetch_array($r);
    $q = "UPDATE {$pro_mysql_vps_ip_table} SET available='no',rdns_addr='mx.xen" . $vps_ip["vps_xen_name"] . "." . $vps_ip["vps_server_hostname"] . "' WHERE vps_xen_name='" . $vps_ip["vps_xen_name"] . "' AND vps_server_hostname='" . $vps_ip["vps_server_hostname"] . "';";
    $r = mysql_query($q) or die("Cannot query : \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said " . mysql_error());
    $exp_date = calculateExpirationDate(date("Y-m-d"), $product["period"]);
    $q = "INSERT INTO {$pro_mysql_vps_table} (id,owner,vps_server_hostname,vps_xen_name,start_date,expire_date,hddsize,ramsize,product_id,bandwidth_per_month_gb,operatingsystem)\n\tVALUES('','{$adm_login}','" . $vps_ip["vps_server_hostname"] . "','" . $vps_ip["vps_xen_name"] . "','" . date("Y-m-d") . "','{$exp_date}','" . $product["quota_disk"] . "','" . $product["memory_size"] . "','{$product_id}','" . $product["bandwidth"] . "','{$operating_system}');";
    $r = mysql_query($q) or die("Cannot query : \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said " . mysql_error());
    updateUsingCron("gen_named='yes',reload_named ='yes'");
    // Subscribe user to the lists of the VPS
    VPS_Server_Subscribe_To_Lists($vps_server_hostname);
    return $vps_ip["vps_xen_name"];
}
Пример #6
0
 function Header()
 {
     global $company;
     global $cc_code_array;
     global $conf_generated_file_path;
     global $client;
     global $product;
     global $completedorder;
     global $pay;
     global $eu_vat_warning;
     global $use_vat;
     global $secpayconf_currency_letters;
     // First line
     $first_line = $company["name"];
     $first_line .= ", " . str_replace("\n", ", ", str_replace("\r", "", $company["address"]));
     $first_line .= ", " . $cc_code_array[$company["country"]];
     $this->SetXY(10, 10);
     $this->SetFont('Arial', '', 8);
     $this->Cell(30, 20, $first_line);
     // Company logo
     $this->SetXY(10, 20);
     if ($company["logo_path"] != "none" && $company["logo_path"] != "") {
         $this->Image("{$conf_generated_file_path}/invoice_pics/" . $company["logo_path"], 10, 22, 80);
     }
     $this->SetXY(130, 20);
     $this->SetFont('Arial', 'BI', 24);
     $this->Cell(40, 22, "Invoice");
     $this->SetXY(130, 28);
     $this->SetFont('Arial', 'I', 12);
     $ze_date = explode("-", $completedorder["date"]);
     $pt_date = $ze_date[0] . $ze_date[1] . $ze_date[2];
     //		$pt_date = $pt_date * 10000;
     //		$pt_date += $completedorder["id"];
     $pt_date_plus = 100000000 + $completedorder["id"];
     $text_number = $pt_date . $pt_date_plus;
     $this->Cell(40, 22, "Number: {$text_number}");
     $this->SetXY(130, 34);
     $this->Cell(40, 22, "Payid: " . $pay["id"]);
     $this->SetXY(130, 40);
     $this->Cell(40, 22, "Payment date: " . $pt_date);
     //header("Content-Disposition: attachment; filename=\"".$pt_date_plus."_gplhost.pdf\"");
     // From:
     $this->SetXY(10, 50);
     $this->SetFont('Arial', 'BU', 12);
     $this->Cell(30, 7, "From:");
     $this->Ln();
     $this->SetFont('Arial', '', 12);
     $this->Cell(120, 6, $company["name"]);
     $this->Ln();
     $addr = str_replace("\r", "", $company["address"]);
     $addr_ar = explode("\n", $addr);
     $nbr_line = sizeof($addr_ar);
     for ($i = 0; $i < $nbr_line; $i++) {
         $this->Cell(30, 5, $addr_ar[$i]);
         $this->Ln();
     }
     $this->Cell(120, 5, $cc_code_array[$company["country"]]);
     $this->Ln();
     if ($company["vat_number"] != "" && $company["vat_rate"] != "0.00") {
         $this->Cell(120, 6, "VAT number: " . $company["vat_number"]);
         $this->Ln();
     }
     $this->Ln();
     $this->Ln();
     $left = $this->GetY();
     // To:
     $this->SetXY(105, 50);
     $this->SetFont('Arial', 'BU', 12);
     $this->Cell(30, 7, "To:");
     $this->Ln();
     $this->SetX(105);
     $this->SetFont('Arial', '', 12);
     $this->Cell(120, 6, $client["christname"] . " " . $client["familyname"]);
     $this->Ln();
     $this->SetX(105);
     if ($client["is_company"]) {
         $this->Cell(120, 6, $client["company_name"]);
         $this->Ln();
         $this->SetX(105);
     }
     $this->Cell(120, 6, $client["addr1"]);
     $this->Ln();
     $this->SetX(105);
     if ($client["addr2"] != "") {
         $this->Cell(120, 6, $client["addr2"]);
         $this->Ln();
         $this->SetX(105);
     }
     if ($client["addr3"] != "") {
         $this->Cell(120, 6, $client["addr3"]);
         $this->Ln();
         $this->SetX(105);
     }
     if ($client["country"] == "US") {
         $this->Cell(120, 6, $client["city"]);
         $this->Ln();
         $this->SetX(105);
         $this->Cell(120, 6, $client["state"] . " " . $client["zipcode"]);
         $this->Ln();
         $this->SetX(105);
     } else {
         $this->Cell(120, 6, $client["zipcode"] . " " . $client["city"]);
         $this->Ln();
         $this->SetX(105);
         if ($client["state"] != "") {
             $this->Cell(120, 6, $client["state"]);
             $this->Ln();
             $this->SetX(105);
         }
     }
     $this->Cell(120, 6, $cc_code_array[$client["country"]]);
     $this->Ln();
     $this->SetX(105);
     if ($eu_vat_warning == "yes") {
         $this->Cell(120, 6, "VAT num: " . $client["vat_num"]);
         $this->Ln();
         $this->SetX(105);
     }
     $this->Ln();
     $this->Ln();
     $right = $this->GetY();
     $this->SetXY(10, max($left, $right));
     // VAT calculation
     if ($use_vat == "yes") {
         $without_vat = round($pay["paiement_total"] / (1 + $pay["vat_rate"] / 100), 2);
         $vat = $pay["paiement_total"] - $without_vat;
     } else {
         $without_vat = $pay["paiement_total"];
         $vat = $pay["paiement_total"] - $without_vat;
     }
     $gateway_cost = $without_vat - $product["price_dollar"];
     // The table
     $this->SetFont('Arial', 'B', 11);
     $this->Cell(80, 7, "Product", "1", 0, "L");
     $this->Cell(20, 7, "Start date", "1", 0, "L");
     $this->Cell(20, 7, "End date", "1", 0, "L");
     $this->Cell(15, 7, "Price", "1", 0, "L");
     $this->Cell(25, 7, "Pay Gateway", "1", 0, "L");
     if ($use_vat == "yes") {
         $this->Cell(30, 7, "Total with VAT", "1", 0, "L");
     } else {
         $this->Cell(30, 7, "Total", "1", 0, "L");
     }
     $this->Ln();
     $this->SetFont('Arial', '', 10);
     $this->Cell(80, 7, $product["name"], "1", 0, "L");
     $this->Cell(20, 7, $completedorder["last_expiry_date"], "1", 0, "L");
     $date_expire = calculateExpirationDate($completedorder["last_expiry_date"], $product["period"]);
     $this->Cell(20, 7, $date_expire, "1", 0, "L");
     $this->Cell(15, 7, $product["price_dollar"] . " " . $secpayconf_currency_letters, "1", 0, "L");
     // $this->Cell(25,7,$pay["paiement_cost"]." ".$secpayconf_currency_letters,"1",0,"L");
     $this->Cell(25, 7, $gateway_cost . " " . $secpayconf_currency_letters, "1", 0, "L");
     $this->Cell(30, 7, $pay["paiement_total"] . " " . $secpayconf_currency_letters, "1", 0, "L");
     $this->Ln();
     // Print the VAT total, etc.
     if ($use_vat == "yes") {
         $this->SetX(120);
         $this->SetFont('Arial', 'B', 12);
         $this->Cell(50, 7, "Total VAT (" . $pay["vat_rate"] . "%):", "1", 0, "L");
         $this->SetFont('Arial', '', 12);
         $this->Cell(30, 7, $vat . " " . $secpayconf_currency_letters, "1", 0, "L");
         $this->Ln();
         $this->SetX(120);
         $this->SetFont('Arial', 'B', 12);
         $this->Cell(50, 7, "Total excluding VAT:", "1", 0, "L");
         $this->SetFont('Arial', '', 12);
         $this->Cell(30, 7, $without_vat . " " . $secpayconf_currency_letters, "1", 0, "L");
         $this->Ln();
         $this->SetX(120);
         $this->SetFont('Arial', 'B', 12);
         $this->Cell(50, 7, "Total paid:", "1", 0, "L");
         $this->SetFont('Arial', '', 12);
         $this->Cell(30, 7, $pay["paiement_total"] . " " . $secpayconf_currency_letters, "1", 0, "L");
         $this->Ln();
     }
     if ($eu_vat_warning == "yes") {
         $this->Cell(190, 7, "Export in the EU: invoice without VAT, and customer shall pay VAT in it's own country.", "1", 0, "L");
         $this->Ln();
     }
     // Free text
     $this->SetFont('Arial', '', 10);
     $this->MultiCell(190, 5, stripslashes($company["text_after"]));
 }