Skip to content

Commit

Permalink
fix(em): prevent use if missing php functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Nov 29, 2024
1 parent 9920a9f commit 94b0d67
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
5 changes: 5 additions & 0 deletions extensions/package-manager/extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
&& is_writable($paths->base.'/composer.lock');

$document->payload['flarum-extension-manager.using_sync_queue'] = resolve(Queue::class) instanceof SyncQueue;

$document->payload['flarum-extension-manager.missing_functions'] = array_values(array_filter(
['proc_open', 'escapeshellarg'],
fn (string $function): bool => ! function_exists($function)
));
}),

new Extend\Locales(__DIR__.'/locale'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import app from 'flarum/admin/app';
import Component from 'flarum/common/Component';
import Alert from 'flarum/common/components/Alert';
import { ComponentAttrs } from 'flarum/common/Component';

import Installer from './Installer';
Expand All @@ -17,18 +15,10 @@ export default class ControlSection extends Component<ComponentAttrs> {
return (
<div className="ExtensionPage-settings ExtensionManager-controlSection">
<div className="container">
{app.data['flarum-extension-manager.writable_dirs'] ? (
<Form>
<Installer />
<Updater />
</Form>
) : (
<div className="Form-group">
<Alert type="warning" dismissible={false}>
{app.translator.trans('flarum-extension-manager.admin.file_permissions')}
</Alert>
</div>
)}
<Form>
<Installer />
<Updater />
</Form>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ControlSection from './ControlSection';
import ConfigureComposer from './ConfigureComposer';
import ConfigureAuth from './ConfigureAuth';
import DiscoverSection from './DiscoverSection';
import Alert from 'flarum/common/components/Alert';

export default class SettingsPage extends ExtensionPage {
content() {
Expand Down Expand Up @@ -43,9 +44,33 @@ export default class SettingsPage extends ExtensionPage {
sections(vnode: Mithril.VnodeDOM<ExtensionPageAttrs, this>): ItemList<unknown> {
const items = super.sections(vnode);

items.add('discover', <DiscoverSection />, 15);
const writableDirs = app.data['flarum-extension-manager.writable_dirs'];
const missingFunctions = app.data['flarum-extension-manager.missing_functions'] as string[] | undefined;
const usable = writableDirs && (!missingFunctions || missingFunctions.length === 0);

items.add('control', <ControlSection />, 10);
if (usable) {
items.add('discover', <DiscoverSection />, 15);

items.add('control', <ControlSection />, 10);
} else {
items.add(
'warning',
<div className="ExtensionPage-settings">
<div className="container">
<div className="Form-group">
<Alert type="error" dismissible={false}>
{!app.data['flarum-extension-manager.writable_dirs']
? app.translator.trans('flarum-extension-manager.admin.file_permissions')
: app.translator.trans('flarum-extension-manager.admin.required_php_functions', {
functions: (app.data['flarum-extension-manager.missing_functions'] as string[]).join(', '),
})}
</Alert>
</div>
</div>
</div>,
10
);
}

items.setPriority('content', 8);

Expand Down
4 changes: 4 additions & 0 deletions extensions/package-manager/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ flarum-extension-manager:
minor_update_confirmation:
content: This will also update any other extensions/packages with available updates.

required_php_functions: >
The extension manager requires the following PHP functions to be enabled: <code>{functions}</code>.
If you do not have access to the PHP configuration, please contact your hosting provider.
sections:
discover:
description: Add new features and integrations to your Flarum forum with extensions.
Expand Down

0 comments on commit 94b0d67

Please sign in to comment.