Commit f695cd54 by san58

проверка TIX

1 parent c3ad4cd5
<?php
namespace app\commands;
use PHPHtmlParser\Dom;
use yii\db\Query;
use yii;
use yii\console\Controller;
use yii\db\Expression;
use yii\helpers\Console;
use app\components\Collection;
use app\models\Host;
use app\models\Filter;
/**
* Парсинг запрещенных ресурсов в РФ.
*/
class TixController extends Controller
{
public $count = 10;
public function beforeAction($action)
{
if (!parent::beforeAction($action)) {
return false;
}
return true;
}
public function options($actionID)
{
return ['count'];
}
public function optionAliases()
{
return ['c' => 'count'];
}
/**
* Парсинг запрещенных ресурсов в РФ.
*/
public function actionIndex()
{
$hosts = (new Query())
->select('id, domain')
->from('{{%host}}')
->where(
[
'wis_status'=>Host::STATUS_WIS_FREE,
'tix_status'=>Host::STATUS_TIX_UNCHECK
]
)
->orderBy(['status'=>SORT_DESC, 'rand()'=>SORT_ASC])
->limit($this->count)
->all();
foreach ($hosts as $h)
{
$host = $h['domain'];
$result = Collection::getTixRawData(Yii::$app->params['tix_url'].$host);
if ($result['errorno'])
echo $result['errorno'] . ' ' . $result['errormessage'];
else if ($result['data']['status']==='OK')
$this->upTix($result['data']['domain'], $result['data']['govalue']);
else
echo '! '.$host.' - '.$result['data']['message'] .' ('.$result['data']['status'].')';
unset($host);
usleep (1000);
}
unset($h);
unset($hosts);
}
private function upTix($domain, $value = 0)
{
echo $domain . ' => ' . $value . "\n";
$update = ['tix'=>(int)$value, 'tix_status' => Host::STATUS_TIX_CHECK, 'tix_date' => new Expression('NOW()')];
Yii::$app->db->createCommand()
->update('{{%host}}', $update, ['domain' => $domain])
->execute();
}
}
\ No newline at end of file \ No newline at end of file
...@@ -112,5 +112,22 @@ class Collection extends Component ...@@ -112,5 +112,22 @@ class Collection extends Component
return ['data' => $response, 'errorno' => $errorNum, 'errormessage' => $errorMsg]; return ['data' => $response, 'errorno' => $errorNum, 'errormessage' => $errorMsg];
} }
public static function getTixRawData($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
$errorNum = curl_errno($ch);
$errorMsg = curl_error($ch);
curl_close($ch);
return ['data' => json_decode($response, true), 'errorno' => $errorNum, 'errormessage' => $errorMsg];
}
} }
...@@ -8,5 +8,6 @@ return [ ...@@ -8,5 +8,6 @@ return [
'registrators_urls' => [ 'registrators_urls' => [
//'https://2ip.ua/ru/services/information-service/domain-information' //'https://2ip.ua/ru/services/information-service/domain-information'
'https://www.cy-pr.com/tools/masswhois/' 'https://www.cy-pr.com/tools/masswhois/'
] ],
'tix_url'=>'https://api.godaddy.com/v1/appraisal/'
]; ];
...@@ -24,6 +24,9 @@ class Host extends \yii\db\ActiveRecord ...@@ -24,6 +24,9 @@ class Host extends \yii\db\ActiveRecord
const STATUS_WIS_FREE = 1; //Свободный const STATUS_WIS_FREE = 1; //Свободный
const STATUS_WIS_BUSY = 2; //Занятый const STATUS_WIS_BUSY = 2; //Занятый
const STATUS_TIX_UNCHECK = 0; //не проверен
const STATUS_TIX_CHECK = 1; //Проверен
const STATUS_OFF = 0; //выключен const STATUS_OFF = 0; //выключен
const STATUS_ON = 1; //Включен const STATUS_ON = 1; //Включен
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!