diff --git a/Panel/modules/reseller/account_details.php b/Panel/modules/reseller/account_details.php new file mode 100755 index 00000000..a2a1b785 --- /dev/null +++ b/Panel/modules/reseller/account_details.php @@ -0,0 +1,185 @@ + +isAdmin($_SESSION['user_id']); + + echo "

".get_lang('account_details')."

"; + + if( isset( $_POST['remove'] ) ) + { + require_once("modules/config_games/server_config_parser.php"); + require_once("includes/lib_remote.php"); + $user_homes = $db->resultQuery( "SELECT * + FROM OGP_DB_PREFIXreseller_homes + WHERE home_id=" . $_POST['home_id'] ); + $user_home = $user_homes[0]; + $user_id = $user_home['user_id']; + $home_id = $user_home['home_id']; + $home_info = $db->getGameHomeWithoutMods($home_id); + $server_info = $db->getRemoteServerById($home_info['remote_server_id']); + $remote = new OGPRemoteLibrary($server_info['agent_ip'], $server_info['agent_port'], $server_info['encryption_key']); + $update_ftp_users = "pure-pw userdel ".$home_id." && pure-pw mkdb"; + $remote->sudo_exec( $update_ftp_users ); + $addresses = $db->getHomeIpPorts($home_id); + foreach($addresses as $address) + { + $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']); + if(isset($server_xml->control_protocol_type))$control_type = $server_xml->control_protocol_type; else $control_type = ""; + $remote->remote_stop_server($home_id,$address['ip'],$address['port'],$server_xml->control_protocol,$home_info['control_password'],$control_type); + } + + // Unassign Home to the current owner at DB. + $db->unassignHomeFrom("user", $user_id, $home_id); + + // Remove the game home from DB + $db->deleteGameHome($home_id); + + // Remove the game home files from remote server + $remote->remove_home($home_info['home_path']); + + print_success(get_lang_f('home_id_deleted_successfully', $home_id) ); + + // Restore slots in the reseller account + $qry_accounts = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE account_id=".$user_home['account_id']); + $account = $qry_accounts[0]; + $update_available_slots = $account['available_slots'] + $user_home['assigned_slots']; + $db->query("UPDATE OGP_DB_PREFIXreseller_accounts SET available_slots=".$update_available_slots." WHERE account_id=".$account['account_id']); + + // Delete the reseller home entry + $db->query( "DELETE FROM OGP_DB_PREFIXreseller_homes + WHERE home_id=" . $home_id); + + print_success(get_lang_f('the_amount_of_available_slots_has_been_incremented_to', $update_available_slots) ); + } + + $filter = isset($_GET['account_id']) ? "account_id=".$_GET['account_id'] : ""; + $filter_and = isset($_GET['account_id']) ? $filter." AND" : ""; + $user_account = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE $filter_and user_id=".$_SESSION['user_id']); + $where_filter = isset($_GET['account_id']) ? " WHERE ".$filter : ""; + $reseller_homes = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_homes".$where_filter); + + if( ! empty($reseller_homes) AND ( !empty($user_account[0]) or $isAdmin ) ) + { + echo ""; + echo "". + ""; + if($isAdmin) + { + echo ""; + } + echo "". + "". + ""; + $i = 0; + foreach($reseller_homes as $user_home) + { + // reseller home data + $account_id = $user_home['account_id']; + $assigned_slots = $user_home['assigned_slots']; + $status = $user_home['status']; + $user_id = $user_home['user_id']; + $home_id = $user_home['home_id']; + + // reseller account data + $rs_account = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE account_id=".$account_id); + // reseller user info + $rs_user_info = $db->getUserById($rs_account[0]['user_id']); + $reseller_username = $rs_user_info['users_login']; + // owner user info + $ow_user_info = $db->getUserById($user_id); + $owner_username = $ow_user_info['users_login']; + + $row = $db->getUserGameHome($user_id,$home_id); + echo "\n"; + echo "\n"; + } + echo "
".get_lang('home_id')."".get_lang('game_server')."".get_lang('owner_user_name')."".get_lang('reseller_user_name')."".get_lang('assigned_slots')."".get_lang('status')."".get_lang('remove_server')."
$home_id$row[game_name]"; + echo empty($row['home_name']) ? get_lang('not_available') : " (".$row['home_name'].")"; + echo ""; + if($isAdmin) + { + ?> + + \n"; + echo ""; + ?> + + $assigned_slots ".get_lang('slots'). + "\n".$status."\n". + "
\n\n
\n". + "
\n"; + } + elseif( $isAdmin AND !isset( $_GET['account_id'] ) ) + print_failure(get_lang('there_is_no_reseller_homes_related_to_any_reseller_account')); + else + { + print_failure(get_lang('there_are_no_game_servers_related_to_the_selected_reseller_account')); + } + echo create_back_button($_GET['m'], $_GET['bt']); +} +?> \ No newline at end of file diff --git a/Panel/modules/reseller/accounts.php b/Panel/modules/reseller/accounts.php new file mode 100755 index 00000000..07481652 --- /dev/null +++ b/Panel/modules/reseller/accounts.php @@ -0,0 +1,187 @@ +query("DELETE FROM OGP_DB_PREFIXreseller_accounts WHERE cart_id=".$_POST['cart_id']); + $query_delete_account = $db->query("DELETE FROM OGP_DB_PREFIXreseller_carts WHERE cart_id=".$_POST['cart_id']); + } + if(isset($_POST['paid'])) + { + $query = "UPDATE OGP_DB_PREFIXreseller_carts + SET paid=1 + WHERE cart_id=".$_POST['cart_id']; + $db->query($query); + + $query = "UPDATE OGP_DB_PREFIXreseller_accounts + SET payment_date=NOW() + WHERE cart_id=".$_POST['cart_id']; + $db->query($query); + + $cart_accounts = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE cart_id=".$_POST['cart_id']); + foreach ( $cart_accounts as $account ) + { + $months = $account['invoice_duration'] == "month" ? 1 : 12; + $total_months = $months * $account['qty']; + + $db->query("UPDATE OGP_DB_PREFIXreseller_accounts + SET available_months=".$total_months. + " WHERE account_id=".$account['account_id'] ); + + $db->query( "UPDATE OGP_DB_PREFIXreseller_accounts ". + "SET status=ADDDATE(DATE(NOW() + INTERVAL ".$total_months." MONTH), 1) ". + "WHERE account_id=".$account['account_id'] ); + } + } + $status_array = array ( "not_paid" => 0, + "paid" => 1, + "awaiting_payment" => 2, + "paid_and_installed" => 3 + ); + ?> +

