find_many(); foreach($result as $value){ $config[$value['setting']]=$value['value']; } date_default_timezone_set($config['timezone']); $d = ORM::for_table('tbl_user_recharges')->where('status','on')->find_many(); 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(); try { $iport = explode(":",$m['ip_address']); $client = new RouterOS\Client($iport[0], $m['username'], $m['password'],($iport[1])?$iport[1]:null); } catch (Exception $e) { die("Unable to connect to the router.
".$e->getMessage()); } $printRequest = new RouterOS\Request('/ip/hotspot/user/print'); $printRequest->setArgument('.proplist', '.id'); $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); $id = $client->sendSync($printRequest)->getProperty('.id'); $setRequest = new RouterOS\Request('/ip/hotspot/user/set'); $setRequest->setArgument('numbers', $id); $setRequest->setArgument('limit-uptime', '00:00:05'); $client->sendSync($setRequest); //remove hotspot active $onlineRequest = new RouterOS\Request('/ip/hotspot/active/print'); $onlineRequest->setArgument('.proplist', '.id'); $onlineRequest->setQuery(RouterOS\Query::where('user', $c['username'])); $id = $client->sendSync($onlineRequest)->getProperty('.id'); $removeRequest = new RouterOS\Request('/ip/hotspot/active/remove'); $removeRequest->setArgument('numbers', $id); $client->sendSync($removeRequest); //update database user dengan status off $u->status = 'off'; $u->save(); }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(); try { $iport = explode(":",$m['ip_address']); $client = new RouterOS\Client($iport[0], $m['username'], $m['password'],($iport[1])?$iport[1]:null); } catch (Exception $e) { die("Unable to connect to the router.
".$e->getMessage()); } $printRequest = new RouterOS\Request('/ppp/secret/print'); $printRequest->setArgument('.proplist', '.id'); $printRequest->setQuery(RouterOS\Query::where('name', $c['username'])); $id = $client->sendSync($printRequest)->getProperty('.id'); $setRequest = new RouterOS\Request('/ppp/secret/disable'); $setRequest->setArgument('numbers', $id); $client->sendSync($setRequest); //remove hotspot active $onlineRequest = new RouterOS\Request('/ppp/active/print'); $onlineRequest->setArgument('.proplist', '.id'); $onlineRequest->setQuery(RouterOS\Query::where('name', $c['username'])); $id = $client->sendSync($onlineRequest)->getProperty('.id'); $removeRequest = new RouterOS\Request('/ppp/active/remove'); $removeRequest->setArgument('numbers', $id); $client->sendSync($removeRequest); $u->status = 'off'; $u->save(); }else echo " : ACTIVE \r\n"; } }