# Path: fabgis/utilities.py
# def append_if_not_present(filename, text, use_sudo=False):
#     """Append to a file if an equivalent line is not already there.
#     :param filename: Name of file to append to.
#     :type filename: str
# 
#     :param text: Text to append.
#     :type text: str
# 
#     :param use_sudo: Run the command as sudo
#     :type use_sudo: bool
#     """
#     if not contains(filename, text):
#         append(filename, text, use_sudo=use_sudo)


from getpass import getpass
from fabric.api import cd, fastprint, prompt
from fabric.contrib.files import contains, exists, append, sed
from fabric.colors import red
from fabric.api import env, task, sudo, local, reboot
from fabric.operations import run
from .utilities import append_if_not_present
import fabtools
    fabtools.deb.update_index(quiet=True)

    # Set up ufw and mosh
    fabtools.require.deb.package('ufw')
    setup_mosh()

    sudo('ufw default deny incoming')
    sudo('ufw default allow outgoing')
    sudo('ufw allow 8697')
    sudo('ufw allow http')
    sudo('ufw allow ssh')
    sudo('ufw allow mosh')
    sudo('ufw allow 25')  # mail
    #Irc freenode
    sudo('ufw allow from 127.0.0.1/32 to 78.40.125.4 port 6667')
    sudo('ufw allow from 127.0.0.1/32 to any port 22')
    sudo('ufw allow 443')
    sudo('ufw allow 53/udp')  # dns
    sudo('ufw allow 53/tcp')
    sudo('ufw allow 1053')  # dns client

    sed('/etc/ssh/sshd_config', 'Port 22', 'Port 8697', use_sudo=True)
    sed('/etc/ssh/sshd_config', 'PermitRootLogin yes',
        'PermitRootLogin no', use_sudo=True)
    sed('/etc/ssh/sshd_config', '#PasswordAuthentication yes',
        'PasswordAuthentication no', use_sudo=True)
    sed('/etc/ssh/sshd_config', 'X11Forwarding yes',
        'X11Forwarding no', use_sudo=True)
    sudo('ufw enable')


# Path: fabgis/utilities.py
# def append_if_not_present(filename, text, use_sudo=False):
#     """Append to a file if an equivalent line is not already there.
#     :param filename: Name of file to append to.
#     :type filename: str
# 
#     :param text: Text to append.
#     :type text: str
# 
#     :param use_sudo: Run the command as sudo
#     :type use_sudo: bool
#     """
#     if not contains(filename, text):
#         append(filename, text, use_sudo=use_sudo)


# Path: fabgis/system.py
from getpass import getpass
from fabric.api import cd, fastprint, prompt
from fabric.contrib.files import contains, exists, append, sed
from fabric.colors import red
from fabric.api import env, task, sudo, local, reboot
from fabric.operations import run
from .utilities import append_if_not_present
import fabtools

    fabtools.deb.update_index(quiet=True)

    # Set up ufw and mosh
    fabtools.require.deb.package('ufw')
    setup_mosh()

    sudo('ufw default deny incoming')
    sudo('ufw default allow outgoing')
    sudo('ufw allow 8697')
    sudo('ufw allow http')
    sudo('ufw allow ssh')
    sudo('ufw allow mosh')
    sudo('ufw allow 25')  # mail
    #Irc freenode
    sudo('ufw allow from 127.0.0.1/32 to 78.40.125.4 port 6667')
    sudo('ufw allow from 127.0.0.1/32 to any port 22')
    sudo('ufw allow 443')
    sudo('ufw allow 53/udp')  # dns
    sudo('ufw allow 53/tcp')
    sudo('ufw allow 1053')  # dns client

    sed('/etc/ssh/sshd_config', 'Port 22', 'Port 8697', use_sudo=True)
    sed('/etc/ssh/sshd_config', 'PermitRootLogin yes',
        'PermitRootLogin no', use_sudo=True)
    sed('/etc/ssh/sshd_config', '#PasswordAuthentication yes',
        'PasswordAuthentication no', use_sudo=True)
    sed('/etc/ssh/sshd_config', 'X11Forwarding yes',
        'X11Forwarding no', use_sudo=True)
    sudo('ufw enable')


    append_if_not_present(