272 lines
6.7 KiB
PHP
272 lines
6.7 KiB
PHP
|
|
|
|
<?php
|
|
require_once dirname( __DIR__ ) . "/static/includes/init.php";
|
|
require_once dirname( __DIR__ ) . '/libs/email/ddeboer/vendor/autoload.php';
|
|
require_once dirname( __DIR__ ) . '/libs/email/phpmailer/vendor/autoload.php';
|
|
|
|
use Ddeboer\Imap\Server;
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use PHPMailer\PHPMailer\SMTP;
|
|
use PHPMailer\PHPMailer\Exception;
|
|
|
|
|
|
if(Input::get('create_email')){
|
|
create_email2();
|
|
}
|
|
if(Input::get('send_email')){
|
|
send_email();
|
|
}
|
|
|
|
// /home/cradle2careertxxyz/websites/www15/portal/dashboard/services/api/php/libs
|
|
|
|
#/home/master/sync/config_files
|
|
|
|
|
|
|
|
|
|
// curl -X POST --data @seed-example.json -H "Content-Type: application/json" http://127.0.0.1:4243/initdb/
|
|
// curl 'http://127.0.0.1:4243/mail/config-v1.1.xml?emailaddress=testing@cradle2careertx.xyz'
|
|
|
|
// curl -X "DELETE" http://127.0.0.1:4243/initdb/
|
|
|
|
// _imaps._tcp.server1.cradle2careertx.xyz SRV 0 1 993 server1.cradle2careertx.xyz.
|
|
// _submission._tcp.server1.cradle2careertx.xyz. SRV 10 20 587 server1.cradle2careertx.xyz.
|
|
|
|
// _imap._tcp.example.com SRV 10 20 143 mail.example.com.
|
|
// _pop3._tcp.example.com SRV 0 1 110 .
|
|
// _pop3s._tcp.example.com SRV 0 1 995 .
|
|
// _smtp._tcp.example.com. SRV 0 1 25 .
|
|
|
|
// https://www2.cradle2careertx.xyz/admin/core/request.php?create_email_account=true&username=it&password=mypass84&domain=cradle2careertx.xyz&type=1&level=0&category=1&backupEmail=equippedcoding@gmail.com
|
|
|
|
|
|
function create_email2($fields = null){
|
|
# $1 username
|
|
# $2 password
|
|
# $3 domain
|
|
# $4 level
|
|
# $5 type
|
|
# $6 category
|
|
# $7 backupEmail
|
|
# $8 firstname
|
|
# $9 lastname
|
|
# $10 token
|
|
# $11 expiry
|
|
# $12 expiry2
|
|
# #13 verified
|
|
|
|
// http://live1.appfactory.studio/plugins/app/php/server/request.php?create_email=true&username=testing11&password=mypass84&domain=cradle2careertx.xyz&type=1&level=0&category=1&backupEmail=my@backup.com
|
|
// "testing11" "mypass84" "cradle2careertx.xyz" 1 3 "my@backup.com"
|
|
//./run_create_email_account "testing9" "mypass84" "cradle2careertx.xyz" "1" "3" "0" "my@backup.com"
|
|
$state = "";
|
|
$username = "";
|
|
$userid = "";
|
|
$password = "";
|
|
$domain = "";
|
|
$type = "";
|
|
$level = "";
|
|
$category = "";
|
|
$backupEmail = "";
|
|
$firstname = "";
|
|
$lastname = "";
|
|
$token = "";
|
|
$expiry = "";
|
|
$verified = "";
|
|
|
|
if($fields!=null){
|
|
$state = $fields["state"];
|
|
$username = $fields["username"];
|
|
$userid = $fields["username"];
|
|
$password = $fields["password"];
|
|
$domain = $fields["domain"];
|
|
$type = $fields["type"];
|
|
$level = $fields["level"];
|
|
$category = $fields["category"];
|
|
$backupEmail = $fields["backupEmail"];
|
|
$firstname = $fields["firstname"];
|
|
$lastname = $fields["lastname"];
|
|
$token = $fields["token"];
|
|
$expiry = $fields["expiry"];
|
|
$verified = $fields["verified"];
|
|
//echo "_5_";
|
|
}else{
|
|
$state = Input::get("state");
|
|
$username = Input::get("username");
|
|
$userid = Input::get("username");
|
|
$password = Input::get("password");
|
|
$domain = Input::get("domain");
|
|
$type = Input::get("type");
|
|
$level = Input::get("level");
|
|
$category = Input::get("category");
|
|
$backupEmail = Input::get("backupEmail");
|
|
$firstname = Input::get("firstname");
|
|
$lastname = Input::get("lastname");
|
|
$token = Input::get("token");
|
|
$expiry = Input::get("expiry");
|
|
$verified = Input::get("verified");
|
|
//echo "_6_";
|
|
}
|
|
|
|
|
|
if($state==0){
|
|
$db = new DB();
|
|
$db->insert("email_users_copy",array(
|
|
"username" => $username,
|
|
"userid" => $username,
|
|
"password" => $password,
|
|
"domain" => $domain,
|
|
"type" => $type,
|
|
"level" => $level,
|
|
"category" => $category,
|
|
"backupEmail" => $backupEmail,
|
|
"firstname" => $firstname,
|
|
"lastname" => $lastname,
|
|
"token" => $token,
|
|
"expiry" => $expiry,
|
|
"verified" => $verified
|
|
));
|
|
//$db = new DB();
|
|
//$db->insert("email_users_copy", $fields);
|
|
$db = null;
|
|
|
|
}else{
|
|
// update email_users_copy
|
|
$db = new DB();
|
|
$rows = $db->query("SELECT * FROM email_users_copy WHERE token='".$token."'");
|
|
if($rows->count() > 0){
|
|
$db->updateFields("email_users_copy",
|
|
array(
|
|
"username" => $username,
|
|
"userid" => $username,
|
|
"expiry" => null,
|
|
"verified" => $verified
|
|
),
|
|
array("token" => $token)
|
|
);
|
|
}
|
|
|
|
$params = $username . " "
|
|
. $password . " "
|
|
. $domain . " "
|
|
. $level . " "
|
|
. $type . " "
|
|
. $category . " "
|
|
. $backupEmail . " "
|
|
. $firstname . " "
|
|
. $lastname . " "
|
|
. $token . " "
|
|
. $verified;
|
|
$cmd = "cd /home/webnetpagescom/websites/www/portal/dashboard/services/server/create_domains;./run_create_email_account " . $params;
|
|
|
|
// change to error file
|
|
$outputfile = "outputfile.txt";
|
|
$pidfile = "pidfile.txt";
|
|
|
|
//echo $params;
|
|
|
|
//https://stackoverflow.com/questions/45953/php-execute-a-background-process
|
|
//exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile), $output);
|
|
|
|
//echo $cmd;
|
|
//echo "<br>\n";
|
|
//echo $params;
|
|
shell_exec($cmd);
|
|
//var_dump($output);
|
|
}
|
|
|
|
|
|
|
|
echo json_encode(array('status' => 'success'));
|
|
}
|
|
|
|
|
|
|
|
function send_email(){
|
|
|
|
$from = Input::get('from');
|
|
$to = Input::get('to');
|
|
$subject = Input::get('subject');
|
|
$body = Input::get('body');
|
|
$server = Input::get('server');
|
|
$password = Input::get("password");
|
|
|
|
$mail = new PHPMailer(true); // Passing `true` enables exceptions
|
|
try {
|
|
//Server settings
|
|
//$mail->SMTPDebug = 2; // Enable verbose debug output
|
|
$mail->isSMTP(); // Set mailer to use SMTP
|
|
$mail->Host = $server; // Specify main and backup SMTP servers
|
|
$mail->SMTPAuth = true; // Enable SMTP authentication
|
|
$mail->Username = $from; // SMTP username
|
|
$mail->Password = $password; // SMTP password
|
|
//$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
|
|
$mail->Port = 587; // TCP port to connect to
|
|
|
|
//Recipients
|
|
$mail->setFrom($from, '');
|
|
$mail->addAddress($to, ''); // Add a recipient
|
|
//$mail->addAddress('ellen@example.com'); // Name is optional
|
|
//$mail->addReplyTo('info@example.com', 'Information');
|
|
//$mail->addCC('cc@example.com');
|
|
//$mail->addBCC('bcc@example.com');
|
|
|
|
//Attachments
|
|
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
|
|
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
|
|
|
|
//Content
|
|
$mail->isHTML(true); // Set email format to HTML
|
|
$mail->Subject = $subject;
|
|
$mail->Body = $body;
|
|
$mail->AltBody = $body;
|
|
|
|
$mail->send();
|
|
echo 'Message has been sent';
|
|
} catch (Exception $e) {
|
|
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|