Skip to content

Commit

Permalink
Merge Complete
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jun 25, 2018
2 parents eb7bce7 + 533adb9 commit 652974c
Show file tree
Hide file tree
Showing 17 changed files with 769 additions and 56 deletions.
99 changes: 83 additions & 16 deletions dsiprouter.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/bash
# Uncomment if you want to debug this script.
#set -x

#Define some global variables

SERVERNAT=0
FLT_CARRIER=8
FLT_PBX=9
REQ_PYTHON_MAJOR_VER=3
Expand All @@ -29,6 +28,21 @@ elif [ -f /etc/debian_version ]; then
DEB_REL=`grep -w "VERSION=" /etc/os-release | sed 's/VERSION=".* (\(.*\))"/\1/'`
fi

function displayLogo {


echo "CiAgICAgXyAgX19fX18gX19fX18gX19fX18gIF9fX19fICAgICAgICAgICAgIF8gCiAgICB8IHwv
IF9fX198XyAgIF98ICBfXyBcfCAgX18gXCAgICAgICAgICAgfCB8ICAgICAgICAgICAKICBfX3wg
fCAoX19fICAgfCB8IHwgfF9fKSB8IHxfXykgfF9fXyAgXyAgIF98IHxfIF9fXyBfIF9fIAogLyBf
YCB8XF9fXyBcICB8IHwgfCAgX19fL3wgIF8gIC8vIF8gXHwgfCB8IHwgX18vIF8gXCAnX198Cnwg
KF98IHxfX19fKSB8X3wgfF98IHwgICAgfCB8IFwgXCAoXykgfCB8X3wgfCB8fCAgX18vIHwgICAK
IFxfXyxffF9fX19fL3xfX19fX3xffCAgICB8X3wgIFxfXF9fXy8gXF9fLF98XF9fXF9fX3xffCAg
IAoKQnVpbHQgaW4gRGV0cm9pdCwgVVNBIC0gUG93ZXJlZCBieSBLYW1haWxpbyAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgClN1cHBv
cnQgY2FuIGJlIHB1cmNoYXNlZCBmcm9tIGh0dHBzOi8vZE9wZW5Tb3VyY2UuY29tL2RzaXByb3V0
ZXIKClRoYW5rcyB0byBvdXIgc3BvbnNvcjogU2t5ZXRlbCAoc2t5ZXRlbC5jb20pCg==" | base64 -d

}

function validateOSInfo {

Expand Down Expand Up @@ -148,7 +162,7 @@ fi

mysql -u $MYSQL_KAM_USERNAME $MYSQL_KAM_PASSWORD $MYSQL_KAM_DATABASE -e "insert into dr_gateways (gwid,type,address,strip,pri_prefix,attrs,description) select null,grp,ip_addr,'','','',tag from address;"

# Setup Outbound Rules to use Flowroute by default
# Setup Outbound Rules to use Skyetel by default
mysql -u $MYSQL_KAM_USERNAME $MYSQL_KAM_PASSWORD $MYSQL_KAM_DATABASE -e "insert into dr_rules values (null,8000,'','','','','1,2','Default Outbound Route');"


Expand All @@ -160,6 +174,33 @@ ln -s ${DSIP_KAMAILIO_CONF_DIR}/kamailio/kamailio${KAM_VERSION}_dsiprouter.cfg
#Fix the mpath
fixMPATH

#Enable SERVERNAT
if [ "$SERVERNAT" == "1" ]; then
enableSERVERNAT

fi
}

