find_many(); foreach ($result as $value) { $config[$value['setting']] = $value['value']; } $_c = $config; date_default_timezone_set($config['timezone']); $textExpired = $_notifmsg['expired']; $d = ORM::for_table('tbl_user_recharges')->where('status', 'on')->find_many(); run_hook('cronjob'); #HOOK foreach ($d as $ds) { if ($ds['type'] == 'Hotspot') { $date_now = strtotime(date("Y-m-d H:i:s")); $expiration = strtotime($ds['expiration'] . ' ' . $ds['time']); echo $ds['expiration'] . " : " . $ds['username']; if ($date_now >= $expiration) { echo " : EXPIRED \r\n"; $u = ORM::for_table('tbl_user_recharges')->where('id', $ds['id'])->find_one(); $c = ORM::for_table('tbl_customers')->where('id', $ds['customer_id'])->find_one(); $m = ORM::for_table('tbl_routers')->where('name', $ds['routers'])->find_one(); if (!$_c['radius_mode']) { $client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']); Mikrotik::setHotspotLimitUptime($client, $c['username']); Mikrotik::removeHotspotActiveUser($client, $c['username']); Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], $textExpired, $config['user_notification_expired']); } //update database user dengan status off $u->status = 'off'; $u->save(); // autorenewal from deposit if ($config['enable_balance'] == 'yes' && $c['auto_renewal']) { $p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one(); if ($p && $p['enabled'] && $c['balance'] >= $p['price']) { if (Package::rechargeUser($ds['customer_id'], $p['routers'], $p['id'], 'Customer', 'Balance')) { // if success, then get the balance Balance::min($ds['customer_id'], $p['price']); echo "plan enabled: $p[enabled] | User balance: $c[balance] | price $p[price]\n"; echo "auto renewall Success\n"; } else { echo "plan enabled: $p[enabled] | User balance: $c[balance] | price $p[price]\n"; echo "auto renewall Failed\n"; Message::sendTelegram("FAILED RENEWAL #cron\n\n#u$c[username] #buy #Hotspot \n" . $p['name_plan'] . "\nRouter: " . $router_name . "\nPrice: " . $p['price']); } }else{ echo "no renewall | plan enabled: $p[enabled] | User balance: $c[balance] | price $p[price]\n"; } }else{ echo "no renewall | balance $config[enable_balance] auto_renewal $c[auto_renewal]\n"; } } else echo " : ACTIVE \r\n"; } else { $date_now = strtotime(date("Y-m-d H:i:s")); $expiration = strtotime($ds['expiration'] . ' ' . $ds['time']); echo $ds['expiration'] . " : " . $ds['username']; if ($date_now >= $expiration) { echo " : EXPIRED \r\n"; $u = ORM::for_table('tbl_user_recharges')->where('id', $ds['id'])->find_one(); $c = ORM::for_table('tbl_customers')->where('id', $ds['customer_id'])->find_one(); $m = ORM::for_table('tbl_routers')->where('name', $ds['routers'])->find_one(); if (!$_c['radius_mode']) { $client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']); Mikrotik::disablePpoeUser($client, $c['username']); Mikrotik::removePpoeActive($client, $c['username']); Message::sendPackageNotification($c['phonenumber'], $c['fullname'], $u['namebp'], $textExpired, $config['user_notification_expired']); } $u->status = 'off'; $u->save(); // autorenewal from deposit if ($config['enable_balance'] == 'yes' && $c['auto_renewal']) { $p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one(); if ($p && $p['enabled'] && $c['balance'] >= $p['price']) { if (Package::rechargeUser($ds['customer_id'], $p['routers'], $p['id'], 'Customer', 'Balance')) { // if success, then get the balance Balance::min($ds['customer_id'], $p['price']); } else { Message::sendTelegram("FAILED RENEWAL #cron\n\n#u$c[username] #buy #Hotspot \n" . $p['name_plan'] . "\nRouter: " . $router_name . "\nPrice: " . $p['price']); } } } } else echo " : ACTIVE \r\n"; } }