+ $paid_value) + { + $carts = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_carts WHERE paid=$paid_value"); + if( $carts > 0 ) + { + ?> +

+
+ + + + + + + + + resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE cart_id=".$cart['cart_id']); + $subtotal = 0; + $i = 0; + foreach($accounts as $account) + { + ?> + + + + + + + + + + + + + +
getUserById($account['user_id']); echo $user['users_login'];?> + 0) + { + ?> + + () + + + resultQuery($qry_services); + $service = $services[0]; + $invoice_duration = $account['qty'] > 1 ? $account['invoice_duration']."s" : $account['invoice_duration']; + echo $service['service_name']." [ ".$service['slot_max_qty']." ".get_lang('slots').", ".$account['qty']." ".get_lang($invoice_duration)." ]";?>
+ +
+ + + "> +
+ +
+ + "> +
+ +
+ + "> +
+ +
+
+ + "> +
+
+ ".number_format( $subtotal , 2 ).$carts[0]['currency'].""; ?> + + ".$cart['tax_amount']."% (".number_format( $cart['tax_amount']/100*$subtotal, 2 ).$carts[0]['currency'].")"; ?> + + ".number_format( $total , 2 ).$carts[0]['currency'].""; ?> +
+
+ \ No newline at end of file diff --git a/Panel/modules/reseller/add_to_cart.php b/Panel/modules/reseller/add_to_cart.php new file mode 100755 index 00000000..56cbc1ed --- /dev/null +++ b/Panel/modules/reseller/add_to_cart.php @@ -0,0 +1,102 @@ +getSettings(); + + $service_id = $_REQUEST['service_id']; + + // Query for Selected service info. + $services = $db->resultQuery("SELECT DISTINCT * FROM OGP_DB_PREFIXreseller_services WHERE service_id=".$service_id); + $service = $services[0]; + //Compiling info about invoice to create an invoice order. + + $qty = $_POST['qty']; + $invoice_duration = $_POST['invoice_duration']; + $user_id = $_SESSION['user_id']; + $tax_amount = $settings['tax_amount']; + $currency = $settings['currency']; + + if ($invoice_duration == "month") + { + $price_pack = $service['price_per_month']; + } + elseif ($invoice_duration == "year") + { + $price_pack = $service['price_per_year']; + } + + $price = $price_pack * $qty; + + if( isset( $_POST['code'] ) and $_POST['code'] != "" ) + { + $discount_info = $db->resultQuery("SELECT DISTINCT percentage FROM OGP_DB_PREFIXreseller_discount_codes WHERE code='".$_POST['code']."'"); + if(!empty($discount_info)) + { + $discount_percentage = $discount_info[0]['percentage']; + $discount_qty = ( $price / 100 ) * $discount_percentage; + if( $discount_qty > 0 ) + $price = $price - $discount_qty; + } + else + { + $discount_percentage = 0; + } + } + else + { + $discount_percentage = 0; + } + + global $view; + + if( isset( $_POST["add_to_cart"] ) ) + { + if( isset( $_SESSION['CART'] ) ) + { + $i = count( $_SESSION['CART'] ); + $i++; + } + else + { + $i = 0; + } + + $_SESSION['CART'][$i] = array( "cart_id" => $i, + "service_id" => $service_id, + "user_id" => $_SESSION['user_id'], + "qty" => $qty, + "invoice_duration" => $invoice_duration, + "discount" => $discount_percentage, + "price" => $price, + "tax_amount" => $tax_amount, + "currency" => $currency, + "paid" => 0, + "status" => 0); + echo ''; + } +} +?> \ No newline at end of file diff --git a/Panel/modules/reseller/assign_server.php b/Panel/modules/reseller/assign_server.php new file mode 100755 index 00000000..d135c332 --- /dev/null +++ b/Panel/modules/reseller/assign_server.php @@ -0,0 +1,592 @@ + + + ".get_lang($selection.'_info').""; +} +function exec_ogp_module() +{ + global $db,$view,$settings; + echo "

".get_lang('rs_assign_servers')."

"; + + $remote_servers = $db->getRemoteServers(); + if( $remote_servers === FALSE ) + { + echo "

".get_lang('no_remote_servers_configured')."

+

".get_lang('add_remote_server')."

"; + + return; + } + + $game_cfgs = $db->getGameCfgs(); + $users = $db->getUserList(); + + if ( $game_cfgs === FALSE ) + { + echo "

".get_lang('no_game_configurations_found')." ".get_lang('game_configurations')."

"; + return; + } + + $selections = array( "allow_updates" => "u", + "allow_file_management" => "f", + "allow_parameter_usage" => "p", + "allow_extra_params" => "e", + "allow_ftp" => "t"); + + if ( isset($_REQUEST['add_game_server']) ) + { + $rserver_id = $_POST['rserver_id']; + $home_cfg_id = $_POST['home_cfg_id']; + $mod_cfg_id = $_POST['mod_cfg_id']; + $max_players = $_POST['max_players']; + $web_user_id = trim($_POST['web_user_id']); + $qry_accounts = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE account_id=".$_POST['account_id']); + $account = $qry_accounts[0]; + $qry_service = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_services WHERE service_id=".$account['service_id']); + $service = $qry_service[0]; + $max_access_rights = $service['max_access_rights']; + $start_port = $service['start_port']; + $end_port = $service['end_port']; + $post_months = $_POST['invoice_duration'] == "month" ? 1 : 12; + $assigned_months = $post_months * $_POST['qty']; + $account_months = $account['invoice_duration'] == "month" ? 1 : 12; + $account_total_months = $account_months * $account['qty']; + + if( $account['available_months'] >= $assigned_months AND $account['available_slots'] >= $max_players ) + { + $control_password = genRandomString(8); + $access_rights = ""; + + $ftp = FALSE; + foreach ($selections as $selection => $flag) + { + if (isset($_POST[$selection])) + { + if( preg_match( "/$flag/", $max_access_rights ) ) + { + $access_rights .= $flag; + if ($flag == "t") + { + $ftp = TRUE; + } + } + } + } + + if ( empty( $web_user_id ) ) + { + print_failure(get_lang('bad_user_name')); + } + else + { + foreach ( $game_cfgs as $cfg ) + { + if($cfg['home_cfg_id'] == $home_cfg_id) $server_name = $cfg['game_name']; + } + foreach ( $remote_servers as $server ) + { + if($server['remote_server_id'] == $rserver_id) $ogp_user = $server['ogp_user']; + } + foreach ( $users as $user ) + { + if($user['user_id'] == $web_user_id) $web_user = $user['users_login']; + } + $ftppassword = genRandomString(8); + $game_path = "/home/".$ogp_user."/"; + if ( ( $new_home_id = $db->addGameHome($rserver_id,$web_user_id,$home_cfg_id, + clean_path($game_path),$server_name,$control_password,$ftppassword) )!== FALSE ) + { + $db->assignHomeTo("user",$web_user_id,$new_home_id,$access_rights); + $home_info = $db->getGameHomeWithoutMods($new_home_id); + require_once('includes/lib_remote.php'); + $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key']); + if($ftp) + { + $host_stat = $remote->status_chk(); + if( $host_stat === 1) + { + $remote->ftp_mgr("useradd", $home_info['home_id'], $home_info['ftp_password'], $home_info['home_path']); + $db->changeFtpStatus('enabled',$home_info['home_id']); + } + } + + $home_id = $new_home_id; + + $remote_server_ips = $db->getRemoteServerIPs($rserver_id); + + $max_id = count($remote_server_ips) - 1; + $ip_id = ( count($remote_server_ips) > 1 ) ? $remote_server_ips[rand(0,$max_id)]['ip_id'] : $remote_server_ips['0']['ip_id']; + + $add_port = $db->addGameIpPort( $home_id, $ip_id, $db->getNextAvailablePort($ip_id,$home_cfg_id) ); + + $mod_id = $db->addModToGameHome($home_id,$mod_cfg_id); + + if ( $mod_id === FALSE ) + { + print_failure(get_lang_f('failed_to_assing_mod_to_home',$mod_cfg_id)); + unset($_POST); + } + else + { + $cliopts = ""; + $cpus = "NA"; + $nice = "0"; + if ( $db->updateGameModParams($max_players,$cliopts,$cpus,$nice,$home_id,$mod_cfg_id) === FALSE ) + { + print_failure(get_lang_f('failed_to_assing_mod_to_home',$mod_cfg_id)); + unset($_POST); + } + else + { + $update_available_slots = $account['available_slots'] - $max_players; + $db->query("UPDATE OGP_DB_PREFIXreseller_accounts SET available_slots=".$update_available_slots." WHERE account_id=".$account['account_id']); + + $status = "ADDDATE(DATE(NOW() + INTERVAL ".$assigned_months." MONTH), 1)"; + + $query = sprintf('INSERT INTO `%1$sreseller_homes` (`home_id`, `user_id`, `account_id`, `assigned_slots`, `status`) + VALUES(\'%2$s\', \'%3$s\', \'%4$s\', \'%5$s\', %6$s) + ON DUPLICATE KEY UPDATE + user_id=VALUES(user_id), + account_id=VALUES(account_id), + assigned_slots=VALUES(assigned_slots), + status=VALUES(status);', + 'OGP_DB_PREFIX', + $db->real_escape_string($home_id), + $db->real_escape_string($web_user_id), + $db->real_escape_string($account['account_id']), + $db->real_escape_string($max_players), + $db->real_escape_string($status)); + + $db->query($query); + + if ($_POST['installation'] == "manual") + { + print_success(get_lang('server_added_successfully_needs_manual_install')); + unset($_POST); + } + else + { + // Getting pre and post commands + $game_mod_precmd = $db->resultQuery("SELECT DISTINCT precmd FROM OGP_DB_PREFIXgame_mods WHERE mod_id='$mod_id'"); + if($game_mod_precmd[0]['precmd'] === NULL OR empty($game_mod_precmd[0]['precmd'])) + { + $config_mod_precmd = $db->resultQuery("SELECT DISTINCT def_precmd FROM OGP_DB_PREFIXconfig_mods WHERE mod_cfg_id='$mod_cfg_id'"); + if ($config_mod_precmd[0]['def_precmd'] === NULL OR empty($config_mod_precmd[0]['def_precmd'])) + $precmd = ""; + else + $precmd = $config_mod_precmd[0]['def_precmd']; + } + else + $precmd = $game_mod_precmd[0]['precmd']; + + + $game_mod_postcmd = $db->resultQuery("SELECT DISTINCT postcmd FROM OGP_DB_PREFIXgame_mods WHERE mod_id='$mod_id'"); + if($game_mod_postcmd[0]['postcmd'] === NULL OR empty($game_mod_postcmd[0]['postcmd'])) + { + $config_mod_postcmd = $db->resultQuery("SELECT DISTINCT def_postcmd FROM OGP_DB_PREFIXconfig_mods WHERE mod_cfg_id='$mod_cfg_id'"); + if ($config_mod_postcmd[0]['def_postcmd'] === NULL OR empty($config_mod_postcmd[0]['def_postcmd'])) + $postcmd = ""; + else + $postcmd = $config_mod_postcmd[0]['def_postcmd']; + } + else + $postcmd = $game_mod_postcmd[0]['postcmd']; + + $home_info = $db->getGameHome($home_id); + $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']); + $exec_folder_path = clean_path($home_info['home_path'] . "/" . $server_xml->exe_location ); + $exec_path = clean_path($exec_folder_path . "/" . $server_xml->server_exec_name ); + // Starting Game server installation + if( $_POST['installation'] == "steam" OR $_POST['installation'] == "steamcmd" ) + { + $mod_xml = xml_get_mod($server_xml, $home_info['mods'][$mod_id]['mod_key']); + $installer_name = $mod_xml->installer_name; + $modkey = $home_info['mods'][$mod_id]['mod_key']; + // Some games like L4D2 require anonymous login + if($mod_xml->installer_login){ + $login = $mod_xml->installer_login; + $pass = ''; + }else{ + $login = $settings['steam_user']; + $pass = $settings['steam_pass']; + } + $modname = ( $installer_name == '90' and !preg_match("/(cstrike|valve)/", $modkey) ) ? $modkey : ''; + $betaname = isset($mod_xml->betaname) ? $mod_xml->betaname : ''; + $betapwd = isset($mod_xml->betapwd) ? $mod_xml->betapwd : ''; + preg_match("/(win|linux)(32|64)?$/", $server_xml->game_key, $matches); + $os = strtolower($matches[1]) == 'linux'? 'linux':'windows'; + $arch = isset($matches[2])?$matches[2]:'32'; + + if($precmd == "") + { + $preInstallCMD = ""; + if(isset($server_xml->post_install)) + $preInstallCMD .= $server_xml->pre_install; + } + else + $preInstallCMD = $precmd; + + if($postcmd == "") + { + $postInstallCMD = ""; + if(isset($server_xml->post_install)) + $postInstallCMD .= $server_xml->post_install; + } + else + $postInstallCMD = $postcmd; + + $postInstallCMD .= "\n{OGP_LOCK_FILE} " . $home_info['home_path'] . "/" . ($server_xml->exe_location ? $server_xml->exe_location . "/" : "") . $server_xml->server_exec_name; + + $remote->steam_cmd($home_info['home_id'],$home_info['home_path'],$installer_name,$modname, + $betaname,$betapwd,$login,$pass,$settings['steam_guard'], + $exec_folder_path,$exec_path,$preInstallCMD,$postInstallCMD,$os,'',$arch); + print_success(get_lang('server_added_successfully_installing')); + unset($_POST); + } + elseif($_POST['installation'] == "rsync") + { + if( isset($server_xml->lgsl_query_name) ) + $rs_name = $server_xml->lgsl_query_name; + elseif( isset($server_xml->gameq_query_name) ) + $rs_name = $server_xml->gameq_query_name; + elseif( isset($server_xml->protocol) ) + $rs_name = $server_xml->protocol; + else + $rs_name = $server_xml->mods->mod['key']; + $url = "rsync.opengamepanel.org"; + + if( preg_match("/win32/", $server_xml->game_key) OR preg_match("/win64/", $server_xml->game_key) ) + $os = "windows"; + elseif( preg_match("/linux/", $server_xml->game_key) ) + $os = "linux"; + + $full_url = "$url/ogp_game_installer/$rs_name/$os/"; + $remote->start_rsync_install($home_id,$home_info['home_path'],"$full_url",$exec_folder_path,$exec_path,$precmd,$postcmd); + print_success(get_lang('server_added_successfully_installing')); + unset($_POST); + } + } + } + + } + } + else + { + print_failure(get_lang_f("failed_to_add_home_to_db",$db->getError())); + unset($_POST); + } + } + } + else + { + if( $account['available_months'] < $assigned_months ) + print_failure( get_lang_f('you_assigned_months_this_amount_exceeds_the_available_months_in_this_reseller_account', $assigned_months, $account['available_months']) ); + elseif( $account['available_slots'] < $max_players ) + print_failure( get_lang_f('you_assigned_max_players_this_amount_exceeds_the_available_slots_in_this_reseller_account', $max_players, $account['available_slots']) ); + $view->refresh('home.php?m=reseller&p=rs_assign_server', 5); + } + } + + + if( isset($_POST['account_id']) ) + { + $qry_accounts = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE user_id=".$_SESSION['user_id']." AND account_id=".$_POST['account_id']); + $account = $qry_accounts[0]; + $qry_service = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_services WHERE service_id=".$account['service_id']); + $service = $qry_service[0]; + $invoice_duration_string = $account['qty'] > 1 ? $account['invoice_duration']."s" : $account['invoice_duration']; + echo "

