Fixed net errors, optimizations and sniffer WIP
Quick fix for package versions compare logic:
- repo update is OK when candidate is the same
- repo update is not ok when all versions different
Change-Id: I6602d5486b98375b254d0d92a6071fb26582b770
Related-PROD: PROD-28199
diff --git a/cfg_checker/common/const.py b/cfg_checker/common/const.py
index cbd0643..966f3d3 100644
--- a/cfg_checker/common/const.py
+++ b/cfg_checker/common/const.py
@@ -31,7 +31,7 @@
ACT_UPGRADE: "upgrade possible",
ACT_NEED_UP: "needs upgrade",
ACT_NEED_DOWN: "needs downgrade",
- ACT_REPO: "needs repo update",
+ ACT_REPO: "repo update",
ACT_NA: ""
}
diff --git a/cfg_checker/modules/packages/checker.py b/cfg_checker/modules/packages/checker.py
index 972b12f..631c992 100644
--- a/cfg_checker/modules/packages/checker.py
+++ b/cfg_checker/modules/packages/checker.py
@@ -30,7 +30,7 @@
)
self.force_tag = force_tag
- self.exclude_repos_keywords = exclude_keywords
+ self.exclude_keywords = exclude_keywords
@staticmethod
def presort_packages(all_packages, full=None):
@@ -190,7 +190,7 @@
logger_cli.info("# Openstack version: {}".format(_os))
logger_cli.info(
"# Release versions repos keyword exclude list: {}".format(
- ", ".join(self.exclude_repos_keywords)
+ ", ".join(self.exclude_keywords)
)
)
@@ -233,15 +233,16 @@
_name,
tag=self.force_tag,
include=[_os, _linux, _arch],
- exclude=self.exclude_repos_keywords
+ exclude=self.exclude_keywords
)
# if nothing found, look everywhere
+ # but with no word 'openstack'
if not _r:
_r = self.rm.get_filtered_versions(
_name,
tag=self.force_tag,
include=[_linux, _arch],
- exclude=self.exclude_repos_keywords
+ exclude=self.exclude_keywords + ['openstack']
)
# if nothing is found at this point,
# repeat search using normal tags
@@ -250,7 +251,7 @@
_name,
tag=_mcp,
include=[_os, _linux, _arch],
- exclude=self.exclude_repos_keywords
+ exclude=self.exclude_keywords
)
# Once again, if nothing found, look everywhere
if not _r:
@@ -258,7 +259,7 @@
_name,
tag=_mcp,
include=[_linux, _arch],
- exclude=self.exclude_repos_keywords
+ exclude=self.exclude_keywords + ['openstack']
)
# repack versions in flat format
_vs = {}
diff --git a/cfg_checker/modules/packages/versions.py b/cfg_checker/modules/packages/versions.py
index c5689d3..e16dab8 100644
--- a/cfg_checker/modules/packages/versions.py
+++ b/cfg_checker/modules/packages/versions.py
@@ -345,8 +345,8 @@
elif i == c:
self.target = c
if i < r:
- # both are old, new target
- self.status = const.VERSION_ERR
+ # both are intact, new target possible
+ self.status = const.VERSION_OK
self.action = const.ACT_REPO
self.target = r
elif i > r:
diff --git a/cfg_checker/reports/reporter.py b/cfg_checker/reports/reporter.py
index 04c9034..a624dd3 100644
--- a/cfg_checker/reports/reporter.py
+++ b/cfg_checker/reports/reporter.py
@@ -46,7 +46,7 @@
const.ACT_UPGRADE: "Upgrade possible",
const.ACT_NEED_UP: "Needs upgrade",
const.ACT_NEED_DOWN: "Needs downgrade",
- const.ACT_REPO: "Needs repo update",
+ const.ACT_REPO: "Repo update",
const.ACT_NA: ""
}
return _act_labels[act]
diff --git a/scripts/sniffer.py b/scripts/sniffer.py
index de18eb2..612ff20 100644
--- a/scripts/sniffer.py
+++ b/scripts/sniffer.py
@@ -1,4 +1,134 @@
-# This will be the basic sniffer script
-# Its purpose is to sniff for a specific packet and return its headers-n-data
+import binascii
+import socket
+import struct
-pass
+
+class unpack:
+ def __init__(self):
+ self.data = None
+
+ # Ethernet Header
+ def eth_header(self, data):
+ storeobj = data
+ storeobj = struct.unpack("!6s6sH", storeobj)
+ destination_mac = binascii.hexlify(storeobj[0])
+ source_mac = binascii.hexlify(storeobj[1])
+ eth_protocol = storeobj[2]
+ data = {"Destination Mac": destination_mac,
+ "Source Mac": source_mac,
+ "Protocol": eth_protocol}
+ return data
+
+ # ICMP HEADER Extraction
+ def icmp_header(self, data):
+ icmph = struct.unpack('!BBH', data)
+ icmp_type = icmph[0]
+ code = icmph[1]
+ checksum = icmph[2]
+ data = {'ICMP Type': icmp_type,
+ "Code": code,
+ "CheckSum": checksum}
+ return data
+
+ # UDP Header Extraction
+ def udp_header(self, data):
+ storeobj = struct.unpack('!HHHH', data)
+ source_port = storeobj[0]
+ dest_port = storeobj[1]
+ length = storeobj[2]
+ checksum = storeobj[3]
+ data = {"Source Port": source_port,
+ "Destination Port": dest_port,
+ "Length": length,
+ "CheckSum": checksum}
+ return data
+
+ # IP Header Extraction
+ def ip_header(self, data):
+ storeobj = struct.unpack("!BBHHHBBH4s4s", data)
+ _version = storeobj[0]
+ _tos = storeobj[1]
+ _total_length = storeobj[2]
+ _identification = storeobj[3]
+ _fragment_Offset = storeobj[4]
+ _ttl = storeobj[5]
+ _protocol = storeobj[6]
+ _header_checksum = storeobj[7]
+ _source_address = socket.inet_ntoa(storeobj[8])
+ _destination_address = socket.inet_ntoa(storeobj[9])
+
+ data = {'Version': _version,
+ "Tos": _tos,
+ "Total Length": _total_length,
+ "Identification": _identification,
+ "Fragment": _fragment_Offset,
+ "TTL": _ttl,
+ "Protocol": _protocol,
+ "Header CheckSum": _header_checksum,
+ "Source Address": _source_address,
+ "Destination Address": _destination_address}
+ return data
+
+ # Tcp Header Extraction
+ def tcp_header(self, data):
+ storeobj = struct.unpack('!HHLLBBHHH', data)
+ _source_port = storeobj[0]
+ _destination_port = storeobj[1]
+ _sequence_number = storeobj[2]
+ _acknowledge_number = storeobj[3]
+ _offset_reserved = storeobj[4]
+ _tcp_flag = storeobj[5]
+ _window = storeobj[6]
+ _checksum = storeobj[7]
+ _urgent_pointer = storeobj[8]
+ data = {"Source Port": _source_port,
+ "Destination Port": _destination_port,
+ "Sequence Number": _sequence_number,
+ "Acknowledge Number": _acknowledge_number,
+ "Offset & Reserved": _offset_reserved,
+ "Tcp Flag": _tcp_flag,
+ "Window": _window,
+ "CheckSum": _checksum,
+ "Urgent Pointer": _urgent_pointer
+ }
+ return data
+
+# Mac Address Formating
+
+
+def mac_formater(a):
+ b = "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x" % (ord(a[0]), ord(
+ a[1]), ord(a[2]), ord(a[3]), ord(a[4]), ord(a[5]))
+ return b
+
+
+def get_host(q):
+ try:
+ k = socket.gethostbyaddr(q)
+ except Exception:
+ k = 'Unknown'
+ return k
+
+
+s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.ntohs(0x0800))
+u = unpack()
+count = 5
+while count > 0:
+ count -= 1
+ # Capture packets from network
+ pkt = s.recvfrom(65565)
+
+ print "\n\n===>> [+] ------------ Ethernet Header----- [+]"
+
+ # print data on terminal
+ for i in u.eth_header(pkt[0][0:14]).iteritems():
+ a, b = i
+ print "{} : {} | ".format(a, b),
+ print "\n===>> [+] ------------ IP Header ------------[+]"
+ for i in u.ip_header(pkt[0][14:34]).iteritems():
+ a, b = i
+ print "{} : {} | ".format(a, b),
+ print "\n===>> [+] ------------ Tcp Header ----------- [+]"
+ for i in u.tcp_header(pkt[0][34:54]).iteritems():
+ a, b = i
+ print "{} : {} | ".format(a, b),
diff --git a/templates/pkg_versions_html.j2 b/templates/pkg_versions_html.j2
index 1bf216d..91b21e7 100644
--- a/templates/pkg_versions_html.j2
+++ b/templates/pkg_versions_html.j2
@@ -69,8 +69,8 @@
}
.status_container .needs_repo {
- color: black;
- background-color: #50aacc;
+ color: #545454;
+ background-color: #a1b1b0;
}
.status_container .needs_up {