Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
asgharhussain committed Nov 29, 2021
0 parents commit 4dbcd36
Show file tree
Hide file tree
Showing 206 changed files with 74,843 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.idea/
.coverage
logs/
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
*.DS_Store
.AppleDouble
.LSOverride
Icon
._*
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
cmake-build-debug/
.idea/**/mongoSettings.xml
*.py[cod]
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
*.manifest
*.spec
pip-log.txt
pip-delete-this-directory.txt
instance/
.webassets-cache
.scrapy
docs/_build/
target/
.python-version
.venv
venv/
ENV/
10 changes: 10 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# List of ExpertDHCP authors for copyright use.
# For contributors to this project, see the CONTRIBUTORS file.
#
# Following are names of authors, their email addresses and their roles in
# this project.

Lumen Inc <*@lumen.com>

Asghar Hussain <to.ajeeb@gmail.com> Systems Architect & Senior Developer
Ajeeb M Basheer <asghar.hussain.dev@gmail.com> Lead Developer
37 changes: 37 additions & 0 deletions Developer_Certificate_of_Origin
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright © 2021 Lumen Technologies Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
ExpertDHCP is a frontend GUI and accompanying REST service that
works in conjunction with ISC Kea DHCP (https://www.isc.org/kea/,
https://gitlab.isc.org/isc-projects/kea).

The Expert DHCP REST service can be used to control many aspects of the Kea DHCP
server. In addition, the ExpertDHCP frontend GUI makes DHCP provisioning easy
for administrators.

ExpertDHCP facilitates DHCP administrators to control multiple Kea DHCP servers
located in geographically different areas.

<br />

**Architecture Diagram**
![Architecture Diagram](docs/Expert_DHCP_Architecture_Diagram.png)

<br />

**Deployment Example**
![Deployment Diagram](docs/Expert_DHCP_Multi_Location_Deployment_Scenario.png)

<br />

- **General Features**
- Control geographically redundant Kea DHCP servers from a single WEB UI
- Configure subnets, reservations, classes and other aspects of Kea DHCP
using a web UI
- Capture DHCP packets for troubleshooting

<br />

- **REST API Features**
- Get DHCP configuration
- Get IP from a given MAC address
- Get reservations
- Add reservations
- Delete reservations
- Add subnet
- Delete subnet
- Modify subnet
- Add subnet options
- Delete subnet options
- Add subnet reservation options
- Delete subnet reservation options
- Get leases
- Add lease
- Update lease
- Delete lease
- Delete all client leases for a subnet
- Add class
- Delete class
- Modify class

<br />

- **GUI Features**
- Configure subnets
- Configure leases
- Configure client classes
- DHCPDUMP console (future)
- RAW REST API console

<br />

- **Platforms**
- Linux (CentOS)
- FreeBSD

<br />

- **Documentation**
- [Documentation](docs/documentation.md)
4 changes: 4 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- Add IPv6 handling
- Add Git backups
- Add dump/log facility
- Fix expertDHCP logging issue. If the log file is changed to /var/log/expertdhcp
Empty file added __init__.py
Empty file.
78 changes: 78 additions & 0 deletions capture/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from capture.config import LOG_FILE_NAME

def create_dir(dir_path):
"""
Creates a directory if it does not exist
:param dir_path:
:return: None
"""
import os
if not os.path.exists(dir_path):
os.makedirs(dir_path)


def check_path(path):
"""
Check if it is a valid path.
:param path:
:return: Boolean for existence of path.
"""
import os
return os.path.isfile(path)


def create_logger(logger_name, file_name):
"""
:param logger_name:
:param file_name:
:return: logger with logger_name as specified and writes to file
"""
import logging
import os
from logging.handlers import RotatingFileHandler
from restservice.config import LOG_LEVEL, LOG_FILE_MAX_SIZE_MB, LOG_FILE_BACKUP_COUNT
print("Defining logger [", logger_name, "] with Level [", LOG_LEVEL, "] and logger name [", LOG_FILE_NAME, "]")

log_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + '/logs/'
print("Log file path is ->", log_path + file_name)
create_dir(log_path)
logger = logging.getLogger(logger_name)
logger.setLevel(LOG_LEVEL)

formatter = logging.Formatter(
"%(asctime)s [%(levelname)-8s] [%(filename)s:%(lineno)-4d] [%(funcName)s] %(message)s"
)

handler = RotatingFileHandler(log_path + file_name,
maxBytes=LOG_FILE_MAX_SIZE_MB*1024*1024,
backupCount=LOG_FILE_BACKUP_COUNT)

handler.setLevel(LOG_LEVEL)
handler.setFormatter(formatter)
logger.addHandler(handler)
print('Logger Created ->', str(logger))
return logger


MONITOR_LOGGER = create_logger('EXPERT-DHCP-CAPTURE-LOGGER', LOG_FILE_NAME)

def create_app():
"""
:return: app object
"""
from flask import Flask
from flask_cors import CORS

LOGGER.info("Creating App object")
app = Flask(__name__, instance_relative_config=True)
CORS(app)
LOGGER.info("Added CORS to App")
app.config.from_mapping(
SECRET_KEY='dev'
)
LOGGER.info("Registering Blueprint to app")
from capture.endpoints import BP
app.register_blueprint(BP)

return app

Empty file.
31 changes: 31 additions & 0 deletions capture/command_scripts/log_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import subprocess
import shlex


class LogHandler(object):
"""
A class to handle the stream of dump and
return stdout in generator fashion
"""
__instance = None

def __init__(self, tail_log_command="tail -f -n 2 {}", logfile='/usr/local/var/log/kea-dhcp4.log'):
self.tail_log_command = tail_log_command.format(logfile)
self.last_field = None

def generate_dump(self):
try:
print(shlex.split(self.tail_log_command))
dhcp_dump_stream_process = subprocess.Popen(shlex.split(self.tail_log_command),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# print("Killable PID log tail",dhcp_dump_stream_process.pid)
for msg in dhcp_dump_stream_process.stdout:
# print('+'*100)
# print(msg)
# print('+'*100)
yield msg

except Exception as err:
print("some exception occured in Log handler")
print(err)
53 changes: 53 additions & 0 deletions capture/command_scripts/stream_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import subprocess
import shlex
import re
import json


class StreamHandler(object):
"""
A singleton class to handle the stream of dump and
return stdout in generator fashion
"""
__instance = None

def __init__(self,
dhcp_dump_command="sudo {} -i {}",
dump_path='/usr/bin/dhcpdump_json',
dump_if='eno1',
msg_sep_regex=r'(-{5,})'):

self.dhcp_dump_command = dhcp_dump_command.format(dump_path, dump_if)
self.message_seperator_pattern = re.compile(msg_sep_regex)
self.last_field = None

if StreamHandler.__instance is not None:
print("Instance already exists for singleton class StreamHandler")
raise Exception("This class is a singleton!")
else:
print("Created instance of class StreamHandler")
StreamHandler.__instance = self

def generate_dump(self):
try:
print(shlex.split(self.dhcp_dump_command))

dhcp_dump_stream_process = subprocess.Popen(shlex.split(self.dhcp_dump_command),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# print("Killable PID dhcpdump",dhcp_dump_stream_process.pid)
for msg in dhcp_dump_stream_process.stdout:
print('-' * 100)
print(msg)
print('-' * 100)
yield json.loads(msg)

except Exception as excp:
import sys, os
print("some exception occured in stream handler")
print(excp)
exc_type, exc_obj, exc_tb = sys.exc_info()
print('%s, %s, %s', exc_type, exc_obj, exc_tb)
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print('%s, %s, %s', str(exc_type), str(fname),
str(exc_tb.tb_lineno))
18 changes: 18 additions & 0 deletions capture/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[KEA]
# KEA DHCP parameters

# KEA DHCP logfile path.
LOGPATH=

# Path of dump file.
DUMP_PATH=

# Interface on which KEA DHCP is listening
DUMP_INTERFACE=

[AUTH]
# Authentication parameters and settings

# Enable/disable API authentication. To enable, set value to "true", otherwise
# authentication will be disabled.
REQUIRE_API_AUTHENTICATION=true
Loading

0 comments on commit 4dbcd36

Please sign in to comment.