$gen_id = time();
 $_SESSION["IDfilter"] = $gen_id;
 $sip_buddy = $iax_buddy = 0;
 if (isset($sip) && $sip == 1) {
     $sip_buddy = 1;
 }
 if (isset($iax) && $iax == 1) {
     $iax_buddy = 1;
 }
 $creditlimit = is_numeric($creditlimit) ? $creditlimit : 0;
 //initialize refill parameter
 $description_refill = gettext("CREATION CARD REFILL");
 $field_insert_refill = " credit,card_id, description";
 $instance_refill_table = new Table("cc_logrefill", $field_insert_refill);
 for ($k = 0; $k < $nbcard; $k++) {
     $arr_card_alias = gen_card_with_alias("cc_card", 0, $cardnumberlenght_list);
     $accountnumber = $arr_card_alias[0];
     $useralias = $arr_card_alias[1];
     if (!is_numeric($addcredit)) {
         $addcredit = 0;
     }
     $passui_secret = MDP_NUMERIC(5) . MDP_STRING(10) . MDP_NUMERIC(5);
     $FG_ADITION_SECOND_ADD_VALUE = "'{$accountnumber}', '{$useralias}', '{$addcredit}', '{$choose_tariff}', 't', '{$gen_id}', '', '', '', '', '', '{$id_country}', '', '', {$choose_simultaccess}, '{$choose_currency}', " . "{$choose_typepaid}, {$creditlimit}, {$enableexpire}, '{$expirationdate}', {$expiredays}, '{$passui_secret}', '{$runservice}', '{$tag}', '{$id_group}', '{$discount}', '{$id_seria}', " . "'{$id_didgroup}', {$sip_buddy}, {$iax_buddy}, '{$vat}'";
     if (DB_TYPE != "postgres") {
         $FG_ADITION_SECOND_ADD_VALUE .= ", now() ";
     }
     $id_cc_card = $instance_sub_table->Add_table($HD_Form->DBHandle, $FG_ADITION_SECOND_ADD_VALUE, null, null, $HD_Form->FG_TABLE_ID);
     //create refill for each cards
     if ($addcredit > 0) {
         $value_insert_refill = "'{$addcredit}', '{$id_cc_card}', '{$description_refill}' ";
         $instance_refill_table->Add_table($HD_Form->DBHandle, $value_insert_refill, null, null);
Esempio n. 2
0
    function Create_Customer($security_key, $instance, $id_callplan, $id_didgroup, $units, $accountnumber_len, $balance, $activated, $status,  $simultaccess, $currency, $typepaid, $sip, $iax,  $language, $voicemail_enabled, $country)
    {
        $arr_check = $this->Check_KeyInstance($security_key, $instance);
		if ($arr_check[0] == 'ERROR') {
		    return $arr_check;
		}
		$id_group = $arr_check[0];
		
		if (!is_numeric($id_callplan)) {
		    return array("ERROR", "NO ID_CALLPLAN PROVIDED");
		}
		
		if ($accountnumber_len < 2 || $accountnumber_len > 40) {
		    return array("ERROR", "WRONG ACCOUNT NUMBER LENGTH - $accountnumber_len");
		}
		
		if (strlen($country)==3)
			$country = strtoupper($country);
		else 
			$country = 'USA';
		
		if (strlen($language)==2)
			$language = strtolower($language);
		else
			$language = 'en';
		
		if ($activated)
			$activated = 't';
	    else
	        $activated = 'f';
		
		$instance_realtime = new Realtime();
        
	    $FG_ADITION_SECOND_ADD_TABLE = "cc_card";
	    $FG_ADITION_SECOND_ADD_FIELDS = "username, useralias, credit, tariff, country, language, activated, simultaccess, currency, typepaid, uipass, id_group, id_didgroup, sip_buddy, iax_buddy";

	    if (DB_TYPE != "postgres") {
		    $FG_ADITION_SECOND_ADD_FIELDS .= ",creationdate ";
	    }
	
	    $instance_sub_table = new Table($FG_ADITION_SECOND_ADD_TABLE, $FG_ADITION_SECOND_ADD_FIELDS);
	    
	    $sip_buddy = $iax_buddy = 0;
	    
	    if (isset ($sip) && $sip == 1)
            $sip_buddy = 1;
        
        if (isset ($iax) && $iax == 1)
            $iax_buddy = 1;
        
	    //initialize refill parameter
	    $description_refill = gettext("CREATION CARD REFILL");
	    $field_insert_refill = "credit, card_id, description";
	    $instance_refill_table = new Table("cc_logrefill", $field_insert_refill);
        $arr_account = array();
        
	    for ($k = 0; $k < $units; $k++) {
		    $arr_card_alias = gen_card_with_alias("cc_card", 0, $accountnumber_len);
		    $accountnumber = $arr_card_alias[0];
		    $useralias = $arr_card_alias[1];
		    if (!is_numeric($balance))
			    $balance = 0;
		    $passui_secret = MDP_NUMERIC(10);
		
		    $FG_ADITION_SECOND_ADD_VALUE = "'$accountnumber', '$useralias', '$balance', '$id_callplan', '$country', '$language', '$activated', ".
		                         " $simultaccess, '$currency', $typepaid, '$passui_secret', '$id_group', '$id_didgroup', $sip_buddy, $iax_buddy";
            
		    if (DB_TYPE != "postgres")
			    $FG_ADITION_SECOND_ADD_VALUE .= ", now() ";
		    
		    $id_cc_card = $instance_sub_table->Add_table($this->DBHandle, $FG_ADITION_SECOND_ADD_VALUE, null, null, 'id');
		    
		    if (!$id_cc_card) {
		        return array(false, "ERROR CREATING ACCOUNT (".$k." Accounts created)");
		    }
		    
		    $arr_account[] = array ($accountnumber, $id_cc_card);
		    
		    // create refill for card
		    if ($balance > 0) {
			    $value_insert_refill = "'$balance', '$id_cc_card', '$description_refill' ";
			    $instance_refill_table->Add_table($this->DBHandle, $value_insert_refill, null, null);
		    }
            
		    $instance_realtime -> insert_voip_config ($sip_buddy, $iax_buddy, $id_cc_card, $accountnumber, $passui_secret, $useralias, $language);
	    }
	    
	    // Save Sip accounts to file
	    $instance_realtime -> create_trunk_config_file ('sip');
	    
	    // Save IAX accounts to file
	    $instance_realtime -> create_trunk_config_file ('iax');
	    
	    
		return array(serialize($arr_account), "Create_Customer SUCCESS - ".$k." ACCOUNTS CREATED");
    }
Esempio n. 3
0
 function Create_Card($security_key, $transaction_code, $account_number, $tariff, $uipass, $credit, $language, $activated, $status, $simultaccess, $currency, $runservice, $typepaid, $creditlimit, $enableexpire, $expirationdate, $expiredays, $lastname, $firstname, $address, $city, $state, $country, $zipcode, $phone, $fax, $callerid_list, $iax_friend, $sip_friend)
 {
     // The wrapper variables for security
     // $security_key = API_SECURITY_KEY;
     $logfile = SOAP_LOGFILE;
     $mysecurity_key = API_SECURITY_KEY;
     $mail_content = "[" . date("Y/m/d G:i:s", mktime()) . "] " . "SOAP API - Request asked: Create_Card [{$transaction_code}, {$account_number}, {$tariff}, {$uipass}, {$credit}, {$language}, {$activated}, {$simultaccess}, {$currency}, {$runservice}, {$typepaid}, {$creditlimit}, {$enableexpire}, {$expirationdate}, {$expiredays}, {$lastname}, {$firstname}, {$address}, {$city}, {$state}, {$country}, {$zipcode}, {$phone}, {$fax}, {$callerid_list}, {$iax_friend}, {$sip_friend}]";
     // CHECK SECURITY KEY
     if (md5($mysecurity_key) !== $security_key || strlen($security_key) == 0) {
         a2b_mail(EMAIL_ADMIN, "ALARM : API - CODE_ERROR SECURITY_KEY ", $mail_content);
         error_log("[" . date("Y/m/d G:i:s", mktime()) . "] " . " CODE_ERROR SECURITY_KEY" . "\n", 3, $logfile);
         sleep(2);
         return array($transaction_code, '', '', '', '', 'Error', 'KEY - BAD PARAMETER' . "{$security_key} - {$mysecurity_key}");
     }
     // Create new account
     $FG_ADITION_SECOND_ADD_TABLE = "cc_card";
     $FG_ADITION_SECOND_ADD_FIELDS = "username, useralias, credit, tariff, id_didgroup, activated, status, lastname, firstname, email, address, city, state, country, zipcode, phone, fax, userpass, simultaccess, currency, typepaid, creditlimit, language, runservice, enableexpire, expirationdate, expiredays, uipass, sip_buddy, iax_buddy";
     $arr_card_alias = gen_card_with_alias('cc_card', 1);
     $cardnum = $arr_card_alias[0];
     $useralias = $arr_card_alias[1];
     if ($uipass == '' || strlen($uipass) == 0) {
         $uipass = MDP_STRING();
     }
     // CHECK PARAMETERS LASTNAME ; FIRSTNAME ; ADDRESS ; ....
     if (!is_numeric($credit) || !is_numeric($creditlimit) || !is_numeric($expiredays) || $activated != 0 && $activated != 1 || $simultaccess != 0 && $simultaccess != 1 || $runservice != 0 && $runservice != 1 || strlen($lastname) > 40 || strlen($firstname) > 40 || strlen($address) > 100 || strlen($city) > 40 || strlen($state) > 40 || strlen($country) > 40 || strlen($zipcode) > 40 || strlen($phone) > 40 || strlen($email) > 60 || strlen($fax) > 40) {
         a2b_mail(EMAIL_ADMIN, "ALARM : API  - BAD PARAMETER ", $mail_content);
         error_log("[" . date("Y/m/d G:i:s", mktime()) . "] " . " - BAD PARAMETER " . "\n", 3, $logfile);
         return array($transaction_code, '', '', '', '', 'Error', 'BAD PARAMETER');
     } else {
         if ($expirationdate == '') {
             $expirationdate = "now()";
         } else {
             $expirationdate = "'{$expirationdate}'";
         }
         $DBHandle = DbConnect();
         $instance_sub_table = new Table($FG_ADITION_SECOND_ADD_TABLE, $FG_ADITION_SECOND_ADD_FIELDS);
         $FG_ADITION_SECOND_ADD_VALUE = "'{$cardnum}', '{$useralias}', '" . $credit . "', '" . $tariff . "', '0', '{$activated}', '{$status}', '{$lastname}', '{$firstname}', '{$email}', '{$address}', '{$city}', " . "'{$state}', '{$country}', '{$zipcode}', '{$phone}', '{$fax}', '{$cardnum}', " . $simultaccess . ", '" . $currency . "', '" . $typepaid . "','" . $creditlimit . "', '" . $language . "', '" . $runservice . "', '" . $enableexpire . "', {$expirationdate}, '{$expiredays}', '{$uipass}', '{$iax_friend}', '{$sip_friend}'";
         $result_query = $instance_sub_table->Add_table($DBHandle, $FG_ADITION_SECOND_ADD_VALUE, null, null, 'id');
         if ($result_query) {
             $id_cc_card = $result_query;
             if (strlen($callerid_list) > 1) {
                 $callerid_list = split(',', $callerid_list);
                 if (count($callerid_list) > 0) {
                     $k = 0;
                     foreach ($callerid_list as $mycallerid) {
                         $k++;
                         if (strlen($mycallerid) > 1) {
                             $QUERY = "SELECT * FROM cc_callerid WHERE cid='{$mycallerid}'";
                             $result = $instance_sub_table->SQLExec($DBHandle, $QUERY);
                             if (!is_array($result)) {
                                 $QUERY = "INSERT INTO cc_callerid (cid, id_cc_card) VALUES ('{$mycallerid}', '{$id_cc_card}')";
                                 $result = $instance_sub_table->SQLExec($DBHandle, $QUERY, 0);
                                 if ($result == false) {
                                     $callerid_result .= "|callerid{$k}-{$mycallerid}=NOK";
                                 } else {
                                     $callerid_result .= "|callerid{$k}-{$mycallerid}=OK";
                                 }
                             } else {
                                 $callerid_result .= "|callerid{$k}-{$mycallerid}=NOK";
                             }
                         }
                     }
                 }
             }
             //return array('transaction_code', 'account_number', 'card_number', $useralias, 'uipass', 'result', "IDCARD_CREATED=$id_cc_card"."$callerid_result");
             //|LASTQUERY=$QUERY
             // CHECK IF THERE IS A FRIEND TO CREATE
             if ($iax_friend || $sip_friend) {
                 // NEW ACCOUNT CREATED
                 $type = FRIEND_TYPE;
                 $allow = FRIEND_ALLOW;
                 $context = FRIEND_CONTEXT;
                 $nat = FRIEND_NAT;
                 $amaflags = FRIEND_AMAFLAGS;
                 $qualify = FRIEND_QUALIFY;
                 $host = FRIEND_HOST;
                 $dtmfmode = FRIEND_DTMFMODE;
                 $uipass = MDP_STRING();
                 $FG_QUERY_ADITION_SIP_IAX = 'name, type, username, accountcode, regexten, callerid, amaflags, secret, md5secret, nat, dtmfmode, qualify, canreinvite,disallow, allow, host, callgroup, context, defaultip, fromuser, fromdomain, insecure, language, mailbox, permit, deny, mask, pickupgroup, port,restrictcid, rtptimeout, rtpholdtimeout, musiconhold, regseconds, ipaddr, cancallforward';
                 // For IAX and SIP
                 $param_add_fields = "name, accountcode, regexten, amaflags, callerid, context, dtmfmode, host,  type, username, allow, secret";
                 $param_add_value = "'{$cardnum}', '{$cardnum}', '{$cardnum}', '{$amaflags}', '{$cardnum}', '{$context}', '{$dtmfmode}','{$host}', '{$type}', '{$cardnum}', '{$allow}', '" . $uipass . "', '{$id_cc_card}', '{$nat}', '{$qualify}'";
                 $list_names = explode(",", $FG_QUERY_ADITION_SIP_IAX);
                 $FG_TABLE_SIP_NAME = "cc_sip_buddies";
                 $FG_TABLE_IAX_NAME = "cc_iax_buddies";
                 for ($ki = 0; $ki < 2; $ki++) {
                     if ($ki == 0) {
                         if (!$sip_friend) {
                             continue;
                         }
                         $cfriend = 'sip';
                         $FG_TABLE_NAME = "cc_sip_buddies";
                         $buddyfile = BUDDY_SIP_FILE;
                     } else {
                         if (!$iax_friend) {
                             continue;
                         }
                         $cfriend = 'iax';
                         $FG_TABLE_NAME = "cc_iax_buddies";
                         $buddyfile = BUDDY_IAX_FILE;
                     }
                     // Insert Sip/Iax account info
                     if ($ki == 0 && $sip_friend || $ki == 1 && $iax_friend) {
                         $instance_table1 = new Table($FG_TABLE_NAME, $FG_QUERY_ADITION_SIP_IAX);
                         $result_query1 = $instance_table1->Add_table($DBHandle, $param_add_value, $param_add_fields, null, null);
                         $instance_table_friend = new Table($FG_TABLE_NAME, 'id, ' . $FG_QUERY_ADITION_SIP_IAX);
                         $list_friend = $instance_table_friend->Get_list($DBHandle, '', null, null, null, null);
                         $fd = fopen($buddyfile, "w");
                         if (!$fd) {
                             a2b_mail($email_alarm, "ALARM : SOAP-API  - Could not open buddy file '{$buddyfile}'", $mail_content);
                             error_log("[" . date("Y/m/d G:i:s", mktime()) . "] " . "[Could not open buddy file '{$buddyfile}'] - SOAP-API " . "\n", 3, $logfile);
                             return array($transaction_code, '', '', '', '', 'Error', 'SOAP-API  - Could not open buddy file $buddyfile');
                         } else {
                             foreach ($list_friend as $data) {
                                 $line = "\n\n[" . $data[1] . "]\n";
                                 if (fwrite($fd, $line) === FALSE) {
                                     error_log("[" . date("Y/m/d G:i:s", mktime()) . "] " . "[Impossible to write to the file ({$buddyfile})] - CODE_ERROR 8" . "\n", 3, $logfile);
                                     return array($transaction_code, '', '', '', '', 'Error', 'SOAP-API Impossible to write to the file ($buddyfile)');
                                 } else {
                                     for ($i = 1; $i < count($data) - 1; $i++) {
                                         if (strlen($data[$i + 1]) > 0) {
                                             if (trim($list_names[$i]) == 'allow') {
                                                 $codecs = explode(",", $data[$i + 1]);
                                                 $line = "";
                                                 foreach ($codecs as $value) {
                                                     $line .= trim($list_names[$i]) . '=' . $value . "\n";
                                                 }
                                             } else {
                                                 $line = trim($list_names[$i]) . '=' . $data[$i + 1] . "\n";
                                             }
                                             if (fwrite($fd, $line) === FALSE) {
                                                 error_log("[" . date("Y/m/d G:i:s", mktime()) . "] " . "[Impossible to write to the file ({$buddyfile})] - CODE_ERROR 8" . "\n", 3, $logfile);
                                                 return array($transaction_code, '', '', '', '', 'Error', 'SOAP-API ERROR : Card created in the DB but Impossible to write to the file ($buddyfile)');
                                             }
                                         }
                                     }
                                 }
                             }
                             fclose($fd);
                         }
                     }
                 }
                 // END OF FOR - KI
             }
             // END if ($iax_friend || $sip_friend)
             return array($transaction_code, $account_number, $cardnum, $useralias, $uipass, 'result=OK', "ID CARD_CREATED={$result_query}{$callerid_result}");
         } else {
             a2b_mail(EMAIL_ADMIN, "ALARM : SOAP-API (Add_table)", "{$FG_ADITION_SECOND_ADD_VALUE}\n\n" . $mail_content);
             error_log("[" . date("Y/m/d G:i:s", mktime()) . "] " . "[SOAP-API CODE_ERROR Add_table " . "\n", 3, $logfile);
             return array($transaction_code, '', '', '', '', 'Error', 'SOAP-API CODE_ERROR Add_table');
         }
     }
     // END - CHECK PARAMETERS LASTNAME ; FIRSTNAME ; ADDRESS ; ....
 }
Esempio n. 4
0
$nb_db_rates = $instance_table->SQLExec($A2B->DBHandle, $query, 1);
if ($verbose > 0) {
    echo "TOTAL DB RATES : " . $nb_db_rates[0][0] . " <br><br>\n\n";
}
// -----------------------------------
// CREATE CARDS
// -----------------------------------
$instance_callplan = new Table("cc_tariffgroup", "id");
$result_callplan_id = $instance_callplan->Get_list($A2B->DBHandle, null, null, null, null, null, 1000, 1);
$nb_db_callplan = sizeof($result_callplan_id);
for ($i = 0; $i < $nb_customer; $i++) {
    if ($verbose > 1) {
        echo "CREATE CARD : {$i}\n";
    }
    $id_callplan = $result_callplan_id[rand(0, $nb_db_callplan)]['id'];
    $array_card_generated = gen_card_with_alias("cc_card", 0, 10, $A2B->DBHandle);
    $card_number = $array_card_generated[0];
    $card_alias = $array_card_generated[1];
    $pass = MDP_NUMERIC(5) . MDP_STRING(10) . MDP_NUMERIC(5);
    $query = "INSERT INTO cc_card (username, useralias, uipass, id_group, credit, language, tariff, id_didgroup, status, simultaccess, currency, runservice, autorefill, initialbalance, typepaid, enableexpire, expirationdate, expiredays, voicemail_permitted, voicemail_activated, invoiceday, lastname, firstname, country, id_timezone, sip_buddy, iax_buddy, inuse, credit_notification, notify_email ) values" . "('1111', '11111', '1111', '1', '10', 'en', '1', '-1', '-1', '1', 'USD', '0', '0', '0', '0', '0', '2018-09-02 23:21:33', '0', '1', '0', '0', '11111', 'card', 'AFG', '1', '0', '0', '0', '-1', '0'); ";
    $instance_table->SQLExec($A2B->DBHandle, $query);
}
$query = "SELECT count(*) FROM cc_card;";
$nb_db_card = $instance_table->SQLExec($A2B->DBHandle, $query, 1);
if ($verbose > 0) {
    echo "TOTAL DB CARDS : " . $nb_db_card[0][0] . " <br><br>\n\n";
}
// Get a list of card
$instance_card = new Table("cc_card", "id");
$result_card_id = $instance_card->Get_list($A2B->DBHandle, null, null, null, null, null, 1000, 1);
$nb_db_card = sizeof($result_card_id);
Esempio n. 5
0
}
$DBHandle = DbConnect();
$FG_TABLE_NAME = 'cc_ecommerce_product, cc_templatemail';
$instance_table = new Table($FG_TABLE_NAME, $FG_QUERY_EDITION);
$ec_prod = get_productinfo($DBHandle, $instance_table, $productid, $email_alarm, $mail_content, $logfile);
if ($FG_DEBUG > 0) {
    echo "GET_PRODUCTINFO<br>";
}
if ($FG_DEBUG > 0) {
    print_r($ec_prod);
}
// Create new account
$FG_ADITION_SECOND_ADD_TABLE = "cc_card";
$FG_ADITION_SECOND_ADD_FIELDS = "username, useralias, credit, tariff, id_didgroup, activated, lastname, firstname, email, address, city, state, country, zipcode, phone, userpass, simultaccess, currency, typepaid, creditlimit, language, runservice, enableexpire, uipass, sip_buddy, iax_buddy";
$gen_id = time();
$arr_card_alias = gen_card_with_alias('cc_card', 1);
$cardnum = $arr_card_alias[0];
$useralias = $arr_card_alias[1];
$uipass = MDP_STRING();
// 0 product_name, creationdate, description, expirationdate, enableexpire, expiredays, credit, tariff, id_didgroup, activated, simultaccess,
// 11 currency, typepaid, creditlimit, language, runservice, sip_friend, iax_friend, cc_ecommerce_product.mailtype, fromemail, fromname,
// 21 subject, messagetext, messagehtml
if ($forceid > 0) {
    // FORCE THE INSERT WITH A DEFINED ID
    $instance_sub_table = new Table($FG_ADITION_SECOND_ADD_TABLE, 'id, ' . $FG_ADITION_SECOND_ADD_FIELDS);
    $FG_ADITION_SECOND_ADD_VALUE = "'{$forceid}', '{$cardnum}', '{$useralias}', '" . $ec_prod[6] . "', '" . $ec_prod[7] . "', '" . $ec_prod[8] . "', 't', '{$lastname}', '{$firstname}', '{$email}', '{$address}', '{$city}', '{$state}', '{$country}', '{$zipcode}', '{$phone}', '{$cardnum}', " . $ec_prod[10] . ", '" . $ec_prod[11] . "', '" . $ec_prod[12] . "', '" . $ec_prod[13] . "', '" . $ec_prod[14] . "', " . $ec_prod[15] . ", 0, '{$uipass}', " . $ec_prod[16] . ", " . $ec_prod[17] . "";
} else {
    // LEAVE THE AUTO INCREMENT FOR THE ID
    $instance_sub_table = new Table($FG_ADITION_SECOND_ADD_TABLE, $FG_ADITION_SECOND_ADD_FIELDS);
    $FG_ADITION_SECOND_ADD_VALUE = "'{$cardnum}', '{$useralias}', '" . $ec_prod[6] . "', '" . $ec_prod[7] . "', '" . $ec_prod[8] . "', 't', '{$lastname}', '{$firstname}', '{$email}', '{$address}', '{$city}', '{$state}', '{$country}', '{$zipcode}', '{$phone}', '{$cardnum}', " . $ec_prod[10] . ", '" . $ec_prod[11] . "', '" . $ec_prod[12] . "', '" . $ec_prod[13] . "', '" . $ec_prod[14] . "', " . $ec_prod[15] . ", 0, '{$uipass}', " . $ec_prod[16] . ", " . $ec_prod[17] . "";
}