Commit 61d6dfcc by Скуратович Александр

обновление статуса домена

1 parent e0b1fd55
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace app\commands; namespace app\commands;
use PHPHtmlParser\Dom;
use yii\db\Query;
use yii; use yii;
use yii\console\Controller; use yii\console\Controller;
use yii\db\Expression; use yii\db\Expression;
...@@ -14,7 +16,7 @@ use app\models\Host; ...@@ -14,7 +16,7 @@ use app\models\Host;
*/ */
class WhoisController extends Controller class WhoisController extends Controller
{ {
public $file = ''; public $count = 30;
public function beforeAction($action) public function beforeAction($action)
{ {
...@@ -39,7 +41,57 @@ class WhoisController extends Controller ...@@ -39,7 +41,57 @@ class WhoisController extends Controller
*/ */
public function actionIndex() public function actionIndex()
{ {
$hosts = (new Query())
->select('id, domain')
->from('{{%host}}')
->where(['in', 'wis_status', [Host::STATUS_NONE, Host::STATUS_BUSY]])
->orderBy('rand()')
->limit($this->count)
->all();
$domainsArr = [];
foreach ($hosts as $h) {
$domainsArr[] = $h['domain'];
}
if ($domainsArr) {
$result = Collection::getRawData(Yii::$app->params['registrators_urls'][0], $domainsArr);
if (!$result['errorno']) {//без ошибок
$dom = new Dom;
$dom->loadStr($result['data']);
$trArr = $dom->find('.tablesorter tbody tr');
if (!count($trArr)) {
foreach ($domainsArr as $d) {
$this->upWhois($d);
}
}
$hasAnswer = [];
foreach ($trArr as $tr) {
$domain = $tr->find('td')[0]->text;
$status = $tr->find('td')[1]->text;
$hasAnswer[] = $domain;
$this->upWhois($domain, $status);
}
foreach (array_diff($domainsArr, $hasAnswer) as $domainDisable) {
$this->upWhois($domainDisable);
}
} else {
echo $result['errorno'] . ' ' . $result['errormessage'];
}
}
}
private function upWhois($domain, $statusStr = 'Занят')
{
switch ($statusStr) {
case 'Свободен':
$status = Host::STATUS_FREE;
break;
default:
$status = Host::STATUS_BUSY;
}
Yii::$app->db->createCommand()
->update('{{%host}}', ['wis_status' => $status, 'wis_date' => new Expression('NOW()')], ['domain' => $domain])
->execute();
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -33,12 +33,13 @@ class Collection extends Component ...@@ -33,12 +33,13 @@ class Collection extends Component
public static function getRawData($url, $domain) public static function getRawData($url, $domain)
{ {
$post = [ $post = [
'a' => 'act', 'doms' => implode("\r\n",$domain),
'ip' => $domain,
]; ];
$ch = curl_init('https://2ip.ua/ru/services/information-service/domain-information'); $ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch); $response = curl_exec($ch);
$errorNum = curl_errno($ch); $errorNum = curl_errno($ch);
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!