Hooking in to FWConsole Framework functions.

Introduction

Your module may need to declare specific permissions to fwconsole chown. Your module may need to perform a task before Asterisk starts or stops. Below we will hook in to the framework functions to make this happen.

Chown

In your modules BMO class we will add a class to declare our files. Please note this is a subsection of code and not a complete class.

Mymodule.class.php

public function chownFreepbx() {     $webroot = \FreePBX::Config()->get('AMPWEBROOT');     $modulebindir = $webroot . '/admin/modules/mymodule/bin/';     $files = array();     $files[] = array('type' => 'dir',                      'path' => $modulebindir,                      'perms' => 0755);     $files[] = array('type' => 'file',                      'path' => $modulebindir . 'notexecexample.txt',                      'perms' => 0644);       return $files; }

Each "file" array has 3 items

  • type - The file type

    • file - single item, interchangeable with dir  

    • dir - single item, interchangeable with file

    • rdir - recursively set directory permission while setting sub-items with the same permission less the execute bit so a 0755 directory becomes a 0644 file. 

    • execdir - recursively sets a directory permissions without stripping the execute bit so the directory and all its files would become 0755.

  • path - The path to the file. Keep in mind  some things like the webroot are not static paths

  • perms - See linux permissions for a full explanation. You MUST add a leading 0.  Most executables/folders will be 0755 or 0775. Most files will 0644 or 0664

Then you have to tell BMO about your hook and what to do with it.

Add the following to your module.xml

module.xml

<hooks>     <framework namespace="FreePBX\Console\Command" class="Chown">         <method namespace="FreePBX\modules" class="Mymodule" callingMethod="fwcChownFiles">chownFreepbx</method>     </framework> </hooks>

Return to Documentation Home I Return to Sangoma Support