" . $service['service_name'] . " / " . $account['qty'] . " " . get_lang( $invoice_duration_string ) . "   [".get_lang_f( 'available_slots', $account['available_slots'] ). + " / ".get_lang_f( 'available_months', $account['available_months'] ). + "] (".get_lang('account_details').")

"; + } + // View form to add more servers. + echo "
"; + echo ""; + if( !isset($_POST['account_id']) ) + { + $accounts = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE user_id=".$_SESSION['user_id']. ""); + if( ! empty( $accounts ) ) + { + echo ""; + } + else + { + print_failure(get_lang('there_is_no_reseller_accounts_available_yet')); + echo create_back_button($_GET['m'],"rs_packs_shop"); + } + } + else + { + if( $account['available_slots'] < 1 ) + { + print_failure(get_lang('there_is_no_slots_available_in_this_reseller_account')); + echo create_back_button($_GET['m'],"rs_packs_shop"); + return; + } + elseif( !isset( $_POST['home_cfg_id'] ) ) + { + $rhost_id = $service['remote_server_id']; + $remote_server = $db->getRemoteServer($rhost_id); + require_once('includes/lib_remote.php'); + $remote = new OGPRemoteLibrary($remote_server['agent_ip'],$remote_server['agent_port'],$remote_server['encryption_key']); + $host_stat = $remote->status_chk(); + if( $host_stat === 1) + $os = $remote->what_os(); + else + { + print_failure(get_lang_f("caution_agent_offline_can_not_get_os_and_arch_showing_servers_for_all_platforms")); + $os = "Unknown OS"; + } + echo ""; + } + elseif( ! isset( $_POST['mod_cfg_id'] ) ) + { + ?> + + + + resultQuery("SELECT DISTINCT home_cfg_file FROM OGP_DB_PREFIXconfig_homes WHERE home_cfg_id=" . $_POST['home_cfg_id']); + $server_xml = read_server_config(SERVER_CONFIG_LOCATION.$cfg_info[0]['home_cfg_file']); + + if( isset( $server_xml->installer ) ) + { + $installation = $server_xml->installer; + } + else + { + if( isset($server_xml->lgsl_query_name) ) + $lgslname = $server_xml->lgsl_query_name; + elseif( isset($server_xml->gameq_query_name) ) + $lgslname = $server_xml->gameq_query_name; + elseif( isset($server_xml->protocol) ) + $lgslname = $server_xml->protocol; + else + $lgslname = $server_xml->mods->mod['key']; + + $sync_list = @file("modules/gamemanager/rsync.list", FILE_IGNORE_NEW_LINES); + + if ( in_array($lgslname, $sync_list) ) + { + $installation = "rsync"; + } + else + { + $installation = "manual"; + } + } + echo ""; + $account['available_slots']; + $max_selectable_players = $server_xml->max_user_amount <= $account['available_slots'] ? $server_xml->max_user_amount : $account['available_slots']; + echo ""; + } + elseif( ! isset( $_POST['invoice_duration'] ) ) + { + echo ""; + ?> + \n". + ""; + // Select permisions + echo ""; + foreach ( $selections as $selection => $flag) + { + if( preg_match( "/$flag/", $max_access_rights ) ) + echo create_selection($selection,$flag); + } + echo ''. + ''. + ''. + ''. + "". + "". + ""; + } + } + echo "
".get_lang('select_reseller_account')."\n"; + echo "
".get_lang('select_game')."\n". + "\n". + "". + "". + "
+ + + + +
"; + if ( $server_xml->max_user_amount ) + { + echo "".get_lang('max_players')."".create_drop_box_from_array(range(0,$max_selectable_players), + 'max_players" onchange="this.form.submit()',0,true). + ''. + ''. + ''. + "". ""; + } + echo "
"; + echo "".get_lang('invoice_duration')." + + + ".get_lang('assign_to')."\n

".get_lang('access_rights')."

". + ""; + "
"; +} +?> diff --git a/Panel/modules/reseller/bill.php b/Panel/modules/reseller/bill.php new file mode 100755 index 00000000..e01f6d08 --- /dev/null +++ b/Panel/modules/reseller/bill.php @@ -0,0 +1,146 @@ +'; + $view->setCharset(get_lang('lang_charset')); + } + $settings = $db->getSettings(); + + $user_id = $_SESSION['user_id']; + $cart_id = $_POST['cart_id']; + + $isAdmin = $db->isAdmin( $_SESSION['user_id'] ); + + if ( $isAdmin ) + $accounts = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE cart_id=".$cart_id ); + else + $accounts = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE cart_id=".$cart_id." AND user_id=".$user_id ); + + $cart = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXreseller_carts WHERE cart_id=".$cart_id ); + + if( !empty($accounts) ) + { + ?> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + resultQuery( "SELECT * + FROM OGP_DB_PREFIXreseller_services + WHERE service_id=".$service_id ); + + $cart = $db->resultQuery( "SELECT * + FROM OGP_DB_PREFIXreseller_carts + WHERE cart_id=".$account['cart_id'] ); + + $currency = $cart[0]['currency']; + $service_name = $service[0]['service_name']; + $slots_max_qty = $service[0]['slot_max_qty']; + $qty = $account['qty']; + $invoice_duration = $account['invoice_duration']; + $discount = $account['discount']; + $price = $account['price']; + $subtotal += $price; + + //Calculating Costs + + if ($invoice_duration == "month") + { + $price_slot=$service[0]['price_per_month']; + } + elseif ($invoice_duration == "year") + { + $price_slot=$service[0]['price_per_year']; + } + + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+
 
:
".$settings['panel_name'].""; ?>
 
:
".$settings['paypal_email'].""; ?>
 
%
 
 
:
:
:
:
:
 
+

+
&type=cleared' > + + +
+ \ No newline at end of file diff --git a/Panel/modules/reseller/cart.css b/Panel/modules/reseller/cart.css new file mode 100755 index 00000000..1f7d51bf --- /dev/null +++ b/Panel/modules/reseller/cart.css @@ -0,0 +1,50 @@ +form table.center tr td{ + width:50%; + width:50%; +} + +table.center{ + color:#333333; + clear:both; + width:100%; + height:35px; + margin-top:-6px; + padding-top:10px; + text-align: center; + color:#FFFF; +} + +table.center tr td{ + border:1px solid #cfcfcf; + background:#e5e5e5; +} + +table.center th{ + border:1px solid #cfcfcf; + background:#c5c5c5; +} + +table.center tr.first_row td{ + border:1px solid #cfcfcf; + background:#c5c5c5; +} + +h4 { + width:250px; + height:25px; + background:#f5f5f5; + border-top-style:solid; + border-top-color:#afafaf; + border-top-width:1px; + border-style: solid; + border-color: #CFCFCF; + border-width: 1px; + padding-top:8px; + text-align: center; + font-family:"Trebuchet MS"; + color:black; + margin-left: auto; + margin-right: auto; + margin-top:20px; + margin-bottom:20px; +} \ No newline at end of file diff --git a/Panel/modules/reseller/cart.php b/Panel/modules/reseller/cart.php new file mode 100755 index 00000000..7b15a30e --- /dev/null +++ b/Panel/modules/reseller/cart.php @@ -0,0 +1,431 @@ +real_escape_string($str); +} + +function saveOrderToDb($account_id,$service_id,$user_id,$qty,$invoice_duration,$discount,$price,$cart_id,$available_slots,$payment_date){ + global $db, $view; + if( $account_id == '' or $account_id <= -1000000) + { + $fields['service_id'] = $service_id; + $fields['user_id'] = $user_id; + $fields['qty'] = $qty; + $fields['invoice_duration'] = $invoice_duration; + $fields['discount'] = $discount; + $fields['price'] = $price; + $fields['cart_id'] = $cart_id; + $fields['available_slots'] = $available_slots; + $fields['payment_date'] = $payment_date; + return $db->resultInsertId('reseller_accounts', $fields); + } + else + { + $query = sprintf("UPDATE + `OGP_DB_PREFIXreseller_accounts` SET + `service_id` = '%d', + `user_id` = '%d', + `qty` = '%s', + `invoice_duration` = '%s', + `discount` = '%s', + `price` = '%s', + `cart_id` = '%d', + `available_slots` = '%d', + `payment_date` = '%s' + WHERE + account_id=%d", + clean($service_id), + clean($user_id), + clean($qty), + clean($invoice_duration), + clean($discount), + clean($price), + clean($cart_id), + clean($available_slots), + clean($payment_date), + clean($account_id)); + if(!$db->query( $query )) + return false; + return $accound_id; + } +} + +function assignOrdersToCart($user_id,$tax_amount,$currency) +{ + global $db; + $fields['user_id'] = $user_id; + $fields['tax_amount'] = $tax_amount; + $fields['currency'] = $currency; + return $db->resultInsertId('reseller_carts', $fields); +} + +function exec_ogp_module() +{ + global $db,$view,$settings; + + if( isset( $_POST["buy"] ) or isset( $_POST["pay"] ) ) + { + if( isset( $_SESSION['CART'] ) ) + { + $accounts = $_SESSION['CART']; + // Create a new cart on DB + $cart_id = assignOrdersToCart($_SESSION['user_id'],$settings['tax_amount'],$settings['currency']); + foreach($accounts as $account) + { + $service_id = $account['service_id']; + $user_id = $account['user_id']; + $qty = $account['qty']; + $invoice_duration = $account['invoice_duration']; + $discount = $account['discount']; + $price = $account['price']; + $paid = $account['paid']; + $service_info = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXreseller_services WHERE service_id=".$service_id ); + $available_slots = $service_info[0]['slot_max_qty']; + //Save account to DB + if(!saveOrderToDb('',$service_id,$user_id,$qty,$invoice_duration,$discount,$price,$cart_id,$available_slots,"0")) + print_failure("A service could not be added to the database"); + } + // Remove Cart From Session + unset($_SESSION['CART']); + $db->query( "UPDATE OGP_DB_PREFIXreseller_carts + SET paid=2 + WHERE cart_id=".$cart_id); + } + else + { + $cart_id = $_POST['cart_id']; + } + } + + if( isset( $_POST["extend"] ) or isset( $_POST["extend_and_pay"] ) ) + { + $accounts = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE account_id=".$_POST['account_id']); + // Create a new cart on DB + $cart_id = assignOrdersToCart($_SESSION['user_id'],$settings['tax_amount'],$settings['currency']); + $account = $accounts[0]; + $service_id = $account['service_id']; + $account_id = $account['account_id']; + $available_slots = $account['available_slots']; + $old_qty = $account['qty']; + $old_invoice_duration = $account['invoice_duration']; + $old_discount = $account['discount']; + $old_price = $account['price']; + $old_payment_date = $account['payment_date']; + // Get new invoice duration + $qty = $_POST['qty']; + $invoice_duration = $_POST['invoice_duration']; + + //Calculating New Price + $services = $db->resultQuery( "SELECT * + FROM OGP_DB_PREFIXreseller_services + WHERE service_id=".$service_id ); + $service = $services[0]; + if ($invoice_duration == "month") + { + $price_pack = $service['price_per_month']; + } + elseif ($invoice_duration == "year") + { + $price_pack = $service['price_per_year']; + } + $price = $price_pack*$qty; + + //Save the old account information in the old cart with a negative signed(-) int for billing purposses + $old_cart_id = $account['cart_id']; + $ext_account_id = ( 0 - $account['account_id'] ) * 1000000; + + do { + $test_account_query = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE account_id=".$ext_account_id); + if( empty( $test_account_query[0] ) ) break; + --$ext_account_id; + } while( ! empty( $test_account_query[0] ) ); + + saveOrderToDb("$ext_account_id",$service_id,$_SESSION['user_id'],$old_qty,$old_invoice_duration,$old_discount,$old_price,$old_cart_id,$available_slots,$old_payment_date); + + //Save the old account in to the new cart. + saveOrderToDb("$account_id",$service_id,$_SESSION['user_id'],$qty,$invoice_duration,"0",$price,$cart_id,$available_slots,"0"); + + //Set status to -2 at the old account information so it's known as an extended account. + $db->query( "UPDATE OGP_DB_PREFIXreseller_accounts + SET status=-2 + WHERE account_id=$ext_account_id"); + + //Set status to 0 at the account information at the new cart, waiting for account extension payment. + $db->query( "UPDATE OGP_DB_PREFIXreseller_accounts + SET status=0 + WHERE account_id=$account_id"); + + //Set status to 0 at the account information at the new cart, awaiting payment. + $db->query( "UPDATE OGP_DB_PREFIXreseller_carts + SET paid=2 + WHERE cart_id=".$cart_id); + } + + if(isset($_POST['remove'])) + { + $cart_id = $_POST['cart_id']; + if( isset( $_SESSION['CART'][$cart_id] ) ) + { + unset($_SESSION['CART'][$cart_id]); + } + $account_id = $_POST['account_id']; + $db->query( "DELETE FROM OGP_DB_PREFIXreseller_accounts WHERE account_id=".$account_id ); + $accounts_in_cart = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE cart_id=".$cart_id ); + if( !$accounts_in_cart ) + { + $db->query( "DELETE FROM OGP_DB_PREFIXreseller_carts WHERE cart_id=".$cart_id ); + } + } + + if ( isset( $_POST["cart_id"] ) AND ( isset( $_POST["pay"] ) or isset( $_POST["extend_and_pay"] ) ) ) + { + $view->refresh('home.php?m=reseller&p=paypal&cart_id='.$_POST["cart_id"], 0); + } + + ?>

resultQuery( "SELECT * FROM OGP_DB_PREFIXreseller_carts WHERE user_id=".$_SESSION['user_id'] ); + + if( $user_carts >=1 ) + { + foreach ( $user_carts as $user_cart ) + { + $cart_id = $user_cart['cart_id']; + $carts[$cart_id] = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXreseller_carts AS cart JOIN + OGP_DB_PREFIXreseller_accounts AS account + ON account.cart_id=cart.cart_id + WHERE cart.cart_id=".$cart_id ); + } + } + + if( empty( $carts ) ) + { + print_failure( get_lang('there_are_no_accounts_in_cart') ); + ?> + + +
+ + + + + + + + + 1 ) ? $account['invoice_duration']."s" : $account['invoice_duration']; + + $subtotal += $account['price']; + $service_info = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXreseller_services WHERE service_id=".$account['service_id'] ); + ?> + + + + + + + + +
+ + + + + + + + +
+ ".$service_info[0]['service_name']." [".$account['qty']." ".get_lang($invoice_duration).", ".$service_info[0]['slot_max_qty']." ".get_lang('slots')."]" ; + ?> + + + + + + + + +
+ + + "> +
+ +
+ + + + + "> +
+ 0 ) + { + ?> +
+ + "> +
+ +
+ + + + + + + + + + + + + + +
+ + +
+ + % +
+ + + + + +
+ + "> +
+ +
+ + "> +
+ +
+ + "> +
+ +
+ + "> +
+ + +
+
+ + + \ No newline at end of file diff --git a/Panel/modules/reseller/cron-shop.php b/Panel/modules/reseller/cron-shop.php new file mode 100755 index 00000000..4e5e6b1e --- /dev/null +++ b/Panel/modules/reseller/cron-shop.php @@ -0,0 +1,137 @@ +resultQuery( "SELECT * + FROM OGP_DB_PREFIXreseller_homes + WHERE status>0 AND statusgetGameHomeWithoutMods($home_id); + $server_info = $db->getRemoteServerById($home_info['remote_server_id']); + $remote = new OGPRemoteLibrary($server_info['agent_ip'], $server_info['agent_port'], $server_info['encryption_key']); + $ftp_login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id; + $remote->ftp_mgr("userdel", $ftp_login); + $db->changeFtpStatus('disabled',$home_id); + $addresses = $db->getHomeIpPorts($home_id); + foreach($addresses as $address) + { + $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']); + if(isset($server_xml->control_protocol_type))$control_type = $server_xml->control_protocol_type; else $control_type = ""; + $remote->remote_stop_server($home_id,$address['ip'],$address['port'],$server_xml->control_protocol,$home_info['control_password'],$control_type); + } + + // Unassign Home to the current owner at DB. + $db->unassignHomeFrom("user", $user_id, $home_id); + + // Remove the game home from DB + $db->deleteGameHome($home_id); + + // Remove the game home files from remote server + $remote->remove_home($home_info['home_path']); + + echo "Home ID $home_id removed successfully.\r\n"; + + // Restore slots in the reseller account + $qry_accounts = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE account_id=".$user_home['account_id']); + $account = $qry_accounts[0]; + $update_available_slots = $account['available_slots'] + $user_home['assigned_slots']; + $db->query("UPDATE OGP_DB_PREFIXreseller_accounts SET available_slots=".$update_available_slots." WHERE account_id=".$account['account_id']); + + // Delete the reseller home entry + $db->query( "DELETE FROM " . $table_prefix . "reseller_homes + WHERE home_id=" . $home_id); + + echo "The amount of available slots available at the reseller account with ID ".$account['account_id']." has been updated,\r\nnow haves ".$update_available_slots." free slots.\r\n"; + } +} +$reseller_accounts = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE status>0" ); +if (!is_array($reseller_accounts)) +{ + echo "Nothing to do at reseller accounts.\r\n"; +} +else +{ + $changes = FALSE; + foreach($reseller_accounts as $account) + { + $months_old_query = $db->resultQuery( "SELECT TIMESTAMPDIFF(MONTH,'".$account['payment_date']."',NOW());" ); + $months_old = $months_old_query[0]["TIMESTAMPDIFF(MONTH,'".$account['payment_date']."',NOW())"]; + if( $months_old > 0 ) + { + $months = $account['invoice_duration'] == "month" ? 1 : 12; + $total_months = $months * $account['qty']; + $update_available_months = $total_months - $months_old; + + if( $update_available_months <= 0 ) + { + $db->query("UPDATE OGP_DB_PREFIXreseller_accounts SET available_months=".$update_available_months." WHERE account_id=".$account['account_id']); + $db->query("UPDATE OGP_DB_PREFIXreseller_accounts SET status=-1 WHERE account_id=".$account['account_id']); + echo "The reseller account with ID ".$account['account_id']." has expired (0 months available).\r\n"; + $changes = TRUE; + } + else + { + if( $account['available_months'] != $update_available_months ) + { + $db->query("UPDATE OGP_DB_PREFIXreseller_accounts SET available_months=".$update_available_months." WHERE account_id=".$account['account_id']); + echo "The amount of available months at reseller account ID ".$account['account_id']." has been updated,\r\n".$update_available_months." months remaining to expire.\r\n"; + $changes = TRUE; + } + } + } + } + if( ! $changes ) + { + echo "Nothing to do at reseller accounts.\r\n"; + } +} + + +?> diff --git a/Panel/modules/reseller/ipn_errors.log b/Panel/modules/reseller/ipn_errors.log new file mode 100755 index 00000000..e69de29b diff --git a/Panel/modules/reseller/ipnlistener.php b/Panel/modules/reseller/ipnlistener.php new file mode 100755 index 00000000..aacd3e50 --- /dev/null +++ b/Panel/modules/reseller/ipnlistener.php @@ -0,0 +1,309 @@ +use_ssl) { + $uri = 'https://'.$this->getPaypalHost().'/cgi-bin/webscr'; + $this->post_uri = $uri; + } else { + $uri = 'http://'.$this->getPaypalHost().'/cgi-bin/webscr'; + $this->post_uri = $uri; + } + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $uri); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_data); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $this->follow_location); + curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, true); + + if ($this->force_ssl_v3) { + curl_setopt($ch, CURLOPT_SSLVERSION, 3); + } + + $this->response = curl_exec($ch); + $this->response_status = strval(curl_getinfo($ch, CURLINFO_HTTP_CODE)); + + if ($this->response === false || $this->response_status == '0') { + $errno = curl_errno($ch); + $errstr = curl_error($ch); + throw new Exception("cURL error: [$errno] $errstr"); + } + } + + /** + * Post Back Using fsockopen() + * + * Sends the post back to PayPal using the fsockopen() function. Called by + * the processIpn() method if the use_curl property is false. Throws an + * exception if the post fails. Populates the response, response_status, + * and post_uri properties on success. + * + * @param string The post data as a URL encoded string + */ + protected function fsockPost($encoded_data) { + + if ($this->use_ssl) { + $uri = 'ssl://'.$this->getPaypalHost(); + $port = '443'; + $this->post_uri = $uri.'/cgi-bin/webscr'; + } else { + $uri = $this->getPaypalHost(); // no "http://" in call to fsockopen() + $port = '80'; + $this->post_uri = 'http://'.$uri.'/cgi-bin/webscr'; + } + + $fp = fsockopen($uri, $port, $errno, $errstr, $this->timeout); + + if (!$fp) { + // fsockopen error + throw new Exception("fsockopen error: [$errno] $errstr"); + } + + $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; + $header .= "Host: ".$this->getPaypalHost()."\r\n"; + $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; + $header .= "Content-Length: ".strlen($encoded_data)."\r\n"; + $header .= "Connection: Close\r\n\r\n"; + + fputs($fp, $header.$encoded_data."\r\n\r\n"); + + while(!feof($fp)) { + if (empty($this->response)) { + // extract HTTP status from first line + $this->response .= $status = fgets($fp, 1024); + $this->response_status = trim(substr($status, 9, 4)); + } else { + $this->response .= fgets($fp, 1024); + } + } + + fclose($fp); + } + + private function getPaypalHost() { + if ($this->use_sandbox) return IpnListener::SANDBOX_HOST; + else return IpnListener::PAYPAL_HOST; + } + + /** + * Get POST URI + * + * Returns the URI that was used to send the post back to PayPal. This can + * be useful for troubleshooting connection problems. The default URI + * would be "ssl://www.sandbox.paypal.com:443/cgi-bin/webscr" + * + * @return string + */ + public function getPostUri() { + return $this->post_uri; + } + + /** + * Get Response + * + * Returns the entire response from PayPal as a string including all the + * HTTP headers. + * + * @return string + */ + public function getResponse() { + return $this->response; + } + + /** + * Get Response Status + * + * Returns the HTTP response status code from PayPal. This should be "200" + * if the post back was successful. + * + * @return string + */ + public function getResponseStatus() { + return $this->response_status; + } + + /** + * Get Text Report + * + * Returns a report of the IPN transaction in plain text format. This is + * useful in emails to order processors and system administrators. Override + * this method in your own class to customize the report. + * + * @return string + */ + public function getTextReport() { + + $r = ''; + + // date and POST url + for ($i=0; $i<80; $i++) { $r .= '-'; } + $r .= "\n[".date('m/d/Y g:i A').'] - '.$this->getPostUri(); + if ($this->use_curl) $r .= " (curl)\n"; + else $r .= " (fsockopen)\n"; + + // HTTP Response + for ($i=0; $i<80; $i++) { $r .= '-'; } + $r .= "\n{$this->getResponse()}\n"; + + // POST vars + for ($i=0; $i<80; $i++) { $r .= '-'; } + $r .= "\n"; + + foreach ($this->post_data as $key => $value) { + $r .= str_pad($key, 25)."$value\n"; + } + $r .= "\n\n"; + + return $r; + } + + /** + * Process IPN + * + * Handles the IPN post back to PayPal and parsing the response. Call this + * method from your IPN listener script. Returns true if the response came + * back as "VERIFIED", false if the response came back "INVALID", and + * throws an exception if there is an error. + * + * @param array + * + * @return boolean + */ + public function processIpn($post_data=null) { + + $encoded_data = 'cmd=_notify-validate'; + + if ($post_data === null) { + // use raw POST data + if (!empty($_POST)) { + $this->post_data = $_POST; + $encoded_data .= '&'.file_get_contents('php://input'); + } else { + throw new Exception("No POST data found."); + } + } else { + // use provided data array + $this->post_data = $post_data; + + foreach ($this->post_data as $key => $value) { + $encoded_data .= "&$key=".urlencode($value); + } + } + + if ($this->use_curl) $this->curlPost($encoded_data); + else $this->fsockPost($encoded_data); + + if (strpos($this->response_status, '200') === false) { + throw new Exception("Invalid response status: ".$this->response_status); + } + + if (strpos($this->response, "VERIFIED") !== false) { + return true; + } elseif (strpos($this->response, "INVALID") !== false) { + return false; + } else { + throw new Exception("Unexpected response from PayPal."); + } + } + + /** + * Require Post Method + * + * Throws an exception and sets a HTTP 405 response header if the request + * method was not POST. + */ + public function requirePostMethod() { + // require POST requests + if ($_SERVER['REQUEST_METHOD'] && $_SERVER['REQUEST_METHOD'] != 'POST') { + header('Allow: POST', true, 405); + throw new Exception("Invalid HTTP request method."); + } + } +} +?> diff --git a/Panel/modules/reseller/module.php b/Panel/modules/reseller/module.php new file mode 100755 index 00000000..3347e063 --- /dev/null +++ b/Panel/modules/reseller/module.php @@ -0,0 +1,102 @@ + 'rs_packs_shop', 'name'=>'Reseller Packs', 'group'=>'user' ), + array( 'subpage' => 'rs_accounts', 'name'=>'Reseller Accounts', 'group'=>'admin' ), + array( 'subpage' => 'rs_services', 'name'=>'Reseller Services', 'group'=>'admin' ), + array( 'subpage' => 'rs_settings', 'name'=>'Reseller Settings', 'group'=>'admin' ) +); + +$install_queries = array(); +$install_queries[0] = array( + "DROP TABLE IF EXISTS `".OGP_DB_PREFIX."reseller_services`;", + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."reseller_services` ( + `service_id` int(11) NOT NULL auto_increment, + `service_name` varchar(60) NOT NULL, + `slot_max_qty` int(11) NOT NULL, + `price_per_month` float(15,4) NOT NULL, + `price_per_year` float(15,4) NOT NULL, + `description` varchar(1000) NOT NULL, + `remote_server_id` int(11) NOT NULL, + `start_port` int(11) NOT NULL, + `end_port` int(11) NOT NULL, + `max_access_rights` varchar(255) NOT NULL, + PRIMARY KEY (`service_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=UTF8;", + + "DROP TABLE IF EXISTS `".OGP_DB_PREFIX."reseller_accounts`;", + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."reseller_accounts` ( + `account_id` int(11) NOT NULL auto_increment, + `service_id` int(11) NOT NULL, + `user_id` int(11) NOT NULL, + `qty` int(11) NULL, + `invoice_duration` varchar(7) NOT NULL, + `discount` int(11) NOT NULL, + `price` int(11) NOT NULL, + `payment_date` varchar(20) NOT NULL DEFAULT '0', + `cart_id` int(11) NOT NULL, + `status` varchar(16) NOT NULL DEFAULT '0', + `available_months` int(11) NOT NULL DEFAULT '0', + `available_slots` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`account_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=UTF8;", + + "DROP TABLE IF EXISTS `".OGP_DB_PREFIX."reseller_carts`;", + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."reseller_carts` ( + `cart_id` int(11) NOT NULL auto_increment, + `user_id` int(11) NOT NULL, + `paid` int(11) NULL, + `tax_amount` varchar(20) NOT NULL DEFAULT '0', + `currency` varchar(3) NOT NULL DEFAULT '0', + PRIMARY KEY (`cart_id`) + ) ENGINE=MyISAM DEFAULT CHARSET=UTF8;", + + "DROP TABLE IF EXISTS `".OGP_DB_PREFIX."reseller_discount_codes`;", + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."reseller_discount_codes` ( + `discount_id` int(11) NOT NULL auto_increment, + `service_id` int(11) NOT NULL, + `percentage` int(11) NOT NULL, + `description` varchar(255) NOT NULL DEFAULT '0', + `code` varchar(255) NOT NULL, + PRIMARY KEY (`discount_id`) + ) ENGINE=MyISAM;", + + "DROP TABLE IF EXISTS `".OGP_DB_PREFIX."reseller_homes`;", + "CREATE TABLE IF NOT EXISTS `".OGP_DB_PREFIX."reseller_homes` ( + `home_id` int(11) NOT NULL, + `user_id` int(11) NOT NULL, + `account_id` int(11) NOT NULL, + `assigned_slots` int(11) NOT NULL, + `status` varchar(16) NOT NULL DEFAULT '0', + PRIMARY KEY (`home_id`) + ) ENGINE=MyISAM;" +); + +?> \ No newline at end of file diff --git a/Panel/modules/reseller/navigation.xml b/Panel/modules/reseller/navigation.xml new file mode 100755 index 00000000..ae9726d6 --- /dev/null +++ b/Panel/modules/reseller/navigation.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Panel/modules/reseller.tar.gz b/Panel/modules/reseller/pack_image.png old mode 100644 new mode 100755 similarity index 63% rename from Panel/modules/reseller.tar.gz rename to Panel/modules/reseller/pack_image.png index bfb358a1..40ea7824 Binary files a/Panel/modules/reseller.tar.gz and b/Panel/modules/reseller/pack_image.png differ diff --git a/Panel/modules/reseller/paid-ipn.php b/Panel/modules/reseller/paid-ipn.php new file mode 100755 index 00000000..72dccaeb --- /dev/null +++ b/Panel/modules/reseller/paid-ipn.php @@ -0,0 +1,166 @@ +use_sandbox = true; + +try { + $listener->requirePostMethod(); + $verified = $listener->processIpn(); +} catch (Exception $e) { + error_log($e->getMessage()); +} + +chdir("../../"); /* It just makes life easier */ + +set_include_path(get_include_path() . PATH_SEPARATOR . "includes/"); + +/* Includes */ +require_once("helpers.php"); +require_once("config.inc.php"); +require_once("functions.php"); +require_once("lib_remote.php"); +require_once("lang.php"); +require_once("modules/config_games/server_config_parser.php"); +ogpLang(); + +/* Query DB */ +$db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix); + +$panel_settings = $db->getSettings(); + +$this_script = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; + +function curPageName() +{ + return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); +} + +$current_folder_url = str_replace( curPageName(), "", $this_script); + +if( empty( $panel_settings['panel_name'] ) ) + $panel_name = "Open Game Panel"; +else + $panel_name = $panel_settings['panel_name']; + +$ipn = $_POST; + +if(empty($ipn)) +{ + exit(0); +} + +$to = $ipn['receiver_email'] . ', ' . $ipn['payer_email']; + +$body = "PayPal Payment For ". + $panel_name."

". + "

Order

". + "- Item: ".$ipn['item_name']."
". + "- Item number: ".$ipn['item_number']."
". + "- Quantity: ".$ipn['quantity']."
". + "- Shipping: ".$ipn['shipping']."
". + "- Tax: ".$ipn['tax']."
". + "- Currency: ".$ipn['mc_currency']."
". + "- Currency fee: ".$ipn['mc_fee']."
". + "- Currency gross: ".$ipn['mc_gross']."
". + "- Transaction type: ".$ipn['txn_type']."
". + "- Transaction ID: ".$ipn['txn_id']."
". + "- Notify version: ".$ipn['notify_version']."

". + "

Payer Info

". + "- ID: ".$ipn['payer_id']."
". + "- First name: ".$ipn['first_name']."
". + "- Last name: ".$ipn['last_name']."
". + "- Email: ".$ipn['payer_email']."
". + "- Email status: ".$ipn['payer_status']."

". + "

Address

". + "- Name: ".$ipn['address_name']."
". + "- Street: ".$ipn['address_street']."
". + "- City: ".$ipn['address_city']."
". + "- State: ".$ipn['address_state']."
". + "- Zip: ".$ipn['address_zip']."
". + "- Country code: ".$ipn['address_country_code']."
". + "- Country: ".$ipn['address_country']."
". + "- Residence country code: ".$ipn['residence_country']."
". + "- Address status: ".$ipn['address_status']."

". + "

Payment Receiver Info

". + "- Email: ".$ipn['receiver_email']."
". + "- ID: ".$ipn['receiver_id']."

". + "

Payment

". + "- Type: ".$ipn['payment_type']."
". + "- Date: ".$ipn['payment_date']."
". + "- Status: ".$ipn['payment_status']."
"; +/* +The processIpn() method returned true if the IPN was "VERIFIED" and false if it +was "INVALID". +*/ +if ($verified AND isset( $ipn['payment_status'] ) ) +{ + if( $ipn['payment_status']=="Completed" OR $ipn['payment_status']=="Canceled_Reversal" ) + { + $query = "UPDATE " . $table_prefix . "reseller_carts + SET paid=1 + WHERE cart_id=".$ipn['item_number']; + $db->query($query); + + $query = "UPDATE " . $table_prefix . "reseller_accounts + SET payment_date=NOW() + WHERE cart_id=".$ipn['item_number']; + $db->query($query); + + $cart_accounts = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE cart_id=".$ipn['item_number']); + foreach ( $cart_accounts as $account ) + { + $months = $account['invoice_duration'] == "month" ? 1 : 12; + $total_months = $months * $account['qty']; + + $db->query("UPDATE OGP_DB_PREFIXreseller_accounts + SET available_months=".$total_months. + " WHERE account_id=".$account['account_id'] ); + + $db->query( "UPDATE OGP_DB_PREFIXreseller_accounts ". + "SET status=ADDDATE(DATE(NOW() + INTERVAL ".$total_months." MONTH), 1) ". + "WHERE account_id=".$account['account_id'] ); + } + } + elseif( $ipn['payment_status']=="Pending" OR $ipn['payment_status']=="In-Progress" ) + { + $query = "UPDATE " . $table_prefix . "reseller_carts + SET paid=2 + WHERE cart_id=".$ipn['item_number']; + $db->query($query); + } + elseif( $ipn['payment_status']=="Reversed" OR $ipn['payment_status']=="Refunded" OR $ipn['payment_status']=="Denied" OR $ipn['payment_status']=="Expired" OR $ipn['payment_status']=="Failed" OR $ipn['payment_status']=="Voided" OR $ipn['payment_status']=="Partially_Refunded" ) + { + $body .= "- Reason code: ".$ipn['reason_code']; + $query = "UPDATE " . $table_prefix . "reseller_carts + SET paid=2 + WHERE cart_id=".$ipn['item_number']; + $db->query($query); + + $cart_accounts = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE cart_id=".$ipn['item_number']); + foreach ( $cart_accounts as $account ) + { + $months = $account['invoice_duration'] == "month" ? 1 : 12; + $total_months = $months * $account['qty']; + + $db->query("UPDATE OGP_DB_PREFIXreseller_accounts + SET available_months=0 ". + "WHERE account_id=".$account['account_id'] ); + + $db->query( "UPDATE OGP_DB_PREFIXreseller_accounts ". + "SET status=0 ". + "WHERE account_id=".$account['account_id'] ); + } + } + $subject = "Payment ".$ipn['payment_status']; + mymail($to, $subject, $body, $panel_settings); +} + +?> \ No newline at end of file diff --git a/Panel/modules/reseller/paid.php b/Panel/modules/reseller/paid.php new file mode 100755 index 00000000..b965af9a --- /dev/null +++ b/Panel/modules/reseller/paid.php @@ -0,0 +1,18 @@ +Success

Thank you for your order.

"; + } + else if (isset($_POST['payment_status']) AND ( $_POST['payment_status']=="Pending" OR $_POST['payment_status']=="In-Progress" OR $_POST['payment_status']=="Partially_Refunded" ) ) + { + echo "Pending

Pending
Thank you for your order.


Payment process is pending

"; + } + else if (isset($_POST['payment_status']) AND ($_POST['payment_status']=="Reversed" OR $_POST['payment_status']=="Refunded" OR $_POST['payment_status']=="Denied" OR $_POST['payment_status']=="Expired" OR $_POST['payment_status']=="Failed" OR $_POST['payment_status']=="Voided")) + { + echo "Reversed OR Refunded

Reversed OR Refunded

"; + } + echo ""; +} +?> diff --git a/Panel/modules/reseller/paypal.class.php b/Panel/modules/reseller/paypal.class.php new file mode 100755 index 00000000..49b1f2ba --- /dev/null +++ b/Panel/modules/reseller/paypal.class.php @@ -0,0 +1,277 @@ +add_field('business', 'somebody@domain.com'); + * $p->add_field('first_name', $_POST['first_name']); + * ... (add all your fields in the same manor) + * $p->submit_paypal_post(); + * + * To process an IPN, have your IPN processing file contain: + * + * $p = new paypal_class; + * if ($p->validate_ipn()) { + * ... (IPN is verified. Details are in the ipn_data() array) + * } + * + * + * In case you are new to paypal, here is some information to help you: + * + * 1. Download and read the Merchant User Manual and Integration Guide from + * http://www.paypal.com/en_US/pdf/integration_guide.pdf. This gives + * you all the information you need including the fields you can pass to + * paypal (using add_field() with this class) aswell as all the fields + * that are returned in an IPN post (stored in the ipn_data() array in + * this class). It also diagrams the entire transaction process. + * + * 2. Create a "sandbox" account for a buyer and a seller. This is just + * a test account(s) that allow you to test your site from both the + * seller and buyer perspective. The instructions for this is available + * at https://developer.paypal.com/ as well as a great forum where you + * can ask all your paypal integration questions. Make sure you follow + * all the directions in setting up a sandbox test environment, including + * the addition of fake bank accounts and credit cards. + * + ******************************************************************************* +*/ + +class paypal_class { + + var $last_error; // holds the last error encountered + + var $ipn_log; // bool: log IPN results to text file? + + var $ipn_log_file; // filename of the IPN log + var $ipn_response; // holds the IPN response from paypal + var $ipn_data = array(); // array contains the POST values for IPN + + var $fields = array(); // array holds the fields to submit to paypal + + + function __construct() { + + // initialization constructor. Called when class is created. + + $this->paypal_url = 'https://www.paypal.com/cgi-bin/webscr'; + + $this->last_error = ''; + + $this->ipn_log_file = '.ipn_results.log'; + $this->ipn_log = true; + $this->ipn_response = ''; + + // populate $fields array with a few default values. See the paypal + // documentation for a list of fields and their data types. These defaul + // values can be overwritten by the calling script. + + $this->add_field('rm','2'); // Return method = POST + $this->add_field('cmd','_xclick'); + + } + + function add_field($field, $value) { + + // adds a key=>value pair to the fields array, which is what will be + // sent to paypal as POST variables. If the value is already in the + // array, it will be overwritten. + + $this->fields["$field"] = $value; + } + + function submit_paypal_post() { + + // this function actually generates an entire HTML page consisting of + // a form with hidden elements which is submitted to paypal via the + // BODY element's onLoad attribute. We do this so that you can validate + // any POST vars from you custom form before submitting to paypal. So + // basically, you'll have your own form which is submitted to your script + // to validate the data, which in turn calls this function to create + // another hidden form and submit to paypal. + + // The user will briefly see a message on the screen that reads: + // "Please wait, your order is being processed..." and then immediately + // is redirected to paypal. + + echo "Processing Payment...\n"; + echo "\n"; + echo "
paypal_url."\">\n"; + + foreach ($this->fields as $name => $value) { + echo "\n"; + } + echo "


If you are not automatically redirected to "; + echo "paypal within 5 seconds...

\n"; + echo "
\n"; + + echo "
\n"; + echo "\n"; + } + + function validate_ipn() { + + // parse the paypal URL + $url_parsed=parse_url($this->paypal_url); + + // generate the post string from the _POST vars aswell as load the + // _POST vars into an arry so we can play with them from the calling + // script. + $post_string = ''; + foreach ($_POST as $field=>$value) { + $this->ipn_data["$field"] = $value; + $post_string .= $field.'='.urlencode(stripslashes($value)).'&'; + } + $post_string.="cmd=_notify-validate"; // append ipn command + + // open the connection to paypal + $fp = fsockopen($url_parsed[host],"80",$err_num,$err_str,30); + if(!$fp) { + + // could not open the connection. If loggin is on, the error message + // will be in the log. + $this->last_error = "fsockopen error no. $errnum: $errstr"; + $this->log_ipn_results(false); + return false; + + } else { + + // Post the data back to paypal + fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n"); + fputs($fp, "Host: $url_parsed[host]\r\n"); + fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); + fputs($fp, "Content-length: ".strlen($post_string)."\r\n"); + fputs($fp, "Connection: close\r\n\r\n"); + fputs($fp, $post_string . "\r\n\r\n"); + + // loop through the response from the server and append to variable + while(!feof($fp)) { + $this->ipn_response .= fgets($fp, 1024); + } + + fclose($fp); // close connection + + } + + if (eregi("VERIFIED",$this->ipn_response)) { + + // Valid IPN transaction. + $this->log_ipn_results(true); + return true; + + } else { + + // Invalid IPN transaction. Check the log for details. + $this->last_error = 'IPN Validation Failed.'; + $this->log_ipn_results(false); + return false; + + } + + } + + function log_ipn_results($success) { + + if (!$this->ipn_log) return; // is logging turned off? + + // Timestamp + $text = '['.date('m/d/Y g:i A').'] - '; + + // Success or failure being logged? + if ($success) $text .= "SUCCESS!\n"; + else $text .= 'FAIL: '.$this->last_error."\n"; + + // Log the POST variables + $text .= "IPN POST Vars from Paypal:\n"; + foreach ($this->ipn_data as $key=>$value) { + $text .= "$key=$value, "; + } + + // Log the response from the paypal server + $text .= "\nIPN Response from Paypal Server:\n ".$this->ipn_response; + + // Write to log + $fp=fopen($this->ipn_log_file,'a'); + fwrite($fp, $text . "\n\n"); + + fclose($fp); // close file + } + + function dump_fields() { + + // Used for debugging, this function will output all the field/value pairs + // that are currently defined in the instance of the class using the + // add_field() function. + + echo "

