def _str_py_post(self, pdata, headers): if 'Content-Type' in headers: if headers['Content-Type'].find('application/jose') != -1 \ or headers['Content-Type'].find('application/josn') != -1: if type(pdata) == dict: pdata = json.dumps(pdata) if type(pdata) == str: pdata = pdata.encode('utf-8') return pdata return public.url_encode(pdata)
def start(self, puri, document_root, last_path=''): ''' @name 开始处理PHP请求 @author hwliang<2020-07-11> @param puri string(URI地址) @return socket or Response ''' if puri in ['/', '', None]: puri = 'index.php' if puri[0] == '/': puri = puri[1:] self.document_root = document_root self.last_path = last_path filename = document_root + puri #如果是PHP文件 if puri[-4:] == '.php': if request.path.find('/phpmyadmin/') != -1: ikey = 'pma_php_version' self.php_version = cache.get(ikey) if not self.php_version: php_version = self.get_phpmyadmin_phpversion() php_versions = self.check_phpmyadmin_phpversion() if not php_versions: if php_versions == False: return Resp( 'Phpmyadmin is not installed, or support for phpMyAdmin4.6 has been discontinued due to security issues, uninstall and install other secure versions in the software store!' ) else: return Resp('phpmyadmin is not installed') if not php_version or not php_version in php_versions: php_version = php_versions self.php_version = self.get_php_version(php_version) if not self.php_version: php_version = self.check_phpmyadmin_phpversion() self.php_version = self.get_php_version(php_version) if not php_version: return Resp( 'No supported PHP version found: {}'.format( php_versions)) if not self.php_version in php_versions: self.php_version = self.get_php_version(php_versions) if not self.php_version: return Resp( 'No supported PHP version found: {}'.format( php_versions)) cache.set(ikey, self.php_version, 1) if request.method == 'POST': #登录phpmyadmin if puri in ['index.php', '/index.php']: content = public.url_encode(request.form.to_dict()) if not isinstance(content, bytes): content = content.encode() self.re_io = StringIO(content) username = request.form.get('pma_username') if username: password = request.form.get('pma_password') if not self.write_pma_passwd(username, password): return Resp('Phpmyadmin is not installed') if puri in ['logout.php', '/logout.php']: self.write_pma_passwd(None, None) else: src_path = '/www/server/panel/adminer' dst_path = '/www/server/adminer' if os.path.exists(src_path): if not os.path.exists(dst_path): os.makedirs(dst_path) public.ExecShell("\cp -arf {}/* {}/".format( src_path, dst_path)) public.ExecShell("chown -R www:www {}".format(dst_path)) public.ExecShell("chmod -R 700 {}".format(dst_path)) public.ExecShell("rm -rf {}".format(src_path)) if not os.path.exists(dst_path + '/index.php'): return Resp( "The AdMiner file is missing. Please try again after the [Fix] panel on the first page!" ) ikey = 'aer_php_version' self.php_version = cache.get(ikey) if not self.php_version: self.php_version = self.get_php_version(None) cache.set(ikey, self.php_version, 10) if not self.php_version: return Resp('没有找到可用的PHP版本') #文件是否存在? if not os.path.exists(filename): return abort(404) #发送到FPM try: return self.request_php(puri) except Exception as ex: if str(ex).find('No such file or directory') != -1: return Resp( 'Specify PHP version: {}, not started, or unable to connect!' .format(self.php_version)) return Resp(str(ex)) if not os.path.exists(filename): return abort(404) #如果是静态文件 return send_file(filename)
def start(self, puri, document_root, last_path=''): ''' @name 开始处理PHP请求 @author hwliang<2020-07-11> @param puri string(URI地址) @return socket or Response ''' if puri in ['/', '', None]: puri = 'index.php' if puri[0] == '/': puri = puri[1:] self.document_root = document_root self.last_path = last_path filename = document_root + puri #如果是PHP文件 if puri[-4:] == '.php': if request.path.find('/phpmyadmin/') != -1: ikey = 'pma_php_version' self.php_version = cache.get(ikey) if not self.php_version: php_version = self.get_phpmyadmin_phpversion() php_versions = self.check_phpmyadmin_phpversion() if not php_versions: if php_versions == False: return Resp( '因安全问题,已停止对phpMyAdmin4.6的支持,到软件商店卸载并安装其它安全版本!') else: return Resp('未安装phpmyadmin') if not php_version or not php_version in php_versions: php_version = php_versions self.php_version = self.get_php_version(php_version) if not self.php_version: php_version = self.check_phpmyadmin_phpversion() self.php_version = self.get_php_version(php_version) if not php_version: return Resp( '没有找到支持的PHP版本: {}'.format(php_versions)) if not self.php_version in php_versions: self.php_version = self.get_php_version(php_versions) if not self.php_version: return Resp( '没有找到支持的PHP版本: {}'.format(php_versions)) cache.set(ikey, self.php_version, 1) if request.method == 'POST': #登录phpmyadmin if puri in ['index.php', '/index.php']: content = public.url_encode(request.form.to_dict()) if not isinstance(content, bytes): content = content.encode() self.re_io = StringIO(content) username = request.form.get('pma_username') if username: password = request.form.get('pma_password') if not self.write_pma_passwd(username, password): return Resp('未安装phpmyadmin') if puri in ['logout.php', '/logout.php']: self.write_pma_passwd(None, None) else: src_path = '/www/server/panel/adminer' dst_path = '/www/server/adminer' if os.path.exists(src_path): if not os.path.exists(dst_path): os.makedirs(dst_path) public.ExecShell("\cp -arf {}/* {}/".format( src_path, dst_path)) public.ExecShell("chown -R www:www {}".format(dst_path)) public.ExecShell("chmod -R 700 {}".format(dst_path)) public.ExecShell("rm -rf {}".format(src_path)) if not os.path.exists(dst_path + '/index.php'): return Resp("adminer文件缺失,请在首页[修复]面板后重试!") ikey = 'aer_php_version' self.php_version = cache.get(ikey) if not self.php_version: self.php_version = self.get_php_version(None) cache.set(ikey, self.php_version, 10) if not self.php_version: return Resp('没有找到可用的PHP版本') #文件是否存在? if not os.path.exists(filename): return abort(404) #发送到FPM try: return self.request_php(puri) except Exception as ex: if str(ex).find('No such file or directory') != -1: return Resp('指定PHP版本: {},未启动,或无法连接!'.format( self.php_version)) return Resp(str(ex)) if not os.path.exists(filename): return abort(404) #如果是静态文件 return send_file(filename)