Exemple #1
0
#    http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Run things as root (or another user) via sudo.

"""
from pycopia import proctools
from pycopia.OS import procutils

SUDO = procutils.which("sudo")


def sudo(command, user=None, password=None, extraopts=None, logfile=None):
    opts = "-S %s" % ("-u %s" % user if user else "")
    cmd = "%s %s %s %s" % (SUDO, opts, extraopts or "", command)
    proc = proctools.spawnpipe(cmd, logfile=logfile, merge=0)
    if password:
        proc.readerr(9)  # discard password prompt
        proc.write("%s\r" % (password, ))
        proc.readerr(1)  # discard newline
    return proc


def sudo_reset():
    proc = proctools.spawnpipe("%s -k" % (SUDO, ), merge=0)
Exemple #2
0
#    http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Run things as root (or another user) via sudo.

"""
from pycopia import proctools
from pycopia.OS import procutils

SUDO = procutils.which("sudo")

def sudo(command, user=None, password=None, extraopts=None, logfile=None):
    opts = "-S %s" % ("-u %s" % user if user else "")
    cmd = "%s %s %s %s" % (SUDO, opts, extraopts or "", command)
    proc = proctools.spawnpipe(cmd, logfile=logfile, merge=0)
    if password:
        proc.readerr(9) # discard password prompt
        proc.write("%s\r" % (password,))
        proc.readerr(1) # discard newline
    return proc

def sudo_reset():
    proc = proctools.spawnpipe("%s -k" % (SUDO,), merge=0)
    proc.read()
    proc.wait()
Exemple #3
0
    "remove_known_host",
    "keygen",
    "keyscan",
    "parse_key",
    "parse_public",
    "parse_private",
]

import os

from pycopia import proctools
from pycopia import expect
from pycopia.OS import procutils


SSH = procutils.which("ssh")
SCP = procutils.which("scp")
KEYGEN = procutils.which("ssh-keygen")
KEYSCAN = procutils.which("ssh-keyscan")
SSH_OPTIONS = "-F %s" % os.path.join("/", "etc", "pycopia", "ssh_config")


class SSHRetry(Exception):
    pass


class SSHExpect(expect.Expect):
    def sshexit(self):
        self.send("\r~.\r")

    def login(self, password=None):
Exemple #4
0
__all__ = [
    'SSHRetry', 'SSHExpect', 'KnownHostsFile', 'SSHKey', 'SSHKeyRSA1',
    'SSHKeyRSA1pub', 'SSHKeyPublic', 'SSHKeyRSA', 'SSHKeyRSApub', 'SSHKeyDSA',
    'SSHKeyDSApub', 'AuthorizedKeys', 'ssh_command', 'get_ssh',
    'get_ssh_unsafe', 'scp', 'location', 'ssh_version', 'get_procs',
    'get_known_hosts', 'get_userdir', 'remove_known_host', 'keygen', 'keyscan',
    'parse_key', 'parse_public', 'parse_private'
]

import os

from pycopia import proctools
from pycopia import expect
from pycopia.OS import procutils

SSH = procutils.which("ssh")
SCP = procutils.which("scp")
KEYGEN = procutils.which("ssh-keygen")
KEYSCAN = procutils.which("ssh-keyscan")
SSH_OPTIONS = '-F %s' % os.path.join("/", "etc", "pycopia", "ssh_config")


class SSHRetry(Exception):
    pass


class SSHExpect(expect.Expect):
    def sshexit(self):
        self.send("\r~.\r")

    def login(self, password=None):
Exemple #5
0
import sys
import os
import socket
import traceback

from pycopia import basicconfig
from pycopia import logging
from pycopia import passwd
from pycopia import proctools
from pycopia.OS import procutils

LTCONFIG = "/etc/pycopia/lighttpd/lighttpd.conf"
# Master site config. controls all virtual host configuration.
SITE_CONFIG = "/etc/pycopia/website.conf"

LIGHTTPD = procutils.which("lighttpd")


def start(config):
    setup(config)
    if config.DAEMON:
        from pycopia import daemonize
        from pycopia import logfile
        lf = logfile.ManagedStdio(config.LOGFILENAME)
        daemonize.daemonize(lf, pidfile=config.PIDFILE)
    else:
        lf = sys.stderr
        with open(config.PIDFILE, "w") as fo:
            fo.write("{}\n".format(os.getpid()))
    start_proc_manager(config, lf)