コード例 #1
0
 def run(self):
     self._whitelist_list = []
     SSH_IP = config.get("SSH", "server_ip")
     SSH_Port = config.getint("SSH", "server_port")
     SSH_User = config.get("SSH", "server_user")
     SSH_Password = config.get("SSH", "server_pass")
     SERVER_Location = config.get("EZ", "server_location")
     for self._whitelist in open('Snap/whitelist.txt'):
         self._whitelist_singal = []
         self._whitelist = self._whitelist.replace('\n', '').replace('\r', '')
         if self._whitelist.endswith("False"):
             self._whitelist = self._whitelist.replace('False', 'false')
         elif self._whitelist.endswith("True"):
             self._whitelist = self._whitelist.replace('True', 'true')
         self.xuid = ''
         self.white_name = self._whitelist.partition(';')[0]
         self.ignoresPlayerLimit_id = self._whitelist.rpartition(';')[2]
         self._whitelist_singal.append(self.white_name)
         self.del_name_id = self._whitelist.find(';')
         self.del_ignore_id = self._whitelist.rfind(';')
         for i in range(0,len(self._whitelist)):
             if i > self.del_name_id and i < self.del_ignore_id:
                 self.xuid = self.xuid + self._whitelist[i]
         self._whitelist_singal.append(self.xuid)
         self._whitelist_singal.append(self.ignoresPlayerLimit_id)
         self._whitelist_list.append(self._whitelist_singal)
     write_whitelist()
     self.OutWhitelist.emit(self._whitelist_list)
     try:
         sshsend(SSH_IP, SSH_Port, SSH_User, SSH_Password, 'Snap/whitelist.json', SERVER_Location+'/whitelist.json')
     except:
         pass
コード例 #2
0
        def ServerBuild(self):
            self.ui.build_build_button.setText('执行中')
            self.ui.build_build_button.setEnabled(False)
            self.ui.progressBar.setRange(0, 100)
            self.ui.build_log_text.clear()
            self.ui.build_log_text.append('开始构建...')
            self.ui.progressBar.setValue(10)

            # 从config读取SSH
            SSH_IP = config.get("SSH", "server_ip")
            SSH_Port = config.getint("SSH", "server_port")
            SSH_User = config.get("SSH", "server_user")
            SSH_Password = config.get("SSH", "server_pass")
            self.ui.build_log_text.append('已读取SSH信息')
            self.ui.progressBar.setValue(15)
            if sshconnect(SSH_IP, SSH_Port, SSH_User, SSH_Password) == True:
                self.ui.build_log_text.append('SSH连接有效!')
                self.ui.progressBar.setValue(17)
            elif sshconnect(SSH_IP, SSH_Port, SSH_User,
                            SSH_Password) == 'Failed':
                self.ui.build_log_text.append('SSH连接失败')
                self.ui.build_build_button.setText('开服')
                self.ui.progressBar.reset()
                self.ui.build_build_button.setEnabled(True)

            # 读取用户自定义下载地址
            download_url = self.ui.log_save_edit_2.text()
            if download_url == '':
                download_url = config.get("Server", "download_url")
                self.ui.build_log_text.append('使用默认下载地址')
                self.ui.progressBar.setValue(20)
            # 本地上传
            elif download_url.startswith(('http', 'https', 'ftp')) != True:
                config.set("Server", "local", download_url)
                config.write(open("config.cfg", "w"))
                self.ui.build_log_text.append('从本地 \'' + download_url +
                                              ' \'获取服务端')
                #time.sleep(5)
                self.ui.progressBar.setValue(20)
                try:
                    sshsend(SSH_IP, SSH_Port, SSH_User, SSH_Password,
                            download_url, '/home/pi/BDX/local.py')
                except:
                    self.ui.build_log_text.append("上传失败!")
                    self.ui.build_build_button.setText('开服')
                    self.ui.progressBar.reset()
                    self.ui.build_build_button.setEnabled(True)
                    return
            elif download_url.startswith(('http', 'https', 'ftp')) == True:
                self.ui.build_log_text.append('使用用户自定义下载地址')
                self.ui.progressBar.setValue(20)
                self.ui.build_log_text.append('')
                self.ui.progressBar.setValue(45)
            return
コード例 #3
0
    def run(self):
        server_name = config.get("CONTROL", 'server-name')
        gamemode = config.get("CONTROL", 'gamemode')
        cheats = config.get("CONTROL", 'allow-cheats')
        max_players = config.getint("CONTROL", 'max-players')
        online_mode = config.get("CONTROL", 'online-mode')
        white_list = config.get("CONTROL", 'white-list')
        view_distance = config.getint("CONTROL", 'view-distance')
        tick_distance = config.getint("CONTROL", 'tick-distance')
        player_idle_timeout = config.getint("CONTROL", 'player-idle-timeout')
        max_threads = config.getint("CONTROL", 'max-threads')
        player_chara = config.get("CONTROL", 'default-player-permission-level')
        texture = config.get("CONTROL", 'texturepack-required')
        error_log = config.get("CONTROL", 'content-log-file-enabled')
        compress = config.getint("CONTROL", 'compression-threshold')
        server_port = config.getint("CONTROL", 'server-port')
        server_port_v6 = config.getint("CONTROL", 'server-portv6')
        try:
            os.mkdir('Snap')
        except:
            pass
        shutil.copy('Server/server.properties.cfg', 'Snap/server.properties2.cfg')

        SSH_IP = config.get("SSH", "server_ip")
        SSH_Port = config.getint("SSH", "server_port")
        SSH_User = config.get("SSH", "server_user")
        SSH_Password = config.get("SSH", "server_pass")
        SERVER_Location = config.get("EZ", "server_location")

        self.OutProgress.emit(50)
        config2 = configparser.ConfigParser()
        config2.read('Snap/server.properties2.cfg')
        config2.set("CONTROL", 'server-name', server_name)
        config2.set("CONTROL", 'gamemode', gamemode)
        config2.set("CONTROL", 'allow-cheats', cheats)
        config2.set("CONTROL", 'max-players', str(max_players))
        config2.set("CONTROL", 'online-mode', online_mode)
        config2.set("CONTROL", 'white-list', white_list)
        config2.set("CONTROL", 'view-distance', str(view_distance))
        config2.set("CONTROL", 'tick-distance', str(tick_distance))
        config2.set("CONTROL", 'player-idle-timeout', str(player_idle_timeout))
        config2.set("CONTROL", 'max-threads', str(max_threads))
        config2.set("CONTROL", 'default-player-permission-level', player_chara)
        config2.set("CONTROL", 'texturepack-required', texture)
        config2.set("CONTROL", 'content-log-file-enabled', error_log)
        config2.set("CONTROL", 'compression-threshold', str(compress))
        config2.set("CONTROL", 'server-port', str(server_port))
        config2.set("CONTROL", 'server-portv6', str(server_port_v6))
        config2.write(open("Snap/server.properties2.cfg", "w"))
        self.OutProgress.emit(60)
        shutil.copy('Snap/server.properties2.cfg', 'Snap/server.properties_snap')
        create_server = open('Snap/server.properties_snap', 'r+')
        open('Snap/server.properties_snap2', 'w').write(re.sub(r"\[CONTROL\]", "# By MCPEManager", create_server.read()))
        create_server.close()
        f = open("Snap/server.properties_snap2")
        conf = f.read()
        conf = conf.replace(" = ","=")
        open('server.properties', 'w').write(conf)
        f.close()
        try:
            sshsend(SSH_IP, SSH_Port, SSH_User, SSH_Password, 'server.properties', SERVER_Location+'server.properties')
            self.OutPut.emit('保存成功!')
            self.OutProgress.emit(100)
        except:
            self.OutPut.emit('保存失败!')
            self.OutProgress.emit(0)
        #try:
        #    sshconnect(SSH_IP, SSH_Port, SSH_User, SSH_Password, command=['screen -S EZ -X quit', 'screen -r EZ', ''])
        #    self.OutPut.emit('保存成功!')
        #    self.OutProgress.emit(100)
        #except:
        #    self.OutPut.emit('保存失败!')
        #    self.OutProgress.emit(0)
        return
