class ConfigManager(object): """ method reading and writing from the configuration file """ def __init__(self): self.logger = Logger() self.config = configparser.ConfigParser() self.installer_config_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/installer_config.yml') self.installer_config_path2 = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/installer.conf') if not os.path.exists( os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../dist')): os.makedirs( os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../dist')) def read(self): try: self.config.read(self.installer_config_path2, encoding="utf-8") config = self.config["COMMANDS"] return config except Exception as e: self.logger.error("Veriler okunurken hata oluştu: " + str(e)) return None def replace_all(self, text, dic): try: for i, j in dic.items(): text = text.replace(i, j) self.logger.info("Dosya güncellenmesi başarıyla tamamlandı") return text except Exception as e: self.logger.error( "Dosya güncellenmesi sırasında beklenmedik bir hata ile karşılaşıldı\n" + str(e)) def date_format(self): date_now = datetime.now().strftime('%Y-%m-%d %H:%M:%S') date_parse = date_now.split(" ") date_list = [] for line in date_parse: date_line = line + "-" date_list.append(date_line) date = ''.join(str(x) for x in date_list) date = date.strip('-') return date
class AhenkInstaller(object): def __init__(self, ssh_api, ssh_status): self.ssh_api = ssh_api self.ssh_status = ssh_status self.logger = Logger() def install(self, data): repo_key = data["repo_key"] repo_key = repo_key.rsplit("/")[-1] config_manager = ConfigManager() cfg_data = config_manager.read() # print(cfg_data) if self.ssh_status == "Successfully Authenticated": result_code = self.ssh_api.run_command( cfg_data["cmd_soft_properties"]) if result_code == 0: self.logger.info("software-properties-common paketi kuruldu") else: self.logger.error( "software-properties-common paketi kurulamadı, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_liderahenk_repo_key"].format( data["repo_key"], repo_key)) if result_code == 0: self.logger.info("Lider Ahenk repo key dosyası indirildi") else: self.logger.error( "Lider Ahenk repo key dosyası indirilemedi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_liderahenk_repo_add"].format(data["repo_addr"])) if result_code == 0: self.logger.info("Lider Ahenk repo adresi eklendi") else: self.logger.error( "Lider Ahenk repo adresi eklenemedi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_update"]) if result_code == 0: self.logger.info("Paket listesi güncellendi(apt update)") else: self.logger.error( "Paket listesi güncellenemdi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_ahenk_install"]) if result_code == 0: self.logger.info("Ahenk paketi kuruldu") else: self.logger.error("Ahenk paketi kurulamadı, result_code: " + str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_ahenk_dep"]) if result_code == 0: self.logger.info("Ahenk bağımlılıkları kuruldu") self.logger.info("Ahenk kurulumu tamamlandı") else: self.logger.error( "Ahenk bağımlılıkları kurulamadı, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_ahenk_register"].format(data["host"], data["ldap_user"], data["ldap_user_pwd"])) if result_code == 0: self.logger.info("Ahenk etki alanına başarıyla alındı") else: self.logger.error( "Ahenk etki alanına alınamadı, result_code: " + str(result_code)) else: self.logger.error( "Ahenk kurulacak istemciye bağlantı sağlanamadığı için kurulum yapılamadı. Lütfen bağlantı ayarlarını kotrol ediniz!" )
class InstallManager(object): def __init__(self): super(InstallManager, self).__init__() self.util = Util() self.ssh_status = "" self.logger = Logger() self.config_maneger = ConfigManager() self.liderahenk_data_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'dist/liderahenk.json') self.liderldap_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../dist/lider_ldap.json') def install_mariadb(self, data): db_installer = MariaDbInstaller(self.util, self.ssh_status) self.logger.info( "======>>>>> Veritabanı sunucu kurulumuna başlanıyor <<<<<======") db_installer.install(data) def install_ejabberd(self, data): ejabberd_installer = EjabberInstaller(self.util, self.ssh_status) self.logger.info( "======>>>>> Ejabberd sunucu kurulumuna başlanıyor. <<<<<======") ejabberd_installer.install(data) def install_ldap(self, data): ldap_installer = OpenLdapInstaller(self.util, self.ssh_status) self.logger.info( "======>>>>> OpenLDAP sunucu kurulumuna başlanıyor. <<<<<======") ldap_installer.install(data) def install_lider(self, data): lider_installer = LiderInstaller(self.util, self.ssh_status) self.logger.info( "======>>>>> Lider sunucu Kurulumuna başlanıyor. <<<<<======") lider_installer.install(data) def install_lider_console(self, data): lider_console_installer = LiderConsoleInstaller( self.util, self.ssh_status) self.logger.info( "======>>>>> Lider Arayüz Kurulumuna başlanıyor. <<<<<======") lider_console_installer.install(data) def install_ahenk(self, data): ahenk_installer = AhenkInstaller(self.util, self.ssh_status) self.logger.info( "======>>>>> Ahenk Kurulumuna başlanıyor. <<<<<======") ahenk_installer.install(data) def ssh_connect(self, data): ssh_status = self.util.connect(data) self.ssh_status = ssh_status if self.ssh_status == "Successfully Authenticated": return True else: return False def ssh_disconnect(self): self.util.disconnect()
class OpenLdapInstaller(object): def __init__(self, ssh_api, ssh_status): self.ssh_api = ssh_api self.ssh_status = ssh_status self.logger = Logger() self.ldap_config_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/ldapconfig_temp') self.update_ldap_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/update_ldap_temp') self.liderahenk_ldif_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/liderahenk.ldif') self.sudo_ldif_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/sudo.ldif') self.ldap_config_out_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../dist/ldapconfig') self.update_ldap_out_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../dist/update_ldap') def install(self, data): config_manager = ConfigManager() cfg_data = config_manager.read() base_dn = self.base_dn_parse(data) l_admin_cn = "cn=" + str(data['l_admin_cn']) ldap_data = { "#BASEDN": base_dn[0], "#CNAME": data["l_base_dn"], "#BASECN": base_dn[1], "#ORGANIZATION": data["l_org_name"], "#ADMINCN": l_admin_cn, "#ADMINPASSWD": data["l_admin_pwd"], "#CNCONFIGADMINDN": data['l_config_admin_dn'], "#CNCONFIGADMINPASSWD": data["l_config_pwd"], "#LIDERCONSOLEUSER": data["ladmin_user"], "#LIDERCONSOLEPWD": data["ladmin_pwd"], "#LIDER_SERVER_ADDR": data["lider_server_addr"], "#SIMPLE_LDAP_USER": data["simple_ldap_user"], "#SIMPLE_LDAP_USER_PWD": data["simple_ldap_user_pwd"] } # copy liderahenk.ldif file to ldap server self.ssh_api.scp_file(self.liderahenk_ldif_path, '/tmp') self.logger.info( "liderahenk.ldif dosyası OpenLDAP sunucusuna koplayandı") if data["ldap_status"] == "new": #edit ldap_install_temp script self.f1 = open(self.ldap_config_path, 'r+') my_text = self.f1.read() txt = config_manager.replace_all(my_text, ldap_data) self.f2 = open(self.ldap_config_out_path, 'w+') self.f2.write(txt) self.f1.close() self.f2.close() if self.ssh_status == "Successfully Authenticated" or data[ 'location'] == 'local': #copy ldap_install script to ldap server self.ssh_api.scp_file(self.ldap_config_out_path, '/tmp') self.logger.info( "ldapconfig betiği OpenLDAP sunucusuna kopyalandı") self.ssh_api.scp_file(self.sudo_ldif_path, '/tmp') ### install slapd package self.ssh_api.run_command(cfg_data["cmd_ldap_remove"]) self.ssh_api.run_command(cfg_data["ldap_deb_frontend"]) self.ssh_api.run_command( cfg_data["ldap_debconf_generated_password"].format( data["l_admin_pwd"])) self.ssh_api.run_command( cfg_data["ldap_debconf_admin_password"].format( data["l_admin_pwd"])) self.ssh_api.run_command(cfg_data["ldap_debconf_conf"]) self.ssh_api.run_command( cfg_data["ldap_debconf_domain"].format(data["l_base_dn"])) self.ssh_api.run_command( cfg_data["ldap_debconf_organization"].format( data["l_org_name"])) self.ssh_api.run_command(cfg_data["ldap_debconf_pwd1"].format( data["l_admin_pwd"])) self.ssh_api.run_command(cfg_data["ldap_debconf_pwd2"].format( data["l_admin_pwd"])) self.ssh_api.run_command(cfg_data["ldap_debconf_selectdb"]) self.ssh_api.run_command(cfg_data["ldap_debconf_purgedb"]) self.ssh_api.run_command(cfg_data["ldap_debconf_movedb"]) self.logger.info("LDAP bilgileri alındı") result_code = self.ssh_api.run_command( cfg_data["cmd_ldap_install"]) if result_code == 0: self.logger.info("slapd ve ldap-utils paketleri kuruldu") else: self.logger.error( "slapd ve ldap-utils paketleri kurulamadı, result_code: " + str(result_code)) self.ssh_api.run_command(cfg_data["cmd_ldap_reconf"]) self.logger.info("slapd paketi reconfigure edildi") self.ssh_api.run_command(cfg_data["cmd_ldapconfig_execute"]) result_code = self.ssh_api.run_command( cfg_data["cmd_ldapconfig_run"]) if result_code == 0: self.logger.info( "ldap config betiği çalıştırıldı ve lider ahenk konfigürasyonları tamamlandı" ) else: self.logger.error( "ldap config betiği çalıştırılırken hata oluştu ve lider ahenk konfigürasyonları tamamlanamadı" ) self.logger.info("OpenLDAP kurulumu tamamlandı") else: self.logger.error( "OpenLDAP sunucusuna bağlantı sağlanamadı için kurulum yapılamadı. Lütfen bağlantı ayarlarını kotrol ediniz!" ) # # print("bağlantı sağlanamadığı için kurulum yapılamadı..") else: self.f1 = open(self.update_ldap_path, 'r+') my_text = self.f1.read() txt = config_manager.replace_all(my_text, ldap_data) self.f2 = open(self.update_ldap_out_path, 'w+') self.f2.write(txt) self.f1.close() self.f2.close() # copy ldap_config script to ldap server self.ssh_api.scp_file(self.update_ldap_out_path, '/tmp') self.logger.info( "update_ldap betiği OpenLDAP sunucusuna koplayandı") self.ssh_api.run_command(cfg_data["cmd_update_ldap_execute"]) self.ssh_api.run_command(cfg_data["cmd_update_ldap_run"]) self.logger.info( "Varolan OpenLDAP Lider Ahenk uygulamasına göre ayarlandı") def base_dn_parse(self, data): ### split for get data['base_dn']: liderahenk.org #BASECN and #BASEDN parse_dn = data["l_base_dn"].split('.') base_cn = parse_dn[0] dn_list = [] for dn in parse_dn: message = 'dc=' + str(dn) + ',' dn_list.append(message) base_dn = ''.join(str(x) for x in dn_list) base_dn = base_dn.strip(',') return base_dn, base_cn
class LiderInstaller(object): def __init__(self, ssh_api, ssh_status): self.ssh_api = ssh_api self.ssh_status = ssh_status self.logger = Logger() self.util = Util() self.config_manager = ConfigManager() self.lider_conf_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/tr.org.liderahenk.cfg') self.db_conf_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/tr.org.liderahenk.datasource.cfg') self.lider_conf_out_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../dist/tr.org.liderahenk.cfg') self.db_conf_out_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../dist/tr.org.liderahenk.datasource.cfg') def install(self, data): repo_key = data["repo_key"] repo_key = repo_key.rsplit("/")[-1] if self.ssh_status == "Successfully Authenticated" or data[ 'location'] == 'local': cfg_data = self.config_manager.read() self.configure_lider_cfg(data) self.configure_db_cfg(data) result_code = self.ssh_api.run_command( cfg_data["cmd_soft_properties"]) if result_code == 0: self.logger.info("software-properties-common paketi kuruldu") else: self.logger.error( "software-properties-common paketi kurulamadı, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_liderahenk_repo_key"].format( data["repo_key"], repo_key)) if result_code == 0: self.logger.info("Lider Ahenk repo key dosyası indirildi") else: self.logger.error( "Lider Ahenk repo key dosyası indirilemedi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_liderahenk_repo_add"].format(data["repo_addr"])) if result_code == 0: self.logger.info("Lider Ahenk repo adresi eklendi") else: self.logger.error( "Lider Ahenk repo adresi eklenemedi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_update"]) if result_code == 0: self.logger.info("Paket listesi güncellendi(apt update)") else: self.logger.error( "Paket listesi güncellenemdi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_lider_install"]) if result_code == 0: self.logger.info("lider-server paketi kurulumu yapıldı") else: self.logger.error( "lider-server paketi kurulamadı, result_code: " + str(result_code)) self.ssh_api.scp_file(self.lider_conf_out_path, cfg_data["lider_des_path"]) self.ssh_api.scp_file(self.db_conf_out_path, cfg_data["lider_des_path"]) self.ssh_api.run_command(cfg_data["cmd_cp_lider_cfg"]) self.logger.info( "lider konfigürasyon dosyası LİDER sunucusuna kopyalandı") self.ssh_api.run_command(cfg_data["cmd_cp_db_cfg"]) self.logger.info( "veritabanı konfigürasyon dosyası LİDER sunucusuna kopyalandı") result_code = self.ssh_api.run_command( cfg_data["cmd_lider_service"]) if result_code == 0: self.logger.info("lider servisi başlatıldı") else: self.logger.error( "lider servisi başlatılamadı, resuşt_code: " + str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_fs_dep"]) if result_code == 0: self.logger.info( "sshpass ve rsync paketleri başarıyla kuruldu") else: self.logger.error("sshpass ve rsync paketleri kurulamadı") agent_files_path = data['fs_agent_file_path'] + '/agent-files' if data['location'] == 'remote': self.ssh_api.run_command( cfg_data["cmd_agents_files"].format(agent_files_path)) self.logger.info("agent-files dizini oluşturuldu") self.ssh_api.run_command( cfg_data["cmd_chown_agents_files"].format( data["username"], agent_files_path)) self.logger.info("agent-files dizini için owner değiştirildi") else: if not self.util.is_exist(agent_files_path): self.util.create_directory_local(agent_files_path) self.logger.info("agent-files dizini oluşturuldu") self.util.change_owner(agent_files_path, data['username'], data['username']) self.logger.info( "agent-files dizini için owner değiştirildi") else: self.logger.info( "{0} dizini zaten var".format(agent_files_path)) result_code = self.ssh_api.run_command( cfg_data["cmd_enable_lider_service"]) self.logger.info("Lider servis olarak ayarlandı.") else: self.logger.error( "LİDER sunucusuna bağlantı sağlanamadığı için kurulum yapılamadı. Lütfen bağlantı ayarlarını kotrol ediniz!" ) def configure_lider_cfg(self, data): l_base_dn = self.base_dn_parse(data) l_admin_dn = "cn=admin," + str(l_base_dn) lider_data = { "#LDAP_SERVER": data['ldap_servers'], "#LDAP_ADMIN_DN": l_admin_dn, "#LDAP_ADMIN_PWD": data['l_admin_pwd'], "#LDAP_ROOT_DN": l_base_dn, "#XMPP_SERVER": data['e_hosts'], "#LIDER_USERNAME": data['lider_username'], "#XMPP_USER_PWD": data['lider_user_pwd'], "#XMPP_SERVICE_NAME": data['e_service_name'], "#LDAP_BASE_DN": l_base_dn, "#FILE_SERVER": data['file_server'], "#FS_USERNAME": data['fs_username'], "#FS_PASSWORD": data['fs_username_pwd'], "#PLUGIN_PATH": data['fs_plugin_path'], "#AGREEMENT_PATH": data['fs_agreement_path'], "#AGENT_FILE_PATH": data['fs_agent_file_path'] } self.f_lider = open(self.lider_conf_path, 'r+') lider_text = self.f_lider.read() txt = self.config_manager.replace_all(lider_text, lider_data) self.f_lider_out = open(self.lider_conf_out_path, 'w+') self.f_lider_out.write(str(txt)) self.f_lider.close() self.f_lider_out.close() self.logger.info("tr.org.liderahenk.cfg dosyası oluşturuldu") def configure_db_cfg(self, data): db_data = { "#DBADDRESS": data['db_server'], "#DBDATABASE": data['db_name'], "#DBUSERNAME": data['db_username'], "#DBPASSWORD": data['db_password'] } self.f_db = open(self.db_conf_path, 'r+') db_text = self.f_db.read() txt = self.config_manager.replace_all(db_text, db_data) self.f_db_out = open(self.db_conf_out_path, 'w+') self.f_db_out.write(txt) self.f_db.close() self.f_db_out.close() self.logger.info("tr.org.datasource.cfg dosyası oluşturuldu") def base_dn_parse(self, data): ### split for get data['base_dn']: liderahenk.org #BASECN and #BASEDN parse_dn = data["l_base_dn"].split('.') dn_list = [] for dn in parse_dn: message = 'dc=' + str(dn) + ',' dn_list.append(message) base_dn = ''.join(str(x) for x in dn_list) base_dn = base_dn.strip(',') return base_dn
class MariaDbInstaller(object): def __init__(self, ssh_api, ssh_status): self.ssh_api = ssh_api self.ssh_status = ssh_status self.logger = Logger() def install(self, data): config_manager = ConfigManager() cfg_data = config_manager.read() # print(cfg_data) repo_key = data["repo_key"] repo_key = repo_key.rsplit("/")[-1] if self.ssh_status == "Successfully Authenticated" or data['location'] == 'local': result_code = self.ssh_api.run_command(cfg_data["cmd_soft_properties"]) if result_code == 0: self.logger.info("software-properties-common paketi kuruldu") else: self.logger.error("software-properties-common paketi kurulamadı, result_code: "+str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_liderahenk_repo_key"].format(data["repo_key"], repo_key)) if result_code == 0: self.logger.info("Lider Ahenk repo key dosyası indirildi") else: self.logger.error("Lider Ahenk repo key dosyası indirilemedi, result_code: "+str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_liderahenk_repo_add"].format(data["repo_addr"])) if result_code == 0: self.logger.info("Lider Ahenk repo adresi eklendi") else: self.logger.error("Lider Ahenk repo adresi eklenemedi, result_code: "+str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_update"]) if result_code == 0: self.logger.info("Paket listesi güncellendi(apt update)") else: self.logger.error("Paket listesi güncellenemdi, result_code: "+str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_deb_frontend"]) result_code = self.ssh_api.run_command(cfg_data["db_debconf_pwd"].format(data["db_password"])) result_code = self.ssh_api.run_command(cfg_data["db_debconf_pwd_again"].format(data["db_password"])) result_code = self.ssh_api.run_command(cfg_data["cmd_db_install"]) if result_code == 0: self.logger.info("Mariadb paketi kuruldu") else: self.logger.error("Mariadb paketi kurulamadı, result_code: "+str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_db_dep"]) if result_code == 0: self.logger.info("Veritabanı bağımlılıkları kuruldu") else: self.logger.error("Veritabanı bağımlılıkları kurulamadı, result_code: "+str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_create_db"].format(data["db_password"], data["db_name"])) if result_code == 0: self.logger.info("liderdb veritabanı oluşturuldu") else: self.logger.error("liderdb veritabanı oluşturulamadı, result_code: "+str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_db_grant_privileges"].format(data["db_password"], data["db_password"])) if result_code == 0: self.logger.info("Veritabanı grant yetkisi verildi") else: self.logger.error("Veritabanı grant yetkisi verilemedi, result_code: "+str(result_code)) # self.ssh_api.run_command(cfg_data["cmd_db_replace_bind_addr"]) result_code = self.ssh_api.run_command(cfg_data["cmd_db_service"]) if result_code == 0: self.logger.info("Veritabanı servisi başlatıldı.") else: self.logger.error("Veritabanı servisi başlatılamadı, result_code: "+str(result_code)) else: self.logger.error("Veritabanı sunucusuna bağlantı sağlanamadığı için kurulum yapılamadı. Lütfen bağlantı ayarlarını kotrol ediniz!")
class Util(object): def __init__(self): self.ssh = None self.ip = {} self.password = None self.location = None self.logger = Logger() def connect(self, data): self.password = data['password'] self.location = data['location'] try: self.ssh = paramiko.SSHClient() self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self.ssh.load_system_host_keys() ssh_status = self.ssh.connect(hostname=data['ip'], username=data['username'], password=data['password'], pkey=None, timeout=10) if ssh_status is None: self.logger.info(data['ip'] + " ip'li sunucuya bağlantı başarıyla sağlandı") return "Successfully Authenticated" except Exception as e: self.logger.error(str(data['ip']) + " ip'li sunucuya bağlantı sırasında beklenmedik hata oluştu \n" + str(e)) return "Authentication Failed" def disconnect(self): self.ssh.close() self.logger.info("Bağlantı kapatıldı") def run_command(self, command): if self.location == 'remote': # run command with sudo user try: # print(command) stdin, stdout, stderr = self.ssh.exec_command(command, get_pty=True) stdin.write(self.password + '\n') stdin.flush() # Wait for the command to terminate while not stdout.channel.exit_status_ready(): # Only print data if there is data to read in the channel if stdout.channel.recv_ready(): rl, wl, xl = select.select([stdout.channel], [], [], 0.0) if len(rl) > 0: # Print data from stdout print(stdout.channel.recv(1024)) result_code = stdout.channel.recv_exit_status() self.logger.info(str(command) + " komutu çalıştırıldı") return result_code except Exception as e: self.logger.error(str(command) + " komutu çalıştırılırken hata oluştu! " + str(e)) # if location local server else: try: echo = subprocess.Popen(['echo', self.password], stdout=subprocess.PIPE,) sudo = subprocess.Popen(['sudo', '-S', 'su'], stdin=echo.stdout, stdout=subprocess.PIPE) process = subprocess.Popen(command, stdin=None, env=None, cwd=None, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True) result_code = process.wait() p_out = process.stdout.read().decode("unicode_escape") p_err = process.stderr.read().decode("unicode_escape") if result_code == 0: self.logger.info(str(command) + " komutu başarıyla çalıştırıldı") else: self.logger.error(str(command) + " komutu çalıştırılırken hata oluştu! " + str(p_err)) return result_code except Exception as e: self.logger.error(str(command) + " komutu çalıştırılırken hata oluştu! " + str(e)) # copy file to remote server with SCPClient method def scp_file(self, src_path, des_path): if self.location == 'remote': try: self.scp = SCPClient(self.ssh.get_transport()) self.scp.put(src_path, recursive=True, remote_path=des_path) self.logger.info(str(src_path) + " kaynağının " + str(des_path) + " hedefine başarıyla kopyalandı") except Exception as e: self.logger.error(str(src_path) + " kaynağının " + str(des_path) + " hedefine kopyalanması sırasında hata oluştu! \n" + str(e)) else: ### copf file to local try: shutil.copy2(str(src_path), str(des_path)) self.logger.info(str(src_path) + " kaynağının " + str(des_path) + " hedefine başarıyla kopyalandı") except Exception as e: self.logger.error("kopyalama yaparken beklenmedik hata oluştu" + str(e)) def create_directory_local(self, dir_path): try: return os.makedirs(dir_path) except: raise def change_owner(self, full_path, user_name=None, group_name=None): try: shutil.chown(full_path, user_name, group_name) except: raise def file_group(self, full_path): try: st = os.stat(full_path) gid = st.st_uid return grp.getgrgid(gid)[0] except: raise def is_exist(self, full_path): try: return os.path.exists(full_path) except: raise
class MariaDbInstaller(object): def __init__(self, ssh_api, ssh_status): self.ssh_api = ssh_api self.ssh_status = ssh_status self.logger = Logger() self.data = None self.liderdb = None # Database configuration self.cmd_deb_frontend = "export DEBIAN_FRONTEND = \"noninteractive\"" self.db_debconf_pwd = "echo \'mariadb-server mysql-server/root_password password {0}\' | sudo debconf -set -selections" self.db_debconf_pwd_again = "echo \'mariadb-server mysql-server/root_password_again password {0}\' | sudo debconf -set -selections" self.cmd_db_install = "sudo apt-get install -y mariadb-server" self.cmd_db_dep = "sudo apt-get -f install" self.cmd_db_set_password = "******"SET PASSWORD FOR 'root'@'localhost' = PASSWORD('{0}')\";" # self.cmd_create_db = "sudo mysql -uroot -p{0} -e \'CREATE DATABASE {1} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci\'" self.cmd_create_db = "CREATE DATABASE {0} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci" # self.cmd_db_replace_bind_addr = "sudo sed -i \'s/^bind-address/#&/\' /etc/mysql/my.cnf" self.cmd_db_replace_bind_addr = "sudo sed -i \'s/^bind-address/#&/\' /etc/mysql/mariadb.conf.d/50-server.cnf" self.cmd_db_service = "sudo systemctl restart mysql.service" self.cmd_db_grant_privileges = "mysql -uroot -p{0} -e \"GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '{1}' WITH GRANT OPTION;\"" # self.cmd_create_config_table = "mysql -uroot -p{0} -e \"CREATE TABLE {1}.c_config (config_id INT NOT NULL, create_date VARCHAR(45) NOT NULL, modify_date VARCHAR(45) NULL, name VARCHAR(45) NOT NULL, value VARCHAR(45) NULL, PRIMARY KEY (config_id));\"" self.cmd_create_config_table = "CREATE TABLE c_config (config_id INT NOT NULL, create_date VARCHAR(45) NOT NULL, modify_date VARCHAR(45) NULL, name VARCHAR(45) NOT NULL, value LONGTEXT NULL, PRIMARY KEY (config_id));" def install(self, data): self.data = data config_manager = ConfigManager() cfg_data = config_manager.read() if self.ssh_status == "Successfully Authenticated": result_code = self.ssh_api.run_command(cfg_data["cmd_update"]) if result_code == 0: self.logger.info("Paket listesi güncellendi(apt update)") else: self.logger.error( "Paket listesi güncellenemdi, result_code: " + str(result_code)) # result_code = self.ssh_api.run_command(self.cmd_deb_frontend) # result_code = self.ssh_api.run_command(self.db_debconf_pwd.format(data["db_password"])) # result_code = self.ssh_api.run_command(self.db_debconf_pwd_again.format(data["db_password"])) result_code = self.ssh_api.run_command(self.cmd_db_install) if result_code == 0: self.logger.info("Mariadb paketi kuruldu") else: self.logger.error("Mariadb paketi kurulamadı, result_code: " + str(result_code)) result_code = self.ssh_api.run_command(self.cmd_db_dep) if result_code == 0: self.logger.info("Veritabanı bağımlılıkları kuruldu") else: self.logger.error( "Veritabanı bağımlılıkları kurulamadı, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( self.cmd_db_set_password.format(data['db_password'])) if result_code == 0: self.logger.info("Veritabanı parolası tanımlandı.") else: self.logger.error( "Veritabanı parolası tanımlanırken hata oluştu. Result Code: {0}" .format(result_code)) result_code = self.ssh_api.run_command(self.cmd_db_service) if result_code == 0: self.logger.info("Veritabanı servisi başlatıldı.") else: self.logger.error( "Veritabanı servisi başlatılamadı, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( self.cmd_db_replace_bind_addr) result_code = self.ssh_api.run_command(self.cmd_db_service) if result_code == 0: self.logger.info("Veritabanı servisi başlatıldı.") else: self.logger.error( "Veritabanı servisi başlatılamadı, result_code: " + str(result_code)) self.logger.info("---------->>>> " + str( self.cmd_db_grant_privileges.format(data["db_password"], data["db_password"]))) result_code = self.ssh_api.run_command( self.cmd_db_grant_privileges.format(data["db_password"], data["db_password"])) if result_code == 0: self.logger.info("Veritabanı grant yetkisi verildi") else: self.logger.error( "Veritabanı grant yetkisi verilemedi, result_code: " + str(result_code)) self.connect_db() self.create_liderdb() self.create_config_table() self.insert_to_config() else: self.logger.error( "Veritabanı sunucusuna bağlantı sağlanamadığı için kurulum yapılamadı. Lütfen bağlantı ayarlarını kotrol ediniz!" ) self.liderdb.close() def connect_db(self): try: self.liderdb = mysql.connector.connect( host=self.data["db_server_addr"], user="******", password=self.data["db_password"]) self.logger.info("Veritabanına bağlantı kuruldu") except Exception as e: self.logger.error( "Veritabanına bağlantı kurulurken hata oluştu. HATA:{0}". format(str(e))) def create_liderdb(self): try: create_database = self.liderdb.cursor() create_database.execute( self.cmd_create_db.format(self.data["db_name"])) create_database.close() self.logger.info("liderdb veritabanı oluşturuldu") except Exception as e: self.logger.error( "lidermysdb oluşturulurken hata oluştu. HATA:{0}".format( str(e))) def create_config_table(self): try: liderdb = mysql.connector.connect( user='******', password=self.data["db_password"], host=self.data["db_server_addr"], database=self.data["db_name"]) cursor = liderdb.cursor() cursor.execute(self.cmd_create_config_table) cursor.close() liderdb.close() self.logger.info("c_config tablosu oluşturuldu") except Exception as e: self.logger.error( "c_config tablosu oluşturulurken hata oluştu. HATA:{0}".format( str(e))) def insert_to_config(self): params = { "adAdminPassword": self.data['ad_user_pwd'], "adAdminUserName": self.data['ad_username'], "adDomainName": self.data['ad_domain_name'], "adHostName": self.data['ad_hostname'], "adIpAddress": self.data['ad_host'], "adPort": self.data['ad_port'], "adAdminUserFullDN": self.data['ad_user_dn'], "agentLdapBaseDn": "ou=Agents,{0}".format(self.base_dn_parse()), "agentLdapIdAttribute": "cn", "agentLdapJidAttribute": "uid", "agentLdapObjectClasses": "pardusDevice,device", "ahenkGroupLdapBaseDn": "ou=Agent,ou=Groups,{0}".format(self.base_dn_parse()), "alarmCheckReport": None, "cronIntervalEntrySize": None, "cronTaskList": None, "disableLocalUser": False, "domainType": "LDAP", "entrySizeLimit": None, "fileServerAgentFilePath": "{path}/agent-files/{agent}/".format( path=self.data['fs_agent_file_path'], agent="{0}"), "fileServerAgreementPath": "{0}/sample-agreement.txt".format(self.data['fs_agreement_path']), "fileServerHost": self.data['file_server'], "fileServerPassword": self.data['fs_username_pwd'], "fileServerPluginPath": "{path}/plugins/ahenk-{param1}_{param2}_amd64.deb".format( path=self.data['fs_plugin_path'], param1="{0}", param2="{1}"), "fileServerPort": 22, "fileServerProtocol": "SSH", "fileServerUsername": self.data['fs_username'], "groupLdapBaseDn": "ou=Groups,{0}".format(self.base_dn_parse()), "groupLdapObjectClasses": "groupOfNames", "hotDeploymentPath": None, "ldapAllowSelfSignedCert": False, "ldapEmailAttribute": "mail", "ldapMailNotifierAttributes": "cn, mail, departmentNumber, uid", "ldapPassword": self.data['l_admin_pwd'], "ldapPort": "389", "ldapRootDn": self.base_dn_parse(), "ldapSearchAttributes": "cn,objectClass,uid,liderPrivilege", "ldapServer": self.data['ldap_servers'], "ldapUseSsl": False, "ldapUsername": "******".format(self.base_dn_parse()), "liderLocale": "tr", "mailAddress": None, "mailCheckPolicyCompletionPeriod": None, "mailCheckTaskCompletionPeriod": None, "mailHost": None, "mailPassword": None, "mailSendOnPolicyCompletion": None, "mailSendOnTaskCompletion": None, "mailSmtpAuth": None, "mailSmtpConnTimeout": None, "mailSmtpPort": None, "mailSmtpSslEnable": None, "mailSmtpStartTlsEnable": None, "mailSmtpTimeout": None, "mailSmtpWriteTimeout": None, "roleLdapObjectClasses": "sudoRole", "taskManagerCheckFutureTask": None, "taskManagerFutureTaskCheckPeriod": None, "userAuthorizationEnabled": True, "userGroupLdapBaseDn": "ou=User,ou=Groups,{0}".format(self.base_dn_parse()), "userLdapBaseDn": "ou=Users,{0}".format(self.base_dn_parse()), "userLdapObjectClasses": "pardusAccount,pardusLider", "userLdapPrivilegeAttribute": "liderPrivilege", "userLdapRolesDn": "ou=Role,ou=Groups,{0}".format(self.base_dn_parse()), "userLdapUidAttribute": "uid", "xmppAllowSelfSignedCert": False, "xmppHost": self.data['e_hosts'], "xmppMaxRetryConnectionCount": 5, "xmppPacketReplayTimeout": 10000, "xmppPassword": self.data['lider_user_pwd'], "xmppPingTimeout": 300, "xmppPort": 5222, "xmppPresencePriority": 1, "xmppResource": "Smack", "xmppServiceName": self.data['e_service_name'], "xmppUseCustomSsl": False, "xmppUseSsl": False, "xmppUsername": "******" } try: # date = datetime.datetime.strptime('my date', "%b %d %Y %H:%M") liderdb = mysql.connector.connect( user='******', password=self.data["db_password"], host=self.data["db_server_addr"], database=self.data["db_name"]) cursor = liderdb.cursor() query = "INSERT INTO c_config (config_id, create_date, modify_date, name, value) VALUES (%s, %s, %s, %s, %s)" values = ("1", time.strftime('%Y-%m-%d %H:%M:%S'), None, "liderConfigParams", json.dumps(params)) cursor.execute(query, values) liderdb.commit() self.logger.info( "liderahenk konfigürasyonlar veritabanına eklendi") except Exception as e: self.logger.error( "liderahenk konfigürasyonlar veritabanına eklenirken hata oluştu. HATA:{0}" .format(str(e))) def base_dn_parse(self): ### split for get data['base_dn']: liderahenk.org #BASECN and #BASEDN parse_dn = self.data["l_base_dn"].split('.') dn_list = [] for dn in parse_dn: message = 'dc=' + str(dn) + ',' dn_list.append(message) base_dn = ''.join(str(x) for x in dn_list) base_dn = base_dn.strip(',') return base_dn
class EjabberInstaller(object): def __init__(self, ssh_api, ssh_status): self.ssh_api = ssh_api self.ssh_status = ssh_status self.logger = Logger() self.config_manager = ConfigManager() self.jabberd_template_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/ejabberd_temp.yml') self.jabberd_out_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../dist/ejabberd.yml') def install(self, data): config_manager = ConfigManager() # configuration ejabberd.yml base_dn = self.base_dn_parse(data) ldap_root_dn = "cn=admin," + str( base_dn) #cn=admnin,dc=liderahenk,dc=org repo_key = data["repo_key"] repo_key = repo_key.rsplit("/")[-1] cfg_data = config_manager.read() conf_data = { "#HOST": data['e_hosts'], "#LDAP_SERVER": data['ldap_servers'], "#LDAP_ROOT_DN": ldap_root_dn, "#LDAP_ROOT_PWD": data['l_admin_pwd'], "#LDAP_BASE_DN": base_dn, "#SERVICE_NAME": data['e_service_name'] } self.f_ejabberd_yml = open(self.jabberd_template_path, 'r+') jabber_data = self.f_ejabberd_yml.read() self.logger.info("Ejabberd sunucu kurulumu için veriler okundu") txt = self.config_manager.replace_all(jabber_data, conf_data) self.f_ejabberd_yml_out = open(self.jabberd_out_path, 'w+') self.f_ejabberd_yml_out.write(txt) self.f_ejabberd_yml.close() self.f_ejabberd_yml_out.close() self.logger.info("ejabberd.yml dosyası oluşturuldu") #run commands of ejabberd if self.ssh_status == "Successfully Authenticated" or data[ 'location'] == 'local': result_code = self.ssh_api.run_command( cfg_data["cmd_soft_properties"]) if result_code == 0: self.logger.info("software-properties-common paketi kuruldu") else: self.logger.error( "software-properties-common paketi kurulamadı, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_liderahenk_repo_key"].format( data["repo_key"], repo_key)) if result_code == 0: self.logger.info("Lider Ahenk repo key dosyası indirildi") else: self.logger.error( "Lider Ahenk repo key dosyası indirilemedi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_liderahenk_repo_add"].format(data["repo_addr"])) if result_code == 0: self.logger.info("Lider Ahenk repo adresi eklendi") else: self.logger.error( "Lider Ahenk repo adresi eklenemedi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_update"]) if result_code == 0: self.logger.info("Paket listesi güncellendi(apt update)") else: self.logger.error( "Paket listesi güncellenemdi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_ejabberd_install"]) if result_code == 0: self.logger.info("Ejabberd paketi kuruldu") else: self.logger.error("Ejabberd paketi kurulamadı, result_code: " + str(result_code)) self.ssh_api.scp_file(self.jabberd_out_path, cfg_data["jabberd_des_path"]) if result_code == 0: self.logger.info( "Ejabberd konfigürasyon dosyası sunucuya kopyalandı") else: self.logger.error( "Ejabberd konfigürasyon dosyası sunucuya kopyalandı") self.ssh_api.run_command(cfg_data["cmd_cp_conf"].format( cfg_data["jabberd_des_path"], cfg_data["jabberd_conf_path"])) result_code = self.ssh_api.run_command( cfg_data["cmd_jabberd_start"].format( cfg_data["cmd_bin_ejabberd_path"])) if result_code == 0: self.logger.info("Ejabberd servisi başlatıldı") else: self.logger.error( "Ejabberd servisi başlatılamadı, result_code: " + str(result_code)) print("---------->>>> Start : %s" % time.ctime()) time.sleep(10) print("-------->>>>> End : %s" % time.ctime()) result_code = self.ssh_api.run_command( cfg_data["cmd_register"].format( cfg_data["cmd_bin_ejabberd_path"], data["e_username"], data["e_service_name"], data["e_user_pwd"])) if result_code == 0: self.logger.info("{0} kullanıcısı kaydedildi".format( data["e_username"])) else: self.logger.error( "{0} kullanıcısı kaydedilemedi, result_code: ".format( data["e_username"]) + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_register"].format( cfg_data["cmd_bin_ejabberd_path"], data["lider_username"], data["e_service_name"], data["lider_user_pwd"])) if result_code == 0: self.logger.info("{0} kullanıcısı kaydedildi".format( data["lider_username"])) else: self.logger.error( "{0} kullanıcısı kaydedilemedi, result_code: ".format( data["lider_username"]) + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_srg_create"].format( cfg_data["cmd_bin_ejabberd_path"], data["e_service_name"])) if result_code == 0: self.logger.info("shared roster grubu oluşturuldu.") else: self.logger.error( "shared roster grubu oluşturulamadı, resuşt_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_srg_user_add"].format( cfg_data["cmd_bin_ejabberd_path"], data["e_service_name"])) if result_code == 0: self.logger.info("Kullanıcılar shared roster grubuna eklendi") else: self.logger.error( "Kullanıcılar shared roster grubuna eklenemedi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_jabberd_restart"].format( cfg_data["cmd_bin_ejabberd_path"])) if result_code == 0: self.logger.info("Ejabberd servisi başlatıldı") else: self.logger.error( "Ejabberd servisi başlatılamadı, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_jabberd_status"].format( cfg_data["cmd_bin_ejabberd_path"])) if result_code == 0: self.logger.info("Ejabberd servisi çalışıyor") else: self.logger.error("Ejabberd servisi çalışmıyor") self.ssh_api.run_command(cfg_data["cmd_hold_ejabberd"]) self.ssh_api.run_command( cfg_data["cmd_copy_ejabberd_service"].format( cfg_data["cmd_bin_ejabberd_path"])) self.logger.info( "ejabberd.service dosyası /etc/systemd/system/ dizinine kopyalandı" ) result_code = self.ssh_api.run_command( cfg_data["cmd_system_reload"]) result_code = self.ssh_api.run_command( cfg_data["cmd_enable_ejabberd_service"]) if result_code == 0: self.logger.info("Ejabberd servis olarak ayarlandı.") else: self.logger.error("Ejabberd servis olarak ayarlanamadı.") else: # print("bağlantı sağlanamadığı için kurulum yapılamadı..") self.logger.error( "XMPP sunucusuna bağlantı sağlanamadığı için kurulum yapılamadı. Lütfen bağlantı ayarlarını kotrol ediniz!" ) def base_dn_parse(self, data): ### split for get data['base_dn']: liderahenk.org #BASECN and #BASEDN parse_dn = data["l_base_dn"].split('.') dn_list = [] for dn in parse_dn: message = 'dc=' + str(dn) + ',' dn_list.append(message) base_dn = ''.join(str(x) for x in dn_list) base_dn = base_dn.strip(',') return base_dn
class LiderConsoleInstaller(object): def __init__(self, ssh_api, ssh_status): self.ssh_api = ssh_api self.ssh_status = ssh_status self.logger = Logger() self.util = Util() self.config_manager = ConfigManager() self.lider_conf_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/tr.org.liderahenk.cfg') self.db_conf_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/tr.org.liderahenk.datasource.cfg') self.lider_conf_out_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../dist/tr.org.liderahenk.cfg') self.db_conf_out_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../dist/tr.org.liderahenk.datasource.cfg') def install(self, data): repo_key = data["repo_key"] repo_key = repo_key.rsplit("/")[-1] if self.ssh_status == "Successfully Authenticated" or data[ 'location'] == 'local': cfg_data = self.config_manager.read() result_code = self.ssh_api.run_command( cfg_data["cmd_soft_properties"]) if result_code == 0: self.logger.info("software-properties-common paketi kuruldu") else: self.logger.error( "software-properties-common paketi kurulamadı, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_liderahenk_repo_key"].format( data["repo_key"], repo_key)) if result_code == 0: self.logger.info("Lider Ahenk repo key dosyası indirildi") else: self.logger.error( "Lider Ahenk repo key dosyası indirilemedi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_liderahenk_repo_add"].format(data["repo_addr"])) if result_code == 0: self.logger.info("Lider Ahenk repo adresi eklendi") else: self.logger.error( "Lider Ahenk repo adresi eklenemedi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_update"]) if result_code == 0: self.logger.info("Paket listesi güncellendi(apt update)") else: self.logger.error( "Paket listesi güncellenemdi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_lider_console_install"]) if result_code == 0: self.logger.info("Lider Console paketi kurulumu yapıldı") else: self.logger.error( "Lider Console paketi kurulamadı, result_code: " + str(result_code)) else: self.logger.error( "Lider Arayüz makinesine bağlantı sağlanamadığı için kurulum yapılamadı. Lütfen bağlantı ayarlarını kontrol ediniz!" )
class LiderInstaller(object): def __init__(self, ssh_api, ssh_status): self.ssh_api = ssh_api self.ssh_status = ssh_status self.logger = Logger() self.util = Util() self.config_manager = ConfigManager() self.lider_conf_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/tr.org.liderahenk.cfg') self.db_conf_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/tr.org.liderahenk.datasource.cfg') self.lider_conf_out_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../dist/tr.org.liderahenk.cfg') self.db_conf_out_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../dist/tr.org.liderahenk.datasource.cfg') self.tomcat_service_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/tomcat.service') self.application_properties_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/lider.properties') self.application_properties_out_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../dist/lider.properties') self.lider_web_url = "http://liderahenk.org/downloads/ROOT.war" self.tomcat_tar_url = "http://liderahenk.org/downloads/apache-tomcat-9.0.36.tar.gz" self.dist_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../dist') self.liderv2_app_properties_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../dist/liderv2/src/main/resources/lider.properties') self.lider_war_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/ROOT.war') self.tomcat_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/apache-tomcat-9.0.36.tar.gz') def install(self, data): repo_key = data["repo_key"] repo_key = repo_key.rsplit("/")[-1] if self.ssh_status == "Successfully Authenticated": cfg_data = self.config_manager.read() self.configure_lider_cfg(data) self.configure_db_cfg(data) self.configure_app_properties(data) result_code = self.ssh_api.run_command( cfg_data["cmd_soft_properties"]) if result_code == 0: self.logger.info("software-properties-common paketi kuruldu") else: self.logger.error( "software-properties-common paketi kurulamadı, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_liderahenk_repo_key"].format( data["repo_key"], repo_key)) if result_code == 0: self.logger.info("Lider Ahenk repo key dosyası indirildi") else: self.logger.error( "Lider Ahenk repo key dosyası indirilemedi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( cfg_data["cmd_liderahenk_repo_add"].format(data["repo_addr"])) if result_code == 0: self.logger.info("Lider Ahenk repo adresi eklendi") else: self.logger.error( "Lider Ahenk repo adresi eklenemedi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command(cfg_data["cmd_update"]) if result_code == 0: self.logger.info("Paket listesi güncellendi(apt update)") else: self.logger.error( "Paket listesi güncellenemdi, result_code: " + str(result_code)) result_code = self.ssh_api.run_command( "sudo apt-get install openjdk-8-jdk-headless -y") if result_code == 0: self.logger.info("openjdk-8 paketi başarıyla kuruldu") else: self.logger.error("openjdk-8 paketi kurulamadı") result_code = self.ssh_api.run_command("sudo groupadd tomcat") if result_code == 0: self.logger.info("tomcat grubu oluşturuldu") result_code = self.ssh_api.run_command( "sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat") if result_code == 0: self.logger.info( "tomcat kullanıcısı oluşturuldu ve ev dizini ayarlandı.") # result_code = self.ssh_api.run_command("wget {0}".format(self.tomcat_tar_url)) # if result_code == 0: # self.logger.info("tomcat başarıyla indirildi.") # else: # self.logger.error("tomcat indirilirken hata oluştu") self.ssh_api.scp_file(self.tomcat_path, '/tmp') result_code = self.ssh_api.run_command("sudo mkdir /opt/tomcat") self.logger.info("tomcat dizini oluşturuldu") result_code = self.ssh_api.run_command( "sudo tar xf /tmp/apache-tomcat-*tar.gz -C /opt/tomcat --strip-components=1" ) result_code = self.ssh_api.run_command( "sudo chgrp -R tomcat /opt/tomcat") result_code = self.ssh_api.run_command( "sudo chmod -R g+r /opt/tomcat/conf") result_code = self.ssh_api.run_command( "sudo chmod g+x /opt/tomcat/conf") result_code = self.ssh_api.run_command( "sudo chown -R tomcat /opt/tomcat/webapps/ /opt/tomcat/work/ /opt/tomcat/temp/ /opt/tomcat/logs/" ) self.ssh_api.scp_file(self.tomcat_service_path, '/tmp/') result_code = self.ssh_api.run_command( "sudo cp /tmp/tomcat.service /etc/systemd/system/") result_code = self.ssh_api.run_command( "sudo systemctl daemon-reload") result_code = self.ssh_api.run_command( "sudo systemctl enable tomcat") result_code = self.ssh_api.run_command( "sudo systemctl start tomcat") self.logger.info("tomcat konfigürastonu tamamlandı") self.ssh_api.scp_file(self.application_properties_out_path, '/tmp') result_code = self.ssh_api.run_command("sudo mkdir -p /etc/lider") result_code = self.ssh_api.run_command( "sudo cp /tmp/lider.properties /etc/lider/") # result_code = self.ssh_api.run_command("wget {0}".format(self.lider_web_url)) # if result_code == 0: # self.logger.info("ROOT.war başarıyla indirildi.") # else: # self.logger.error("ROOT.war indirilirken hata oluştu") self.ssh_api.scp_file(self.lider_war_path, '/tmp') result_code = self.ssh_api.run_command( "sudo cp /tmp/ROOT.war /opt/tomcat/webapps/") result_code = self.ssh_api.run_command( "sudo chown tomcat:tomcat /opt/tomcat/webapps/ROOT.war") # result_code = self.ssh_api.run_command("sudo systemctl restart tomcat.service") result_code = self.ssh_api.run_command( "sudo apt-get install guacd -y") if result_code == 0: self.logger.info("Uzak masaüstü sunucusu yapılandırıldı") else: self.logger.error( "Uzak masaüstü sunucusu yapılandırılırken hata oluştu. guacd uygulaması kurulamadı" ) # filer server configuration self.ssh_api.run_command("mkdir -p {0}/agent-files".format( data["fs_agent_file_path"])) self.ssh_api.run_command( "sudo chown {0}:{0} {1}/agent-files".format( data['fs_username'], data['fs_agent_file_path'])) self.ssh_api.run_command("sudo apt-get install -y sshpass rsync") self.logger.info("lider kurulumu tamamlandı") else: self.logger.error( "LİDER sunucusuna bağlantı sağlanamadığı için kurulum yapılamadı. Lütfen bağlantı ayarlarını kotrol ediniz!" ) def configure_lider_cfg(self, data): l_base_dn = self.base_dn_parse(data) l_admin_dn = "cn=admin," + str(l_base_dn) lider_data = { "#LDAP_SERVER": data['ldap_servers'], "#LDAP_ADMIN_DN": l_admin_dn, "#LDAP_ADMIN_PWD": data['l_admin_pwd'], "#LDAP_ROOT_DN": l_base_dn, "#XMPP_SERVER": data['e_hosts'], "#LIDER_USERNAME": data['lider_username'], "#XMPP_USER_PWD": data['lider_user_pwd'], "#XMPP_SERVICE_NAME": data['e_service_name'], "#LDAP_BASE_DN": l_base_dn, "#FILE_SERVER": data['file_server'], "#FS_USERNAME": data['fs_username'], "#FS_PASSWORD": data['fs_username_pwd'], "#PLUGIN_PATH": data['fs_plugin_path'], "#AGREEMENT_PATH": data['fs_agreement_path'], "#AGENT_FILE_PATH": data['fs_agent_file_path'], "#AD_DOMAIN_NAME": data["ad_domain_name"], "#AD_HOSTNAME": data["ad_hostname"], "#AD_HOST": data["ad_host"], "#AD_USER_PWD": data["ad_user_pwd"], "#AD_USER_NAME": data["ad_username"], "#AD_PORT": data["ad_port"] } self.f_lider = open(self.lider_conf_path, 'r+') lider_text = self.f_lider.read() txt = self.config_manager.replace_all(lider_text, lider_data) self.f_lider_out = open(self.lider_conf_out_path, 'w+') self.f_lider_out.write(str(txt)) self.f_lider.close() self.f_lider_out.close() self.logger.info("tr.org.liderahenk.cfg dosyası oluşturuldu") def configure_db_cfg(self, data): db_data = { "#DBADDRESS": data['db_server_addr'], "#DBDATABASE": data['db_name'], "#DBUSERNAME": data['db_username'], "#DBPASSWORD": data['db_password'] } self.f_db = open(self.db_conf_path, 'r+') db_text = self.f_db.read() txt = self.config_manager.replace_all(db_text, db_data) self.f_db_out = open(self.db_conf_out_path, 'w+') self.f_db_out.write(str(txt)) self.f_db.close() self.f_db_out.close() self.logger.info("tr.org.datasource.cfg dosyası oluşturuldu") def base_dn_parse(self, data): ### split for get data['base_dn']: liderahenk.org #BASECN and #BASEDN parse_dn = data["l_base_dn"].split('.') dn_list = [] for dn in parse_dn: message = 'dc=' + str(dn) + ',' dn_list.append(message) base_dn = ''.join(str(x) for x in dn_list) base_dn = base_dn.strip(',') return base_dn def configure_app_properties(self, data): db_server = data["db_server_addr"] # if data['ip'] == db_server: # db_server = "127.0.0.1" db_data = { "##DATABASEADDRESS##": db_server, "##DATABASENAME##": data['db_name'], "##DATABASEUSERNAME##": data['db_username'], "##DATABASAPASSWORD##": data['db_password'] } self.f_db = open(self.application_properties_path, 'r+') db_text = self.f_db.read() txt = self.config_manager.replace_all(db_text, db_data) self.f_db_out = open(self.application_properties_out_path, 'w+') self.f_db_out.write(str(txt)) self.f_db.close() self.f_db_out.close() self.logger.info("application properties dosyası oluşturuldu")
class InstallManager(object): def __init__(self): super(InstallManager, self).__init__() self.util = Util() self.ssh_status = "" self.logger = Logger() self.config_maneger = ConfigManager() self.liderahenk_data_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'dist/liderahenk.json') self.liderldap_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../dist/lider_ldap.json') def install_mariadb(self, data): db_installer = MariaDbInstaller(self.util, self.ssh_status) self.logger.info( "======>>>>> Veritabanı sunucu kurulumuna başlanıyor <<<<<======") db_installer.install(data) def install_ejabberd(self, data): ejabberd_installer = EjabberInstaller(self.util, self.ssh_status) self.logger.info( "======>>>>> Ejabberd sunucu kurulumuna başlanıyor. <<<<<======") ejabberd_installer.install(data) def install_ldap(self, data): ldap_installer = OpenLdapInstaller(self.util, self.ssh_status) self.logger.info( "======>>>>> OpenLDAP sunucu kurulumuna başlanıyor. <<<<<======") ldap_installer.install(data) def install_lider(self, data): lider_installer = LiderInstaller(self.util, self.ssh_status) self.logger.info( "======>>>>> Lider sunucu Kurulumuna başlanıyor. <<<<<======") lider_installer.install(data) def install_lider_console(self, data): lider_console_installer = LiderConsoleInstaller( self.util, self.ssh_status) self.logger.info( "======>>>>> Lider Arayüz Kurulumuna başlanıyor. <<<<<======") lider_console_installer.install(data) def install_ahenk(self, data): ahenk_installer = AhenkInstaller(self.util, self.ssh_status) self.logger.info( "======>>>>> Ahenk Kurulumuna başlanıyor. <<<<<======") ahenk_installer.install(data) def ssh_connect(self, data): ssh_status = self.util.connect(data) self.ssh_status = ssh_status if self.ssh_status == "Successfully Authenticated": return True else: return False def ssh_disconnect(self): self.util.disconnect() # self.logger.info("installation successfull") def start_install(self): # copy installer.log file with open(self.liderahenk_data_path) as f: data = json.load(f) self.logger.info("liderahenk.json dosyasından veriler okunuyor") if data['location'] == 'remote': self.ssh_connect(data) if data['db_install'] is True: self.install_mariadb(data) if data['ldap_install'] is True: self.install_ldap(data) if data['ejabberd_install'] is True: self.install_ejabberd(data) if data['lider_install'] is True: self.install_lider(data) if data['location'] == 'remote': self.ssh_disconnect() else: self.logger.info("Lider Sunucu kurulumu tamamlandı") self.logger.info("installation successfull")
class ConfigManager(object): """ method reading and writing from the configuration file """ def __init__(self): self.yaml = YAML() self.yaml.indent(mapping=4) self.logger = Logger() self.installer_config_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../../conf/installer_config.yml') if not os.path.exists( os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../dist')): os.makedirs( os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../dist')) def read(self): with open(self.installer_config_path, 'r') as stream: try: return yaml.load(stream) # return self.yaml.load(stream) except Exception as e: self.logger.error("Veriler okunurken hata oluştu: " + str(e)) return None def read_temp_yml_file(self, path): with open(path, 'r') as stream: try: return self.yaml.load(stream) except Exception as e: self.logger.error(e) return None def write_to_yml(self, data, path): with io.open(path, 'w', encoding='utf8') as outfile: #self.yaml.dump(data, outfile, default_flow_style=False, allow_unicode=True) self.yaml.dump(data, outfile) def replace_all(self, text, dic): try: for i, j in dic.items(): text = text.replace(i, j) self.logger.info("Dosya güncellenmesi başarıyla tamamlandı") return text except Exception as e: self.logger.error( "Dosya güncellenmesi sırasında beklenmedik bir hata ile karşılaşıldı\n" + str(e)) def date_format(self): date_now = datetime.now().strftime('%Y-%m-%d %H:%M:%S') date_parse = date_now.split(" ") date_list = [] for line in date_parse: date_line = line + "-" date_list.append(date_line) date = ''.join(str(x) for x in date_list) date = date.strip('-') return date