예제 #1
0
 public function ajax_sample()
 {
     $time_start = microtime(true);
     $response["error"] = "none";
     $response["html"] = "";
     $themeid = 1;
     if (isset($_POST["themeid"])) {
         $themeid = intval($_POST["themeid"]);
     }
     if ($themeid < 1) {
         $themeid = 1;
     }
     $checkid = $_POST["checkid"];
     if (USE_DB) {
         $history = new History();
         $themInfo = $history->getFewInfo($themeid);
         $hash = $themInfo["hash"];
         $fileValidator = FileValidator::unserialize($hash);
         $fileValidator->validate($checkid);
         //if (UserMessage::getCount(ERRORLEVEL_FATAL) == 0) // serialize only if no fatal errors
         $validationResults = $fileValidator->getValidationResults(I18N::getCurLang());
         if (count($validationResults->check_critical) > 0 || count($validationResults->check_warnings) > 0 || count($validationResults->check_info) > 0) {
             $url = TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => "en", "phpfile" => "results", "hash" => $hash));
             $html = '<h2 style="color:#D00;">' . $themInfo["name"] . '<a href="' . $url . '" target="_blank" style="font-size:14px;margin-left:6px"><span class="glyphicon glyphicon-new-window"></span></a>' . '</h2>';
         }
         if (count($validationResults->check_critical) > 0) {
             //$html .= '<h2 style="line-height:100px;color:#D00;">'.__("Critical alerts").'</h2>';
             $html .= '<ol>';
             foreach ($validationResults->check_critical as $check) {
                 $html .= '<h4 style="color:#666;margin-top:40px;"><li>' . $check->title . ' : ' . $check->hint . '</li></h4>';
                 if (!empty($check->messages)) {
                     $html .= '<p style="color:#c94b4b;">' . implode('<br/>', $check->messages) . '</p>';
                 }
             }
             $html .= '</ol>';
         }
         if (count($validationResults->check_warnings) > 0) {
             //$html .= '<h2 style="line-height:100px;color:#eea43a;">'.__("Warnings").'</h2>';
             $html .= '<ol>';
             foreach ($validationResults->check_warnings as $check) {
                 $html .= '<h4 style="color:#666;margin-top:40px;"><li>' . $check->title . ' : ' . $check->hint . '</li></h4>';
                 if (!empty($check->messages)) {
                     $html .= '<p style="color:#eea43a;">' . implode('<br/>', $check->messages) . '</p>';
                 }
             }
             $html .= '</ol>';
         }
         if (count($validationResults->check_info) > 0) {
             //$html .= '<h2 style="line-height:100px;color:#eea43a;">'.__("Warnings").'</h2>';
             $html .= '<ol>';
             foreach ($validationResults->check_info as $check) {
                 $html .= '<h4 style="color:#666;margin-top:40px;"><li>' . $check->title . ' : ' . $check->hint . '</li></h4>';
                 if (!empty($check->messages)) {
                     $html .= '<p style="color:#00b6e3;">' . implode('<br/>', $check->messages) . '</p>';
                 }
             }
             $html .= '</ol>';
         }
         $response["html"] = $html;
         $prevId = $history->getPrevId($themeid);
         if (!empty($prevId)) {
             $themInfoNext = $history->getFewInfo($prevId);
             $response["next_id"] = $prevId;
             $response["next_name"] = $themInfoNext["name"];
         } else {
             $response["next_id"] = null;
             $response["next_name"] = null;
         }
     }
     $time_end = microtime(true);
     $time = $time_end - $time_start;
     $response["duration"] = $time;
     //ob_clean();
     header('Content-Type: application/json');
     echo json_encode($response);
 }
