Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php /** * VersionCheckEventHandler.php * Copyright (c) 2019 [email protected] * ..

Decoded Output download

<?php

/**
 * VersionCheckEventHandler.php
 * Copyright (c) 2019 [email protected]
 *
 * This file is part of Firefly III (https://github.com/firefly-iii).
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
declare(strict_types=1);

namespace FireflyIII\Handlers\Events;

use FireflyIII\Events\RequestedVersionCheckStatus;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Update\UpdateTrait;
use FireflyIII\Models\Configuration;
use FireflyIII\Repositories\User\UserRepositoryInterface;

/**
 * Class VersionCheckEventHandler
 */
class VersionCheckEventHandler
{
    use UpdateTrait;

    /**
     * Checks with GitHub to see if there is a new version.
     *
     * @throws FireflyException
     *
     * @deprecated ?
     */
    public function checkForUpdates(RequestedVersionCheckStatus $event): void
    {
        app('log')->debug('Now in checkForUpdates()');

        // should not check for updates:
        $permission    = app('fireflyconfig')->get('permission_update_check', -1);
        $value         = (int)$permission->data;
        if (1 !== $value) {
            app('log')->debug('Update check is not enabled.');
            $this->warnToCheckForUpdates($event);

            return;
        }

        /** @var UserRepositoryInterface $repository */
        $repository    = app(UserRepositoryInterface::class);
        $user          = $event->user;
        if (!$repository->hasRole($user, 'owner')) {
            app('log')->debug('User is not admin, done.');

            return;
        }

        /** @var Configuration $lastCheckTime */
        $lastCheckTime = app('fireflyconfig')->get('last_update_check', time());
        $now           = time();
        $diff          = $now - $lastCheckTime->data;
        app('log')->debug(sprintf('Last check time is %d, current time is %d, difference is %d', $lastCheckTime->data, $now, $diff));
        if ($diff < 604800) {
            app('log')->debug(sprintf('Checked for updates less than a week ago (on %s).', date('Y-m-d H:i:s', $lastCheckTime->data)));

            return;
        }
        // last check time was more than a week ago.
        app('log')->debug('Have not checked for a new version in a week!');
        $release       = $this->getLatestRelease();

        session()->flash($release['level'], $release['message']);
        app('fireflyconfig')->set('last_update_check', time());
    }

    /**
     * @throws FireflyException
     */
    protected function warnToCheckForUpdates(RequestedVersionCheckStatus $event): void
    {
        /** @var UserRepositoryInterface $repository */
        $repository    = app(UserRepositoryInterface::class);
        $user          = $event->user;
        if (!$repository->hasRole($user, 'owner')) {
            app('log')->debug('User is not admin, done.');

            return;
        }

        /** @var Configuration $lastCheckTime */
        $lastCheckTime = app('fireflyconfig')->get('last_update_warning', time());
        $now           = time();
        $diff          = $now - $lastCheckTime->data;
        app('log')->debug(sprintf('Last warning time is %d, current time is %d, difference is %d', $lastCheckTime->data, $now, $diff));
        if ($diff < 604800 * 4) {
            app('log')->debug(sprintf('Warned about updates less than four weeks ago (on %s).', date('Y-m-d H:i:s', $lastCheckTime->data)));

            return;
        }
        // last check time was more than a week ago.
        app('log')->debug('Have warned about a new version in four weeks!');

        session()->flash('info', (string)trans('firefly.disabled_but_check'));
        app('fireflyconfig')->set('last_update_warning', time());
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php

/**
 * VersionCheckEventHandler.php
 * Copyright (c) 2019 [email protected]
 *
 * This file is part of Firefly III (https://github.com/firefly-iii).
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
declare(strict_types=1);

namespace FireflyIII\Handlers\Events;

use FireflyIII\Events\RequestedVersionCheckStatus;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Update\UpdateTrait;
use FireflyIII\Models\Configuration;
use FireflyIII\Repositories\User\UserRepositoryInterface;

/**
 * Class VersionCheckEventHandler
 */
class VersionCheckEventHandler
{
    use UpdateTrait;

    /**
     * Checks with GitHub to see if there is a new version.
     *
     * @throws FireflyException
     *
     * @deprecated ?
     */
    public function checkForUpdates(RequestedVersionCheckStatus $event): void
    {
        app('log')->debug('Now in checkForUpdates()');

        // should not check for updates:
        $permission    = app('fireflyconfig')->get('permission_update_check', -1);
        $value         = (int)$permission->data;
        if (1 !== $value) {
            app('log')->debug('Update check is not enabled.');
            $this->warnToCheckForUpdates($event);

            return;
        }

        /** @var UserRepositoryInterface $repository */
        $repository    = app(UserRepositoryInterface::class);
        $user          = $event->user;
        if (!$repository->hasRole($user, 'owner')) {
            app('log')->debug('User is not admin, done.');

            return;
        }

        /** @var Configuration $lastCheckTime */
        $lastCheckTime = app('fireflyconfig')->get('last_update_check', time());
        $now           = time();
        $diff          = $now - $lastCheckTime->data;
        app('log')->debug(sprintf('Last check time is %d, current time is %d, difference is %d', $lastCheckTime->data, $now, $diff));
        if ($diff < 604800) {
            app('log')->debug(sprintf('Checked for updates less than a week ago (on %s).', date('Y-m-d H:i:s', $lastCheckTime->data)));

            return;
        }
        // last check time was more than a week ago.
        app('log')->debug('Have not checked for a new version in a week!');
        $release       = $this->getLatestRelease();

        session()->flash($release['level'], $release['message']);
        app('fireflyconfig')->set('last_update_check', time());
    }

    /**
     * @throws FireflyException
     */
    protected function warnToCheckForUpdates(RequestedVersionCheckStatus $event): void
    {
        /** @var UserRepositoryInterface $repository */
        $repository    = app(UserRepositoryInterface::class);
        $user          = $event->user;
        if (!$repository->hasRole($user, 'owner')) {
            app('log')->debug('User is not admin, done.');

            return;
        }

        /** @var Configuration $lastCheckTime */
        $lastCheckTime = app('fireflyconfig')->get('last_update_warning', time());
        $now           = time();
        $diff          = $now - $lastCheckTime->data;
        app('log')->debug(sprintf('Last warning time is %d, current time is %d, difference is %d', $lastCheckTime->data, $now, $diff));
        if ($diff < 604800 * 4) {
            app('log')->debug(sprintf('Warned about updates less than four weeks ago (on %s).', date('Y-m-d H:i:s', $lastCheckTime->data)));

            return;
        }
        // last check time was more than a week ago.
        app('log')->debug('Have warned about a new version in four weeks!');

        session()->flash('info', (string)trans('firefly.disabled_but_check'));
        app('fireflyconfig')->set('last_update_warning', time());
    }
}

Function Calls

None

Variables

None

Stats

MD5 260ee763b017aa0f9a419aedba8ac7a1
Eval Count 0
Decode Time 87 ms