-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #440 from LibreQoE/main
Update Develop
- Loading branch information
Showing
6 changed files
with
218 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ jobs: | |
- run: pytest . || true | ||
- run: pytest --doctest-modules . || true | ||
- run: shopt -s globstar && pyupgrade --py37-plus **/*.py || true | ||
- run: safety check | ||
- run: safety check --ignore=62044 | ||
#- uses: pyupio/[email protected] | ||
# with: | ||
# api-key: ${{secrets.SAFETY_API_KEY}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
from pythonCheck import checkPythonVersion | ||
checkPythonVersion() | ||
import requests | ||
import warnings | ||
from ispConfig import excludeSites, findIPv6usingMikrotik, bandwidthOverheadFactor, exceptionCPEs, powercode_api_key, powercode_api_url | ||
from integrationCommon import isIpv4Permitted | ||
import base64 | ||
from requests.auth import HTTPBasicAuth | ||
if findIPv6usingMikrotik == True: | ||
from mikrotikFindIPv6 import pullMikrotikIPv6 | ||
from integrationCommon import NetworkGraph, NetworkNode, NodeType | ||
from urllib3.exceptions import InsecureRequestWarning | ||
|
||
def getCustomerInfo(): | ||
headers= {'Content-Type': 'application/x-www-form-urlencoded'} | ||
url = powercode_api_url + ":444/api/preseem/index.php" | ||
data = {} | ||
data['apiKey'] = powercode_api_key | ||
data['action'] = 'list_customers' | ||
|
||
r = requests.post(url, data=data, headers=headers, verify=False, timeout=10) | ||
return r.json() | ||
|
||
def getServiceInfo(customerID): | ||
headers= {'Content-Type': 'application/x-www-form-urlencoded'} | ||
url = powercode_api_url + ":444/api/1/index.php" | ||
data = {} | ||
data['apiKey'] = powercode_api_key | ||
data['action'] = 'readCustomerService' | ||
data['customerID'] = customerID | ||
|
||
r = requests.post(url, data=data, headers=headers, verify=False, timeout=10) | ||
servicesDict = {} | ||
for service in r.json()['services']: | ||
if 'internetInfo' in service: | ||
servicesDict[service['serviceID']] = {} | ||
servicesDict[service['serviceID']]['downloadMbps'] = int(round(int(service['internetInfo']['maxIn']) / 1000)) | ||
servicesDict[service['serviceID']]['uploadMbps'] = int(round(int(service['internetInfo']['maxOut']) / 1000)) | ||
return servicesDict | ||
|
||
def createShaper(): | ||
net = NetworkGraph() | ||
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) | ||
print("Fetching data from Powercode") | ||
|
||
customerInfo = getCustomerInfo() | ||
|
||
customerIDs = [] | ||
for customer in customerInfo: | ||
if customer['id'] != '1': | ||
if customer['id'] != '': | ||
if customer['status'] == 'Active': | ||
customerIDint = int(customer['id']) | ||
if customerIDint != 0: | ||
if customerIDint != None: | ||
if customerIDint not in customerIDs: | ||
customerIDs.append(customerIDint) | ||
|
||
allServices = {} | ||
for customerID in customerIDs: | ||
allServices.update(getServiceInfo(customerID)) | ||
|
||
acceptableEquipment = ['Customer Owned Equipment', 'Router', 'Customer Owned Equipment', 'Managed Routers'] #'CPE' | ||
|
||
devicesByCustomerID = {} | ||
for customer in customerInfo: | ||
if customer['status'] == 'Active': | ||
chosenName = '' | ||
if customer['name'] != '': | ||
chosenName = customer['name'] | ||
elif customer['company_name'] != '': | ||
chosenName = customer['company_name'] | ||
else: | ||
chosenName = customer['id'] | ||
for equipment in customer['equipment']: | ||
if equipment['type'] in acceptableEquipment: | ||
if equipment['service_id'] in allServices: | ||
device = {} | ||
device['id'] = "c_" + customer['id'] + "_s_" + "_d_" + equipment['id'] | ||
device['name'] = equipment['name'] | ||
device['ipv4'] = equipment['ip_address'] | ||
device['mac'] = equipment['mac_address'] | ||
if customer['id'] not in devicesByCustomerID: | ||
devicesByCustomerID[customer['id']] = {} | ||
devicesByCustomerID[customer['id']]['name'] = chosenName | ||
devicesByCustomerID[customer['id']]['downloadMbps'] = allServices[equipment['service_id']]['downloadMbps'] | ||
devicesByCustomerID[customer['id']]['uploadMbps'] = allServices[equipment['service_id']]['uploadMbps'] | ||
if 'devices' not in devicesByCustomerID[customer['id']]: | ||
devicesByCustomerID[customer['id']]['devices'] = [] | ||
devicesByCustomerID[customer['id']]['devices'].append(device) | ||
|
||
for customerID in devicesByCustomerID: | ||
customer = NetworkNode( | ||
type=NodeType.client, | ||
id=customerID, | ||
displayName=devicesByCustomerID[customerID]['name'], | ||
address='', | ||
customerName=devicesByCustomerID[customerID]['name'], | ||
download=devicesByCustomerID[customerID]['downloadMbps'], | ||
upload=devicesByCustomerID[customerID]['uploadMbps'], | ||
) | ||
net.addRawNode(customer) | ||
for device in devicesByCustomerID[customerID]['devices']: | ||
newDevice = NetworkNode( | ||
id=device['id'], | ||
displayName=device["name"], | ||
type=NodeType.device, | ||
parentId=customerID, | ||
mac=device["mac"], | ||
ipv4=[device['ipv4']], | ||
ipv6=[] | ||
) | ||
net.addRawNode(newDevice) | ||
net.prepareTree() | ||
net.plotNetworkGraph(False) | ||
if net.doesNetworkJsonExist(): | ||
print("network.json already exists. Leaving in-place.") | ||
else: | ||
net.createNetworkJson() | ||
net.createShapedDevices() | ||
|
||
def importFromPowercode(): | ||
#createNetworkJSON() | ||
createShaper() | ||
|
||
if __name__ == '__main__': | ||
importFromPowercode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters