예제 #1
0
파일: bar.php 프로젝트: carriercomm/bar
function bar_output($vars)
{
    if (!bar_checkDB()) {
        return false;
    }
    $modulelink = $vars['modulelink'];
    $version = $vars['version'];
    $LANG = $vars['_lang'];
    $id = intval($_REQUEST['id']);
    $userid = intval($_REQUEST['userid']);
    if ($id) {
        $query = mysql_query("SELECT * FROM `tblhosting` where `id` = " . $id);
        if (!mysql_num_rows($query) || !($u = mysql_fetch_assoc($query))) {
            bar_message('An undefined error occured x02');
            return false;
        }
    }
    bar_getstatus($u['username'], $status, $from, $to);
    if (!($toserver = intval($_REQUEST['toserver']))) {
        $toserver = $to;
    }
    if ($toserver) {
        $query = mysql_query("SELECT * FROM `tblservers` where `type` = 'cpanel' and `id` = " . $toserver);
        if (!mysql_num_rows($query) || !($n = mysql_fetch_assoc($query))) {
            bar_message('An undefined error occured x01');
            return false;
        }
    }
    if (!($fromserver = intval($_REQUEST['fromserver']))) {
        $fromserver = $from;
    }
    if (!$fromserver) {
        $fromserver = $u['server'];
    }
    if ($fromserver) {
        $query = mysql_query("SELECT * FROM `tblservers` where `type` = 'cpanel' and `id` = " . $fromserver);
        if (!mysql_num_rows($query) || !($s = mysql_fetch_assoc($query))) {
            bar_message('An undefined error occured x03');
            return false;
        }
    }
    $action = $_REQUEST['ac'];
    if ($action == 'et') {
        //execute transfer
        //bar_getlastbackup($s,$u);
        //die($_REQUEST['dotransfer'].':'.$fromserver.'->'.$toserver);
        $query = mysql_query("SELECT * FROM `tblhosting` where `id` = " . $id);
        if (!mysql_num_rows($query) || !($u = mysql_fetch_assoc($query))) {
            echo 'Couldn\'t retrieve cPanel username';
        } else {
            if (isset($_REQUEST['dotransfer'])) {
                echo "Launching transfer for " . $u['username'] . '<br />';
                bar_backup($id, $fromserver, $toserver, $vars);
            } elseif (isset($_REQUEST['doreset'])) {
                echo "Reset done for " . $u['username'] . '<br />';
                bar_updatestatus($u['username'], '');
            } elseif (isset($_REQUEST['dorestore'])) {
                echo "Launching restore for " . $u['username'] . '<br />';
                $result = bar_restore($id, $fromserver, $toserver, $vars);
                if ($result['output']) {
                    bar_message('The restore generated the following output:<div style="padding:10px;background-color:#F5F5F5;font-size:smaller;">' . $result['output'] . '</div>');
                }
            } elseif (isset($_REQUEST['dobackup'])) {
                echo "Launching backup for " . $u['username'] . '<br />';
                bar_backup($id, $fromserver, 0, $vars);
            } elseif ($status == 'backingup') {
                list($backup, $time) = bar_getlastbackup($s, $u);
                echo "A backup is currently running for " . $u['username'] . ':' . $backup . '<br />';
            } else {
                echo "A process is currently running for " . $u['username'] . ':' . $status . '<br />';
            }
        }
    } elseif ($action == 'pt') {
        //prepare transfer
        echo '<form method="post" action="addonmodules.php?module=bar">';
        echo '<table class="form" width="100%" border="0" cellspacing="2" cellpadding="3">';
        echo '<tr><td class="fieldlabel" width="20%">Client</td><td class="fieldarea">' . $userid . '</td><td></td></tr>';
        echo '<tr><td class="fieldlabel" width="20%">Product</td><td class="fieldarea">' . $u['domain'] . ' (' . $id . ')</td><td></td></tr>';
        if ($status && $status != 'completed') {
            echo '<tr><td class="fieldlabel" width="20%">Status</td><td class="fieldarea">' . $LANG[$status] . '</td><td></td></tr>';
        }
        echo '<tr><td class="fieldlabel" width="20%">Origin server</td><td class="fieldarea">';
        echo '<select name="fromserver">';
        $servers = mysql_query("SELECT `id`,`name`,`type`,`ipaddress` FROM `tblservers` where `type` = 'cpanel'");
        if (mysql_num_rows($servers)) {
            while ($s = mysql_fetch_assoc($servers)) {
                if ($s['id'] == $fromserver) {
                    $selected = 'selected="selected"';
                } else {
                    $selected = '';
                }
                echo ' <option value="' . $s['id'] . '"' . $selected . '>' . $s['name'] . ' (' . $s['ipaddress'] . ')</option>' . "\r\n";
            }
        }
        echo '</select></td><td style="font-size:smaller">This is the server from where the backup is taken in case of a simple backup as well as for a transfer.</td></tr>';
        echo '<tr><td class="fieldlabel" width="20%">Destination server</td><td class="fieldarea">';
        echo '<select name="toserver">';
        $servers = mysql_query("SELECT `id`,`name`,`type`,`ipaddress` FROM `tblservers` where `type` = 'cpanel'");
        if (mysql_num_rows($servers)) {
            while ($s = mysql_fetch_assoc($servers)) {
                if ($toserver && $s['id'] == $toserver || $fromserver && $s['id'] == $fromserver) {
                    $selected = 'selected="selected"';
                } else {
                    $selected = '';
                }
                echo ' <option value="' . $s['id'] . '"' . $selected . '>' . $s['name'] . ' (' . $s['ipaddress'] . ')</option>' . "\r\n";
            }
        }
        echo '</select>';
        echo '</td><td style="font-size:smaller">This is the server where the backup will be restored, in case of a simple restore as well as in case of a transfer.</td></tr>';
        echo '</table>';
        echo '<input type="hidden" name="userid" value="' . $userid . '">';
        echo '<input type="hidden" name="id" value="' . $id . '">';
        echo '<input type="hidden" name="ac" value="et">';
        echo '<div align="center">';
        if ($status == '' || $status == 'completed') {
            echo '<input type="submit" name="dobackup" value="Backup" class="button">';
        }
        if ($status == '' || $status == 'completed' || $status == 'restorefail' || $status == 'backingup' && $to) {
            echo '<input type="submit" name="dorestore" value="Restore" class="button">';
        }
        if ($status == '' || $status == 'completed' || $status == 'restorefail') {
            echo '<input type="submit" name="dotransfer" value="Transfer" class="button">';
        }
        if ($status && $status != 'completed') {
            echo '<input type="submit" name="doreset" value="Reset" class="button">';
        }
        echo '</div>';
        echo '</form>';
    } else {
        echo '<ul>';
        echo bar_getprocesses($vars, false);
        echo '</ul>';
    }
    echo '<hr /><p>' . $LANG['intro'] . '</p><p>' . $LANG['description'] . '</p><p>' . $LANG['documentation'] . '</p>';
}
예제 #2
0
파일: hooks.php 프로젝트: carriercomm/bar
function bar_clientareapage()
{
    global $smarty, $barEcho;
    $barEcho = false;
    $tpl = '';
    //temporary
    if ($_REQUEST['action'] == 'productdetails' && ($smarty->_tpl_vars['module'] == 'cpanel' || $smarty->_tpl_vars['server']['type'] == 'cpanel')) {
        //
        if (!function_exists('bar_restore')) {
            require dirname(__FILE__) . '/bar.php';
        }
        $vars = bar_vars();
        if ($vars['clientrestore'] != 'on') {
            return;
        }
        //load language file
        $language = strtolower($smarty->_tpl_vars['language']);
        $langFile = dirname(__FILE__) . '/lang/' . strtolower($smarty->_tpl_vars['language']) . '.php';
        if (file_exists($langFile)) {
            require_once $langFile;
        } else {
            require_once dirname(__FILE__) . '/lang/english.php';
        }
        //product ID
        $productId = $smarty->_tpl_vars['id'];
        //$module=$smarty['module'];
        //$module=$smarty['server']['type'];
        //echo "<pre>_tpl_vars: " . print_r($smarty->_tpl_vars,TRUE) . "</pre>";
        //	var_dump($smarty);
        //systemurl
        if ($_REQUEST['ac'] == 'pr') {
            $tpl .= $_ADDONLANG['Launching restore for'] . " " . $smarty->_tpl_vars['username'] . '<br />';
            $tpl .= '<script type="text/javascript">';
            $tpl .= 'var barUrl=\'' . $smarty->_tpl_vars['systemurl'] . 'clientarea.php?action=productdetails\';';
            $tpl .= 'var barPost=\'' . '&ac=er&id=' . $productId . '\';';
            $tpl .= '</script>';
            $tpl .= '<script type="text/javascript" src="modules/addons/bar/bar.js"></script>';
            $tpl .= '<div style="min-height:66px;" id="barresult"><img src="modules/addons/bar/loader.gif" /></div>';
        } elseif ($_REQUEST['ac'] == 'er') {
            $query = mysql_query("SELECT * FROM `tblhosting` where `id` = " . $productId);
            if (!mysql_num_rows($query) || !($s = mysql_fetch_assoc($query))) {
                $result['result'] = false;
            } else {
                $result = bar_restore($productId, $s['server'], $s['server'], $vars);
            }
            if ($result['result']) {
                echo $_ADDONLANG['clientarearestoresuccess'];
            } else {
                echo $_ADDONLANG['clientarearestorefail'];
            }
            die;
        } else {
            $tpl .= '<form method="post" action="' . $smarty->_tpl_vars['systemurl'] . 'clientarea.php?action=productdetails">';
            $tpl .= '<input type="hidden" name="id" value="' . $productId . '">';
            $tpl .= '<input type="hidden" name="ac" value="pr">';
            $tpl .= '<input type="hidden" name="action" value="productdetails">';
            $tpl .= '<input class="btn" type="submit" onclick="return confirm(\'' . $_ADDONLANG['clientconfirm'] . '\');" value="' . $_ADDONLANG['clientarearestorebackup'] . '">';
            $tpl .= '</form>';
        }
        $tpl .= '<br />';
        $smarty->assign('moduleclientarea', $tpl . $smarty->_tpl_vars['moduleclientarea']);
    }
}