PHP Classes

Airship barge: Build extensions for the Airship CMS

Recommend this page to a friend!
  Info   View files Example   View files View files (21)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 40 This week: 1All time: 10,833 This week: 560Up
Version License PHP version Categories
airship-barge 1.0MIT/X Consortium ...5PHP 5, Content management
Description 

Author

This package can be used to build extensions for the Airship CMS.

It works as a command line program that can access a site with the Airship CMS installed and can generate several types of extension for this CMS after the user replies to several questions to configure the type of extension that you want to build.

Currently it can build Cabins, which self-contained applications, Gadgets which can alter the functionality of an existing Cabin or the Airship Engine itself, or Motifs that can alters the appearance of an existing Cabin.

The barge command can assembles a .phar or .zip of your extension that can be manually installed these into Airship.

Innovation Award
PHP Programming Innovation award nominee
January 2019
Number 9
Airship is a CMS system built with great security practices in mind since its design.

It can be extended in several ways with plugins defined by other developers, such as self-contained applications, gadgets which can alter those self-contained applications or the Airship Engine itself, or the the appearance of the pages generated by the CMS.

The package provides a command that makes it easier to start developing Airship extensions just by answering a few questions.

Manuel Lemos
Picture of Scott Arciszewski
  Performance   Level  
Name: Scott Arciszewski <contact>
Classes: 36 packages by
Country: United States United States
Age: ???
All time rank: 1180171 in United States United States
Week rank: 51 Up6 in United States United States Up
Innovation award
Innovation award
Nominee: 28x

Winner: 1x

Example

<?php
declare(strict_types=1);

use \
Airship\Barge\Command;
use \
Airship\Barge\Commands\Help;
use \
ParagonIE\Halite\Halite;
/**
 * This script is the entry point for all Barge commands.
 */
\define('AIRSHIP_ROOT', __DIR__);
$homeDir = isset($_SERVER['HOME'])
    ?
$_SERVER['HOME']
    : \
posix_getpwuid(posix_getuid())['dir'];
define('AIRSHIP_USER_HOME', $homeDir);
define('AIRSHIP_LOCAL_CONFIG', AIRSHIP_USER_HOME . DIRECTORY_SEPARATOR . '.airship');

if (!\
is_dir(AIRSHIP_LOCAL_CONFIG)) {
    \
mkdir(AIRSHIP_LOCAL_CONFIG, 0700);
}

/**
 * 1. Register an autoloader for all the classes we use
 */
require __DIR__."/autoload.php";
// Also, use the Composer autoloader:
require \dirname(__DIR__)."/vendor/autoload.php";

/**
 * 2. Load the configuration
 */
if (\is_readable(AIRSHIP_LOCAL_CONFIG."/config.json")) {
   
// Allow people to edit the JSON config and define their own locations
   
$config = \json_decode(
        \
file_get_contents(AIRSHIP_LOCAL_CONFIG."/config.json"),
       
true
   
);
} else {
   
// Sane defaults
   
$config = [
       
'skyports' => [
            [
               
'url' =>
                   
'https://airship.paragonie.com/atc/',
               
'public_key' =>
                   
'6386dabb7c57006fbbd5092d77d34398332f475f7340ae32d02cda6bc4295da6'
           
]

        ],
       
'suppliers' => []
    ];
}
if (!\
extension_loaded('libsodium')) {
   
// We need this
   
die(
       
"Please install libsodium and the libsodium-php extension from PECL\n\n".
       
"\thttps://paragonie.com/book/pecl-libsodium/read/00-intro.md#installing-libsodium\n"
   
);
}

/**
 * Let the user know precisely what's wrong, if anything is wrong.
 */
if (!Halite::isLibsodiumSetupCorrectly()) {
   
// Easiest way to grab this info:
   
\ob_start(); \phpinfo(); $data = \ob_get_clean();

   
$version = '';
    foreach (\
explode("\n", $data) as $line) {
        if (empty(
$line)) {
            continue;
        }
        if (\
strpos($line, 'libsodium compiled version') !== false) {
           
$version = \trim(\substr(\trim($line), -6));
            break;
        }
    }

    die(
       
"Your libsodium is not setup correctly. Please make sure you have at least:\n\n" .
       
"\tlibsodium v1.0.10 (Installed: " . \Sodium\version_string() .")\n" .
       
"\tlibsodium-php v1.0.6 (Installed: " . $version . ")\n"
   
);
}

/**
 * 3. Process the CLI parameters
 */
$showAll = true;
if (
$argc < 2) {
   
// Default behavior: Display the help menu
   
$argv[1] = 'help';
   
$showAll = false;
   
$argc = 2;
}


// Create a little cache for the Help command, if applicable. Doesn't contain objects.
$commands = [];

