All pastes #638029 Raw Edit

Anonymous

public php v1 · immutable
#638029 ·published 2007-07-29 13:56 UTC
rendered paste body
#!/usr/bin/env php<?php/** @ignore */ini_set('include_path', '../lib' . PATH_SEPARATOR . ini_get('include_path'));/** @see Zend_Loader */include_once 'Zend/Loader.php';Zend_loader::registerAutoload();try {    $opts = new Zend_Console_Getopt(array(        'enable|e=s'    => 'enable given domain, will accept wildcards',        'disable|d=s'   => 'disable given domain, will accept wildcards'    ));    $opts->setOption('ruleMode', Zend_Console_Getopt::MODE_GNU);    $opts->parse();    if (null == $opts->getOptions()) {        throw new Zend_Console_Getopt_Exception('no options supplied', $opts->getUsageMessage());    }    try {        $db = new Zend_Db_Adapter_Pdo_Sqlite(array(            'dbname'    => '/home/cameron/projects/vhost-tool/db/vhosts.sqdb'        ));    } catch (Zend_Db_Adapter_Exception $e) {        echo $e->getMessage(), "\n";        exit;    }    $username = $_SERVER['USERNAME'];    $arg = array_shift($opts->getOptions());    $domain   = $opts->getOption($arg);    if ($arg === 'enable' || $arg === 'disable') {        $results = $db->fetchAll($db->quoteInto('SELECT * FROM vhosts WHERE vhost_domain = ?', $domain));        if ($username === $results[0]['vhost_owner']) {            if ('enable' === $arg) {                $output = shell_exec("a2ensite $domain");            }            if ('disable' === $arg) {                $output = shell_exec("a2dissite $domain");            }        }        else {            $output = 'you do not own this site, there for you can not disable or enable it.';        }    }    /* add support for adding vhosts and removing them via this tool    else if ($arg === 'add' || $arg === 'delete') {    } */    echo $output, "\n";    exit;} catch (Zend_Console_Getopt_Exception $e) {    echo $e->getUsageMessage(), "\n";    exit;}