generation.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:service.vpn.manager 作者: Zomboided 项目源码 文件源码
def generateSecureVPN():
    # Can't use a template as SecureVPN use multiple everything. 
    # Copy the file to the target directory and strip it of user keys
    existing_profiles = glob.glob(getUserDataPath("providers/SecureVPN" + "/*.ovpn"))
    for connection in existing_profiles:
        xbmcvfs.delete(connection)
    # Get the list from the provider data directory
    profiles = getProfileList("SecureVPN")
    destination_path = getProviderPath("SecureVPN" + "/")   
    for profile in profiles:
        shortname = profile[profile.index("SecureVPN")+10:]
        shortname = shortname[:shortname.index(".")]
        proto = "(UDP)"
        filename = shortname + " " + proto + ".ovpn"
        profile_file = open(profile, 'r')
        output_file = open(destination_path + filename, 'w')
        profile_contents = profile_file.readlines()
        profile_file.close()
        output = ""
        i = 0
        write = True;
        for line in profile_contents:
            line = line.strip(' \t\n\r')
            if not (line == "" or line.startswith("#")) :
                if "<key>" in line or "<cert>" in line: write = False
                if "</key>" in line: 
                    write = True
                    line = "key #USERKEY"
                if "</cert>" in line:
                    write = True
                    line = "cert #USERCERT"
                if write : output_file.write(line + "\n")
            i = i + 1    
        output_file.close()
    generateMetaData("SecureVPN", MINIMUM_LEVEL)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号