paypal_class->dump_fields() Output:

"; + echo " + + + + "; + + ksort($this->fields); + foreach ($this->fields as $key => $value) { + echo ""; + } + + echo "
Field NameValue
$key".urldecode($value)." 

"; + } +} + + + diff --git a/Panel/modules/reseller/paypal.php b/Panel/modules/reseller/paypal.php new file mode 100755 index 00000000..56c409f2 --- /dev/null +++ b/Panel/modules/reseller/paypal.php @@ -0,0 +1,78 @@ +getSettings(); + + $cart_id = $_GET['cart_id']; + + if(!empty($cart_id)) + { + $accounts = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXreseller_accounts WHERE cart_id=".$cart_id ); + $carts = $db->resultQuery( "SELECT * FROM OGP_DB_PREFIXreseller_carts WHERE cart_id=".$cart_id ); + $cart = $carts[0]; + if( !empty( $accounts ) ) + { + $cart['price'] = 0; + foreach($accounts as $account) + { + if( $account['qty'] > 1 ) + $account['invoice_duration'] = $account['invoice_duration']."s"; + + $cart['price'] += $account['price']; + + if( !isset( $cart['name'] ) ) + $cart['name'] = $account['qty'].get_lang($account['invoice_duration']).",".$account['available_slots'].get_lang('slots'); + else + $cart['name'] .= ' + '.$account['qty'].get_lang($account['invoice_duration']).",".$account['available_slots'].get_lang('slots'); + } + + $total = $cart['price']+($cart['tax_amount']/100*$cart['price']); + if ($total === 0) + { + $db->query("UPDATE " . $table_prefix . "reseller_carts + SET paid=1 + WHERE cart_id=".$cart_id); + $view->refresh("home.php?m=reseller&p=cart",0); + } + else + { + // Setup class + require_once('paypal.class.php'); // include the class file + + $receiver_email = $settings['paypal_email']; + + $p = new paypal_class; // initiate an instance of the class + //$p->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; // Paypal Sandbox URL for developers (https://developer.paypal.com) + $p->paypal_url = 'https://www.paypal.com/cgi-bin/webscr'; // PayPal url + + // setup a variable for this script (ie: 'http://www.micahcarrick.com/paypal.php') + $this_script = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; + + function curPageName() + { + return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); + } + + $current_folder_url = str_replace( curPageName(), "", $this_script); + + $p->add_field('business', $receiver_email); + $p->add_field('currency_code', $settings['currency']); + $p->add_field('return', $this_script.'?m=reseller&p=paid'); + $p->add_field('cancel_return', $this_script.'?m=reseller&p=cart'); + $p->add_field('notify_url', $current_folder_url.'modules/reseller/paid-ipn.php'); + $p->add_field('item_name', $cart['name']); + $p->add_field('item_number', $cart_id); + $p->add_field('amount', number_format( $total , 2 )); + echo "

".get_lang('redirecting_to_paypal')."

"; + echo "
"; + $p->submit_paypal_post(); // submit the fields to paypal + //$p->dump_fields(); // for debugging, output a table of all the fields + } + } + } +} +?> \ No newline at end of file diff --git a/Panel/modules/reseller/rs_accounts.css b/Panel/modules/reseller/rs_accounts.css new file mode 100755 index 00000000..1f7d51bf --- /dev/null +++ b/Panel/modules/reseller/rs_accounts.css @@ -0,0 +1,50 @@ +form table.center tr td{ + width:50%; + width:50%; +} + +table.center{ + color:#333333; + clear:both; + width:100%; + height:35px; + margin-top:-6px; + padding-top:10px; + text-align: center; + color:#FFFF; +} + +table.center tr td{ + border:1px solid #cfcfcf; + background:#e5e5e5; +} + +table.center th{ + border:1px solid #cfcfcf; + background:#c5c5c5; +} + +table.center tr.first_row td{ + border:1px solid #cfcfcf; + background:#c5c5c5; +} + +h4 { + width:250px; + height:25px; + background:#f5f5f5; + border-top-style:solid; + border-top-color:#afafaf; + border-top-width:1px; + border-style: solid; + border-color: #CFCFCF; + border-width: 1px; + padding-top:8px; + text-align: center; + font-family:"Trebuchet MS"; + color:black; + margin-left: auto; + margin-right: auto; + margin-top:20px; + margin-bottom:20px; +} \ No newline at end of file diff --git a/Panel/modules/reseller/rs_assign_server.css b/Panel/modules/reseller/rs_assign_server.css new file mode 100755 index 00000000..9a2bf3ed --- /dev/null +++ b/Panel/modules/reseller/rs_assign_server.css @@ -0,0 +1,30 @@ +form table.center tr td{ + width:50%; + width:50%; +} + +table.center{ + color:#333333; + clear:both; + width:100%; + height:35px; + margin-top:-6px; + padding-top:10px; + text-align: center; + color:#FFFF; +} + +table.center tr td{ + border:1px solid #cfcfcf; + background:#e5e5e5; +} + +table.center th{ + border:1px solid #cfcfcf; + background:#c5c5c5; +} + +table.center tr.first_row td{ + border:1px solid #cfcfcf; + background:#c5c5c5; +} diff --git a/Panel/modules/reseller/rs_packs_shop.css b/Panel/modules/reseller/rs_packs_shop.css new file mode 100755 index 00000000..4afb7f6f --- /dev/null +++ b/Panel/modules/reseller/rs_packs_shop.css @@ -0,0 +1,30 @@ +form table.center tr td{ + width:50%; + width:50%; +} + +table.center{ + color:#333333; + clear:both; + width:100%; + height:35px; + margin-top:-6px; + padding-top:10px; + text-align: center; + color:#FFFF; +} + +table.center tr td{ + border:1px solid #cfcfcf; + background:#e5e5e5; +} + +table.center th{ + border:1px solid #cfcfcf; + background:#c5c5c5; +} + +table.center tr.first_row td{ + border:1px solid #cfcfcf; + background:#c5c5c5; +} \ No newline at end of file diff --git a/Panel/modules/reseller/services.php b/Panel/modules/reseller/services.php new file mode 100755 index 00000000..e2201143 --- /dev/null +++ b/Panel/modules/reseller/services.php @@ -0,0 +1,395 @@ + +real_escape_string($str); +} + +function exec_ogp_module() +{ + global $db; + //Querying UPDATE a service FROM DB + if (isset($_POST['service']) AND isset($_POST['edit_service'])) + { + //Sanitize the POST values + $new_price_per_month = clean($_POST['new_price_per_month']); + $new_price_per_year = clean($_POST['new_price_per_year']); + $remote_server_id = clean($_POST['remote_server_id']); + $start_port = clean($_POST['start_port']); + $end_port = clean($_POST['end_port']); + $service = clean($_POST['service']); + + $change_service_settings = "UPDATE OGP_DB_PREFIXreseller_services SET + price_per_month='".$new_price_per_month."', + price_per_year='".$new_price_per_year."', + remote_server_id='".$remote_server_id."', + start_port='".$start_port."', + end_port='".$end_port."' + WHERE service_id=".$service; + $db->query($change_service_settings); + } + + //Querying INSERT new service INTO DB + if(isset($_POST['slot_max_qty']) AND isset($_POST['price_per_month']) AND isset($_POST['price_per_year'])) + { + //Sanitize the POST values + $service_name = clean($_POST['service_name']); + $slot_max_qty = clean($_POST['slot_max_qty']); + $price_per_month = clean($_POST['price_per_month']); + $price_per_year = clean($_POST['price_per_year']); + $description = clean($_POST['description']); + $remote_server_id = clean($_POST['remote_server_id']); + $start_port = clean($_POST['start_port']); + $end_port = clean($_POST['end_port']); + $max_access_rights = ""; + if(isset($_POST['allow_updates']))$max_access_rights .= clean($_POST['allow_updates']); + if(isset($_POST['allow_file_management']))$max_access_rights .= clean($_POST['allow_file_management']); + if(isset($_POST['allow_parameter_usage']))$max_access_rights .= clean($_POST['allow_parameter_usage']); + if(isset($_POST['allow_extra_params']))$max_access_rights .= clean($_POST['allow_extra_params']); + if(isset($_POST['allow_ftp_usage']))$max_access_rights .= clean($_POST['allow_ftp_usage']); + + $qry_add_service = "INSERT INTO OGP_DB_PREFIXreseller_services(service_id, + service_name, + slot_max_qty , + price_per_month, + price_per_year, + description, + remote_server_id, + start_port, + end_port, + max_access_rights) VALUES(NULL, '".$service_name. + "', '".$slot_max_qty. + "', '".$price_per_month. + "', '".$price_per_year. + "', '".$description. + "', '".$remote_server_id. + "', '".$start_port. + "', '".$end_port. + "', '".$max_access_rights."')"; + $db->query($qry_add_service); + } + + //Querying DELETE service FROM DB + if (isset($_POST['remove_service']) AND isset($_POST['service_id'])) + { + $db->query( "DELETE FROM OGP_DB_PREFIXreseller_services WHERE service_id=" . $_POST['service_id'] ); + $db->query( "DELETE FROM OGP_DB_PREFIXreseller_discount_codes WHERE service_id=" . $_POST['service_id'] ); + } + + if( isset( $_POST['add_discount_code'] ) ) + { + //Sanitize the POST values + $service_id = clean($_POST['service_id']); + echo $service_id; + $percentage = clean($_POST['percentage']); + $description = clean($_POST['description']); + $code = clean($_POST['code']); + $add_code = "INSERT INTO OGP_DB_PREFIXreseller_discount_codes(discount_id, service_id, percentage, description, code) VALUES(NULL, '".$service_id."', '".$percentage."', '".$description."', '".$code."')"; + $db->query($add_code); + } + + if (isset($_POST['remove_code']) AND isset($_POST['discount_id'])) + { + $db->query( "DELETE FROM OGP_DB_PREFIXreseller_discount_codes WHERE discount_id=" . $_POST['discount_id'] ); + } + + global $settings; + ?> +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ - + +
+
+
+
+
+ +
+
+ resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_services"); + if ($services > 0) + { + ?> +

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + + + + + +
+
+ + +
+
+
+

+
+ + + + + + + + + + + + + + + + + + + + +
+ +
%
+
+
+ resultQuery("SELECT * FROM OGP_DB_PREFIXreseller_discount_codes"); + if ($discount_codes > 0) + { + ?> +

+ + + + + + + + resultQuery("SELECT service_name FROM OGP_DB_PREFIXreseller_services WHERE service_id=".$row['service_id']); + $service_name = $service[0]['service_name']; + } + else + { + $service_name = get_lang('all_services'); + } + + ?> + + + + + + + + + +
%
+
+ + + + + + +
+
+ +
+
+
+ \ No newline at end of file diff --git a/Panel/modules/reseller/settings.php b/Panel/modules/reseller/settings.php new file mode 100755 index 00000000..28658513 --- /dev/null +++ b/Panel/modules/reseller/settings.php @@ -0,0 +1,83 @@ + "EUR", + 1 => "USD", + 2 => "AUD", + 3 => "BRL", + 4 => "CAD", + 5 => "CZK", + 6 => "DKK", + 8 => "HKD", + 9 => "HUF", + 10 => "ILS", + 11 => "JPY", + 12 => "MYR", + 13 => "MXN", + 14 => "NOK", + 15 => "NZD", + 16 => "PHP", + 17 => "PLN", + 18 => "GBP", + 19 => "SGD", + 20 => "SEK", + 21 => "CHF", + 22 => "TWD", + 23 => "THB", + 24 => "TRY" + ); + + $settings = $db->getSettings(); + $settings['currency'] = isset($settings['currency']) ? $settings['currency'] : "EUR"; + $settings['price_per_month'] = isset($settings['price_per_month']) ? $settings['price_per_month'] : 1; + $settings['price_per_year'] = isset($settings['price_per_year']) ? $settings['price_per_year'] : 1; + $settings['tax_amount'] = isset($settings['tax_amount']) ? $settings['tax_amount'] : 21; + $settings['paypal_email'] = isset($settings['paypal_email']) ? $settings['paypal_email'] : "Business@E-mail"; + function checked($value){ + global $settings; + if( $settings[$value] == 1 ) + return 'checked="checked"'; + } + + if ( isset($_REQUEST['update_settings']) ) + { + $settings = array("currency" => $_REQUEST['currency'], + "price_per_month" => @$_REQUEST['price_per_month'], + "price_per_year" => @$_REQUEST['price_per_year'], + "tax_amount" => $_REQUEST['tax_amount'], + "paypal_email" => $_REQUEST['paypal_email']); + $db->setSettings($settings); + print_success(get_lang('settings_updated')); + $view->refresh("?m=reseller&p=rs_settings"); + return; + } + + echo "

".get_lang('reseller_settings')."

"; + $ft = new FormTable(); + $ft->start_form("?m=reseller&p=rs_settings"); + echo "

".get_lang('currency')."

"; + $ft->start_table(); + $ft->add_custom_field('currency', + create_drop_box_from_array($currencies,"currency",$settings['currency'])); + $ft->end_table(); + echo "

".get_lang('available_invoice_types')."

"; + $ft->start_table(); + $ft->add_custom_field('price_per_month',''); + $ft->add_custom_field('price_per_year',''); + $ft->end_table(); + echo "

".get_lang('tax_amount')."

"; + $ft->start_table(); + $ft->add_field('string','tax_amount',$settings['tax_amount'],2); + $ft->end_table(); + echo "

".get_lang('paypal_email')."

"; + $ft->start_table(); + $ft->add_field('string','paypal_email',$settings['paypal_email'],35); + $ft->end_table(); + $ft->add_button("submit","update_settings",get_lang('update_settings')); + $ft->end_form(); +} +?> diff --git a/Panel/modules/reseller/shop.php b/Panel/modules/reseller/shop.php new file mode 100755 index 00000000..183a9abd --- /dev/null +++ b/Panel/modules/reseller/shop.php @@ -0,0 +1,234 @@ +real_escape_string($str); +} + +function exec_ogp_module() +{ + global $db, $settings; + + if(!isset($settings['price_per_month']) and !isset($settings['price_per_year'])) + { + print_failure("Configure the reseller settings"); + return; + } + + if(isset($settings['price_per_month']) and $settings['price_per_month'] == 0 and isset($settings['price_per_year']) and $settings['price_per_year'] == 0) + { + print_failure("Atleast one invoice type must be checked in the reseller settings."); + return; + } + + if (isset($_POST['save']) AND !empty($_POST['description'])) + { + $new_description = clean($_POST['description']); + $service = clean($_POST['service_id']); + + $change_description = "UPDATE OGP_DB_PREFIXreseller_services + SET description ='".$new_description."' + WHERE service_id=".$service; + $save = $db->query($change_description); + } + ?> + + + + + + + + + + + +
+ + + [+] +
+ +
+ +
+ isAdmin($_SESSION['user_id'] ); + if(isset($_REQUEST['service_id'])) $where_service_id = " WHERE service_id=".$_REQUEST['service_id']; else $where_service_id = ""; + $qry_services = "SELECT * FROM OGP_DB_PREFIXreseller_services".$where_service_id; + $services = $db->resultQuery($qry_services); + if(empty($services)) + { + if($isAdmin) + { + ?> + + $row) { + $service_id[$key] = $row['service_id']; + $slot_max_qty[$key] = $row['slot_max_qty']; + $price_per_month[$key] = $row['price_per_month']; + $price_per_year[$key] = $row['price_per_year']; + $description[$key] = $row['description']; + $max_access_rights[$key] = $row['max_access_rights']; + } + array_multisort($service_id, + $slot_max_qty, + $price_per_month, + $price_per_year, + $description, + $max_access_rights, SORT_DESC, $services); + ?> +
+ +
+
+ + +
+ +
" . + floatval(round(($row['price_per_month']),2 )) . " " . $settings['currency'] . "/" . get_lang('month') ;?>
+ +
" . + floatval(round(($row['price_per_year']),2 )) . " " . $settings['currency'] . "/" . get_lang('year') ;?>
+ +
+
+ +
+ Bad Image +
"; + + if($isAdmin) + { + if(!isset($_POST['edit'])) + { + echo "

$row[description]

"; + echo "

". + "". + "". + "
"; + } + else + { + echo "
". + "
". + "". + "". + "
"; + } + } + else + echo "

$row[description]

"; + ?> +

+ + + + + + + + + + + + + + + + + + + +
:: + +
:: + +
:: + + +
+ + + +
+
+ +
+
+ +
+ \ No newline at end of file