importloggingimportosimportplatformaspyplatformimportsignalimportsubprocess__version__='2.2.6'# Global stateproduct=None""" Custom product name """config=None""" Configuration dict"""users=None""" Users list for auth plugin """version=None""" Ajenti version """platform=None""" Current platform """platform_unmapped=None""" Current platform without "Ubuntu is Debian"-like mapping """platform_string=None""" Human-friendly platform name """server=None""" Web server """debug=False""" Debug mode """dev=False""" Dev mode """context=Noneedition='vanilla'master=Trueplugin_providers=[]sessions={}python_version=None__all__=['config','platform','platform_string','platform_unmapped','version','server','debug','init','exit','restart','python_version']defdetect_version():return__version__## No git tag yet for ajenti 2# p = subprocess.Popen(# 'git describe --tags 2> /dev/null',# shell=True,# stdout=subprocess.PIPE# )# if p.wait() != 0:# return __version__# return p.stdout.read().strip(b'\n ').decode()defdetect_python():returnpyplatform.python_version()defdetect_platform():base_mapping={'gentoo base system':'gentoo','centos linux':'centos','mandriva linux':'mandriva','elementary os':'ubuntu','trisquel':'ubuntu','linaro':'ubuntu','linuxmint':'ubuntu','amazon':'ubuntu','redhat enterprise linux':'rhel','red hat enterprise linux server':'rhel','oracle linux server':'rhel','fedora':'rhel','olpc':'rhel','xo-system':'rhel','kali linux':'debian',}platform_mapping={'ubuntu':'debian','rhel':'centos',}ifhasattr(pyplatform,'mac_ver')andpyplatform.mac_ver()[0]!='':return'osx','osx'ifpyplatform.system()!='Linux':res=pyplatform.system().lower()returnres,resdist=''(major,minor,_)=pyplatform.python_version_tuple()major=int(major)minor=int(minor)if(major*10+minor)>=36:importdistrodist=distro.linux_distribution()[0].split()[0]elif(major*10+minor)>=26:dist=pyplatform.linux_distribution()[0]else:dist=pyplatform.dist()[0]ifdist=='':ifos.path.exists('/etc/os-release'):release=open('/etc/os-release').read()if'Arch Linux'inrelease:dist='arch'ifdist=='':ifos.path.exists('/etc/system-release'):release=open('/etc/system-release').read()if'Amazon Linux AMI'inrelease:dist='centos'ifdist=='':try:dist=subprocess.check_output(['strings','-4','/etc/issue']).split()[0].strip().decode()exceptsubprocess.CalledProcessErrorase:dist='unknown'res=dist.strip(' \'"\t\n\r').lower()ifresinbase_mapping:res=base_mapping[res]res_mapped=resifresinplatform_mapping:res_mapped=platform_mapping[res]returnres,res_mappeddefdetect_platform_string():try:returnsubprocess.check_output(['lsb_release','-sd']).strip().decode()exceptsubprocess.CalledProcessErrorase:returnsubprocess.check_output(['uname','-mrs']).strip().decode()exceptFileNotFoundError:logging.warning('Please install lsb_release to detect the platform!')returnsubprocess.check_output(['uname','-mrs']).strip().decode()
[docs]definit():importajaj.version=detect_version()ifaj.platformisNone:aj.platform_unmapped,aj.platform=detect_platform()else:logging.warning('Platform ID was enforced by commandline!')aj.platform_unmapped=aj.platformaj.platform_string=detect_platform_string()aj.python_version=detect_python()