//add an ftp if (_post('task') == 'add_ftp') { //authorize #$cpanel_ftp = new HW_CPanel_Ftp($host, $cpaneluser, $cpaneluser_pass); $cpanel_ftp = HW_CPanel_Ftp::init($cpanel); $ftp = array('user' => _post('ftp_username'), 'pass' => _post('ftp_passwd'), 'quota' => _post('ftp_quota'), 'homedir' => _post('ftp_homedir')); $res = $cpanel_ftp->create_ftp($ftp); add_message($res); if (is_string($res)) { $res = json_decode($res); } if (isset($res->cpanelresult->event->result) && $res->cpanelresult->event->result == '1') { //success ftp creation //save ftp acct to db if (_post('acc')) { $rs = add_acctftp(array('ftp_user' => $ftp['user'], 'ftp_pass' => $ftp['pass'], 'path' => $ftp['homedir']), _post('acc')); add_message($rs); } } } } invalid_form: //list saved accounts $accts = list_whm_accts(); ?> <html> <head> <title>FTP - Manager</title> <?php include 'template/head.php'; ?>
/** * set ftp password * @param $data */ function setftp_pass($data) { $ftpuser = _post('user'); $ftppass = _post('pass'); /*$query = "/json-api/cpanel?cpanel_jsonapi_user={$cpaneluser}&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Ftp&cpanel_jsonapi_func=passwd&user={$ftpuser}&pass={$ftppass}"; $cpanel = HW_CPanel::loadacct_instance($acc_id, false); #$cpanel = new HW_CPanel($host, $cpaneluser, $cpaneluser_pass, false); $result = $cpanel->cpanelapi($query);*/ //authorize #$cpanel = HW_CPanel::loadacct_instance($acc_id,0); #$cpanel_ftp = HW_CPanel_Ftp::init($acc_id); $cpanel_ftp = HW_CPanel_Ftp::loadacct($data->acc_id); $result = $cpanel_ftp->setftp_pass(array('ftp_user' => $ftpuser, 'ftp_pass' => $ftppass)); ajax_output($result); //save to db $result = json_decode($result); if (isset($result->cpanelresult->data[0]) && isset($result->cpanelresult->data[0]->result) && $result->cpanelresult->data[0]->result == '1') { $result = add_acctftp(array('ftp_user' => $ftpuser, 'ftp_pass' => $ftppass), $data->acc_id); ajax_output($result); } }