Example #1
0
    def file(self):
        file_path = configuration.get("DownloadSite", "client_path")

        if not file_path or not os.path.exists(file_path):
            msg = "I can't serve the file {} because it doesn't exist.".format(
                file_path)
            mainlog.error(msg)
            raise cherrypy.HTTPError(404,
                                     message=msg)  # Won't create an exception

        # I don't inject at update time because if one copies
        # a delivery_slips in, then that delivery_slips must be injected as well.

        public_ip = configuration.get("DEFAULT", "public_ip")

        if not public_ip:
            public_ip = guess_server_public_ip()
            mainlog.warn(
                "Server configuration is borken : missing DEFAULT/public_ip. I'll default to what I guessed instead : {}"
                .format(public_ip))

        inject_public_ip_in_client(public_ip)

        return cherrypy.lib.static.serve_download(
            file_path, name=configuration.get("Globals", "codename") + '.zip')
Example #2
0
    def load_server_configuration(self):

        config_spec = os.path.join(resource_dir, "server_config_check.cfg")

        data_dir = os.path.join(
            shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0),
            codename)
        config_file = os.path.join(data_dir, 'server.cfg')

        if not os.path.exists(os.path.join(data_dir)):
            os.mkdir(data_dir)

        if not os.path.exists(os.path.join(config_file)):
            self.base_configuration = configobj.ConfigObj(encoding='utf-8')

            self.base_configuration['Database'] = {}
            self.base_configuration['Database'][
                'url'] = 'postgresql://*****:*****@{}:5432/horsedb'.format(
                    guess_server_public_ip())
            self.base_configuration['Database'][
                'admin_url'] = 'postgresql://*****:*****@localhost:5432/horsedb'
            self.base_configuration.filename = config_file
            self.base_configuration.write()

        self.load(config_file, config_spec)
Example #3
0
    def check_server(self):
        self._clear_log()
        self._log("<b>Checking web server")

        # Because of difficulties with cxFreeze and cherrypy and windows service, the
        # Koi windows service is not installed; only a scheduled taks is installed.

        # if platform.system() == "Windows":
        #
        #     cmd = ["sc", "query", self.SERVER_NAME+self.SERVER_NAME_SUFFIX]
        #
        #     try:
        #         if self._run_shell(cmd):
        #             self._log_error("Can't find the server's Windows service ({}). Check your installation or use 'Install services'. If this PC restarts, the server won't start, making the system unusable.".format(self.SERVER_NAME+self.SERVER_NAME_SUFFIX))
        #             return
        #     except Exception as ex:
        #         return

        v = get_server_version(configuration.update_url_version)

        db_url = None
        try:
            self._log("Looking for advertised DB version at {}".format(
                configuration.database_url_source()))
            response = urlopen(configuration.database_url_source(), timeout=2)
            db_url = response.read()
        except Exception as ex:
            self._log_error(
                "Unable to connect to the web server. Is it running ? I tried to get the databse url from it. If the server is running, check the configuration at DownloadSite/base_url and verify it's good."
            )

            HOST = guess_server_public_ip()
            self._log(
                "Looking again for advertised DB version at {}".format(HOST))
            response = urlopen("http://{}".format(HOST), timeout=2)
            db_url = response.read()

            pass

        if v and db_url:
            self._log("Server version : {}".format(v))
            self._log("Public announced database : {}".format(db_url))
            self._log("")
            self._log("<b><font color='green'>Server is fine")
        else:
            self._log_error(
                "Server didn't answer. Maybe you should start it manually ?")
Example #4
0
    def __init__(self, parent):
        super(AskIPAddress, self).__init__()

        layout = QVBoxLayout(self)
        layout.addWidget(QLabel("Please enter a valid address"))

        glayout = QGridLayout()

        self.address = QLineEdit()
        glayout.addWidget(QLabel("IP Address"), 0, 0)
        glayout.addWidget(self.address, 0, 1)

        self.address.setText(guess_server_public_ip())
        layout.addLayout(glayout)

        self.buttons = QDialogButtonBox()
        self.buttons.addButton(QDialogButtonBox.Ok)
        layout.addWidget(self.buttons)

        self.setLayout(layout)

        self.buttons.accepted.connect(self.accept)
