Last active
September 5, 2019 07:58
-
-
Save D4R4/b2bc5b815fea17492c74e135b78aa8f2 to your computer and use it in GitHub Desktop.
Cronjob to sync domain pricing in WHMCS with Faraso.org resellers prices, Just correct the configuration and add it to a daily cron schedule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$profit = 0; | |
$irt = true; | |
$ir_r = 10000; | |
$ir_t = 10000; | |
$ir_n = 10000; | |
include "../public_html/configuration.php"; | |
// Get the string from the URL | |
$json = file_get_contents('https://www.faraso.org/resellerdmnprice/?tld=all'); | |
$data = json_decode($json); | |
if (sizeof($data) < 100) | |
{ | |
echo "Could not fetch data, terminating..."; | |
die(); | |
} | |
$mysqli = new mysqli($db_host , $db_username, $db_password, $db_name); | |
if ($mysqli->connect_errno) { | |
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; | |
} | |
if (!$mysqli->query("DELETE FROM tbldomainpricing")) | |
{ | |
echo "Table creation failed: (" . $mysqli->errno . ") " . $mysqli->error; | |
die(); | |
} | |
$mysqli->query("DELETE FROM tblpricing WHERE type='domainregister' OR type= 'domaintransfer' OR type = 'domainrenew'; "); | |
$id = 1; | |
$mysqli->query("insert into `tbldomainpricing` (`id`, `extension`, `dnsmanagement`, `emailforwarding`, `idprotection`, `eppcode`, `autoreg`, `order`, `group`) values('$id','.ir','on','','on','on','subirnic','$id','');"); | |
$mysqli->query("insert into `tblpricing` (`type`, `currency`, `relid`, `msetupfee`, `qsetupfee`, `ssetupfee`, `asetupfee`, `bsetupfee`, `tsetupfee`, `monthly`, `quarterly`, `semiannually`, `annually`, `biennially`, `triennially`) values('domainregister','1',$id,$ir_r,'-1.00','-1.00','-1.00','-1.00','0.00','-1.00','-1.00','-1.00','-1.00','-1.00','0.00');"); | |
$mysqli->query("insert into `tblpricing` (`type`, `currency`, `relid`, `msetupfee`, `qsetupfee`, `ssetupfee`, `asetupfee`, `bsetupfee`, `tsetupfee`, `monthly`, `quarterly`, `semiannually`, `annually`, `biennially`, `triennially`) values('domaintransfer','1',$id,$ir_t,'-1.00','-1.00','-1.00','-1.00','0.00','-1.00','-1.00','-1.00','-1.00','-1.00','0.00');"); | |
$mysqli->query("insert into `tblpricing` (`type`, `currency`, `relid`, `msetupfee`, `qsetupfee`, `ssetupfee`, `asetupfee`, `bsetupfee`, `tsetupfee`, `monthly`, `quarterly`, `semiannually`, `annually`, `biennially`, `triennially`) values('domainrenew','1',$id,$ir_n,'-1.00','-1.00','-1.00','-1.00','0.00','-1.00','-1.00','-1.00','-1.00','-1.00','0.00');"); | |
foreach ($data as $row) { | |
$id += 1; | |
$tld = $row->tld; | |
$mysqli->query("insert into `tbldomainpricing` (`id`, `extension`, `dnsmanagement`, `emailforwarding`, `idprotection`, `eppcode`, `autoreg`, `order`, `group`) values('$id','$tld','on','','on','on','farasoreseller','$id','');"); | |
$p_r = $row->register; | |
$p_t = $row->transfer; | |
$p_n = $row->renew; | |
if ($irt) | |
{ | |
$p_r *= .1; | |
$p_t *= .1; | |
$p_n *= .1; | |
} | |
$p_r += $profit; | |
$p_t += $profit; | |
$p_n += $profit; | |
$mysqli->query("insert into `tblpricing` (`type`, `currency`, `relid`, `msetupfee`, `qsetupfee`, `ssetupfee`, `asetupfee`, `bsetupfee`, `tsetupfee`, `monthly`, `quarterly`, `semiannually`, `annually`, `biennially`, `triennially`) values('domainregister','1',$id,$p_r,'-1.00','-1.00','-1.00','-1.00','0.00','-1.00','-1.00','-1.00','-1.00','-1.00','0.00');"); | |
$mysqli->query("insert into `tblpricing` (`type`, `currency`, `relid`, `msetupfee`, `qsetupfee`, `ssetupfee`, `asetupfee`, `bsetupfee`, `tsetupfee`, `monthly`, `quarterly`, `semiannually`, `annually`, `biennially`, `triennially`) values('domaintransfer','1',$id,$p_t,'-1.00','-1.00','-1.00','-1.00','0.00','-1.00','-1.00','-1.00','-1.00','-1.00','0.00');"); | |
$mysqli->query("insert into `tblpricing` (`type`, `currency`, `relid`, `msetupfee`, `qsetupfee`, `ssetupfee`, `asetupfee`, `bsetupfee`, `tsetupfee`, `monthly`, `quarterly`, `semiannually`, `annually`, `biennially`, `triennially`) values('domainrenew','1',$id,$p_n,'-1.00','-1.00','-1.00','-1.00','0.00','-1.00','-1.00','-1.00','-1.00','-1.00','0.00');"); | |
} | |
$mysqli->close(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment