Пример #1
0
def executeWithoutTimeout(command):
    try:
        proc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
        (dist, err) = proc.communicate()
        dist = dist.decode('UTF-8')
        if (dist.strip() == ""):
            message.log_info(command + " " + "returning null")

        return (dist.strip())
    except Exception as e:
        message.log_error("Exception occurred")
        return ("")
Пример #2
0
    def on_close_notification_click(self, button, notification_text,
                                    notification_index):
        try:
            hostname = controls.execute("hostname")
            data = {
                "machine_name": hostname,
                "message": notification_text,
                "index": notification_index
            }

            resp = requests.delete(self.notifications_address,
                                   data=data).json()
            message.log_info(resp)
        except Exception as e:
            message.log_error("Exception occurred: " + str(e))
Пример #3
0
 def get_notifications(self, tray):
     try:
         hostname = controls.execute("hostname")
         data = {"machine_name": hostname}
         self.response = (requests.post(self.get_notifications_address,
                                        data=data)).json()
         self.count = self.response['count']
         if (self.count > 0):
             tray.set_from_file(summary.MAINDIR + "images/Notification.png")
         else:
             tray.set_from_file(summary.MAINDIR + "images/Computer.png")
         tray.is_server_up = True
     except Exception as e:
         tray.is_server_up = False
         tray.set_from_file(summary.MAINDIR + "images/Computer.png")
         message.log_error("Exception occurred: " + str(e))
Пример #4
0
    def on_send_click(self, button):
        loading_window = loading.Loading()
        while Gtk.events_pending():
            Gtk.main_iteration()

        try:
            imagename = summary.MAINDIR + 'ss/ss-' + str(
                datetime.datetime.now().timestamp()) + '.jpg'
            os.system("import -window root " + imagename)
            send_window.show_window()
        except Exception as e:
            message.log_error("Exception occured: " + str(e))
            message.MessageDialogWindow().error_dialog(
                _("Error"),
                _("There has been an error while taking a screenshot. Please try again later"
                  ))

        loading_window.destroy()
Пример #5
0
def getNTPTime(host):
    try:
        port = 123
        buf = 1024
        address = (host, port)
        msg = '\x1b' + 47 * '\0'

        TIME1970 = 2208988800  # 1970-01-01 00:00:00
        client = socket.socket(AF_INET, SOCK_DGRAM)
        client.sendto(msg.encode('utf-8'), address)
        msg, address = client.recvfrom(buf)

        t = struct.unpack("!12I", msg)[10]
        t -= TIME1970

        return time.ctime(t).replace("  ", " ")
    except socket.timeout:
        message.log_error(("Could not fetch time from NTP server"))
        return _("Fail")
Пример #6
0
    def on_send_click(self, button):
        try:
            buffer = self.textview.get_buffer()
            text = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter(), False)
            print(text)
 
            hostname = controls.execute("hostname")
            username = controls.execute("whoami")           


            list_of_files = glob.glob(summary.MAINDIR+'ss/*')
            latest_file = max(list_of_files, key=os.path.getctime)

            data = []
            data.append({
                "machine_name": hostname,
                "username": username,
                "note": text,
                "filename": latest_file
            })

            with open(summary.MAINDIR + "ss/main.json", "a") as outfile:
                json.dump(data, outfile)

            file_object = open(summary.MAINDIR + "ss/main.json", 'a')
            file_object.write("\n")
            file_object.close()

            # create new script that handles all api calls

            self.window.close()
        except Exception as e:
            message.log_error("Exception occurred: " + str(e))
            message.MessageDialogWindow().error_dialog(_("Error"), 
                _("There has been an error while sending information to the server. Please try again later"))
            
            self.window.close()
        return True
Пример #7
0
    def show_window(self):
        if self.is_window_open == True:
            return

        if checkPalamar() == False:
            message.log_error("Palamar is not installed")
            message.MessageDialogWindow().error_dialog(
                _("Error"),
                _("Palamar is not installed. Please try installing first"))

            return

        button_label = ""
        label = ""
        is_in_domain = False
        if (summary.getDomain() != ""):
            is_in_domain = True
            label = _("Machine is in domain")
            button_label = _("Leave Domain")
        else:
            label = _("Machine is not in domain")
            button_label = _("Join Domain")

        label = Gtk.Label(label=("<b>" + label + "</b>"), use_markup=True)
        self.grid.attach(label, 0, 0, 4, 1)

        separator1 = Gtk.Separator()
        self.grid.attach_next_to(separator1, label, Gtk.PositionType.BOTTOM, 4,
                                 1)

        button = Gtk.Button(label=button_label)
        button.set_size_request(80, 30)

        if is_in_domain == True:  # this will be false in release
            button.connect("clicked", self.on_join_button_clicked)

            if checkConfigFiles() == False:
                separator2 = Gtk.Separator()

                label3 = Gtk.Label(label=_("Domain Username:"******"Domain Password:"******"Domain IP:"))
                label5.set_halign(Gtk.Align.END)
                self.domain_ip_entry = Gtk.Entry()

                label6 = Gtk.Label(label=_("Hostname:"))
                label6.set_halign(Gtk.Align.END)
                self.hostname_entry = Gtk.Entry()

                self.grid.attach_next_to(label5, separator1,
                                         Gtk.PositionType.BOTTOM, 1, 2)
                self.grid.attach_next_to(self.domain_ip_entry, label5,
                                         Gtk.PositionType.RIGHT, 3, 2)
                self.grid.attach_next_to(label6, label5,
                                         Gtk.PositionType.BOTTOM, 1, 2)
                self.grid.attach_next_to(self.hostname_entry, label6,
                                         Gtk.PositionType.RIGHT, 3, 2)

                self.grid.attach_next_to(label3, label6,
                                         Gtk.PositionType.BOTTOM, 1, 2)
                self.grid.attach_next_to(self.domain_username_entry, label3,
                                         Gtk.PositionType.RIGHT, 3, 2)
                self.grid.attach_next_to(label4, label3,
                                         Gtk.PositionType.BOTTOM, 1, 2)
                self.grid.attach_next_to(self.domain_pass_entry, label4,
                                         Gtk.PositionType.RIGHT, 3, 2)

                separator1 = label4  # little hack for grid attachment correction
        else:
            button.connect("clicked", self.on_leave_button_clicked)

        self.grid.attach_next_to(button, separator1, Gtk.PositionType.BOTTOM,
                                 4, 2)

        self.window.set_icon_from_file(summary.ICONComputer)
        self.window.connect('delete-event', self.on_delete_event)
        self.is_window_open = True
        self.window.add(self.grid)
        self.window.show_all()