Source of file ClamAVAdmin.php
Size: 5,346 Bytes - Last Modified: 2021-12-23T10:21:01+00:00
/var/www/docs.ssmods.com/process/src/src/Admin/ClamAVAdmin.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 | <?php namespace Symbiote\SteamedClams\Admin; use SilverStripe\Admin\ModelAdmin; use SilverStripe\Control\Controller; use SilverStripe\Control\HTTPResponse; use SilverStripe\Core\Injector\Injector; use SilverStripe\Forms\GridField\GridFieldAddNewButton; use SilverStripe\Forms\GridField\GridFieldDeleteAction; use SilverStripe\Forms\GridField\GridFieldEditButton; use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\ReadonlyField; use SilverStripe\Security\Permission; use SilverStripe\View\Requirements; use Symbiote\SteamedClams\ClamAV; use Symbiote\SteamedClams\Forms\GridFieldClamAVAction; use Symbiote\SteamedClams\Model\ClamAVScan; use SilverStripe\AssetAdmin\Controller\AssetAdmin; /** * Class Symbiote\SteamedClams\ClamAVAdmin * */ class ClamAVAdmin extends ModelAdmin { /** * @var string */ private static $url_segment = 'clamav'; /** * @var string */ private static $menu_title = 'ClamAV'; /** * @var array */ private static $managed_models = [ ClamAVScan::class, ]; /** * @var string */ private static $menu_icon = 'vendor/symbiote/silverstripe-steamedclams/client/images/clamav_icon.png'; /** * @var array */ private static $allowed_actions = [ 'Assets', ]; /** * Unable to directly link to a File in the AssetAdmin, so set * the required FileID via `setCurrentPageID` and redirect. * * @return HTTPResponse|string */ public function Assets() { $request = $this->getRequest(); $id = $request->shift(); if (!$id) { return $this->redirect($this->Link()); } $assetAdmin = singleton(AssetAdmin::class); if (!$assetAdmin->canView()) { return $this->redirect($this->Link()); } $assetAdmin->setCurrentPageID($id); //Session::set($assetAdmin->class.".currentPage", (int)$id); return $this->redirect( Controller::join_links($assetAdmin->Link('EditForm'), 'field', 'File', 'item', $id, 'edit') ); } public function getEditForm($id = null, $fields = null) { $self = &$this; $this->beforeExtending('updateEditForm', function ($form) use ($self) { Requirements::css('symbiote/silverstripe-steamedclams:client/css/ClamAVCMS.css'); $fields = $form->Fields(); $insertBeforeFieldName = str_replace('\\', '-', $self->config()->managed_models[0]); $gridField = $fields->dataFieldByName($insertBeforeFieldName); if ($gridField) { $gridConfig = $gridField->getConfig(); $gridConfig->removeComponentsByType(GridFieldAddNewButton::class); // NOTE(Jake): These buttons shouldn't be necessary, but incase you want to bring // them back, add '?fullview' if ((Permission::check('ADMIN') && isset($_GET['fullview'])) === false) { $gridConfig->removeComponentsByType(GridFieldEditButton::class); $gridConfig->removeComponentsByType(GridFieldDeleteAction::class); } $gridConfig->addComponent(Injector::inst()->create(GridFieldClamAVAction::class)); } $clamAV = Injector::inst()->get(ClamAV::class); $version = $clamAV->version(); $reason = ''; if ($version === ClamAV::OFFLINE) { $version = '<p style="margin-bottom: 20px"><strong style="color: #C00;">OFFLINE</strong></p>'; $exception = $clamAV->getLastException(); if ($exception) { $reason = 'Reason: ' . $exception->getMessage(); } } else { $version = '<p style="margin-bottom: 20px"><strong style="color: #18BA18;">ONLINE</strong> (' . $version . ')</p>'; } $versionField = LiteralField::create('ClamAV_Version', $version); $versionField->setRightTitle($reason); $versionField->dontEscape = true; $fields->insertBefore($versionField, $insertBeforeFieldName); // Files to scan with install task $listCount = 0; $list = $clamAV->getInitialFileToScanList(); if ($list) { $listCount = $list->count(); } if ($listCount > 0) { $fields->insertBefore( ReadonlyField::create( 'ClamAV_InitialScan', 'Files to scan with install task', $listCount . ' ' ), $insertBeforeFieldName ); } //Files that failed to scan $listCount = 0; $list = $clamAV->getFailedToScanFileList(); if ($list) { $listCount = $list->count(); } $fields->insertBefore( ReadonlyField::create('ClamAV_NeedScan', 'Files that failed to scan', $listCount . ' ') ->setRightTitle('Due to ClamAV daemon being inaccessible/offline.'), $insertBeforeFieldName ); }); $form = parent::getEditForm($id, $fields); return $form; } } |