예제 #2
0
 public function prepare()
 {
     $routeParts = Route::getInstance()->match();
     // There are 2 types of results to display
     // 1 - Display an already evaluated file which results were stored on the server. Just need the id. e.g : results?id=162804c3c358267d3a16855686ab1887
     // 2 - Unknown file. Need $_FILES and $_POST["filetype"]
     if (isset($routeParts["ut"])) {
         $path_item = TC_ROOTDIR . '/include/unittests/';
         $filename = urldecode($routeParts["ut"]);
         if (!(substr($filename, -4) == ".zip" && file_exists($path_item . $filename))) {
             echo $path_item . $filename . ' does not exist. Cannot continue';
             die;
         }
         $themeInfo = FileValidator::prepareThemeInfo($path_item . $filename, $filename, 'application/zip', false);
         $this->fileValidator = new FileValidator($themeInfo);
         $this->fileValidator->validate();
         $this->validationResults = $this->fileValidator->getValidationResults(I18N::getCurLang());
     } else {
         if (isset($routeParts["hash"])) {
             $hash = $routeParts["hash"];
             $this->fileValidator = FileValidator::unserialize($hash);
             $themeInfo = $this->fileValidator->themeInfo;
             $checkfiles = scandir(TC_INCDIR . '/Checks');
             $youngestCheckTimestamp = 0;
             foreach ($checkfiles as $f) {
                 if ($f == '.' || $f == '..') {
                     continue;
                 }
                 $m = filemtime(TC_INCDIR . '/Checks/' . $f);
                 if ($youngestCheckTimestamp < $m) {
                     $youngestCheckTimestamp = $m;
                 }
             }
             if ($this->fileValidator->themeInfo->validationDate < $youngestCheckTimestamp) {
                 $this->fileValidator->validate();
                 if (UserMessage::getCount(ERRORLEVEL_FATAL) == 0) {
                     // serialize only if no fatal errors
                     $this->fileValidator->serialize(true);
                 }
             }
             $this->validationResults = $this->fileValidator->getValidationResults(I18N::getCurLang());
         } else {
             if (count($_FILES) > 0 && isset($_FILES["file"]) && !empty($_FILES["file"]["name"])) {
                 if (TC_ENVIRONMENT == "dev" || isset($_SESSION['token_' . $_POST['token']])) {
                     unset($_SESSION['token_' . $_POST['token']]);
                     $themeInfo = FileValidator::upload();
                     if ($themeInfo) {
                         $this->fileValidator = new FileValidator($themeInfo);
                         $this->fileValidator->validate();
                         if (isset($_POST["donotstore"]) || UserMessage::getCount(ERRORLEVEL_FATAL) > 0) {
                             $this->fileValidator->clean();
                         } else {
                             $this->fileValidator->serialize(true);
                         }
                         $this->validationResults = $this->fileValidator->getValidationResults(I18N::getCurLang());
                         if (isset($_POST["donotstore"])) {
                             $this->inlinescripts[] = "ga('send', 'event', 'theme', 'submit', 'not stored');";
                         } else {
                             $this->inlinescripts[] = "ga('send', 'event', 'theme', 'submit', 'stored');";
                         }
                     }
                 } else {
                     UserMessage::enqueue(__("Unvalid form"), ERRORLEVEL_FATAL);
                 }
             } else {
                 UserMessage::enqueue(__("No file uploaded."), ERRORLEVEL_FATAL);
                 $this->meta["title"] = __("No file uploaded");
                 $this->meta["description"] = __("No file uploaded");
                 return;
             }
         }
     }
     if (!empty($themeInfo)) {
         if ($themeInfo->themetype == TT_JOOMLA) {
             $this->meta["title"] = sprintf(__("%s%% : Joomla template %s"), htmlspecialchars($themeInfo->score), htmlspecialchars($themeInfo->name));
             $this->meta["description"] = sprintf(__("Security and code quality score of Joomla template %s."), htmlspecialchars($themeInfo->name));
         } else {
             $this->meta["title"] = sprintf(__("%s%% : Wordpress theme %s"), htmlspecialchars($themeInfo->score), htmlspecialchars($themeInfo->name));
             $this->meta["description"] = sprintf(__("Security and code quality score of Wordpress theme %s."), htmlspecialchars($themeInfo->name));
         }
         if ($themeInfo->score < 100.0) {
             if ($themeInfo->score > 95) {
                 $this->meta["favicon"] = "favicon100";
             } else {
                 if ($themeInfo->score > 80) {
                     $this->meta["favicon"] = "favicon95";
                 } else {
                     $this->meta["favicon"] = "favicon80";
                 }
             }
         }
     } else {
         $this->meta["title"] = __("Check results");
         $this->meta["description"] = __("Security and code quality score");
     }
     global $ExistingLangs;
     foreach ($ExistingLangs as $l) {
         if ($this->fileValidator) {
             $themeInfo = $this->fileValidator->themeInfo;
             if (!empty($themeInfo) && $themeInfo->serializable && USE_DB) {
                 $this->samepage_i18n[$l] = TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => $l, "phpfile" => "results", "hash" => $themeInfo->hash));
             } else {
                 $this->samepage_i18n[$l] = null;
             }
         } else {
             $this->samepage_i18n[$l] = TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => $l, "phpfile" => "results"));
         }
     }
 }