Skip to content

Commit

Permalink
Update MysqlBandReset
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzm committed Aug 31, 2017
1 parent fcdeddd commit 977ba8e
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 4 deletions.
97 changes: 97 additions & 0 deletions Crons/MysqlBandReset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?
define('DB_NAME', '');//数据库名字
define('DB_USER', '');//数据库用户名
define('DB_PASS', '');//数据库密码
define('DB_HOST', 'localhost');//数据库IP/域名

define('WHMCS_DB_NAME', '');//WHMCS数据库名字
define('WHMCS_DB_USER', '');//WHMCS数据库用户名
define('WHMCS_DB_PASS', '');//WHMCS数据库密码
define('WHMCS_DB_HOST', 'localhost');//WHMCS数据库IP/域名

function resetband($id){
$ssmysql = new mysqli(DB_HOST, DB_USER, DB_PASS , DB_NAME);
if(!$ssmysql) {
die('Unable to connect to database.');
}else{
$ssmysql->query("UPDATE `user` SET `u` = '0', `d` = '0' where `sid` = ".$id);
$ssmysql->query("delete from `user_usage` WHERE `sid` = ".$id);
echo("ID:".$id." Has been reset</br>");
}
}

function daysInmonth($year='',$month=''){
if(empty($year)) $year = date('Y');
if(empty($month)) $month = date('m');
if (in_array($month, array(1, 3, 5, 7, 8, '01', '03', '05', '07', '08', 10, 12))) {
$text = '31'; //月大
}elseif ($month == 2 || $month == '02'){
if ( ($year % 400 == 0) || ( ($year % 4 == 0) && ($year % 100 !== 0) ) ) { //判断是否是闰年
$text = '29'; //闰年2月
} else {
$text = '28'; //平年2月
}
} else {
$text = '30'; //月小
}

return $text;
}

function calcreset($product,$whmcs,$day){
switch($product['need_reset']){
case 0:
break;
case 1:
if(date("d", strtotime($whmcs['nextduedate'])) == date('d')){
resetband($product['sid']);
}
if(date('d') == $day){
if(date("d", strtotime($whmcs['nextduedate'])) > $day){
resetband($product['sid']);
}
}
break;
case 2:
if(date('d') == 1){
resetband($product['sid']);
}
break;
case 3:
if(date('d') == $day){
resetband($product['sid']);
}
break;
}
}

$mysql = new mysqli(WHMCS_DB_HOST, WHMCS_DB_USER, WHMCS_DB_PASS , WHMCS_DB_NAME);
if(!$mysql) {
die("Can't connect to WHMCS Database");
}else{
$produ = array();
$sql = "SELECT * FROM `tblhosting` WHERE `domainstatus` = 'Active'";
$whmcspro = mysqli_fetch_all($mysql->query($sql),MYSQLI_ASSOC);
$mysql->close();
if($whmcspro){
foreach($whmcspro as $whmcs){
$produ[$whmcs['id']] = $whmcs;
}
}else{
die("Nothing Active In tblhosting in WHMCS Database");
}
$ssmysql = new mysqli(DB_HOST, DB_USER, DB_PASS , DB_NAME);
$sql = "SELECT * FROM `user` WHERE `enable` = 1 order by `sid`";
$ssacc = mysqli_fetch_all($ssmysql->query($sql),MYSQLI_ASSOC);
$ssmysql->close();
$days = daysInmonth(date('y'),date('m'));
if($ssacc){
foreach($ssacc as $ssa){
$pro = $produ[$ssa['sid']];
calcreset($ssa,$pro,$days);
}
}else{
die("Nothing isset in SS/SSR's User Table(users)");
}
echo("Reset Done");
}
4 changes: 2 additions & 2 deletions Crons/ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Usage|用法
* APIbandreset.php is used to reset the traffic with api|APIbandreset.php是用来根据到期时间的日(day)来重置流量的
* MysqlBandReset.php is used to reset the traffic with api|MysqlBandReset.php是用来根据到期时间的日(day)来重置流量的
* cron.php has been removed(Not useful)|cron.php已被移除(无用)
* ChartInfo.php is used to record the traffic|ChartInfo.php是用来记录使用流量的,可不配置。
* ResetCard.php is used to Disable the outdated Bandwidth|ResetCard.php是用来停用过期的额外流量包的,可不配置。

## Suggested Usage|建议用法
0 0 * * * php -q /home/wwwroot/APIbandreset.php
0 0 * * * php -q /home/wwwroot/MysqlBandReset.php
1 */3 * * * php -q /home/wwwroot/ChartInfo.php
0 0 * * * php -q /home/wwwroot/ResetCard.php
2 changes: 1 addition & 1 deletion Crons/APIbandreset.php → Crons/old/APIbandreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function resetband($id){
if(!$mysql) {
die('Unable to connect to database.');
} else {
$mysql->query("UPDATE `user` SET `u` = '0', `d` = '0' where `need_reset` = 1 AND `sid` = ".$id);
$mysql->query("UPDATE `user` SET `u` = '0', `d` = '0' where `sid` = ".$id);
$mysql->query("delete from `user_usage` WHERE `sid` = ".$id);
echo("ID:".$id." Has been reset</br>");
}
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Added Announcements Support|加入公告信息支持
* Added Additional Bandwidth System|已加入额外流量包系统
* Added Support for SS&SSR compatible mode|加入SS&SSR兼容模式支持
* Added Band reset mode(start of month,end of month,calc by duedate)|新增流量重置模式(每月开始,每月底,由结算日计算)

## TO-DO List
* ~~Readd custom traffic module|重新添加自定义流量系统~~
Expand All @@ -21,14 +22,15 @@
* ~~Fix The Bug of APIBandreset|修正APIBandreset的时间bug~~

## Attentions
* To use APIBandReset,You MUST Add API IP in System->General->security|如果要使用APIBandReset,你必须在System->General->security中添加访问API的ip
* To use MysqlBandReset,You MUST edit the database info in MysqlBandReset.php|如果要使用MysqlBandReset,你必须在MysqlBandReset.php中配置数据库信息
* You must add a server and select it in Product->Module Settings|请添加服务器并在产品->模块设置中选择服务器
* Please RESET the product AFTER you update the plugin and CHECK every thing is right|请在更新插件后确认全部的产品和服务器配置正确
* Database is the same as before|数据库兼容旧版
* RouteList has changed,Please check|路线列表进行了更新,请检查然后更正
* Because of removed 'AccessHash',configoptions has some small changes so please RESET the Prooduct->ModuleSettings|因为移除了访问哈希,请重新配置产品->模块设置
* Please upload user_usage.sql if you need traffic chart function|如果你需要流量图表功能,请上传user_usage.sql
* Random Password means you can leave blank in Custom Strings|随机密码的意思是你可以在购买时不填写自定义密码(避免眼滑用户看不见自定义密码选项)
* To use APIBandReset,You MUST Add API IP in System->General->security|如果要使用APIBandReset,你必须在System->General->security中添加访问API的ip
* For More support,You can open an issue or email me|需要更多支持,请开issue或者给我发邮件

## Other
Expand Down

0 comments on commit 977ba8e

Please sign in to comment.