Skip to content

Commit

Permalink
Merge v0.55+ent changes into v0.60+ent
Browse files Browse the repository at this point in the history
  - merge in cdr and backup/restore changes
  - various styling / syntax fixes
  - make bootstrap-datepicker.css local
  - update docker compose file for v0.60
  - fix some remaining db session bugs missed b4
  - fix dsiprouter syslog not logging pid issue
  • Loading branch information
devopsec committed Mar 12, 2020
1 parent 62dc6be commit 91d038e
Show file tree
Hide file tree
Showing 21 changed files with 804 additions and 217 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@



### Merge v0.55+ent changes into v0.60+ent

> Branches Affected: v0.60+ent
> Tags Affected:
> Date: Thu, 12 Mar 2020 16:24:26 -0400
> Author: Tyler Moore ([email protected])
> Committer: Tyler Moore ([email protected])

- merge in cdr and backup/restore changes
- various styling / syntax fixes
- make bootstrap-datepicker.css local
- update docker compose file for v0.60
- fix some remaining db session bugs missed b4
- fix dsiprouter syslog not logging pid issue


---


### Merge dmq-feature branch into v0.60+ent

> Branches Affected: v0.60+ent
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ services:
image: mysql:5.7
volumes:
- /tmp/dbdata:/var/lib/mysql
- ./dsiprouter/sql/v0.522:/docker-entrypoint-initdb.d/
- ./testing/sql/v0.60+ent:/docker-entrypoint-initdb.d/
ports:
- "3306:3306"
environment:
Expand Down
7 changes: 5 additions & 2 deletions dsiprouter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ function configureKamailio {
fi

# Install schema for custom LCR logic
mysql -s -N --user="$MYSQL_ROOT_USERNAME" --password="$MYSQL_ROOT_PASSWORD" $KAM_DB_NAME < ${DSIP_DEFAULTS_DIR}/lcr.sql
mysql -s -N --user="$MYSQL_ROOT_USERNAME" --password="$MYSQL_ROOT_PASSWORD" $KAM_DB_NAME < ${DSIP_DEFAULTS_DIR}/dsip_lcr.sql

# Install schema for custom MaintMode logic
mysql -s -N --user="$MYSQL_ROOT_USERNAME" --password="$MYSQL_ROOT_PASSWORD" $KAM_DB_NAME < ${DSIP_DEFAULTS_DIR}/dsip_maintmode.sql
Expand All @@ -613,6 +613,9 @@ function configureKamailio {
# Install schema for gw2gwgroup
mysql -s -N --user="$MYSQL_ROOT_USERNAME" --password="$MYSQL_ROOT_PASSWORD" $KAM_DB_NAME < ${DSIP_DEFAULTS_DIR}/dsip_gw2gwgroup.sql

# Install schema for dsip_cdrinfo
mysql -s -N --user="$MYSQL_ROOT_USERNAME" --password="$MYSQL_ROOT_PASSWORD" $MYSQL_KAM_DATABASE < ${DSIP_DEFAULTS_DIR}/dsip_cdrinfo.sql

# Install schema for dsip_settings
mysql -s -N --user="$MYSQL_ROOT_USERNAME" --password="$MYSQL_ROOT_PASSWORD" $KAM_DB_NAME < ${DSIP_DEFAULTS_DIR}/dsip_settings.sql

Expand Down Expand Up @@ -1095,7 +1098,7 @@ function uninstallKamailio {
removeDependsOnInit "kamailio.service"

# Remove the hidden installed file, which denotes if it's installed or not
rm -f ${DSIP_SYSTEM_CONFIG_DIR}/.kamailioinstalled
rm -f ${DSIP_SYSTEM_CONFIG_DIR}/.kamailioinstalled

printdbg "kamailio was uninstalled"
}
Expand Down
12 changes: 12 additions & 0 deletions gui/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,18 @@ def __init__(self, dr_ruleid, did, dr_groupid):

pass

class dSIPCDRInfo(object):
"""
Schema for dsip_cdrinfo table\n
"""

def __init__(self, gwgroupid, email, send_date):
self.gwgroupid = gwgroupid
self.email = email
self.send_date = send_date

pass

class dSIPFailFwd(object):
"""
Schema for dsip_failfwd table\n
Expand Down
23 changes: 22 additions & 1 deletion gui/dsiprouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ def index():
error = "server"
return showError(type=error)

@app.route('/backupandrestore')
def backupandrestore():
try:
if (settings.DEBUG):
debugEndpoint()

if not session.get('logged_in'):
return render_template('index.html', version=settings.VERSION)
else:
action = request.args.get('action')
return render_template('backupandrestore.html', show_add_onload=action, version=settings.VERSION)

except http_exceptions.HTTPException as ex:
debugException(ex, log_ex=False, print_ex=True, showstack=False)
error = "http"
return showError(type=error)
except Exception as ex:
debugException(ex, log_ex=False, print_ex=True, showstack=False)
error = "server"
return showError(type=error)

@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),
Expand Down Expand Up @@ -661,7 +682,7 @@ def displayCDRS():
error = "server"
return showError(type=error)

# TODO: why are we doing this weird api workaround, instead of making the gui and pai separate??
# TODO: why are we doing this weird api workaround, instead of making the gui and api separate??
@app.route('/endpointgroups', methods=['POST'])
def addUpdateEndpointGroups():
"""
Expand Down
41 changes: 34 additions & 7 deletions gui/modules/api/api_cron_functions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from shared import debugException, IO
from database import SessionLoader, DummySession, Subscribers, dSIPLeases,Gateways
from database import SessionLoader, DummySession, Subscribers, dSIPLeases, Gateways, dSIPCDRInfo
from datetime import datetime
from sqlalchemy import case, func, exc as sql_exceptions
from modules.api.api_routes import revokeEndpointLease
from sqlalchemy import case, func, exc as sql_exceptions,or_
from modules.api.api_routes import revokeEndpointLease, generateCDRS
import settings

def cleanup_leases():
Expand Down Expand Up @@ -37,14 +37,41 @@ def cleanup_leases():
db.rollback()
db.flush()
finally:
SessionLoader.remove()
db.close()

def send_monthly_cdrs():
db = DummySession()

def api_cron(settings):
try:
db = SessionLoader()

now = datetime.now()
day = now.strftime("%d")
date = now.strftime('%Y-%m-%d')

CDRReports = db.query(dSIPCDRInfo).filter(dSIPCDRInfo.send_date == day).filter(or_(dSIPCDRInfo.last_sent < date, dSIPCDRInfo.last_sent == None))
for CDRReport in CDRReports:
generateCDRS(gwgroupid=CDRReport.gwgroupid,type='csv',email="True")
db.query(dSIPCDRInfo).filter(dSIPCDRInfo.gwgroupid == CDRReport.gwgroupid).update({"last_sent":date})
db.commit()

except sql_exceptions.SQLAlchemyError as ex:
debugException(ex)
db.rollback()
db.flush()
except Exception as ex:
debugException(ex)
db.rollback()
db.flush()
finally:
db.close()

def api_cron():
try:
cleanup_leases()
send_monthly_cdrs()
except Exception as ex:
IO.printerr(str(ex))
debugException(ex)

if __name__ == "__main__":
api_cron(settings)
api_cron()
Loading

0 comments on commit 91d038e

Please sign in to comment.