Fusionpbx device register – multiple device register

PhoneLite, register method 1
PhoneLite register method 2

the domain DNS must be the IP adress of fusionpbx

the softphone public IP need to be allowed in iptables

Multiple device register: Advanced -> sip profile -> edit internal

Status -> sip status -> (check rescan + restart) sip profile
# monitor device register, /home/wu/monitor_extension.php
# monitor fusionpbx extension registered
#*/5 * * * *  /usr/bin/php /home/wu/monitor_extension.php 8xxxxx.voipit.space 107 >> /dev/null 2>&1

<?php

if ($argc != 3) {
   print "miss pameters: monitor_extension.php 845x63975x.voipit.space 107\n";
   exit;
}

/*******************************************
******* EDIT BELOW VALUES TO SUIT *********
******************************************/

// Enter the admin email to receive alerts (mandatory)
$mailto = "xxxx@voipitservices.com";

// Enter the from email address or leave it as it is.
$mailfrom = "pbx@steadyxxx.com";

// Enter a friendly sender name or leave it as it is.
$fromname = "FusionPBX";

// Enter an email subject or leave it as it is.
$mailsub = "[ALERT] FusionPBX Extension Failure!";

// Location of fs_cli command.
$fscli = "/usr/bin/fs_cli";

// Enter extension numbers to check and optionally, email address.
// Make sure extension exists
$extensions = array(
    $argv[2] => $argv[1]
);

/*******************************************
****** DO NOT EDIT BELOW THIS LINE *******
******************************************/

// Function to check extension registration status
function checkExtn($ext, $tenant){
    global $fscli;
    // $ext_tenant = $ext."@".$tenant;
    // $command = $fscli . ' -x "sofia status profile internal reg ' . $ext .'"' . " grep ". $tenant;
    // /usr/bin/fs_cli -x "sofia status profile internal user 101@8452639754.voipit.space " |grep "Ping-Status"
    $command = $fscli . ' -x "sofia status profile internal user ' . $ext . "@" . $tenant . '"';
print $command."\n";

    $res = shell_exec($command);
    $regex = '/returned:\s(\d+)/';
    preg_match($regex, $res, $matches);

    if($matches[1] > 0) {
        return true;
    }else {
        return false;
    }
}

// Function to send email
function sendMail($msg){
    global $fromname, $mailfrom, $mailsub, $mailto;
    // Format from name
    $from = $fromname . "\<" . $mailfrom . "\>";
    // Email command line
    $recipe = 'echo "%s" | mail -a "Content-Type: text/html" -s "%s" -aFrom:%s "%s"';
    // Format email command
    $cooked = sprintf($recipe,$msg,$mailsub,$from,$mailto);
print "\n";
print $cooked."\n";

    // Send email
    shell_exec($cooked);
}

// Function to check whether FreeSWITCH is running
function checkFS(){
    $fs = trim(shell_exec('pidof "freeswitch"'));
    if(! strlen($fs)){
        return false;
    }else{
         return true;
    }
}

// Set global variable to collect messages
$msg = "";
/* Check if FS is running; restart if it isn't
if(! checkFS()){
    $msg .= "FreeSWITCH isn't running, trying a service restart... <br />";
    $msg .= shell_exec('systemctl restart freeswitch.service');
    sleep(5);
    if(! checkFS()){
        $msg .= "<br /> FreeSWITCH wouldn't start; exiting... <br />";
        sendMail($msg);
        exit;
    }else{
        $msg .= "<br /> FreeSWITCH is running... <br />";
        sleep(60);
    }
}
*/

// Iterate through nominated extensions for registration status
foreach($extensions as $ext => $tenant){
    if(! checkExtn($ext, $tenant)) {
        if(strlen(trim($tenant))) {
            $tenant = ', ' . $tenant;
        }
print $ext."\n";
        sendMail($msg . 'Your phone ' . $ext . ' is offline; please check connectivity.', $tenant);
    }
}

?>