function enableSERVERNAT {


EXTERNAL_IP=`curl -s ip.alt.io`
INTERNAL_IP=`hostname -I | awk '{print $1}'`
INTERNAL_NET=$(awk -F"." '{print $1"."$2"."$3".*"}' <<<$INTERNAL_IP)

sed -i 's/##!define WITH_SERVERNAT/#!define WITH_SERVERNAT/' ${DSIP_KAMAILIO_CONF_DIR}/kamailio/kamailio${KAM_VERSION}_dsiprouter.cfg
sed -i 's/!INTERNAL_IP_ADDR!.*!g/!INTERNAL_IP_ADDR!'$INTERNAL_IP'!g/' ${DSIP_KAMAILIO_CONF_DIR}/kamailio/kamailio${KAM_VERSION}_dsiprouter.cfg
sed -i 's/!INTERNAL_IP_NET!.*!g/!INTERNAL_IP_NET!'$INTERNAL_NET'!g/' ${DSIP_KAMAILIO_CONF_DIR}/kamailio/kamailio${KAM_VERSION}_dsiprouter.cfg
sed -i 's/!EXTERNAL_IP_ADDR!.*!g/!EXTERNAL_IP_ADDR!'$EXTERNAL_IP'!g/' ${DSIP_KAMAILIO_CONF_DIR}/kamailio/kamailio${KAM_VERSION}_dsiprouter.cfg


}

function disableSERVERNAT {


sed -i 's/#!define WITH_SERVERNAT/##!define WITH_SERVERNAT/' ${DSIP_KAMAILIO_CONF_DIR}/kamailio/kamailio${KAM_VERSION}_dsiprouter.cfg

}

#Try to locate the Kamailio modules directory. It will use the last modules directory found
Expand Down Expand Up @@ -313,10 +354,17 @@ if [ $DISTRO == "debian" ]; then

#cp /etc/rtpengine/rtpengine.sample.conf /etc/rtpengine/rtpengine.conf

if [ "$SERVERNAT" == "0" ]; then
INTERFACE=$EXTERNAL_IP
else
INTERFACE=$INTERNAL_IP!$EXTERNAL_IP

fi

echo -e "
[rtpengine]
table = -1
interface = $INTERNAL_IP!$EXTERNAL_IP
interface = $INTERFACE
listen-ng = 7722
port-min = 10000
port-max = 30000
Expand Down Expand Up @@ -427,7 +475,7 @@ if [ $DISTRO == "centos" ]; then
systemctl restart rsyslog

#Setup Firewall rules for RTPEngine
firewall-cmd --zone=public --add-port=10000-20000/udp --permanent
firewall-cmd --zone=public --add-port=10000-30000/udp --permanent
firewall-cmd --reload

#Enable the RTPEngine to start during boot
Expand Down Expand Up @@ -509,10 +557,11 @@ if [ ! -f "./.installed" ]; then
systemctl restart kamailio
if [ $? -eq 0 ]; then
touch ./.installed
echo -e "-----------------------"
echo -e "dSIPRouter is installed"
echo -e "-----------------------\n\n"
echo -e "The username and dynamically generated password is below:\n"
echo -e "\e[32m-------------------------\e[0m"
echo -e "\e[32mInstallation is complete! \e[0m"
echo -e "\e[32m-------------------------\e[0m\n"
displayLogo
echo -e "\n\nThe username and dynamically generated password are below:\n"

#Generate a unique admin password
generatePassword
Expand Down Expand Up @@ -644,7 +693,7 @@ function start {
nohup $PYTHON_CMD ./gui/dsiprouter.py runserver -h 0.0.0.0 -p ${DSIP_PORT} --threaded >/dev/null 2>&1 &
else

nohup $PYTHON_CMD ./gui/dsiprouter.py runserver -h 0.0.0.0 -p ${DSIP_PORT} > /var/log/dsiprouter.log 2>&1 &
nohup $PYTHON_CMD ./gui/dsiprouter.py runserver -h 0.0.0.0 -p ${DSIP_PORT} --threaded > /var/log/dsiprouter.log 2>&1 &
fi
# Store the PID of the process
PID=$!
Expand Down Expand Up @@ -721,13 +770,13 @@ password=`date +%s | sha256sum | base64 | head -c 16`
password1=\'$password\'
sed -i 's/PASSWORD[[:space:]]\?=[[:space:]]\?.*/PASSWORD = '$password1'/g' ${DSIP_KAMAILIO_CONF_DIR}/gui/settings.py

echo -e "username: admin\npassword:$password\n"
echo -e "username: admin\npassword: $password\n"

}

