loco.py 文件源码

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

项目:loco 作者: kootenpv 项目源码 文件源码
def public_port_exists(rline, authorized_keys_file, restrictions, public_key, port):
    port = str(port)
    new_restrictions = []
    replaced = False
    for restriction in restrictions.split("\n"):
        if public_key in restriction:
            if ":" + port + '"' not in restriction:
                new_opens = 'no-pty,permitopen="localhost:{0}",permitopen="127.0.0.1:{0}",'
                restriction = restriction.replace("no-pty,", new_opens.format(port))
                replaced = True
            else:
                print("public_key and port already exists in", authorized_keys_file)
                return
        new_restrictions.append(restriction)
    print("Adding key+port rule to file")
    if replaced:
        result = "\n".join(new_restrictions)
    else:
        result = rline
    with open(authorized_keys_file, "w") as f:
        f.write(result + "\n")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号