Beispiel #1
0
/**
 * set cron job backup
 * @param $data
 */
function add_cronbackup($data)
{
    $cpanel_file = $data->get_instance('fileman1');
    //new HW_CPanel_Fileman($data->host, $data->cpaneluser, $data->cpaneluser_pass);
    //check cron backup for exists
    #$cpanel_file->delcron();
    $args = array("command" => _post('command'), "day" => _post('day'), "hour" => _post('hour'), "minute" => _post('minute'), "month" => _post('month'), "weekday" => _post('weekday'));
    $res = $cpanel_file->create_cron($args);
    $result = json_decode($res);
    if (isset($result->cpanelresult->data) && isset($result->cpanelresult->data[0]->linekey)) {
        //cron success creation
        //update cron key for this acc in db
        update_cpacct(array('cron_key' => $result->cpanelresult->data[0]->linekey), $data->acc_id);
    }
    ajax_output($res);
}
Beispiel #2
0
}
/**
 * add account
 *
 */
if (_post('task') == 'add_acc') {
    $cpanel = authorize_hwm();
    $acct = array('username' => _post('cp_username'), 'password' => _post('cp_password'), 'domain' => _post('cp_domain'), 'contactemail' => _post('cp_contactemail'));
    //create cpanel from whm
    $result = $cpanel->createacct($acct);
    if (isset($result->result) && isset($result->result[0]) && isset($result->result[0]->status) && $result->result[0]->status) {
        //check for exists acct
        $id = get_cpanel_info(array('cpanel_user' => $acct['username'], 'cpanel_host' => HW_WHM_IP));
        $_acc_id = isset($id['id']) ? $id['id'] : '';
        //add new acct to db
        update_cpacct(array('cpanel_user' => $acct['username'], 'cpanel_pass' => encrypt($acct['password']), 'cpanel_domain' => $acct['domain'], 'cpanel_host' => HW_WHM_IP, 'cpanel_email' => $acct['contactemail']), $_acc_id);
    }
    if (isset($result->result)) {
        add_message($result->result);
    } else {
        add_message('Failt !');
    }
}
?>
<html>
<head>
    <title>Accounts</title>
    <?php 
include 'template/head.php';
?>
    <script>
Beispiel #3
0
/**
 * generate ssh key
 * @param $data
 */
function generate_sshkey($data)
{
    $result = array();
    $cpanel = $data->get_instance('cpanel');
    $cpanel_file = $data->get_instance('fileman_no_auth');
    #$cpanel_file = new HW_CPanel_Fileman($host,$cpaneluser, $cpaneluser_pass);
    if ($cpanel) {
        $key = $data->cpaneluser . '-sshkey';
        $keypass = generateStrongPassword(20, false, 'lud');
        //create safe password
        //list keys
        $keys = $cpanel->list_sshkeys();
        $keys = json_decode($keys);
        if (isset($keys->cpanelresult->data) && is_array($keys->cpanelresult->data)) {
            foreach ($keys->cpanelresult->data as $_key) {
                if (strpos($_key->name, $key) !== false) {
                    //del putty key file
                    $putty_key = "/home/{$data->cpaneluser}/.ssh/putty/{$_key->name}.ppk";
                    $cpanel_file->delfiles($putty_key);
                    //remove ssh key file on server
                    $cpanel->del_sshkey($_key->name);
                    //del private key
                    $cpanel->del_sshkey($_key->name, 1);
                    //del public key
                    /*unlink($key->file);
                      if(!empty($key->haspub) && $key->haspub) {
                          unlink($key->file.".pub");
                      }*/
                }
            }
        }
        //generate ssh key
        $res = $cpanel->generate_sshkey($key, $keypass);
        $result[] = array('sshkey' => array('key' => $key, 'pass' => $keypass));
        $result[] = (array) json_decode($res);
        //save ssh key to db for this account
        $data = array('ssh_key' => $key, 'ssh_key_pass' => $keypass);
        update_cpacct($data, $data->acc_id);
        //authorize key
        $res = $cpanel->authorizes_sshkey($key);
        $result[] = (array) json_decode($res);
        //convert key to ppk
        $res = $cpanel->sshkey_converttoppk($key, $keypass);
        $result[] = (array) json_decode($res);
        ajax_output($result);
    }
}