function usageOptions {

echo -e "\nUsage: $0 install|uninstall [-rtpengine]"
echo -e "\nUsage: $0 install|uninstall [-rtpengine [-servernat]]"
echo -e "Usage: $0 start|stop|restart"
echo -e "Usage: $0 resetpassword"
echo -e "\ndSIPRouter is a Web Management GUI for Kamailio based on use case design, with a focus on ITSP and Carrier use cases.This means that we aren’t a general purpose GUI for Kamailio."
Expand All @@ -749,7 +798,11 @@ function processCMD {
case $key in
install)
shift
if [ "$1" == "-rtpengine" ]; then
if [ "$1" == "-rtpengine" ] && [ "$2" == "-servernat" ]; then
SERVERNAT=1
installRTPEngine

elif [ "$1" == "-rtpengine" ]; then
installRTPEngine
fi
install
Expand Down Expand Up @@ -794,25 +847,39 @@ function processCMD {
exit 0
;;
rtpengineonly)
shift
if [ "$1" == "-servernat" ]; then
SERVERNAT=1
fi
installRTPEngine
exit 0
;;
configurekam)
configureKamailio
exit 0
;;
installmodules)
installmodules)
installModules
exit 0
;;
fixmpath)
fixMPATH
exit 0
;;
resetpassword)
enableservernat)
enableSERVERNAT
echo "SERVERNAT is enabled - Restarting Kamailio is required. You can restart it by excuting: systemctl restart kamailio"
exit 0
;;
disableservernat)
disableSERVERNAT
echo "SERVERNAT is disabled - Restarting Kamailio is required. You can restart it by excuting: systemctl restart kamailio"
exit 0
;;
resetpassword)
resetPassword
exit 0
;;
;;
-h)
usageOptions
exit 0
Expand Down
9 changes: 9 additions & 0 deletions dsiprouter/debian/logrotate/kamailio
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/var/log/kamailio {
missingok
size=50M
rotate 7
create 0644 root root
postrotate
/bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}
9 changes: 9 additions & 0 deletions dsiprouter/debian/logrotate/rtpengine
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/var/log/rtpengine {
missingok
size=50M
rotate 7
create 0644 root root
postrotate
/bin/kill -HUP `cat /var/run/ngcp-rtpengine-daemon.pid 2> /dev/null` 2> /dev/null || true
endscript
}
84 changes: 70 additions & 14 deletions gui/dsiprouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def displayOutboundRoutes(db_err=0):

if session.get('logged_in'):
try:
rows = db.query(OutboundRoutes).filter((OutboundRoutes.groupid == groupid) | (OutboundRoutes.groupid >= 10000)).outerjoin(dSIPLCR, dSIPLCR.dr_groupid == OutboundRoutes.groupid).add_columns(dSIPLCR.from_prefix,dSIPLCR.cost,OutboundRoutes.ruleid, OutboundRoutes.prefix,OutboundRoutes.routeid,OutboundRoutes.gwlist,OutboundRoutes.timerec,OutboundRoutes.priority,OutboundRoutes.description)
rows = db.query(OutboundRoutes).filter((OutboundRoutes.groupid == groupid) | (OutboundRoutes.groupid >= 10000)).outerjoin(dSIPLCR, dSIPLCR.dr_groupid == OutboundRoutes.groupid).add_columns(dSIPLCR.from_prefix,dSIPLCR.cost,dSIPLCR.dr_groupid,OutboundRoutes.ruleid, OutboundRoutes.prefix,OutboundRoutes.routeid,OutboundRoutes.gwlist,OutboundRoutes.timerec,OutboundRoutes.priority,OutboundRoutes.description)

teleblock = {}
teleblock["gw_enabled"] = settings.TELEBLOCK_GW_ENABLED
Expand Down Expand Up @@ -411,7 +411,7 @@ def addUpateOutboundRoutes():
return index()

# group for the default outbound routes
groupid = 8000
default_carrier_group = 8000

# id in dr_rules table
ruleid = None
Expand All @@ -421,7 +421,14 @@ def addUpateOutboundRoutes():
if request.form['ruleid']:
ruleid = request.form['ruleid']

groupid = request.form.get('groupid',default_carrier_group)
if isinstance(groupid,str):
if len(groupid) == 0 or (groupid == 'None'):
groupid = 8000


