<?php

class KpiSkimmerCronCronModuleFrontController extends ModuleFrontController
{
    public $ssl = true;

    public function initContent()
    {
        parent::initContent();

        $token = (string)Tools::getValue('token');
        $expected = $this->module->getCronToken();

        if (!$token || !hash_equals($expected, $token)) {
            header('HTTP/1.1 403 Forbidden');
            die('Forbidden');
        }

        $res = $this->module->runScanAndMaybeAlert(false);

        header('Content-Type: text/plain; charset=utf-8');
        if ($res['ok']) {
            echo "OK\n";
            echo $res['message']."\n";
        } else {
            header('HTTP/1.1 500 Internal Server Error');
            echo "ERROR\n";
            echo $res['message']."\n";
        }
        exit;
    }
}