foreach (\
glob(__DIR__.'/Commands/*.php') as $file) {
   
// Let's build a queue of all the file names
   
    // Grab the filename from the Commands directory:
   
$className = \preg_replace('#.*/([A-Za-z0-9_]+)\.php$#', '$1', $file);
   
$index = \strtolower($className);
   
   
// Append to $commands array
   
$commands[$index] = $className;

    if (
$argv[1] !== 'help') {
       
// If this is the command the user passed...
       
if ($index === $argv[1]) {
           
// Instantiate this object
           
$exec = Command::getCommandStatic($className);
           
// Store the relevant storage devices in the command, in case they're needed
           
$exec->storeConfig($config);
           
// Execute it, passing the extra parameters to the command's fire() method
           
try {
               
$exec->fire(
                    \
array_values(
                        \
array_slice($argv, 2)
                    )
                );
            } catch (\
Exception $e) {
                echo
$e->getMessage(), "\n";
               
$code = $e->getCode();
                echo
$e->getTraceAsString(). "\n";
                exit(
$code > 0 ? $code : 255);
            }
           
$exec->saveConfig();
            exit(
0);
        }
    }
}

/**
 * 4. If all else fails, fall back to the help class...
 */
$help = new Help($commands);
$help->showAll = $showAll;
$help->storeConfig($config);
$help->fire(
    \
array_values(
        \
array_slice($argv, 2)
    )
);
$help->saveConfig();
exit(
0);


Details

Barge

A command line interface for developing and distributing Airship cabins, gadgets, and motifs.

How to Install Barge

First, checkout our Git repository.

git checkout https://github.com/paragonie/airship-barge.git

Next, make sure you can execute the barge command.

cd airship-barge
chmod u+x barge

Make sure you install the dependencies via Composer. This will get Halite and our constant-time encoding library installed (both are libraries that barge uses extensively):

composer update

Finally, you'll want to create a symlink in /usr/bin so you can run barge commands by simply typing barge commandgoeshere:

ln -s ./barge /usr/bin/barge

How to Use Barge

Recommended: Create a workspace directory.

cd ~
mkdir barge-workspace
cd barge-workspace

If you don't already have a Supplier account, register one here.

Now you're ready to run your first barge command.

barge login

If this is your first time logging in, you'll need to run barge key twice. (Before the final version, we intend to make this process a lot smoother.)

barge key
# Follow the prompts to generate your master keypair
barge key
# Follow the prompts to generate your signing keypair, which you'll need to sign with your master key

Once your keypairs are generated, their public counterparts are uploaded to the server and synchronized to the entire network in an append-only data structure.

Once your keys are set up, you can begin to build CMS Airship extensions. What do you want to build?

  • A full application that can stand alone from Hull or Bridge: run `airship cabin`
  • A backend modification to an existing cabin: run `airship gadget`
  • A frontend modification to an existing cabin: run `airship motif`

After you follow the prompts, you should have a skeletal project directory waiting to be fleshed out.

Ready to deploy your first version? Okay, first:

barge build

This assembles a .phar or .zip of your extension. You can manually install these into a local Airship to test them out (recommended).

If you're ready to release it, first sign it with your signing key:

barge sign

And then release it:

barge release

If you've followed these steps, your package should be available for install in CMS Airship. If you release an update in this manner, it should be deployed and installed on all of your users' machines automatically (typically within an hour, unless they changed their configuration).


  Files folder image Files  
File Role Description
Files folder imagesrc (5 files, 1 directory)
Accessible without login Plain text file barge Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file SECURITY.md Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageCommands (10 files, 1 directory)
  Accessible without login Plain text file autoload.php Aux. Auxiliary script
  Accessible without login Plain text file barge.php Example Example script
  Accessible without login Plain text file Command.php Class Class source
  Accessible without login Plain text file HTTP.php Class Class source
  Accessible without login Plain text file MetaData.php Class Class source

  Files folder image Files  /  src  /  Commands  
File Role Description
Files folder imageProto (1 file)
  Accessible without login Plain text file Build.php Class Class source
  Accessible without login Plain text file Cabin.php Class Class source
  Accessible without login Plain text file Gadget.php Class Class source
  Accessible without login Plain text file Help.php Class Class source
  Accessible without login Plain text file Key.php Class Class source
  Accessible without login Plain text file Keygen.php Class Class source
  Accessible without login Plain text file Login.php Class Class source
  Accessible without login Plain text file Motif.php Class Class source
  Accessible without login Plain text file Release.php Class Class source
  Accessible without login Plain text file Sign.php Class Class source

  Files folder image Files  /  src  /  Commands  /  Proto  
File Role Description
  Accessible without login Plain text file Init.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:40
This week:1
All time:10,833
This week:560Up