Skip to content

Instantly share code, notes, and snippets.

@bulentsakarya
Created December 13, 2019 07:20
Show Gist options
  • Save bulentsakarya/44af996ed577528d290202a63642bcef to your computer and use it in GitHub Desktop.
Save bulentsakarya/44af996ed577528d290202a63642bcef to your computer and use it in GitHub Desktop.
vesta add user and db wiyh api
/**
* Vesta Bilgileri
*/
$vst_hostname = 'localhost';
$vst_username = 'admin';
$vst_password = '123';
/**
* Kullanıcı Bilgileri
*/
$vesta_username = 'kullanici';
$site_database = 'kullanici_db';
$site_db_user = 'kullanici_dbuser';
$site_db_pass = 'kullanici_pass';
/**
* Kullanıcı Ekleme
*/
$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'returncode' => 'yes',
'cmd' => 'v-add-user',
'arg1' => $vesta_username,
'arg2' => '246',
'arg3' => $this->input->post('user_email'),
'arg4' => 'gainsboro',
'arg5' => $this->input->post('user_name'),
'arg6' => $this->input->post('user_surname')
);
$postdata = http_build_query($postvars);
$user_curl = curl_init();
curl_setopt($user_curl, CURLOPT_URL, 'https://' . $vst_hostname . ':8083/api/');
curl_setopt($user_curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($user_curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($user_curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($user_curl, CURLOPT_POST, true);
curl_setopt($user_curl, CURLOPT_POSTFIELDS, $postdata);
$user_answer = curl_exec($user_curl);
curl_close($user_answer);
if($user_answer == 0) {
/**
* DB Ekleme
*/
$dbvars = array(
'user' => $vst_username,
'password' => $vst_password,
'returncode' => 'yes',
'cmd' => 'v-add-database',
'arg1' => $vesta_username,
'arg2' => $site_database,
'arg3' => $site_db_user,
'arg4' => $site_db_pass,
'arg5' => 'mysql',
'arg6' => 'localhost',
'arg7' => 'utf8'
);
$dbdata = http_build_query($dbvars);
$db_curl = curl_init();
curl_setopt($db_curl, CURLOPT_URL, 'https://' . $vst_hostname . ':8083/api/');
curl_setopt($db_curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($db_curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($db_curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($db_curl, CURLOPT_POST, true);
curl_setopt($db_curl, CURLOPT_POSTFIELDS, $dbdata);
$db_answer = curl_exec($db_curl);
curl_close($db_answer);
if($db_answer == 0) {
$body = $this->mailer->create_user($mailname, $code);
$this->load->helper('email_helper');
$to = $data['user_email'];
$subject = 'Üyelik Bilgileriniz';
$message = $body ;
if(sendEmail($to, $subject, $message, $file = '' , $cc = '')) {
$this->messages = [
'success' => "Kullanıcı başarıyla eklendi, bilgiler e-posta adresine gönderildi.",
'title' => "Başarılı!",
'icon' => "fas fa-check"
];
$this->session->set_flashdata($this->messages);
}
} else {
$this->messages = [
'error' => "Veritabanı oluşturulurken bir hata oluştu.",
'title' => "Upss!",
'icon' => "fas fa-info"
];
$this->session->set_flashdata($this->messages);
}
} else {
$this->messages = [
'error' => "Vesta Hesabı Oluşturulurken bir sorun oluştu.",
'title' => "Upss!",
'icon' => "fas fa-info"
];
$this->session->set_flashdata($this->messages);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment