Amportal commands don't work, blank admin web page,

PBX is using Freepbx12 on 32 bit Ubuntu (14.04.1 LTS). Manual install. Getting blank admin gui page, amportal commands return nothing. Asterisk is running. MySQL is running. No calls going through. Rebooting server doesn’t help. Can get into asterisk CLI.

Where do I start?

Contents of freepbx.conf

<?php
$amp_conf['AMPDBUSER']  = 'asteriskuser';
$amp_conf['AMPDBPASS']  = 'ommited';
$amp_conf['AMPDBHOST']  = 'localhost';
$amp_conf['AMPDBNAME']  = 'asterisk';
$amp_conf['AMPDBENGINE'] = 'mysql';
$amp_conf['datasource'] = ''; //for sqlite3

require_once('/var/www/html/admin/bootstrap.php');

Contents of /etc/asterisk/asterisk.conf

[directories]
astetcdir => /etc/asterisk
astmoddir => /usr/lib/asterisk/modules
astvarlibdir => /var/lib/asterisk
astagidir => /var/lib/asterisk/agi-bin
astspooldir => /var/spool/asterisk
astrundir => /var/run/asterisk
astlogdir => /var/log/asterisk

[options]
transmit_silence_during_record = yes
languageprefix=yes
execincludes=yes

Contents of /usr/local/sbin/amportal were empty. I noticed there was an amportal.bak, so I made a copy and renamed it to amportal. Now when I run amportal it shows as “Please wait…”.

Contents of amportal

#!/usr/bin/env bash

ROOT_UID=0       # root uid is 0
E_NOTROOT=67     # Non-root exit error
# define freepbx config file if not alreaddy set
if [ -z "$FREEPBX_CONF" ]; then
        if [ -e "/etc/freepbx.conf" ]; then
                FREEPBX_CONF="/etc/freepbx.conf"
        elif [ -e "/etc/asterisk/freepbx.conf" ]; then
                FREEPBX_CONF="/etc/asterisk/freepbx.conf"
        else
                FREEPBX_CONF="/etc/freepbx.conf"
        fi
fi

echo
# check to see if we are root
if [ "$UID" -ne "$ROOT_UID" ]
then
        echo "Sorry, you must be root to run this script."
        echo
        exit $E_NOTROOT
fi

# get settings from db/config file

if [[ -e $FREEPBX_CONF && -w "/etc/amportal.conf" && -z "$FORCE_AMPORTAL_CONF" ]]; then        # Check if file exists.

        php -r > /dev/null 2>&1
        if [ $? -eq 0 ]; then
                echo "Please wait..."
                `php -r '
                $bootstrap_settings["freepbx_auth"] = false;
                $bootstrap_settings["skip_astman"] = true;
                $restrict_mods = true;
                if ([email protected]_once(getenv("FREEPBX_CONF") ? getenv("FREEPBX_CONF") : "/etc/freepbx.conf")) {
                        include_once("/etc/asterisk/freepbx.conf");
                }
                foreach($amp_conf as $key => $val) {
                        $val = str_replace(array("\r", "\n", "\r\n"), ",", $val);
                        if (is_bool($val)) {
                                echo "export " . trim($key) . "=" . ($val?"TRUE":"FALSE") ."\n";
                        } else {
                                echo "export " . trim($key) . "=" . escapeshellcmd(trim($val)) ."\n";
                        }
                }
                '`
        elif [ -e "/var/lib/asterisk/bin/gen_amp_conf.php" ]; then
                echo "Fetching FreePBX settings with gen_amp_conf.php.."
                `/var/lib/asterisk/bin/gen_amp_conf.php`
        elif [ -e "/etc/amportal.conf" ]; then # Check if file exists.
                echo "Fetching settings from amportal.conf file.."
                . /etc/amportal.conf
        else
                echo;
                echo "FreePBX settings could not be fetched and no backup config file found!";
                echo "Have you installed FreePBX?";
                exit;
        fi
elif [ -e "/etc/amportal.conf" ]; then # Check if file exists.
        . /etc/amportal.conf
else
        echo;
        echo "FreePBX config file not found!";
        echo "Have you installed FreePBX?";
        exit;
fi

if [ -x ${AMPBIN}/freepbx_engine ]; then
        ${AMPBIN}/freepbx_engine [email protected]
elif [ -x ${ASTVARLIBDIR}/bin/freepbx_engine ]; then
        ${ASTVARLIBDIR}/bin/freepbx_engine [email protected]
elif [ -x /var/lib/asterisk/bin/freepbx_engine ]; then
        /var/lib/asterisk/bin/freepbx_engine [email protected]
else
        echo "FATAL: can not find freepbx_engine to start Asterisk"
fi

There is something funky going on in the var/www/ directory. It seems every file in the var/www/ directory is there but showing 0kb, like everything in them got wiped.

Look for hidden files, weird cron jobs, extra dialplan added to extensions_custom.conf, stuff like that. It sounds like your server has been compromised. Did you have the /recordings (old user interface before UCP) enabled? In the past, there were some vulnerabilities there that could allow an attacker to control your system.

The system is not open to the internet, so if it was compromised it would have to be from an internal source. Something happened after I enabled the CDR reports module.

I copied the entire www directory from a similar system and am setting permissions recursively on the folder for 0755 and owner asterisk (since amportal chown isn’t working). Hopefully this works.

The web GUI is partially back up. I can log into it but many of the menu options are greyed out (Asterisk is not running it says, even though it is). Disconnect somewhere between FreePBX and Asterisk?

is asterisk running as root

How can I tell? Sorry I’m not too familiar with Asterisk/FreePBX. Have to do everything manually as none of the amportal commands are working.

Ran amportal a ma refreshsignatures and it found framework signature invalid. Then I did a amportal a reload and results in

Please wait...

Error(s) have occured, the following is the retrieve_conf output:
exit: 255
found language dir fr for directory, not installed on system, skipping
Added to globals: OPERATOR_XTN =
Added to globals: VMX_LOOPS = 1
Added to globals: VMX_OPTS_DOVM =
Added to globals: VMX_OPTS_LOOP =
Added to globals: VMX_REPEAT = 1
Added to globals: VMX_TIMEOUT = 2
Added to globals: VM_DDTYPE = b
Added to globals: VM_GAIN = 12
Added to globals: VM_OPTS = s
Added to globals: ASTETCDIR = /etc/asterisk
Added to globals: ASTMODDIR = /usr/lib/asterisk/modules
Added to globals: ASTVARLIBDIR = /var/lib/asterisk
Added to globals: ASTAGIDIR = /var/lib/asterisk/agi-bin
Added to globals: ASTSPOOLDIR = /var/spool/asterisk
Added to globals: ASTRUNDIR = /var/run/asterisk
Added to globals: ASTLOGDIR = /var/log/asterisk
Added to globals: CWINUSEBUSY = true
Added to globals: AMPMGRUSER = admin
Added to globals: AMPMGRPASS = amp111
Added to globals: AMPDBENGINE = mysql
Added to globals: AMPDBHOST = localhost
Added to globals: AMPDBNAME = asterisk
Added to globals: AMPDBUSER = asteriskuser
Added to globals: AMPDBPASS = ommited
Added to globals: VMX_CONTEXT = from-internal
Added to globals: VMX_PRI = 1
Added to globals: VMX_TIMEDEST_CONTEXT =
Added to globals: VMX_TIMEDEST_EXT = dovm
Added to globals: VMX_TIMEDEST_PRI = 1
Added to globals: VMX_LOOPDEST_CONTEXT =
Added to globals: VMX_LOOPDEST_EXT = dovm
Added to globals: VMX_LOOPDEST_PRI = 1
Added to globals: MIXMON_DIR =
Added to globals: MIXMON_POST =
Added to globals: DIAL_OPTIONS = Ttr
Added to globals: TRUNK_OPTIONS = Tt
Added to globals: TRUNK_RING_TIMER = 300
Added to globals: MIXMON_FORMAT = wav
Added to globals: REC_POLICY = caller
Added to globals: RINGTIMER_DEFAULT = 15
Added to globals: TRANSFER_CONTEXT = from-internal-xfer
PHP Fatal error:  Uncaught exception 'Exception' with message 'Tried to remove key noload from section modules, but that section doesn't exist' in /var/www/html/admin/libraries/BMO/ConfigFile.class.php:79
Stack trace:
#0 /var/www/html/admin/libraries/BMO/ModulesConf.class.php(63): ConfigFile->removeEntry('modules', 'noload', 'chan_sip.so')
#1 /var/www/html/admin/modules/core/functions.inc/PJSip.class.php(234): ModulesConf->removenoload('chan_sip.so')
#2 /var/www/html/admin/libraries/BMO/FileHooks.class.php(100): FreePBX\modules\Core\PJSip->writeConfig(Array)
#3 /var/www/html/admin/libraries/BMO/FileHooks.class.php(25): FileHooks->processNewHooks()
#4 /var/lib/asterisk/bin/retrieve_conf(740): FileHooks->processFileHooks(Array)
#5 {main}
  thrown in /var/www/html/admin/libraries/BMO/ConfigFile.class.php on line 79

Ended up having to replace the modules.conf in etc/asterisk as it had one line. Asterisk and FreePBX seem to be working and now I can hit “apply config”. Calls are working now too.

;--------------------------------------------------------------------------------;
;          Do NOT edit this file as it is auto-generated by FreePBX.             ;
;--------------------------------------------------------------------------------;
; For information on adding additional paramaters to this file, please visit the ;
; FreePBX.org wiki page, or ask on IRC. This file was created by the new FreePBX ;
; BMO - Big Module Object. Any similarity in naming with BMO from Adventure Time ;
; is totally deliberate.                                                         ;
;--------------------------------------------------------------------------------;

[modules]
autoload=yes
preload = pbx_config.so
preload = chan_local.so
noload = chan_woomera.so
noload = pbx_gtkconsole.so
noload = pbx_kdeconsole.so
noload = app_intercom.so
noload = chan_modem.so
noload = chan_modem_bestdata.so
noload = chan_modem_i4l.so
noload = app_trunkisavail.so
noload = chan_alsa.so
noload = chan_oss.so
noload = app_directory_odbcstorage.so 
noload = app_voicemail_odbcstorage.so 
noload = chan_modem_aopen.so
noload = cdr_radius.so
noload = cel_radius.so
noload = chan_woomera.so
load = format_wav.so
load = format_pcm.so
load = format_mp3.so
load = res_musiconhold.so