View file upload/src/addons/xenMade/ACPE/XF/Admin/Controller/Log.php

File size: 6.22Kb
<?php

namespace xenMade\ACPE\XF\Admin\Controller;


class Log extends XFCP_Log
{
    public function actionFirewallLogs()
    {
        $perPage = 20;
        $page = $this->filterPage();

        $entries = $this->fetchLogins($page, $perPage);

        $viewParams = [
            'entries' => $entries,
            'page' => $page,
            'perPage' => $perPage,
            'total' => $this->countLogins()
        ];
        return $this->view('XF:Log\FirewallLogs\Listing', 'acpe_log_firewall_logins_list', $viewParams);
    }

    public function actionFirewallLogsDelete()
    {
        $logId = $this->filter('id', 'uint');
        $entry = $this->fetchLogin($logId);

        if(!$entry)
        {
            return $this->error(\XF::phrase('requested_log_entry_not_found'));
        }

        if ($this->isPost())
        {
            $this->deleteLogin($logId);

            return $this->redirect($this->buildLink('logs/firewall-logs'));
        }
        else
        {
            $viewParams = [
                'entry' => $entry
            ];

            return $this->view('XF:Log\FirewallLogs\delete', 'acpe_log_firewall_login_delete', $viewParams);
        }
    }

    public function actionFirewallLogsClear()
    {
        if ($this->isPost())
        {
            $this->getErrorLogRepo()->clearFirewallLog();

            return $this->redirect($this->buildLink('logs/firewall-logs'));
        }
        else
        {
            return $this->view('XF:Log\FirewallLogs\Clear', 'acpe_log_firewall_clear');
        }
    }





    public function actionEmailBouncesClear()
    {
        if ($this->isPost())
        {
            $this->getErrorLogRepo()->clearEmailBouncesLog();

            return $this->redirect($this->buildLink('logs/email-bounces'));
        }
        else
        {
            return $this->view('XF:Log\EmailBounces\Clear', 'acpe_log_email_bounces_clear');
        }
    }

    public function actionUserChangeClear()
    {
        if ($this->isPost())
        {
            $this->getErrorLogRepo()->clearUserChangeLog();

            return $this->redirect($this->buildLink('logs/user-change'));
        }
        else
        {
            return $this->view('XF:Log\UserChangeClear\Clear', 'acpe_log_user_change_clear');
        }
    }

    public function actionModeratorClear()
    {
        if ($this->isPost())
        {
            $this->getErrorLogRepo()->clearModeratorLog();

            return $this->redirect($this->buildLink('logs/moderator'));
        }
        else
        {
            return $this->view('XF:Log\Moderator\Clear', 'acpe_log_moderator_clear');
        }
    }

    public function actionAdminClear()
    {
        if ($this->isPost())
        {
            $this->getErrorLogRepo()->clearAdminLog();

            return $this->redirect($this->buildLink('logs/admin'));
        }
        else
        {
            return $this->view('XF:Log\Admin\Clear', 'acpe_log_admin_clear');
        }
    }

    public function actionSpamTriggerClear()
    {
        if ($this->isPost())
        {
            $this->getErrorLogRepo()->clearSpamTriggerLog();

            return $this->redirect($this->buildLink('logs/spam-trigger'));
        }
        else
        {
            return $this->view('XF:Log\SpamTrigger\Clear', 'acpe_log_spam_trigger_clear');
        }
    }

    public function actionSpamCleanerClear()
    {
        if ($this->isPost())
        {
            $this->getErrorLogRepo()->clearSpamCleanerLog();

            return $this->redirect($this->buildLink('logs/spam-cleaner'));
        }
        else
        {
            return $this->view('XF:Log\SpamCleaner\Clear', 'acpe_log_spam_cleaner_clear');
        }
    }

    public function actionRejectedUserclear()
    {
        if ($this->isPost())
        {
            $this->getErrorLogRepo()->clearUserRejectLog();

            return $this->redirect($this->buildLink('logs/rejected-users'));
        }
        else
        {
            return $this->view('XF:Log\SpamCleaner\Clear', 'acpe_log_rejected_users_clear');
        }
    }

    public function actionImageProxyclear()
    {
        if ($this->isPost())
        {
            $this->getErrorLogRepo()->clearImageProxyLog();

            return $this->redirect($this->buildLink('logs/image-proxy'));
        }
        else
        {
            return $this->view('XF:Log\ImageProxy\Clear', 'acpe_log_image_proxy_clear');
        }
    }

    public function actionLinkProxyclear()
    {
        if ($this->isPost())
        {
            $this->getErrorLogRepo()->clearLinkProxyLog();

            return $this->redirect($this->buildLink('logs/link-proxy'));
        }
        else
        {
            return $this->view('XF:Log\LinkProxy\Clear', 'acpe_log_link_proxy_clear');
        }
    }

    public function actionOembedclear()
    {
        if ($this->isPost())
        {
            $this->getErrorLogRepo()->clearOembedLog();

            return $this->redirect($this->buildLink('logs/oembed'));
        }
        else
        {
            return $this->view('XF:Log\LinkProxy\Clear', 'acpe_log_oembed_clear');
        }
    }





    protected function fetchLogins($page, $perPage)
    {
        $offset = ($page - 1) * $perPage;
        $limit = $perPage;

        return $this->app()->db()->fetchAllKeyed(
            "
				SELECT logins.*
				FROM xf_xenmade_acpe_login_log AS logins
				ORDER BY logins.dateline DESC
				LIMIT {$offset}, {$limit}
			", 'log_id');
    }

    protected function fetchLogin($logId)
    {
        return $this->app()->db()->fetchRow(
            "
				SELECT logins.*
				FROM xf_xenmade_acpe_login_log AS logins
				WHERE log_id = ?
			", $logId);
    }

    protected function deleteLogin($logId)
    {
        return $this->app()->db()->query("DELETE FROM xf_xenmade_acpe_login_log WHERE log_id = ?", $logId);
    }

    protected function countLogins()
    {
        return $this->app()->db()->fetchOne("
			SELECT COUNT(*)
			FROM xf_xenmade_acpe_login_log
		");
    }
}
if (false)
{
    class XFCP_Log extends \XF\Admin\Controller\Log {}
}