mirror of
https://github.com/evilsocket/opensnitch.git
synced 2025-03-04 08:34:40 +01:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
b0a6c0d01f
commit
34ec05a5d2
4 changed files with 42 additions and 12 deletions
|
@ -3,6 +3,7 @@ package conman
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/evilsocket/opensnitch/daemon/dns"
|
"github.com/evilsocket/opensnitch/daemon/dns"
|
||||||
"github.com/evilsocket/opensnitch/daemon/log"
|
"github.com/evilsocket/opensnitch/daemon/log"
|
||||||
|
@ -112,6 +113,8 @@ func NewConnection(nfp *netfilter.NFPacket, ip *layers.IPv4) (c *Connection, err
|
||||||
// lookup pid by inode and process by pid
|
// lookup pid by inode and process by pid
|
||||||
if pid, found := sockets[c.Entry.INode]; found == false {
|
if pid, found := sockets[c.Entry.INode]; found == false {
|
||||||
return nil, fmt.Errorf("Could not find process id for: %s", c)
|
return nil, fmt.Errorf("Could not find process id for: %s", c)
|
||||||
|
} else if pid == os.Getpid() {
|
||||||
|
return nil, nil
|
||||||
} else if c.Process = procmon.FindProcess(pid); c.Process == nil {
|
} else if c.Process = procmon.FindProcess(pid); c.Process == nil {
|
||||||
return nil, fmt.Errorf("Could not find process by its pid %d for: %s", pid, c)
|
return nil, fmt.Errorf("Could not find process by its pid %d for: %s", pid, c)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@ class PromptDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
||||||
self._lock = threading.Lock()
|
self._lock = threading.Lock()
|
||||||
self._con = None
|
self._con = None
|
||||||
self._rule = None
|
self._rule = None
|
||||||
|
self._local = True
|
||||||
|
self._peer = None
|
||||||
self._trigger.connect(self.on_connection_triggered)
|
self._trigger.connect(self.on_connection_triggered)
|
||||||
self._done = threading.Event()
|
self._done = threading.Event()
|
||||||
|
|
||||||
|
@ -52,11 +54,13 @@ class PromptDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
||||||
self._what_combo = self.findChild(QtWidgets.QComboBox, "whatCombo")
|
self._what_combo = self.findChild(QtWidgets.QComboBox, "whatCombo")
|
||||||
self._duration_combo = self.findChild(QtWidgets.QComboBox, "durationCombo")
|
self._duration_combo = self.findChild(QtWidgets.QComboBox, "durationCombo")
|
||||||
|
|
||||||
def promptUser(self, connection):
|
def promptUser(self, connection, is_local, peer):
|
||||||
# one at a time
|
# one at a time
|
||||||
with self._lock:
|
with self._lock:
|
||||||
# reset state
|
# reset state
|
||||||
self._rule = None
|
self._rule = None
|
||||||
|
self._local = is_local
|
||||||
|
self._peer = peer
|
||||||
self._con = connection
|
self._con = connection
|
||||||
self._done.clear()
|
self._done.clear()
|
||||||
# trigger on_connection_triggered
|
# trigger on_connection_triggered
|
||||||
|
@ -72,7 +76,11 @@ class PromptDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def _render_connection(self, con):
|
def _render_connection(self, con):
|
||||||
app_name, app_icon, desk = self._apps_parser.get_info_by_path(con.process_path, "terminal")
|
if self._local:
|
||||||
|
app_name, app_icon, _ = self._apps_parser.get_info_by_path(con.process_path, "terminal")
|
||||||
|
else:
|
||||||
|
app_name, app_icon = "", "terminal"
|
||||||
|
|
||||||
if app_name == "":
|
if app_name == "":
|
||||||
self._app_name_label.setText(con.process_path)
|
self._app_name_label.setText(con.process_path)
|
||||||
else:
|
else:
|
||||||
|
@ -82,18 +90,33 @@ class PromptDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
||||||
pixmap = icon.pixmap(icon.actualSize(QtCore.QSize(48, 48)))
|
pixmap = icon.pixmap(icon.actualSize(QtCore.QSize(48, 48)))
|
||||||
self._app_icon_label.setPixmap(pixmap)
|
self._app_icon_label.setPixmap(pixmap)
|
||||||
|
|
||||||
self._message_label.setText("<b>%s</b> is connecting to <b>%s</b> on %s port %d" % ( \
|
if self._local:
|
||||||
con.process_path,
|
message = "<b>%s</b> is connecting to <b>%s</b> on %s port %d" % ( \
|
||||||
con.dst_host or con.dst_ip,
|
con.process_path,
|
||||||
con.protocol,
|
con.dst_host or con.dst_ip,
|
||||||
con.dst_port
|
con.protocol,
|
||||||
))
|
con.dst_port )
|
||||||
|
else:
|
||||||
|
message = "The process <b>%s</b> running on the computer <b>%s</b> is connecting to <b>%s</b> on %s port %d" % ( \
|
||||||
|
con.process_path,
|
||||||
|
self._peer.split(':')[1],
|
||||||
|
con.dst_host or con.dst_ip,
|
||||||
|
con.protocol,
|
||||||
|
con.dst_port )
|
||||||
|
|
||||||
|
self._message_label.setText(message)
|
||||||
|
|
||||||
self._src_ip_label.setText(con.src_ip)
|
self._src_ip_label.setText(con.src_ip)
|
||||||
self._dst_ip_label.setText(con.dst_ip)
|
self._dst_ip_label.setText(con.dst_ip)
|
||||||
self._dst_port_label.setText("%s" % con.dst_port)
|
self._dst_port_label.setText("%s" % con.dst_port)
|
||||||
self._dst_host_label.setText(con.dst_host)
|
self._dst_host_label.setText(con.dst_host)
|
||||||
self._uid_label.setText("%d (%s)" % (con.user_id, pwd.getpwuid(con.user_id).pw_name))
|
|
||||||
|
if self._local:
|
||||||
|
uid = "%d (%s)" % (con.user_id, pwd.getpwuid(con.user_id).pw_name)
|
||||||
|
else:
|
||||||
|
uid = "%d" % con.user_id
|
||||||
|
|
||||||
|
self._uid_label.setText(uid)
|
||||||
self._pid_label.setText("%s" % con.process_id)
|
self._pid_label.setText("%s" % con.process_id)
|
||||||
self._args_label.setText(' '.join(con.process_args))
|
self._args_label.setText(' '.join(con.process_args))
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ class StatsDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
||||||
|
|
||||||
self.daemon_connected = False
|
self.daemon_connected = False
|
||||||
|
|
||||||
|
self._address = address
|
||||||
self._stats = None
|
self._stats = None
|
||||||
self._trigger.connect(self._on_update_triggered)
|
self._trigger.connect(self._on_update_triggered)
|
||||||
|
|
||||||
|
@ -107,8 +108,11 @@ class StatsDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
||||||
self._udp_label.setText("%s" % self._stats.by_proto['udp'] or 0)
|
self._udp_label.setText("%s" % self._stats.by_proto['udp'] or 0)
|
||||||
|
|
||||||
by_users = {}
|
by_users = {}
|
||||||
for uid, hits in self._stats.by_uid.iteritems():
|
if self._address is None:
|
||||||
by_users["%s (%s)" % (pwd.getpwuid(int(uid)).pw_name, uid)] = hits
|
for uid, hits in self._stats.by_uid.iteritems():
|
||||||
|
by_users["%s (%s)" % (pwd.getpwuid(int(uid)).pw_name, uid)] = hits
|
||||||
|
else:
|
||||||
|
by_users = self._stats.by_uid
|
||||||
|
|
||||||
self._render_table(self._addrs_table, self._stats.by_address)
|
self._render_table(self._addrs_table, self._stats.by_address)
|
||||||
self._render_table(self._hosts_table, self._stats.by_host)
|
self._render_table(self._hosts_table, self._stats.by_host)
|
||||||
|
|
|
@ -189,7 +189,7 @@ class UIService(ui_pb2_grpc.UIServicer, QtWidgets.QGraphicsObject):
|
||||||
|
|
||||||
def AskRule(self, request, context):
|
def AskRule(self, request, context):
|
||||||
self._asking = True
|
self._asking = True
|
||||||
rule = self._prompt_dialog.promptUser(request)
|
rule = self._prompt_dialog.promptUser(request, self._is_local_request(context), context.peer())
|
||||||
self._last_ping = datetime.now()
|
self._last_ping = datetime.now()
|
||||||
self._asking = False
|
self._asking = False
|
||||||
return rule
|
return rule
|
||||||
|
|
Loading…
Add table
Reference in a new issue