Need to add extensions outside of GUI

I’m losing hope here.

I have a strong need to create extensions and manage secrets outside the FreePBX GUI. We have an in-house built user management system where we store user information/passwords, etc. We need a way to create new extensions using existing user/passwords from our custom system, or change existing passwords. We don’t want to have to move back and forth between multiple systems to do something as simple (from a user standpoint) as adding a user and assigning an extension.

I’ve been looking and find nothing but similar questions with little or no response. This single issue (changes outside of the GUI) renders FreePBX and asterisk in general as a poor choice, at least for us. I don’t want to have to start over with FreeSwitch.

I would appreciate any help.

You will need to populate appropriately these mysql database tables, sip (or other technology) , devices and users, also populate the asterisk database with AMPUSER (extension)/*.

Use a working extension to extract exactly what is needed for that template.

Can you leverage PHP scripting? If so we can provide examples but you didn’t state how you want to interact with FreePBX. In fact you gave no details and instead posted an idle threat at the end.

Give some details and we/I can help you out.

Sorry for the lack of info. My first choice would be a web service since FreePBX would be external to our main admin site, which is .NET. The admin site would need to fire a request off to the offsite FreePBX location to handle the update. I could set the update to run from any server on that network. PHP is a definite possibility.

Not looking to punish anyone, just want to get this to work.

Since FreePBX is OpenSource you can go look at the simple PHP code in core and see how we add and remove users. Its not overly complicated and lots of it is in functions.

You’ll have to go with PHP. you can easily create PHP hooks (RESTFUL) if you wish. It’s not a hard thing to do. As tony mentioned I would go look at core/functions.inc.php the code to add and remove users is right there. I will give you more information as time permits. Right now I’m pretty swamped. But I don’t think you’d find it any easier in the freeswitch world…

Thanks for the info. Still pretty new to this, and I’m getting too old to learn new stuff :slight_smile:

Thanks for the help here. I did find a script that has the ability to update the extension, but when I run it I get “No direct script access allowed”. I’ve tried placing the code in the html and admin folder with the same results. I got the code from here http://samyantoun.50webs.com/asterisk/freepbx/createext.php.txt.

Sorry for acting like a newbie, but that’s what I am.

That page is extremely old. You could have completely messed up you install by running that blindly. Which is what you did.

<?php
$bootstrap_settings = array();
$bootstrap_settings['freepbx_auth'] = false;
if (!@include_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) { 
      include_once('/etc/asterisk/freepbx.conf'); 
}

/*
USER VARS:
Array
(
    [extension] => 0224
    [password] => 
    [name] => Display Name
    [voicemail] => default
    [ringtimer] => 0
    [noanswer] => 
    [recording] => 
    [outboundcid] => 
    [sipname] => 
    [noanswer_cid] => 
    [busy_cid] => 
    [chanunavail_cid] => 
    [noanswer_dest] => 
    [busy_dest] => 
    [chanunavail_dest] => 
    [mohclass] => default
    [callwaiting] => enabled
    [cid_masquerade] => 0224
    [call_screen] => 0
    [pinless] => disabled
    [cfringtimer] => 0
    [concurrency_limit] => 0
    [dialopts] => 
    [recording_in_external] => dontcare
    [recording_out_external] => dontcare
    [recording_in_internal] => dontcare
    [recording_out_internal] => dontcare
    [recording_ondemand] => disabled
    [recording_priority] => 10
)
*/
$vars = array(
"extension" => 255,
"name" => "Bobby"
);
core_users_add($vars);
//core_devices_add($id,$tech,$dial,$devicetype,$user,$description,$emergency_cid=null,$editmode=false)

core_devices_add(255,'sip','','fixed',255,'Bobby');

It’s all dev at this point so not a real issue. But I appreciate the message. I’d never do that on a production box.

Thanks for the code. I’ll test it out and let you know. I really appreciate your help here. If you know of any good books in this area I’d like to do some reading instead of blind key presses.

I’m still having newbie issues here. I take the script shown above and load into a php file or html for that matter. I execute that file using localhost and I get ‘No direct script access allowed’. Are there permissions I need to set or do I need to execute this in a different manner.

Thanks in advance.

Where are you running it from? This is not something you can just blindly run from the web browser. It’s a command line orientated script to be run outside of the html directory.

I would like to initiate the script using a web request, hopefully not blindly. This will be initiated from a web site with a call to the FreePBX system to add the extension. Whatever means is best suited to do this I am open to. This update would only be allowed from a single IP with credentials. I understand the importance of limited access here. The important thing is to have the extension/user data added from a remote site in a background operation.

You are doing something wrong on your own server as I can run that script anywhere on the system at any time.

I can run it successfully from terminal if I place it anywhere other than html. But I need to fire the script using http from a remote site. Yeah, I know, I’m a Windows guy trying something new.

Curiosity are you trying to generate the PBX account as part of an Active Directory script for new employees?

Not an AD account. We built a management system for a call center where the user and extension are created within this management system. I’d like to update the PBX with this user and extension remotely.

<?php define("FREEPBX_IS_AUTH", "1");

I was able to get this to work in a web page. I had to add the following lines to the script.

require_once “/var/www/html/admin/functions.inc.php”;
require_once “/var/www/html/admin/modules/core/functions.inc.php”;

Once added, I was able to run the script with no errors. I also had to add “pinless” => “disabled” to get around another state error.

The issue I’m having now is with the password. I’m including “password” => “testpw123” in the array. the password is added correctly to the users table. But the secret in the GUI appears to be an auto generated pw. I looked in the sip table and there is no secret set. Should the script use core_devices_add or core_devices_addsip?