SARK V6 API

From sailpbx
Revision as of 08:03, 28 May 2020 by Adminwiki (talk | contribs) (Agents)
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 so you can run it on metal or in virtual as the muse takes you.

Update your existing deb packages

sudo apt update
sudo apt upgrade

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

GiT 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.


Next we need to add the composer bin to our path

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

So far so good. Now we have to create a wrapper directory and clone the api into it

mkdir www
cd www
git clone https://github.com/aelintra/sark6api.git

Next we use composer to add the required Laravel dependencies (which aren't on the Git image)

cd sark6api
composer install

Next we have to add a .env file for Laravel. Create a file called .env in sark6api and paste this into it

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=sqlite

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

Now generate an encryption key

php artisan key:generate

Methods

Agents

GET /agents/{agent?}

POST /agents

Body
  • 'pkey' = 'required';
  • 'cluster' = 'required|exists:cluster';
  • 'name' = 'required|alpha_dash';
  • 'passwd' = 'required|integer';

PUT /agents/{agent}

Body
  • 'cluster' => 'exists:cluster,pkey',
  • 'name' => 'alpha_dash',
  • 'passwd' => 'integer',
  • 'queue1' => 'exists:queue,pkey|nullable',
  • 'queue2' => 'exists:queue,pkey|nullable',
  • 'queue3' => 'exists:queue,pkey|nullable',
  • 'queue4' => 'exists:queue,pkey|nullable',
  • 'queue5' => 'exists:queue,pkey|nullable',
  • 'queue6' => 'exists:queue,pkey|nullable'

DELETE /agents/{agent}

Route::get('agents', 'AgentController@index'); Route::get('agents/{agent}', 'AgentController@show'); Route::post('agents', 'AgentController@save'); Route::put('agents/{agent}', 'AgentController@update'); Route::delete('agents/{agent}', 'AgentController@delete');

Route::get('astami', 'AstAmiController@index');

Route::get('astami/CoreSettings', 'AstAmiController@coresettings'); Route::get('astami/CoreStatus', 'AstAmiController@corestatus');

Route::get('astami/DBget/{id}/{key}', 'AstAmiController@dbget'); Route::get('astami/ExtensionState/{id}{context?}', 'AstAmiController@extensionstate'); Route::get('astami/MailboxCount/{id}', 'AstAmiController@mailboxcount'); Route::get('astami/MailboxStatus/{id}', 'AstAmiController@mailboxstatus'); Route::get('astami/QueueStatus/{id}', 'AstAmiController@queuestatus'); Route::get('astami/QueueSummary/{id}', 'AstAmiController@queuesummary'); Route::get('astami/Reload', 'AstAmiController@reload'); Route::get('astami/SIPshowpeer/{id}', 'AstAmiController@sipshowpeer'); Route::get('astami/{action}', 'AstAmiController@getlist');

Route::post('astami/originate', 'AstAmiController@originate');

Route::put('astami/DBdel/{id}/{key}', 'AstAmiController@dbdel'); Route::put('astami/DBput/{id}/{key}/{value}', 'AstAmiController@dbput');

Route::get('backups', 'BackupController@index'); Route::get('backups/new', 'BackupController@new'); Route::get('backups/{backup}', 'BackupController@download'); Route::post('backups', 'BackupController@save'); Route::put('backups/{backup}', 'BackupController@update'); Route::delete('backups/{backup}', 'BackupController@delete');

Route::get('coscloses', 'CosCloseController@index'); Route::get('coscloses/{cosclose}', 'CosCloseController@show'); Route::post('coscloses', 'CosCloseController@save'); Route::put('coscloses/{cosclose}', 'CosCloseController@update'); Route::delete('coscloses/{cosclose}', 'CosCloseController@delete');

Route::get('cosopens', 'CosOpenController@index'); Route::get('cosopens/{cosopen}', 'CosOpenController@show'); Route::post('cosopens', 'CosOpenController@save'); Route::put('cosopens/{cosopen}', 'CosOpenController@update'); Route::delete('cosopens/{cosopen}', 'CosOpenController@delete');

Route::get('cosrules', 'ClassOfServiceController@index'); Route::get('cosrules/{classofservice}', 'ClassOfServiceController@show'); Route::post('cosrules', 'ClassOfServiceController@save'); Route::put('cosrules/{classofservice}', 'ClassOfServiceController@update'); Route::delete('cosrules/{classofservice}', 'ClassOfServiceController@delete');

Route::get('customapps', 'CustomAppController@index'); Route::get('customapps/{customapp}', 'CustomAppController@show'); Route::post('customapps', 'CustomAppController@save'); Route::put('customapps/{customapp}', 'CustomAppController@update'); Route::delete('customapps/{customapp}', 'CustomAppController@delete');

Route::get('daytimers', 'DayTimerController@index'); Route::get('daytimers/{daytimer}', 'DayTimerController@show'); Route::post('daytimers', 'DayTimerController@save'); Route::put('daytimers/{daytimer}', 'DayTimerController@update'); Route::delete('daytimers/{daytimer}', 'DayTimerController@delete');

Route::get('destinations', 'DestinationController@index');

Route::get('extensions', 'ExtensionController@index'); Route::get('extensions/{extension}', 'ExtensionController@show'); Route::get('extensions/{extension}/runtime', 'ExtensionController@showruntime'); Route::post('extensions/mailbox', 'ExtensionController@mailbox'); Route::post('extensions/provisioned', 'ExtensionController@provisioned'); Route::post('extensions/vxt', 'ExtensionController@vxt'); Route::post('extensions/unprovisioned', 'ExtensionController@unprovisioned'); Route::put('extensions/{extension}', 'ExtensionController@update'); Route::put('extensions/{extension}/runtime', 'ExtensionController@updateruntime'); Route::delete('extensions/{extension}', 'ExtensionController@delete');

Route::get('firewall', 'FirewallController@index'); Route::get('firewall/ipv4', 'FirewallController@ipv4'); Route::get('firewall/ipv6', 'FirewallController@ipv6'); Route::post('firewall/ipv4', 'FirewallController@ipv4save'); Route::post('firewall/ipv6', 'FirewallController@ipv6save'); Route::put('firewall/ipv4', 'FirewallController@ipv4restart'); Route::put('firewall/ipv6', 'FirewallController@ipv6restart');

Route::get('greetings', 'GreetingController@index'); Route::get('greetings/{greeting}', 'GreetingController@download'); Route::post('greetings', 'GreetingController@save'); Route::delete('greetings/{greeting}', 'GreetingController@delete');

Route::get('holidaytimers', 'HolidayTimerController@index'); Route::get('holidaytimers/{holidaytimer}', 'HolidayTimerController@show'); Route::post('holidaytimers', 'HolidayTimerController@save'); Route::put('holidaytimers/{holidaytimer}', 'HolidayTimerController@update'); Route::delete('holidaytimers/{holidaytimer}', 'HolidayTimerController@delete');

Route::get('inboundroutes', 'InboundRouteController@index'); Route::get('inboundroutes/{inboundroute}', 'InboundRouteController@show'); Route::post('inboundroutes', 'InboundRouteController@save'); Route::put('inboundroutes/{inboundroute}', 'InboundRouteController@update'); Route::delete('inboundroutes/{inboundroute}', 'InboundRouteController@delete');

Route::get('ivrs', 'IvrController@index'); Route::get('ivrs/{ivr}', 'IvrController@show'); Route::post('ivrs', 'IvrController@save'); Route::put('ivrs/{ivr}', 'IvrController@update'); Route::delete('ivrs/{ivr}', 'IvrController@delete');

Route::get('logs', 'LogController@index'); Route::get('logs/cdrs/{limit?}', 'LogController@showcdr');

Route::get('queues', 'QueueController@index'); Route::get('queues/{queue}', 'QueueController@show'); Route::post('queues', 'QueueController@save'); Route::put('queues/{queue}', 'QueueController@update'); Route::delete('queues/{queue}', 'QueueController@delete');

Route::get('snapshots', 'SnapShotController@index'); Route::get('snapshots/new', 'SnapShotController@new'); Route::get('snapshots/{snapshot}', 'SnapShotController@download'); Route::post('snapshots', 'SnapShotController@save'); Route::put('snapshots/{snapshot}', 'SnapShotController@update'); Route::delete('snapshots/{snapshot}', 'SnapShotController@delete');

Route::get('ringgroups', 'RingGroupController@index'); Route::get('ringgroups/{ringgroup}', 'RingGroupController@show'); Route::post('ringgroups', 'RingGroupController@save'); Route::put('ringgroups/{ringgroup}', 'RingGroupController@update'); Route::delete('ringgroups/{ringgroup}', 'RingGroupController@delete');

Route::get('routes', 'RouteController@index'); Route::get('routes/{route}', 'RouteController@show'); Route::post('routes', 'RouteController@save'); Route::put('routes/{route}', 'RouteController@update'); Route::delete('routes/{route}', 'RouteController@delete');

Route::get('syscommands', 'SysCommandController@index'); Route::get('syscommands/commit', 'SysCommandController@commit'); Route::get('syscommands/reboot', 'SysCommandController@reboot'); Route::get('syscommands/pbxrunstate', 'SysCommandController@pbxrunstate'); Route::get('syscommands/pbxstart', 'SysCommandController@start'); Route::get('syscommands/pbxstop', 'SysCommandController@stop');

Route::get('sysglobals', 'SysglobalController@index'); Route::put('sysglobals', 'SysglobalController@update');

Route::get('templates', 'TemplateController@index'); Route::get('templates/{template}', 'TemplateController@show'); Route::post('templates', 'TemplateController@save'); Route::put('templates/{template}', 'TemplateController@update'); Route::delete('templates/{template}', 'TemplateController@delete');

Route::get('tenants', 'TenantController@index'); Route::get('tenants/{tenant}', 'TenantController@show'); Route::post('tenants', 'TenantController@save'); Route::put('tenants/{tenant}', 'TenantController@update'); Route::delete('tenants/{tenant}', 'TenantController@delete');

Route::get('trunks', 'TrunkController@index'); Route::get('trunks/{trunk}', 'TrunkController@show'); Route::post('trunks', 'TrunkController@save'); Route::put('trunks/{trunk}', 'TrunkController@update'); Route::delete('trunks/{trunk}', 'TrunkController@delete');