Example #5
0
    def __init__(self):
        super(MainWindow, self).__init__()

        self.edit_config = EditConfigurationDialog(self)
        self.edit_config.load_configuration()

        w = QWidget(self)

        big_hlayout = QHBoxLayout()

        layout = QVBoxLayout()
        big_hlayout.addLayout(layout)
        big_hlayout.addWidget(self.edit_config)

        layout.addWidget(
            QLabel("<h1>{} administration</h1>".format(
                configuration.get("Globals", "name"))))

        glayout = QGridLayout()

        row = 0

        HOST = "{} or {}".format(guess_server_public_ip(),
                                 socket.gethostname())
        glayout.addWidget(QLabel("<b>Server's IP address"), row, 0)
        ip_address = configuration.get("DEFAULT", "public_ip")
        if not ip_address:
            ip_address = "<font color='red'><b>NOT DEFINED</b></font>"
        glayout.addWidget(QLabel("{} (guessed: {})".format(ip_address, HOST)),
                          row, 1)

        row += 1
        glayout.addWidget(QLabel("<b>Client database URL"), row, 0)
        db_url = configuration.get("Database", "url")
        self.public_url_edit = QLabel(db_url)
        glayout.addWidget(self.public_url_edit, row, 1)

        row += 1
        glayout.addWidget(QLabel("<b>Client server URL"), row, 0)
        url = configuration.get("DownloadSite", "public_url")
        self.public_web_url_edit = QLabel(url)
        glayout.addWidget(self.public_web_url_edit, row, 1)

        row += 1
        glayout.addWidget(QLabel("Server local DB URL"), row, 0)
        db_url = configuration.get("Database", "admin_url")
        self.url_edit = QLabel(db_url)
        glayout.addWidget(self.url_edit, row, 1)

        row += 1
        glayout.addWidget(QLabel("Backup directory"), row, 0)
        db_url = configuration.get("Backup", "backup_directory")
        self.backup_directory_edit = QLabel(db_url)
        glayout.addWidget(self.backup_directory_edit, row, 1)

        row += 1
        glayout.addWidget(QLabel("Data/logs directory"), row, 0)
        self.data_directory_edit = QLabel(get_data_dir())
        glayout.addWidget(self.data_directory_edit, row, 1)

        qgb = QGroupBox("Life data")
        qgb.setLayout(glayout)
        layout.addWidget(qgb)

        hlayout = QHBoxLayout()
        b = QPushButton("Check database")
        b.clicked.connect(self.check_database)
        hlayout.addWidget(b)

        b = QPushButton("Check web server")
        b.clicked.connect(self.check_server)
        hlayout.addWidget(b)

        b = QPushButton("Show delivery_slips download page")
        b.clicked.connect(self.show_client_dowload_page)
        hlayout.addWidget(b)

        qgb = QGroupBox("Checks")
        qgb.setLayout(hlayout)
        layout.addWidget(qgb)

        hlayout = QHBoxLayout()
        # b = QPushButton("Set backup directory")
        # b.clicked.connect(self.set_backup_directory)
        # hlayout.addWidget( b)

        b = QPushButton("Restore backup")
        b.clicked.connect(self.restore_backup)
        hlayout.addWidget(b)

        b = QPushButton("Reset admin account")
        b.clicked.connect(self.create_root_account)
        hlayout.addWidget(b)

        # b = QPushButton("Set public IP")
        # b.clicked.connect(self.set_public_ip)
        # hlayout.addWidget( b)

        # Please use the command line, this is not for the faint hearted.

        # b = QPushButton("Clear database")
        # b.clicked.connect(self.create_database)
        # hlayout.addWidget( b)

        qgb = QGroupBox("Actions")
        qgb.setLayout(hlayout)
        layout.addWidget(qgb)

        vlayout = QVBoxLayout()

        # if platform.system() == 'Windows':
        #     # when running on Linux, it's expected that the
        #     # whole server configuration is set up by us
        #
        #     hlayout = QHBoxLayout()
        #     b = QPushButton("Start server manually")
        #     b.clicked.connect(self.start_server_manually)
        #     hlayout.addWidget( b)
        #
        #     b = QPushButton("Stop server manually")
        #     b.clicked.connect(self.stop_server_manually)
        #     hlayout.addWidget( b)
        #     vlayout.addLayout(hlayout)
        #
        #     hlayout = QHBoxLayout()
        #     b = QPushButton("Install services")
        #     b.clicked.connect(self.install_service)
        #     hlayout.addWidget( b)
        #
        #     b = QPushButton("Uninstall services")
        #     b.clicked.connect(self.uninstall_service)
        #     hlayout.addWidget( b)
        #     vlayout.addLayout(hlayout)
        #
        #     b = QPushButton("Install scheduled services")
        #     b.clicked.connect(self.install_on_start_tasks)
        #     vlayout.addWidget( b)
        #
        #     # b = QPushButton("Upgrade delivery_slips")
        #     # b.clicked.connect(self.upgrade_client)
        #     # layout.addWidget( b)
        #
        #     qgb = QGroupBox("Service & installation")
        #     qgb.setLayout(vlayout)
        #     layout.addWidget(qgb)

        self.log_view = QTextEdit()
        layout.addWidget(self.log_view)

        self.url_edit.setTextInteractionFlags(Qt.TextSelectableByMouse)
        self.public_url_edit.setTextInteractionFlags(Qt.TextSelectableByMouse)
        self.public_web_url_edit.setTextInteractionFlags(
            Qt.TextSelectableByMouse)
        self.backup_directory_edit.setTextInteractionFlags(
            Qt.TextSelectableByMouse)

        self.log_view.setReadOnly(True)

        w.setLayout(big_hlayout)

        self.setCentralWidget(w)