コード例 #4
0
    def run(self):
        # 从config读取SSH
        SSH_IP = config.get("SSH", "server_ip")
        SSH_Port = config.getint("SSH", "server_port")
        SSH_User = config.get("SSH", "server_user")
        SSH_Password = config.get("SSH", "server_pass")
        self.consoleOutPut.emit('已读取SSH信息')
        # time.sleep(5)

        # 验证SSH连接
        if sshconnect(SSH_IP, SSH_Port, SSH_User, SSH_Password) == True:
            self.consoleOutPut.emit('SSH连接有效!')
            self.OutProgress.emit(17)
            # time.sleep(4)

        elif sshconnect(SSH_IP, SSH_Port, SSH_User, SSH_Password) == False:
            self.consoleOutPut.emit('SSH连接失败!')
            return
        download_url = config.get("Server", "download_user")

        # 使用默认下载地址
        if download_url == '':
            download_url = config.get("Server", "download_url")
            self.consoleOutPut.emit('使用默认下载地址')
            self.OutProgress.emit(20)
            try:
                with open('build-shell\\build-debian10.sh','r') as command:
    	            command_all = command.read().splitlines()
                self.OutProgress.emit(40)
                progress = 40
                if os.path.exists('Snap/build_log.txt'):
                    pass
                else:
                    log_txt = open('Snap/build_log.txt','w')
                    log_txt.close()
                    self.consoleOutPut_All.emit(True)
                for i in command_all:
                    if i == 'cd wine-5.12; ./configure --enable-win64 --without-freetype; make; make install':
                        self.consoleOutPut.emit('正在编译安装Wine,可能需要20-60分钟,具体时长因机器性能而异...')
                    sshconnect(SSH_IP, SSH_Port, SSH_User, SSH_Password,'build_log.txt',i)
                    progress += 5
                    self.OutProgress.emit(progress)
            except:
                self.consoleOutPut.emit("开服失败!")
                return
            self.OutProgress.emit(100)
            time.sleep(1)
            self.consoleOutPut.emit('开服成功!执行日志已保存在Log文件夹中,关闭软件则会被删除。')
            self.stopcheck.emit(True)
            return

        # 本地上传
        elif download_url.startswith(('http', 'https', 'ftp')) != True:
            self.consoleOutPut.emit('从本地 \'' + download_url + ' \'获取服务端')
            #time.sleep(5)
            self.OutProgress.emit(20)
            if not download_url.endswith(('zip')):
                self.consoleOutPut.emit('上传的文件不是zip格式,无法上传!')
                return
            try:
                sshsend(SSH_IP, SSH_Port, SSH_User, SSH_Password, download_url, '/root/EZ/local.zip')
                with open('build-shell\\build-debian10-local.sh','r') as command:
    	            command_all = command.read().splitlines()
                self.OutProgress.emit(56)
                progress = 56
                for i in command_all:
                    if os.path.exists('Snap/build_log.txt'):
                        pass
                    else:
                        log_txt = open('Snap/build_log.txt','w')
                        log_txt.close()
                    seof.consoleOutPut_All.emit(True)
                    sshconnect(SSH_IP, SSH_Port, SSH_User, SSH_Password,'build_log.txt',i)
                    progress += 4
                    self.OutProgress.emit(progress)
                self.consoleOutPut.emit('开服成功!')

                return
            except:
                self.consoleOutPut.emit("上传失败!")
                return

        # 使用用户自定义下载地址
        elif download_url.startswith(('http', 'https', 'ftp')) == True:
            self.consoleOutPut.emit('使用用户自定义下载地址')
            self.ui.progressBar.setValue(20)
            try:
                sshsend(SSH_IP, SSH_Port, SSH_User, SSH_Password, download_url, '/root/EZ/local.zip')
            except:
                self.consoleOutPut.emit("上传失败!")
            return