# set default values
#from_prefix = ""
prefix = ""
timerec = ""
priority = 0
Expand All @@ -447,6 +454,8 @@ def addUpateOutboundRoutes():

# Adding
if not ruleid:
#if len(from_prefix) > 0 and len(prefix) == 0 :
# return displayOutboundRoutes()
if from_prefix != None :
print("from_prefix: {}".format(from_prefix))
#return displayOutboundRoutes()
Expand Down Expand Up @@ -476,24 +485,71 @@ def addUpateOutboundRoutes():
db.flush()

# Updating
else:
OMap = db.query(OutboundRoutes).filter(OutboundRoutes.ruleid == ruleid).update({
'prefix': prefix, 'timerec': timerec, 'priority': priority,
else: #Handle the simple case of a To prefix being updated
if (from_prefix is None) and (prefix is not None):
print(groupid)
oldgroupid = groupid
if (groupid is None) or (groupid == "None"):
groupid=8000

#Convert the dr_rule back to a default carrier rule
OMap = db.query(OutboundRoutes).filter(OutboundRoutes.ruleid == ruleid).update({
'prefix': prefix, 'groupid': groupid,'timerec': timerec, 'priority': priority,
'routeid': routeid, 'gwlist': gwlist, 'description': description
})
db.commit()
})

#Delete from LCR table using the old group id
d1 = db.query(dSIPLCR).filter(dSIPLCR.dr_groupid==oldgroupid)
d1.delete(synchronize_session=False)

db.commit()

if from_prefix:
#Update the existing LCR mapping

# Setup new pattern
# Setup pattern
pattern = from_prefix + "-" + prefix

OMap = db.query(OutboundRoutes).filter(OutboundRoutes.ruleid == ruleid).first()
db.commit()

db.query(dSIPLCR).filter(dSIPLCR.dr_groupid==OMap.groupid).update({
'pattern': pattern, 'from_prefix': from_prefix})
#Check if pattern already exists
exists = db.query(dSIPLCR).filter(dSIPLCR.pattern==pattern).scalar()
if exists:
return displayOutboundRoutes()

elif (prefix is not None) and (groupid == 8000): #Adding a From prefix to an existing To
#Create a new groupid
mlcr = db.query(dSIPLCR).filter(dSIPLCR.dr_groupid >= 10000).order_by(dSIPLCR.dr_groupid.desc()).first()
db.commit()

#Start LCR routes with a groupid of 10000
if mlcr is None:
groupid=10000
else:
groupid=int(mlcr.dr_groupid)+1

# Setup new pattern
pattern = from_prefix + "-" + prefix

#Add the lcr map
if pattern != None:
OLCRMap = dSIPLCR(pattern,from_prefix,groupid)
db.add(OLCRMap)
db.commit()
db.flush()

OMap = db.query(OutboundRoutes).filter(OutboundRoutes.ruleid == ruleid).update({
'groupid': groupid, 'prefix': prefix, 'timerec': timerec, 'priority': priority,
'routeid': routeid, 'gwlist': gwlist, 'description': description
})
db.commit()
elif (int(groupid) >=10000): #Update existing pattern
db.query(dSIPLCR).filter(dSIPLCR.dr_groupid == groupid).update({
'pattern':pattern, 'from_prefix':from_prefix })


#Update the dr_rules table
OMap = db.query(OutboundRoutes).filter(OutboundRoutes.ruleid == ruleid).update({
'prefix': prefix, 'groupid': groupid,'timerec': timerec, 'priority': priority,
'routeid': routeid, 'gwlist': gwlist, 'description': description
})
db.commit()

return displayOutboundRoutes()
Expand Down
7 changes: 6 additions & 1 deletion gui/modules/fusionpbx/dsiprouter.nginx.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
server {
listen 80;
location /app/provision/ {
location /provision/ {
proxy_pass http://fusionpbx;
proxy_redirect off;
proxy_next_upstream error timeout http_404 http_403 http_500 http_502 http_503 http_504 non_idempotent;
Expand All @@ -17,5 +17,10 @@
error_page 404 /404.html;
}

location /images/ {
alias /etc/nginx/html/images/;
}

}
Loading

0 comments on commit 652974c

Please sign in to comment.