SARK V6 API

From sailpbx
Revision as of 19:37, 27 May 2020 by Adminwiki (talk | contribs) (Installation)
Jump to: navigation, search

back to SARK contents

sark6api

sark6api is fairly vanilla OAS api so it should be familiar to anyone who uses modern api's in their work. It allows you to programmatically do (almost) anything you can do at the SARK V6 browser. Why would you want to do that? Well maybe you have an idea for an extension to SARK, maybe you want to rewrite all or parts of the SARK browser and incorporate it into a package of your own. Maybe you want to control a remote SARK from a management layer. All of these things are possible with the API.

sark6api can be installed onto buster (Debian 10) or bionic (Ubuntu 18). Only 64 bit architectures are supported for both X86 and ARM.

It was tested with Postman 7.2 and developed on Vagrant Homestead running Ubuntu 18.04. sark6api uses the Laravel 7 API framework.

Requirements

  • PHP 7.2.5 or higher
  • PHP Composer
  • Laravel 7
  • GiT
  • SARK V6.0.1-50 or higher

Before you begin

If you haven't used Postman before then it would be a good idea to familiarise yourself with it before you begin. Postman is a general purpose API testing tool which is easy to use (at least for what we want to do). It runs as an app on OSX or Windows and there is also a version for Ubuntu desktop. It makes testing and exploring API's a breeze. In my view it's essential for this kind of work.


WARNING

The initial release of sark6api works as a "trusted" peer. It has no security of its own so you must use fixed IP's and secure firewall rules to keep it safe from baddies. So, for now, no dynamic IP clients. We are working on an OAuth security blanket and it will be ready as soon as we can get it out the door but you can test with it as-is as long as you observe point-to-point security using the host SARK firewall rules.

The srk6api runs at port 44300 (HTTPS).

Installation=

You will need a SARKV6 host running on buster or bionic. Doesn't matter what the underlying platform is.

Update your existing deb packages

sudo apt update
sudo apt upgrade

NB - this will bring your SARK up to the latest V6 release.

  • GiT - it should already be installed as part of the sark6 install. If not then you can do
sudo apt install git

There are a few PHP extensions you may need over and above what gets dragged along with SARK. However, my Vagrant Homestead dev box doesn't appear to have any of them and chugs along OK so YMMV.

  • BCMath PHP Extension (php-bcmath)
  • Ctype PHP Extension (php-ctype)
  • Fileinfo PHP extension (php-fileinfo)
  • Tokenizer PHP Extension (php-tokenizer)
  • zip (php-zip)

I'm not sure about these because my Vagrant Homestead dev box doesn't appear to have any of them except php-zip yet it chugs along OK so YMMV. So, lets install zip

apt install php-zip


Next, you can install composer. Composer is the PHP package manager. You can think of it a bit like the Debian package manager but with a lot of stuff in it just for PHP. It has more or less become the tool of choice for GiT PHP developers to package their code and we need it to enable the Laravel API framework.

apt install composer

You will also need a regular user account on the box. It doesn't much matter what you choose, it's just an anchor to install the code.

adduser s6api

logout and back in and su to the new account

sudo su - s6api


OK, we're now in out new user and ready to install laravel.

composer global require laravel/installer

If composer hits any dependency problems it will tell you so you can just go fetch 'em and then run the above command again. Once it works it will spit out a fair bit of text which will end

...
Writing lock file
Generating autoload files


Next we need to add the composer bin to outr path

export PATH=$PATH:$HOME/.config/composer/vendor/bin

So far so good. Now we have to create a wrapper directory and install the base Laravel skeleton into it

mkdir www
cd www
laravel new sark6api

Finally we can clone sark6api into the new directory we just created.

git clone https://github.com/aelintra/sark6api.git