22 "deleteTaskId" => null,
26 $this->opLog =
"SITE_STATUS";
31 $path = Yii::app()->getBasePath() .
'/json_temp';
32 $reqFile = tempnam($path,
'');
33 $this->requestFile = $reqFile;
34 $file = fopen($reqFile,
'w');
41 $api = Yii::app()->params[
'api'];
42 $path = Yii::app()->getBasePath() .
'/shell/';
43 $pathJson = Yii::app()->getBasePath() .
'/json_temp/';
44 $cmd =
"sh " . $path .
"site_find_by_criterions.sh $api $this->requestFile";
45 $json = shell_exec($cmd);
46 $resFile = tempnam($pathJson,
'');
47 $this->responseFile = $resFile;
48 $file = fopen($resFile,
'w');
56 $api = Yii::app()->params[
'api'];
57 $path = Yii::app()->getBasePath() .
'/shell/';
58 $pathTemp = Yii::app()->getBasePath() .
'/json_temp/';
59 $cmd =
"sh " . $path .
"site_status.sh $api $this->requestFile";
60 $json = shell_exec($cmd);
61 $resFile = tempnam($pathTemp,
'');
62 $this->responseFile = $resFile;
63 $file = fopen($resFile,
'w');
71 return file_get_contents($this->responseFile);
74 public function findSite($userId, $reqFile, $one =
false)
85 $data[
'manError'][
'isError'] =
true;
86 $data[
'manError'][
'errorBody'] = $error;
100 $dataProvider = CJSON::decode(
$json);
101 $data[0] = $dataProvider[
"itemsList"][0][
"itemObject"];
102 $userDataStr =
$data[0][
'userId'];
104 foreach ($userData as $v) {
105 $userDataStr .=
' / ' . $v;
110 $links = $links .
'<a class = "ext" target = "_blank" href="' . $url[
"url"] .
'">' . $url[
"url"] .
'</a>' .
"<br>";
113 $data[0][
"urls_act"] = $links;
117 $data[0][
"userData"] = $userDataStr;
118 return new CArrayDataProvider(
$data);
125 if(isset(
$data[
'itemsList'][0][
'itemObject'][$n])){
126 $state =
$data[
'itemsList'][0][
'itemObject'][$n][
'state'];
128 $state =
$data[
'itemsList'][0][
'itemObject'][
'state'];
147 if(isset(
$data[
'itemsList'][0][
'itemObject'][$n])){
148 $state =
$data[
'itemsList'][0][
'itemObject'][$n][
'urlType'];
150 $state =
$data[
'itemsList'][0][
'itemObject'][
'urlType'];
169 if(isset(
$data[
'itemsList'][0][
'itemObject'][$n])){
170 $state =
$data[
'itemsList'][0][
'itemObject'][$n][
'fetchType'];
172 $state =
$data[
'itemsList'][0][
'itemObject'][
'fetchType'];
190 $counters[
'collectedURLs'] = 0;
191 $counters[
'deletedURLs'] = 0;
192 $counters[
'contents'] = 0;
193 $counters[
'errors'] = 0;
194 $counters[
'iterations'] = 0;
195 $counters[
'newURLs'] = 0;
196 $counters[
'size'] = 0;
197 $counters[
'resources'] = 0;
198 $counters[
'avgSpeed'] = 0;
199 $counters[
'avgSpeedCNT'] = 0;
201 foreach (
$json[
'itemsList'] as $item) {
202 foreach ($item[
'itemObject'] as $siteItem) {
203 if ($siteItem[
'id'] == $siteId) {
204 $counters[
'collectedURLs'] += $siteItem[
'collectedURLs'];
205 $counters[
'deletedURLs'] += $siteItem[
'deletedURLs'];
206 $counters[
'contents'] += $siteItem[
'contents'];
207 $counters[
'errors'] += $siteItem[
'errors'];
208 $counters[
'iterations'] += $siteItem[
'iterations'];
209 $counters[
'newURLs'] += $siteItem[
'newURLs'];
210 $counters[
'size'] += $siteItem[
'size'];
211 $counters[
'resources'] += $siteItem[
'resources'];
212 $counters[
'avgSpeed'] += $siteItem[
'avgSpeed'];
213 $counters[
'avgSpeedCNT']++;
217 $counters[
'avgSpeed'] = round($counters[
'avgSpeed'] / $counters[
'avgSpeedCNT']);
226 $dataProvider = CJSON::decode(
$json);
227 foreach ($dataProvider[
"itemsList"][0][
"itemObject"] as $key => $item) {
228 foreach ($item[
"urls"] as
$url) {
231 $links = $links .
'<a class = "ext" target = "_blank" href="' . $url[
"url"] .
'">' . $url[
"url"] .
'</a>' .
"<br>";
233 $item[
"urls"] =
$urls;
234 $item[
"urls_act"] = $links;
236 $item[
"state_str"] = $this->
getState($userId, $key);
242 $data[
'manError'][
'isError'] =
false;
246 public function createRequest($pattern, $state, $limit, $uid, $pN, $sortBy, $sortDirection)
249 $from = $pN*$limit-$limit;
250 if ($state ==
"all") {
253 $state =
"AND `sites`.`State`=$state";
257 'criterions' => array(
259 "`sites`.`User_Id`=$uid AND `sites`.`Id`=`sites_urls`.`Site_Id` $state AND `sites_urls`.`URL` LIKE '%$pattern%' GROUP BY sites.Id",
260 "LIMIT" =>
"$from, $limit",
261 "ORDER BY" =>
"sites.$sortBy $sortDirection"
264 $json = json_encode($criterions);
267 $path = Yii::app()->getBasePath() .
'/json_temp/';
268 $reqFile = tempnam($path,
'');
269 $file = fopen($reqFile,
'w');
270 $this->requestFile = $reqFile;
271 fwrite($file,
$json);
279 $filtersItems = array();
282 $filters =
$data[
'itemsList'][0][
'itemObject'][
'filters'];
283 foreach ($filters as $item) {
284 $item[
"n"] = $counter++;
286 $filtersItems[] = $item;
288 $filtersProvider =
new CArrayDataProvider($filtersItems, array(
291 return $filtersProvider;
296 $propsProvider = array();
299 $props =
$data[
'itemsList'][0][
'itemObject'][
'properties'];
300 $propsProvider = $props;
301 return new CArrayDataProvider($propsProvider, array(
302 'keyField' =>
'name',
303 'pagination' =>
false
309 $limitsProvider = array();
312 $limitsProvider[] = array(
313 'limit_name' =>
'Priority',
314 'limit_value' =>
$data[
'itemsList'][0][
'itemObject'][
'priority'],
315 'limit_name_f' =>
'priority'
317 $limitsProvider[] = array(
318 'limit_name' =>
'Max Urls',
319 'limit_value' =>
$data[
'itemsList'][0][
'itemObject'][
'maxURLs'],
320 'limit_name_f' =>
'maxURLs'
322 $limitsProvider[] = array(
323 'limit_name' =>
'Max resources',
324 'limit_value' =>
$data[
'itemsList'][0][
'itemObject'][
'maxResources'],
325 'limit_name_f' =>
'maxResources'
327 $limitsProvider[] = array(
328 'limit_name' =>
'Max Errors',
329 'limit_value' =>
$data[
'itemsList'][0][
'itemObject'][
'maxErrors'],
330 'limit_name_f' =>
'maxErrors'
332 $limitsProvider[] = array(
333 'limit_name' =>
'Max resource size',
334 'limit_value' =>
$data[
'itemsList'][0][
'itemObject'][
'maxResourceSize'],
335 'limit_name_f' =>
'maxResourceSize'
337 $limitsProvider[] = array(
338 'limit_name' =>
'Max URLs from page',
339 'limit_value' =>
$data[
'itemsList'][0][
'itemObject'][
'maxURLsFromPage'],
340 'limit_name_f' =>
'maxURLsFromPage'
342 $limitsProvider[] = array(
343 'limit_name' =>
'Processing delay, ms',
344 'limit_value' =>
$data[
'itemsList'][0][
'itemObject'][
'processingDelay'],
345 'limit_name_f' =>
'processingDelay'
347 $limitsProvider[] = array(
348 'limit_name' =>
'Request delay, ms',
349 'limit_value' =>
$data[
'itemsList'][0][
'itemObject'][
'requestDelay'],
350 'limit_name_f' =>
'requestDelay'
352 $limitsProvider[] = array(
353 'limit_name' =>
'HTTP timeout, ms',
354 'limit_value' =>
$data[
'itemsList'][0][
'itemObject'][
'httpTimeout'],
355 'limit_name_f' =>
'httpTimeout'
357 return new CArrayDataProvider($limitsProvider, array(
358 'keyField' =>
'limit_name',
359 'pagination' =>
false
365 if (!isset(Yii::app()->request->cookies[
'UserId'])) {
367 $cookie =
new CHttpCookie(
'UserId', $userId);
368 $cookie->expire = time() + 31536000;
369 Yii::app()->request->cookies[
'UserId'] = $cookie;
372 return Yii::app()->request->cookies[
'UserId']->value;
377 return md5(Yii::app()->session->sessionID);
385 $mask =
$data[
'itemsList'][0][
'itemObject'][
'errorMask'];
386 for ($power = 0; $power <= 64; $power++) {
387 $error = $mask & pow(2, $power);
393 return new CArrayDataProvider($errors, array(
394 'keyField' =>
'errorType',
395 'pagination' =>
false
402 if (is_null(
$data)) {
405 if (!is_array(
$data[
"itemsList"][0][
"itemObject"])) {
416 unlink($this->requestFile);
417 unlink($this->responseFile);
427 $absInSites = array_diff(
$urls[
'Urls'],
$urls[
'Sites']);
428 $absInUrls = array_diff(
$urls[
'Sites'],
$urls[
'Urls']);
429 if (empty($absInSites) && empty($absInUrls)){
434 if (!empty($absInSites) && !isset($absInSites[
'empty'])) {
435 foreach ($absInSites as $k => $v) {
438 'arrow' =>
'<div class = "arrows">⇨</div>',
443 if (!empty($absInUrls) && !isset($absInUrls[
'empty'])) {
444 foreach ($absInUrls as $k => $v) {
447 'arrow' =>
'<div class = "arrows">⇨</div>',
462 $siteStatus->createRequestSingle(
false, $siteId,
true);
463 $json = $siteStatus->commandStatus(
false);
464 $jsonDecoded = CJSON::decode(
$json);
465 if (empty($jsonDecoded[
'itemsList'][0][
'itemObject'][
'urls'])) {
466 $URLs[
'empty'] =
'empty';
468 foreach ($jsonDecoded[
'itemsList'][0][
'itemObject'][
'urls'] as
$url) {
469 $URLs[$url[
'urlMd5']] = $url[
'url'];
477 $userId = Yii::app()->user->id;
478 $json = $urlFetch->fetch($userId, array(
485 'sortDirection' =>
'',
487 unset(
$json[
'manError']);
489 $URLs[
'empty'] =
'empty';
492 $URLs[$url[
'urlMd5']] = $url[
'url'];