initial commit 2

This commit is contained in:
equippedcoding-master
2025-09-17 15:19:57 -05:00
parent e2c98790b2
commit 1c59875b8a
55391 changed files with 15 additions and 0 deletions

View File

@@ -0,0 +1,221 @@
CREATE DATABASE IF NOT EXISTS fakedb;
CREATE USER 'fake'@'localhost' IDENTIFIED BY 'jdkfjRGfdkE305@fklldgkl';
GRANT ALL ON fakedb.* TO 'fake'@'localhost';
CREATE DATABASE IF NOT EXISTS roundcubedb;
CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'jdkfjRGfdkE305@fklldgkl';
GRANT ALL ON roundcubedb.* TO 'roundcube'@'localhost';
ALTER USER 'fake'@'localhost' IDENTIFIED WITH mysql_native_password BY 'jdkfjRGfdkE305@fklldgkl';
FLUSH PRIVILEGES;
FLUSH HOSTS;
USE fakedb;
CREATE TABLE IF NOT EXISTS managed_domain (
id INT AUTO_INCREMENT PRIMARY KEY,
SubDomain VARCHAR(255) NULL,
Domain VARCHAR(255) NULL,
EmailUrl TEXT,
EmailServer VARCHAR(255) NULL,
AutoEmailLoginUrl VARCHAR(255) NULL,
PaypayServiceUrl VARCHAR(255) NULL,
AppfactoryUrl VARCHAR(255) NULL,
Address VARCHAR(255) NULL,
PayPalPort VARCHAR(255) NULL,
PayPalEndPoint VARCHAR(255) NULL,
CertPrivateKeyLocation VARCHAR(255) NULL,
CertPublicKeyLocation VARCHAR(255) NULL,
PaypalClientId VARCHAR(255) NULL,
PaypalAppSecret VARCHAR(255) NULL,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
INSERT INTO managed_domain \
(SubDomain,\
Domain,\
EmailUrl,\
EmailServer,\
AutoEmailLoginUrl,\
PaypayServiceUrl,\
AppfactoryUrl,\
Address,\
PaypalPort,\
PaypalEndPoint,\
CertPrivateKeyLocation,\
CertPublicKeyLocation,\
PaypalClientId,\
PaypalAppSecret) \
VALUES ( \
"www", \
"webnetpages.com", \
"https://www.webnetpages.com/portal/validation/email_account/normal/index.php", \
"server1.webnetpages.com", \
"https://www.webnetpages.com/portal/mailclient/1/RoundcubeAutoLogin.php", \
"https://www.webnetpages.com:9001/get_token", \
"http://live1.appfactory.studio/plugins/app/php/server/request.php",\
"https://www.webnetpages.com",\
"9011",\
"paypal_checkout",\
"/etc/letsencrypt/live/www.webnetpages.com/privkey.pem",\
"/etc/letsencrypt/live/www.webnetpages.com/cert.pem",\
"AbehsBM-Cg5UwIx6pAWObkiltltLPwN82QlhN-u4qwYMD7Fzly_mDmUGYnSJqHuMLIWjhBk9I5iKsvIN",\
"EIMOBpKnMGNlgaofARDgpuigkvpoSilNUJQSXSmXhNRwxrVosOVp1DCpb7Ky2OfjX7rR0SqszgRMyg1-");
CREATE TABLE IF NOT EXISTS email_users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NULL,
password VARCHAR(255) NULL,
domain VARCHAR(255) NULL,
userid VARCHAR(255) NULL,
home VARCHAR(255) NULL,
type INT DEFAULT 1,
level INT DEFAULT 0,
category INT DEFAULT 0,
verified INT DEFAULT 0,
backupEmail VARCHAR(255) NULL,
firstname VARCHAR(255) NULL,
lastname VARCHAR(255) NULL,
token VARCHAR(255) NULL,
expiry TIMESTAMP NULL,
uid VARCHAR(255) NULL,
gid INT NULL,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS email_users_copy (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NULL,
password VARCHAR(255) NULL,
domain VARCHAR(255) NULL,
userid VARCHAR(255) NULL,
home VARCHAR(255) NULL,
type INT DEFAULT 1,
level INT DEFAULT 0,
category INT DEFAULT 0,
verified INT DEFAULT 0,
backupEmail VARCHAR(255) NULL,
firstname VARCHAR(255) NULL,
lastname VARCHAR(255) NULL,
token VARCHAR(255) NULL,
expiry TIMESTAMP NULL,
uid VARCHAR(255) NULL,
gid INT NULL,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS admin_users (
id INT AUTO_INCREMENT PRIMARY KEY,
Username VARCHAR(255) NULL,
Email VARCHAR(255) NULL,
Password VARCHAR(255) NULL,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS application_settings (
id INT AUTO_INCREMENT PRIMARY KEY,
category VARCHAR(255) NULL,
json MEDIUMTEXT,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS webbuilder (
id INT AUTO_INCREMENT PRIMARY KEY,
ProjectName VARCHAR(255) NULL,
ImagesDirectory VARCHAR(255) NULL,
ImageUploadURL VARCHAR(255) NULL,
ImageUploadName VARCHAR(255) NULL,
WebsiteData MEDIUMTEXT,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS receipts (
id INT AUTO_INCREMENT PRIMARY KEY,
type VARCHAR(255) NULL,
name VARCHAR(255) NULL,
email VARCHAR(255) NULL,
amount VARCHAR(255) NULL,
processor VARCHAR(255) NULL,
receipt MEDIUMTEXT,
orderId VARCHAR(255) NULL,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS subscribers (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NULL,
name INT DEFAULT 1,
subscribed INT DEFAULT 1,
subscriptions VARCHAR(255) NULL,
assigned_from VARCHAR(255) NULL,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS contact_us_form (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NULL,
email VARCHAR(255) NULL,
message TEXT,
assigned_from VARCHAR(255) NULL,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS contact (
id INT AUTO_INCREMENT PRIMARY KEY,
type VARCHAR(255) NULL,
email VARCHAR(255) NULL,
phone VARCHAR(255) NULL,
address VARCHAR(255) NULL,
name VARCHAR(255) NULL,
message TEXT,
assigned_from VARCHAR(255) NULL,
checked INT DEFAULT 0,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS event_rsvp (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NULL,
PlusOne VARCHAR(255) NULL,
EventId INT,
Email VARCHAR(255) NULL,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS event_reminders (
id INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(255) NULL,
CanBeNotified INT DEFAULT 1,
Notified INT DEFAULT 0,
Email VARCHAR(255) NULL,
EventDate TIMESTAMP,
EventName VARCHAR(255) NULL,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS sponsorships (
id INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(255) NULL,
Type INT DEFAULT 1,
Available INT DEFAULT 1,
BasePrice VARCHAR(255) NULL,
CanAdjust INT DEFAULT 0,
Description TEXT,
Image VARCHAR(255) NULL,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE IF NOT EXISTS sponsors (
id INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(255) NULL,
Email VARCHAR(255) NULL,
CompanyName VARCHAR(255) NULL,
Approved INT DEFAULT 2,
Active INT DEFAULT 1,
SponsorshipId INT NULL,
Company INT DEFAULT 0,
Months INT DEFAULT 1,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);

View File

@@ -0,0 +1,5 @@
cd /home/webnetpagescom/websites/www/portal/dashboard/services/server/create_domains/

View File

@@ -0,0 +1 @@
www

View File

@@ -0,0 +1,56 @@
<?php
#1 database=
#2 dbuser=
#3 dbpasswd=
#4 user_group=
#5 php_config_file=
#6 roundcube_passwd=
#7 root=
$database = $argv[1];
$dbuser = $argv[2];
$dbpasswd = $argv[3];
$user_group = $argv[4];
$php_config_file = $argv[5];
$roundcube_passwd = $argv[6];
$root = $argv[7];
$h = "
CREATE USER '$dbuser'@'localhost' IDENTIFIED BY '$dbpasswd';
CREATE USER 'roundcube'@'localhost' IDENTIFIED BY '$roundcube_passwd';
";
$myfile = fopen("users.sql", "w") or die("Unable to open file!");
fwrite($myfile, $h);
fclose($myfile);
$h = "
CREATE DATABASE IF NOT EXISTS $database;
GRANT ALL ON $database.* TO '$dbuser'@'localhost';
CREATE DATABASE IF NOT EXISTS roundcubedb;
GRANT ALL ON roundcubedb.* TO 'roundcube'@'localhost';
ALTER USER '$dbuser'@'localhost' IDENTIFIED WITH mysql_native_password BY '$dbpasswd';
ALTER USER 'roundcube'@'localhost' IDENTIFIED WITH mysql_native_password BY '$roundcube_passwd';
FLUSH PRIVILEGES;
FLUSH HOSTS;
USE $database;
";
$one = file_get_contents("./create_database.sql");
$two = file_get_contents("./update_database.sql");
$h .= $one;
$h .= $two;
$myfile = fopen("combined.sql", "w") or die("Unable to open file!");
fwrite($myfile, $h);
fclose($myfile);

View File

@@ -0,0 +1,62 @@
#!/bin/sh
declare database=$1
declare dbuser=$2
declare dbpasswd=$3
declare user_group=$4
declare php_config_file=$5
declare roundcube_passwd=$6
declare root=$7
touch $php_config_file
cat > $php_config_file <<- EOM
<?php
\$GLOBALS['config'] = array(
'mysql' => array(
'host' => "localhost",
'username' => "${dbuser}",
'password' => "${dbpasswd}",
'db' => "${database}"
)
);
EOM
chown $user_group $php_config_file
chmod 775 $php_config_file
#cat > $sql_config_file <<- EOM EOM
string=$(cat << EOF
CREATE DATABASE IF NOT EXISTS ${database};\n
CREATE USER '${dbuser}'@'localhost' IDENTIFIED BY '${dbpasswd}';\n
GRANT ALL ON ${database}.* TO '${dbuser}'@'localhost';\n
\n
CREATE DATABASE IF NOT EXISTS roundcubedb;\n
CREATE USER 'roundcube'@'localhost' IDENTIFIED BY '${roundcube_passwd}';\n
GRANT ALL ON roundcubedb.* TO 'roundcube'@'localhost';\n
\n
ALTER USER '${dbuser}'@'localhost' IDENTIFIED WITH mysql_native_password BY '${dbpasswd}';\n
\n
FLUSH PRIVILEGES;\n
FLUSH HOSTS;\n
\n
USE ${database};\n
\n
EOF
)
echo $string > combined.sql
# cat create_database.sql > combined.sql
# cat update_database.sql > combined.sql
# mysql -u root -p$root < combined.sql

View File

View File

@@ -0,0 +1,32 @@
#!/bin/sh
#1 database=
#2 dbuser=
#3 dbpasswd=
#4 user_group=
#5 php_config_file=
#6 sql_config_file=
#7 roundcube_passwd=
#8 root=
# cd /home/cradle2careertxxyz/websites/www5/portal/dashboard/system
php initialize_database.php \
fakedb \
fake \
jdkfjRGfdkE305@fklldgkl \
cradle2careertxxyz.apache \
../../dashboard/services/static/includes/config/config_init.php \
jdkfjRGfdkE305@fklldgkl \
GOODnews84!
sleep 5
mysql -u root -pGOODnews84! < users.sql
mysql -u root -pGOODnews84! < combined.sql

View File

@@ -0,0 +1,71 @@
#!/bin/sh
user=$1 # user
subdomain=$2 # www2 23.239.24.44
# install paypal npm packages
cd /home/$user/websites/$subdomain/portal/admin/core/appfactory/payments_systems/paypal/node/advanced-integration/; npm install;
pm2 restart $1
echo $1 > type.txt
# Paypal services
# pm2 start server.js --name "www4" -- www4
# create email shell scripts
#cd /home/webnetpagescom/websites/www/portal/dashboard/services/server/create_domains/
gcc wrapper.c -o run_create_email_account
chown root run_create_email_account
chmod u=rwx,go=xr,+s run_create_email_account
# /etc/letsencrypt/live/www.webnetpages.com/fullchain.pem
# /etc/letsencrypt/live/www.webnetpages.com/privkey.pem
postsuper -d ALL
df -h
du -hs /var/spool
tail -f -n50 /var/log/maillog
tail -f -n50 /var/log/php-fpm/www-error.log
tail -f -n50 /var/log/mylog.txt
tail -f -n50 /home/webnetpagescom/websites/www/portal/dashboard/services/server/create_domains/output
systemctl start vsftpd
systemctl start httpd
systemctl start dovecot
systemctl start postfix
systemctl start mysqld
systemctl start amavisd
systemctl start spamassassin
systemctl start opendkim
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
systemctl enable --now snapd.socket
https://webnetpages.com/portal/dashboard/
#sh initialize_databse.sh "cradle2careertxdb" "cradle2careertx" "jdkfjRGfdkE305@fklldgkl" "cradle2careertxxyz.apache"
cd;\
rm -rf /home/cradle2careertxxyz/websites/www10;\
afsserver --move www15 www10;\
pm2 delete www10;\
cd /home/cradle2careertxxyz/websites/www10/portal/dashboard/services/static/appfactory/payments_systems/paypal/node/advanced-integration;\
pm2 start server.js --name "www10" -- www10
cd /home/master/runnables/tmp;\
unzip webfiles4.zip -d www15;\
chmod -R 775 /home/cradle2careertxxyz/websites/www15;\
chown -R cradle2careertxxyz.apache /home/cradle2careertxxyz/websites/www15
/home/cradle2careertxxyz/websites

View File

@@ -0,0 +1,47 @@
#!/bin/sh
# portal/dashboard/system
#sh initialize_databse.sh "db" "dbuser" "dbpassword" "user.apache"
# setup database
# install letencrypt certs
# create email compiled program in create_domains folder
# pm2 services such as paypal/payment
# mount storage
# install paypal npm packages
# // portal/dashboard/services/static/appfactory/payments_systems/paypal/node/advanced-integration/server.js
#cd portal/dashboard/services/static/appfactory/payments_systems/paypal/node/advanced-integration
#cd /home/$user/websites/$subdomain/portal/admin/core/appfactory/payments_systems/paypal/node/advanced-integration/; npm install;
#pm2 restart $1
echo $1 > type.txt
# create email shell scripts
#cd /home/webnetpagescom/websites/www/portal/dashboard/services/server/create_domains/
# cd portal/dashboard/services/server/create_domains
# gcc wrapper.c -o run_create_email_account
# chown root run_create_email_account
# chmod u=rwx,go=xr,+s run_create_email_account
# 23.239.24.44 - datafiles002
# To get started with a new volume, youll want to create a filesystem on it:
### mkfs.ext4 "/dev/disk/by-id/scsi-0Linode_Volume_datafiles002"
# Once the volume has a filesystem, you can create a mountpoint for it:
### mkdir "/mnt/datafiles002"
# Then you can mount the new volume:
### mount "/dev/disk/by-id/scsi-0Linode_Volume_datafiles002" "/mnt/datafiles002"
# If you want the volume to automatically mount every time your Linode boots, youll want to add a line like the following to your /etc/fstab file:
#/dev/disk/by-id/scsi-0Linode_Volume_datafiles002 /mnt/datafiles002 ext4 defaults,noatime,nofail 0 2

View File

@@ -0,0 +1,26 @@
named_conf=$1
zone_file=$2
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
new_named_conf=$named_conf.$current_time
new_zone_file=$zone_file.$current_time
mkdir -p /etc/backup/
mkdir -p /var/named/zones/backup/
mv /etc/named.conf /etc/backup/$new_named_conf
mv named.conf /etc/
mv /var/named/zones/$zone_file /var/named/zones/backup/$new_zone_file
mv $zone_file /var/named/zones
systemctl restart named

View File

@@ -0,0 +1,35 @@
set domain_user [lindex $argv 0]
set password [lindex $argv 1]
#set timeout 10
spawn adduser $domain_user
sleep 2
spawn passwd $domain_user
expect "password:"
send "${password}\r"
expect "password:"
send "${password}\r"
sleep 1
spawn systemctl restart httpd
expect ".*" { send "server\r" }
interact
exec [pwd]/create_http_domain2.sh $domain_user

View File

@@ -0,0 +1,24 @@
domain_user=$1
mkdir -p /home/$domain_user/websites/www
mkdir -p /home/$domain_user/websites/dev
touch /home/$domain_user/websites/www/index.php
touch /home/$domain_user/websites/dev/index.php
echo "<?php echo 'Under Contruction'; ?> " > /home/$domain_user/websites/www/index.php
echo "<?php echo 'Under Contruction'; ?> " > /home/$domain_user/websites/dev/index.php
chown -R $domain_user.apache /home/$domain_user/
chmod -R 775 /home/$domain_user/

View File

@@ -0,0 +1,59 @@
<?php
function my_dns_options(){
$zonefile = <<<EOT
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
/*
- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
- If you are building a RECURSIVE (caching) DNS server, you need to enable
recursion.
- If your recursive DNS server has a public IP address, you MUST enable access
control to limit queries to your legitimate users. Failing to do so will
cause your server to become part of large scale DNS amplification
attacks. Implementing BCP38 within your network would greatly
reduce such attack surface
*/
recursion no;
dnssec-enable yes;
dnssec-validation yes;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
#additional-from-auth no;
#additional-from-cache no;
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
EOT;
return $dns_options;
}
?>

View File

@@ -0,0 +1,8 @@
#!/bin/bash
if [ ! -r "$1" ]; then echo "File $1 is not readable - skipping. "; fi

View File

@@ -0,0 +1,95 @@
<?php
session_start();
/*
* Database config data. This is set during initial
* setup of the application. This file can be modified
*
*/
//require_once 'config/master_config.php';
/*
*** FILE TO BE INLCUDING IN ALL PHP SCRIPTS ***
*
* This is the initial script for all php files to follow
* To except mulitiple DB connection just add another config
* with in the array. Calling DB::getInstance() without a
* param uses the default mysql config to get a specific DB
* specify the key as the param for DB::getInstance('key');
* and that will return that DB connection.
*
*
*
*/
$GLOBALS['config'] = array(
'mysql' => array(
'host' => "localhost",//,
'username' => "webnetpages",//,
'password' => "hfkeGGGd983vnskjale!",//,
'db' => "webnetpagesdb"//
),
'mysql_mail' => array(
'host' => "localhost",//,
'username' => "mailman",//,
'password' => "GOODnews84!",//,
'db' => "mail"//
),
'remember' => array(
'cookie_name' => 'hash',
'cookie_expiry' => 604800 // cookie expires in seconds
),
'session' => array(
'session_name' => 'user',
'token_name' => 'token'
)
);
//echo dirname(__DIR__,3);
//require_once '../../../control_panel/admin/core/';
spl_autoload_register(function($class){
//echo 'WORKING<br>';
$sources = array(
dirname(__DIR__,3).'/control_panel/admin/core/classes/' . $class . '.php',
dirname(__DIR__,3)."/control_panel/admin/core/myclasses/".$class.".php"
);
//foreach ($sources as $source) {
for($i=0; $i<count($sources); $i++){
//echo $sources[$i]."\n <br>";
if (file_exists($sources[$i])) {
//echo "EXITS\n <br>";
require_once $sources[$i];
}
}
});
/*
require_once 'functions/sanitize.php';
if(Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('session/session_name'))){
$hash = Cookie::get(Config::get('remember/cookie_name'));
$hashCheck = DB::getInstance()->get('users_sessions', array('hash', '=', $hash));
if($hashCheck->count()){
$user = new User($hashCheck->first()->user_id);
$user->login();
}
}
*/
?>

View File

@@ -0,0 +1,366 @@
<?php
require 'init.php';
require 'dns_options.php';
if(Input::get('get_all_domains')){
get_all_domains();
}
if(Input::get('update_passwd')){
update_passwd();
}
if(Input::get('get_mail_data')){
get_mail_data();
}
if(Input::get('get_dns_zone_data')){
get_dns_zone_data();
}
if(Input::get('create_zone_file')){
create_zone_file();
}
if(Input::get('update_dns_records')){
update_dns_records();
}
function update_dns_records(){
$data = json_decode( Input::get('data') );
$zone = $data->zone;
$records = $data->records;
// id: 1
// ttl: "86400"
// origin: "webnetpages.com."
// soa: "ns1.webnetpages.com."
// soa_email: "dnsadmin.server.webnetpages.com."
// serial: "5"
// refresh: "3600"
// retry: "7200"
// expire: "1209600"
// minimum: "86400"
$text = <<<EOT
\$TTL $zone->ttl
\$ORIGIN $zone->origin
@ 86400 IN SOA $zone->soa $zone->soa_email (
$zone->serial ; serial, todays date+todays
$zone->refresh ; refresh, seconds
$zone->retry ; retry, seconds
$zone->expire ; expire, seconds
$zone->minimum ) ; minimum, seconds
EOT;
for ($i=0; $i < count($records); $i++) {
$text .= $records[$i]->resource . "\t". $records[$i]->type . "\t" .$records[$i]->value . "\n";
}
$text .= "\n\n\n\n\n";
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
fwrite($myfile, $text);
fclose($myfile);
echo $text;
}
function update_passwd(){
$db = DB::getInstance();
$data = json_decode(Input::get('data'));
$db->query('UPDATE users SET password="'.$data->password.'" WHERE username="'.$data->username.'"' );
}
function get_mail_data(){
$db = DB::getInstance('mysql_mail');
$data = json_decode(Input::get('data'));
$domains = array();
$results = $db->query("SELECT * FROM users WHERE domain=\"".$data->domain."\"");
if($results->count()>0){
for($i=0; $i<$results->count(); $i++){
$domains[$i] = array(
'id' => $results->results()[$i]->id,
'domain' => $results->results()[$i]->domain,
'userid' => $results->results()[$i]->userid,
'password' => $results->results()[$i]->password,
'date' => $results->results()[$i]->date
);
}
}
echo json_encode($domains);
//print_r(json_encode($domains));
}
function get_all_domains(){
$db = DB::getInstance();
$domains = array();
$results = $db->query("SELECT * FROM users");
if($results->count()>0){
for($i=0; $i<$results->count(); $i++){
$domains[$i] = array(
'id' => $results->results()[$i]->id,
'domain' => $results->results()[$i]->domain_name,
'username' => $results->results()[$i]->username,
'password' => $results->results()[$i]->password,
'date' => $results->results()[$i]->date
);
}
}
echo json_encode($domains);
}
function get_dns_zone_data(){
$db = DB::getInstance();
$data = json_decode(Input::get('data'));
$domain_name = $data->domain_name;
$zone = array();
$results_zone = $db->query('SELECT * FROM dns_zones WHERE domain_name="'.$domain_name.'"');
if($results_zone->count()>0){
$zone['zone'] = array(
"id" => $results_zone->results()[0]->id,
"ttl" => $results_zone->results()[0]->ttl,
"origin" => $results_zone->results()[0]->origin,
"soa" => $results_zone->results()[0]->soa,
"soa_email" => $results_zone->results()[0]->soa_email,
"serial" => $results_zone->first()->serial,
"refresh" => $results_zone->first()->refresh,
"retry" => $results_zone->first()->retry,
"expire" => $results_zone->first()->expire,
"minimum" => $results_zone->first()->minimum
);
$zone['records'] = array();
$results_records = $db->query('SELECT * FROM dns_records WHERE domain_name="'.$domain_name.'"');
if($results_records->count()>0){
for ($i=0; $i < $results_records->count(); $i++) {
$zone['records'][$i] = array(
"id" => $results_records->results()[$i]->id,
"exist" => true,
"comment" => $results_records->results()[$i]->comment,
"resource" => $results_records->results()[$i]->resource,
"type" => $results_records->results()[$i]->type,
"value" => $results_records->results()[$i]->value
);
}
}
echo json_encode($zone);
}
}
// function create_zone_file(){
// $results_zone = $db->query('SELECT * FROM dns_zones WHERE domain_name="webnetpages.com"');
// if($results_zone->count()>0){
// $zone_file = "";
// $zone_file .= "\$TTL ". $results_zone->results()[0]->ttl . "\n";
// $zone_file .= "\$ORIGIN ". $results_zone->first()->origin . "\n";
// $zone_file .= "@ 86400 IN SOA ". $results_zone->first()->soa . " ". $results_zone->first()->soa_email . " (\n";
// $zone_file .= " ". $results_zone->first()->serial . " ; serial, todays date+todays\n";
// $zone_file .= " ". $results_zone->first()->refresh . " ; refresh, seconds\n";
// $zone_file .= " ". $results_zone->first()->retry . " ; retry, seconds\n";
// $zone_file .= " ". $results_zone->first()->expire . " ; expire, seconds\n";
// $zone_file .= " ". $results_zone->first()->minimum . " ) ; minimum, seconds\n";
// $results_records = $db->query('SELECT * FROM dns_records WHERE domain_name="webnetpages.com"');
// if($results_records->count()>0){
// for ($i=0; $i < $results_records->count(); $i++) {
// if($results_records->results()[$i]->comment!="_none_" && $results_records->results()[$i]->comment!=""){
// $zone_file .= ";".$results_records->results()[$i]->comment . "\n";
// }
// $zone_file .= $results_records->results()[$i]->resource . "\t" . $results_records->results()[$i]->type . "\t" . $results_records->results()[$i]->value. "\n\n\n";
// }// end of loop
// }// end of $results_records
// // $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
// // $txt = $zone_file;
// // fwrite($myfile, $txt);
// // fclose($myfile);
// $m = array();
// $out = 1000;
// echo exec('systemctl start named',$m, $out) ."\n";
// echo $out;
// // $results123 = print_r($m, true);
// // $myfile = fopen("newfile2.txt", "w") or die("Unable to open file!");
// // $txt = $zone_file;
// // fwrite($myfile, $results123);
// // fclose($myfile);
// echo "\n";
// }// $results_zones
// }
function update_dns_zone_config_file(){
$zonefile = <<<EOT
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// See the BIND Administrator's Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
/*
- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
- If you are building a RECURSIVE (caching) DNS server, you need to enable
recursion.
- If your recursive DNS server has a public IP address, you MUST enable access
control to limit queries to your legitimate users. Failing to do so will
cause your server to become part of large scale DNS amplification
attacks. Implementing BCP38 within your network would greatly
reduce such attack surface
*/
recursion no;
dnssec-enable yes;
dnssec-validation yes;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
#additional-from-auth no;
#additional-from-cache no;
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
zone "38.79.45.in-addr.arpa" IN {
type master;
file "reverse/38.79.45_in-addr.zone";
};
zone "179.51.79.in-addr.arpa" IN {
type master;
file "reverse/179.51.79_in-addr.zone";
};
EOT;
//
$db = DB::getInstance();
$db = DB::getInstance();
$insert = array(
'username' => $val->username,
'password' => $password,
'email' => $val->email,
'email_verified' => "1",
'access_level' => "1"
);
$db->insert('dns_zone_config',$insert);
}
?>

View File

@@ -0,0 +1,220 @@
<?php
require '../init.php';
ob_start();
$db = DB::getInstance();
ob_clean();
/*
CREATE TABLE dns_records (
id INT AUTO_INCREMENT PRIMARY KEY,
domain_name VARCHAR(255) NULL,
resource VARCHAR(255) NULL,
type VARCHAR(255) NULL,
value TEXT,
comment TEXT,
date TIMESTAMP);
*/
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "@",
"type" => "IN NS",
"value" => "ns1.webnetpages.com.",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "@",
"type" => "IN NS",
"value" => "ns2.webnetpages.com.",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "@",
"type" => "IN A",
"value" => "45.79.38.89",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "server",
"type" => "IN A",
"value" => "45.79.38.89",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "smtp",
"type" => "IN A",
"value" => "45.79.38.89",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "imap",
"type" => "IN A",
"value" => "45.79.38.89",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "@",
"type" => "IN NS",
"value" => "ns1.webnetpages.com.",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "ns1",
"type" => "IN A",
"value" => "45.79.38.89",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "ns2",
"type" => "IN A",
"value" => "45.79.51.179",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "www",
"type" => "IN A",
"value" => "45.79.38.89",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "mail",
"type" => "IN A",
"value" => "45.79.38.89",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "ftp",
"type" => "IN A",
"value" => "45.79.38.89",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "development",
"type" => "IN A",
"value" => "45.79.38.89",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "dev",
"type" => "IN A",
"value" => "45.79.38.89",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "bcma1",
"type" => "IN A",
"value" => "45.79.38.89",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "@",
"type" => "TEXT",
"value" => "\"v=spf1 mx ~all\"",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "_dmarc",
"type" => "TEXT",
"value" => "\"v=DMARC1; p=none; pct=100; rua=mailto:mail-reports@webnetpages.com\"",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "@",
"type" => "IN MX 10",
"value" => "server.webnetpages.com.",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "@",
"type" => "IN TXT",
"value" => "\"mailconf=https://autoconfig.webnetpages.com/mail/config-v1.1.xml\"",
"comment" => "_none_",
"date" => date("Y-m-d H:i:s")
));
$result = $db->insert('dns_records',array(
"domain_name" => "webnetpages.com",
"resource" => "default._domainkey",
"type" => "IN TXT",
"value" => "( \"v=DKIM1; k=rsa; \"
\"p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbrC0G5LTE+laZuKg5yYTLw1C9YgLJ5Ds9wTcQxe152M1dX9y5XfmwHyXV3AYe2j1RnvLMEV03VroEgwgLjJFV65JepSc5efNzy0VZ+ROOey98Gpg9V4abh1aGlbbhNplsoDfyMZnyyWWxZA+5wOANuPyl66OMnAB8ubUvVbL+wwIDAQAB\" )",
"comment" => " ----- DKIM key default for webnetpages.com",
"date" => date("Y-m-d H:i:s")
));
/*
CREATE TABLE dns_zones (
id INT AUTO_INCREMENT PRIMARY KEY,
domain_name VARCHAR(125) NULL,
ttl VARCHAR(125) NULL,
origin VARCHAR(125) NULL,
soa VARCHAR(125) NULL,
soa_email VARCHAR(125) NULL,
serial VARCHAR(125) NULL,
refresh VARCHAR(125) NULL,
expire VARCHAR(125) NULL,
minimum VARCHAR(125) NULL,
date TIMESTAMP);
*/
$result = $db->insert('dns_zones',array(
"ttl" => "86400",
"domain_name" => "webnetpages.com",
"origin" => "webnetpages.com.",
"soa" => "ns1.webnetpages.com.",
"soa_email" => "dnsadmin.server.webnetpages.com.",
"serial" => "5",
"refresh" => "3600",
"expire" => "1209600",
"minimum" => "86400",
"date" => date("Y-m-d H:i:s")
));
?>

View File

@@ -0,0 +1,165 @@
<?php
require '../init.php';
ob_start();
$db = DB::getInstance();
ob_clean();
if (isset($argc)) {
for ($i = 0; $i < $argc; $i++) {
//echo "Argument #" . $i . " - " . $argv[$i] . "\n";
}
}
else {
//echo "argc and argv disabled\n";
}
/*
CREATE TABLE dns_zones (
id INT AUTO_INCREMENT PRIMARY KEY,
domain_name VARCHAR(125) NULL,
ttl VARCHAR(125) NULL,
origin VARCHAR(125) NULL,
soa VARCHAR(125) NULL,
soa_email VARCHAR(125) NULL,
serial VARCHAR(125) NULL,
refresh VARCHAR(125) NULL,
expire VARCHAR(125) NULL,
retry VARCHAR(125) NULL,
minimum VARCHAR(125) NULL,
filename VARCHAR(255) NULL,
date TIMESTAMP);
CREATE TABLE dns_records (
id INT AUTO_INCREMENT PRIMARY KEY,
domain_name VARCHAR(255) NULL,
resource VARCHAR(255) NULL,
type VARCHAR(255) NULL,
value TEXT,
comment TEXT,
date TIMESTAMP);
*/
// INSERT INTO dns_zones
// () VALUES
// ()
$results_zone = $db->query('SELECT * FROM dns_zones WHERE domain_name="webnetpages.com"');
if($results_zone->count()>0){
$zone_file = "";
$zone_file .= "\$TTL ". $results_zone->results()[0]->ttl . "\n";
$zone_file .= "\$ORIGIN ". $results_zone->first()->origin . "\n";
$zone_file .= "@ 86400 IN SOA ". $results_zone->first()->soa . " ". $results_zone->first()->soa_email . " (\n";
$zone_file .= " ". $results_zone->first()->serial . " ; serial, todays date+todays\n";
$zone_file .= " ". $results_zone->first()->refresh . " ; refresh, seconds\n";
$zone_file .= " ". $results_zone->first()->retry . " ; retry, seconds\n";
$zone_file .= " ". $results_zone->first()->expire . " ; expire, seconds\n";
$zone_file .= " ". $results_zone->first()->minimum . " ) ; minimum, seconds\n";
$results_records = $db->query('SELECT * FROM dns_records WHERE domain_name="webnetpages.com"');
if($results_records->count()>0){
for ($i=0; $i < $results_records->count(); $i++) {
if($results_records->results()[$i]->comment!="_none_" && $results_records->results()[$i]->comment!=""){
$zone_file .= ";".$results_records->results()[$i]->comment . "\n";
}
$zone_file .= $results_records->results()[$i]->resource . "\t" . $results_records->results()[$i]->type . "\t" . $results_records->results()[$i]->value. "\n\n\n";
}// end of loop
}// end of $results_records
// $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
// $txt = $zone_file;
// fwrite($myfile, $txt);
// fclose($myfile);
$m = array();
$out = 1000;
echo exec('systemctl start named',$m, $out) ."\n";
echo $out;
// $results123 = print_r($m, true);
// $myfile = fopen("newfile2.txt", "w") or die("Unable to open file!");
// $txt = $zone_file;
// fwrite($myfile, $results123);
// fclose($myfile);
echo "\n";
}// $results_zones
// $results = $db->query('SELECT * FROM dns_zones WHERE main_origin="webnetpages.com"');
// if($results->count()>0){
// $domains = array();
// for($i=0; $i<$results->count(); $i++){
// $domains[$i] = array(
// 'id' => $results->results()[$i]->id,
// 'main_entry' => $results->results()[$i]->main_entry,
// 'main_serial' => $results->results()[$i]->main_serial,
// 'main_refresh' => $results->results()[$i]->main_refresh,
// 'main_expire' => $results->results()[$i]->main_expire,
// 'main_minimum' => $results->results()[$i]->main_minimum,
// 'main_ttl' => $results->results()[$i]->main_ttl,
// 'main_origin' => $results->results()[$i]->main_origin,
// 'main_soa_email' => $results->results()[$i]->main_soa_email,
// 'domain_name' => $results->results()[$i]->domain_name,
// 'name_server' => $results->results()[$i]->name_server,
// 'resource' => $results->results()[$i]->resource,
// 'type' => $results->results()[$i]->type,
// 'value' => $results->results()[$i]->value,
// 'comment' => $results->results()[$i]->comment,
// //'ttl' => $results->results()[$i]->ttl,
// 'date' => $results->results()[$i]->date
// );
// }
// $zone_file = "";
// // $zone_file .= "\$TTL 86400\n";
// // $zone_file .= "\$ORIGIN webnetpages.com.\n";
// // $zone_file .= "@ 86400 IN SOA ns1.webnetpages.com. dnsadmin.server.webnetpages.com. (\n";
// // $zone_file .= " 201700836 ; serial, todays date+todays\n";
// // $zone_file .= " 3600 ; refresh, seconds\n";
// // $zone_file .= " 7200 ; retry, seconds\n";
// // $zone_file .= " 1209600 ; expire, seconds\n";
// // $zone_file .= " 86400 ) ; minimum, seconds\n";
// for ($i=0; $i < count($domains); $i++) {
// $zone_file .= "";
// $zone_file .= "";
// if($domains[$i]["comment"]!=null || $domains[$i]["comment"]!="_none_"){
// //$zone_file .= $domains[$i]["comment"] . "\n";
// }
// if($domains[$i]["resource"]!=null && $domains[$i]["resource"]!="_none_"
// && $domains[$i]["type"]!=null && $domains[$i]["type"]!="_none_"){
// $zone_file .= $domains[$i]["resource"] . "\tIN" . $domains[$i]["type"] . "\t" . $domains[$i]["value"] . "\n";
// }
// }// end of loop
// echo $zone_file;
// }// end of results

View File

@@ -0,0 +1,146 @@
CREATE DATABASE webnetpagesdb;
CREATE USER 'webnetpages'@'localhost' IDENTIFIED BY 'hfkeGGGd983vnskjale!';
GRANT ALL ON webnetpagesdb.* TO 'webnetpages'@'localhost';
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
domain_name VARCHAR(255) NULL,
username VARCHAR(255) NULL,
password VARCHAR(255) NULL,
date TIMESTAMP);
INSERT INTO users (domain_name,username,password,date) VALUES ('webnetpages.com','webnetpages','webnetpages9765',now());
INSERT INTO users (domain_name,username,password,date) VALUES ('2wokegurls.com','2wokegurls','2wokegurls9765',now());
INSERT INTO users (domain_name,username,password,date) VALUES ('bcmaryanpto.org','bcmaryanpto','bcmaryanpto9765',now());
INSERT INTO users (domain_name,username,password,date) VALUES ('equippedcoding.com','equippedcoding','equippedcoding9765',now());
INSERT INTO users (domain_name,username,password,date) VALUES ('appfactoryjs.com','appfactoryjs','appfactoryjs9765',now());
bcmaryanpto.org
2wokegurls.com
equippedcoding.com
appfactoryjs.com
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NULL,
password VARCHAR(255) NULL,
email VARCHAR(255) NULL,
email_confirmed VARCHAR(255) NULL,
terms_and_conditions VARCHAR(255) NULL,
phone VARCHAR(255) NULL,
phone_confirmed VARCHAR(255) NULL,
address VARCHAR(255) NULL,
city VARCHAR(255) NULL,
state VARCHAR(255) NULL,
zip VARCHAR(255) NULL,
last_signin VARCHAR(255) NULL,
date TIMESTAMP);
CREATE TABLE domains (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NULL,
domain_name VARCHAR(255) NULL,
date TIMESTAMP);
#######################################################
#######################################################
#######################################################
#######################################################
#######################################################
##### DNS TABLES #####
CREATE TABLE dns_records (
id INT AUTO_INCREMENT PRIMARY KEY,
domain_name VARCHAR(255) NULL,
resource TEXT,
type VARCHAR(255) NULL,
value TEXT,
comment TEXT,
date TIMESTAMP);
+-------------+--------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| domain_name | varchar(255) | YES | | NULL | |
| resource | varchar(255) | YES | | NULL | |
| type | varchar(255) | YES | | NULL | |
| value | text | YES | | NULL | |
| comment | text | YES | | NULL | |
| date | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------------+--------------+------+-----+-------------------+-----------------------------+
CREATE TABLE dns_zones (
id INT AUTO_INCREMENT PRIMARY KEY,
domain_name VARCHAR(255) NULL,
ttl TEXT,
origin VARCHAR(255) NULL,
soa VARCHAR(255) NULL,
soa_email VARCHAR(255) NULL,
serial VARCHAR(255) NULL,
refresh VARCHAR(255) NULL,
expire VARCHAR(255) NULL,
minimum VARCHAR(255) NULL,
retry VARCHAR(255) NULL,
filename VARCHAR(255) NULL,
date TIMESTAMP);
+-------------+--------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| domain_name | varchar(125) | YES | | NULL | |
| ttl | varchar(125) | YES | | NULL | |
| origin | varchar(125) | YES | | NULL | |
| soa | varchar(125) | YES | | NULL | |
| soa_email | varchar(125) | YES | | NULL | |
| serial | varchar(125) | YES | | NULL | |
| refresh | varchar(125) | YES | | NULL | |
| expire | varchar(125) | YES | | NULL | |
| minimum | varchar(125) | YES | | NULL | |
| date | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| retry | varchar(125) | YES | | 7200 | |
| filename | varchar(255) | YES | | NULL | |
+-------------+--------------+------+-----+-------------------+-----------------------------+
CREATE TABLE dns_zone_config (
id INT AUTO_INCREMENT PRIMARY KEY,
domain VARCHAR(255) NULL,
active INT DEFAULT 1,
data TEXT,
date TIMESTAMP);
{
domain: "",
type: "",
file: ""
}
+--------+--------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| domain | varchar(255) | YES | | NULL | |
| active | int(11) | YES | | 1 | |
| data | text | YES | | NULL | |
| date | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+--------+--------------+------+-----+-------------------+-----------------------------+
#zone "domainname.com" IN {
# type master;
# file "reverse/206.189.211_in-addr.zone";
#};

View File

@@ -0,0 +1,67 @@
<?php
require '../init.php';
require '../dns_options.php';
/*
CREATE TABLE dns_zone_config (
id INT AUTO_INCREMENT PRIMARY KEY,
domain VARCHAR(255) NULL,
active INT DEFAULT 1,
data TEXT,
date TIMESTAMP);
{domain:\"webnetpages.com\",type:\"master\",file:\"zones/webnetpages.com\"}
INSERT INTO dns_zone_config (domain,data) VALUES ("webnetpages.com","{\"domain\":\"webnetpages.com\",\"type\":\"master\",\"file\": \"zones/webnetpages.com\"}");
*/
$zonefile = my_dns_options();
$servername = $GLOBALS['config']['mysql']['host'];
$username = $GLOBALS['config']['mysql']['username'];
$password = $GLOBALS['config']['mysql']['password'];
$dbname = $GLOBALS['config']['mysql']['db'];
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM dns_zone_config where active=1";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
// echo "Domain: " . $row['domain'] . "\n" . "Date: " . $row['date'] . "\n" . "Data: " . $row['data'] . "\n";
$data = json_decode($row['data']);
$zonefile .= <<<EOT
zone "$data->domain" IN {
type $data->type;
file "$data->file";
};
EOT;
}
$myfile = fopen("mydnsfile.conf", "w") or die("Unable to open file!");
fwrite($myfile, $zonefile);
fclose($myfile);
} else {
echo "0 results\n";
}
mysqli_close($conn);
?>

View File

@@ -0,0 +1,20 @@
$TTL 86400
;@ IN SOA 51.79.45.in-addr.arpa. root.localhost. (
@ IN SOA ns2.webnetpages.com. root.localhost. (
991079292 ; serial
28800 ; refresh
14400 ; retry
3600000 ; expire
86400 ; default_ttl
)
@ IN NS ns2.webnetpages.com.
@ IN NS ns1.webnetpages.com.
@ IN NS server.webnetpages.com.
179 IN PTR ns2.webnetpages.com.
89 IN PTR ns1.webnetpages.com.
89 IN PTR 2wokegurls.com.
89 IN PTR www.2wokegurls.com.

View File

@@ -0,0 +1,161 @@
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// See the BIND Administrator's Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
/*
- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
- If you are building a RECURSIVE (caching) DNS server, you need to enable
recursion.
- If your recursive DNS server has a public IP address, you MUST enable access
control to limit queries to your legitimate users. Failing to do so will
cause your server to become part of large scale DNS amplification
attacks. Implementing BCP38 within your network would greatly
reduce such attack surface
*/
recursion no;
dnssec-enable yes;
dnssec-validation yes;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
#additional-from-auth no;
#additional-from-cache no;
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
zone "webnetpages.com" IN {
type master;
file "zones/webnetpages.com";
};
zone "38.79.45.in-addr.arpa" IN {
#zone "84.93.142.in-addr.arpa" IN {
type master;
#file "reverse/142.93.84_in-addr.zone";
file "reverse/38.79.45_in-addr.zone";
};
zone "179.51.79.in-addr.arpa" IN {
#zone "138.68.51.in-addr.arpa" IN {
type master;
#file "reverse/138.68.51_in-addr.zone";
file "reverse/179.51.79_in-addr.zone";
};
#zone "211.189.206.in-addr.arpa" IN {
# type master;
# file "reverse/206.189.211_in-addr.zone";
#};
zone "2wokegurls.com" IN {
type master;
file "zones/twowokegurlscom.zone";
};
zone "equippedcoding.xyz" IN {
type master;
file "zones/equippedcodingxyz.zone";
};
#zone "webpages.email" IN {
# type master;
# file "zones/webpages.email";
#};
#zone "netpages.email" IN {
# type master;
# file "zones/netpages.email";
#};
zone "6shaundra.com" IN {
type master;
file "zones/6shaundra.com.zone";
};
#zone "shaundrasimmonsfoundation.org" IN {
# type master;
# file "zones/shaundrasimmonsfoundation.org.zone";
#};
#zone "shaundrasimmonsfoundation.com" IN {
# type master;
# file "zones/shaundrasimmonsfoundation.com.zone";
#};
#zone "erotass.com" IN {
# type master;
# file "zones/webnetpages_zones/tmp/erotass.com.zone";
#};
zone "houstonvote.org" IN {
type master;
file "zones/houstonvote.org.zone";
};
zone "equippedcoding.net" IN {
type master;
file "zones/equippedcoding.net.zone";
};
zone "appfactoryjs.xyz" IN {
type master;
file "zones/appfactoryjs.com.zone";
};
zone "equippedcoding.org" IN {
type master;
file "zones/equippedcoding.org.zone";
};
zone "equippedcoding.com" IN {
type master;
file "zones/equippedcoding.com.zone";
};
zone "eonofages.com" IN {
type master;
file "zones/eonofages.com.zone";
};

View File

@@ -0,0 +1,73 @@
$TTL 86400
$ORIGIN webnetpages.com.
@ 86400 IN SOA ns1.webnetpages.com. dnsadmin.server.webnetpages.com. (
201700836 ; serial, todays date+todays
3600 ; refresh, seconds
7200 ; retry, seconds
1209600 ; expire, seconds
86400 ) ; minimum, seconds
@ IN NS ns1.webnetpages.com.
@ IN NS ns2.webnetpages.com.
@ IN A 45.79.38.89
server IN A 45.79.38.89
smtp IN A 45.79.38.89
imap IN A 45.79.38.89
ns1 IN A 45.79.38.89
ns2 IN A 45.79.51.179
www IN A 45.79.38.89
mail IN A 45.79.38.89
ftp IN A 45.79.38.89
development IN A 45.79.38.89
dev IN A 45.79.38.89
bcma1 IN A 45.79.38.89
@ TXT "v=spf1 mx ~all"
_dmarc TXT "v=DMARC1; p=none; pct=100; rua=mailto:mail-reports@webnetpages.com"
autoconfig IN A 45.79.38.89
autodiscover IN A 45.79.38.89
;@ IN A ullrs5h7p3b76zorrppt6gg2w5kgngym._domainkey.webnetpages.com.
@ IN MX 10 server.webnetpages.com.
@ IN TXT "mailconf=https://autoconfig.webnetpages.com/mail/config-v1.1.xml"
;_imaps._tcp SRV 0 1 993 server.webnetpages.com.
;_submission._tcp SRV 0 1 465 server.webnetpages.com.
;_autodiscover._tcp SRV 0 0 443 autodiscover.webnetpages.com.
; Stripe credit card processing DNS
@ IN TXT "stripe-verification=a08ba3a27f501966b190eb20893c14cf835948844edd2236d6d5b1813c17f0a9"
4cbhhb6xozzvtysypqhtbaweodtqteir._domainkey IN CNAME 4cbhhb6xozzvtysypqhtbaweodtqteir.dkim.custom-email-domain.stripe.com.
qhfg4ttshm6pkojwspd7vbrtiaaii2cg._domainkey IN CNAME qhfg4ttshm6pkojwspd7vbrtiaaii2cg.dkim.custom-email-domain.stripe.com.
;qhfg4ttshm6pkojwspd7vbrtiaaii2cg._domainkey IN CNAME qhfg4ttshm6pkojwspd7vbrtiaaii2cg.dkim.custom-email-domain.stripe.com.
ullrs5h7p3b76zorrppt6gg2w5kgngym._domainkey IN CNAME ullrs5h7p3b76zorrppt6gg2w5kgngym.dkim.custom-email-domain.stripe.com.
ci2h4r2ayk4h6oldg5ht7vhzwpjfchmk._domainkey IN CNAME ci2h4r2ayk4h6oldg5ht7vhzwpjfchmk.dkim.custom-email-domain.stripe.com.
xdeq2yilgpu57efjmgoyd6ystyccx7gg._domainkey IN CNAME xdeq2yilgpu57efjmgoyd6ystyccx7gg.dkim.custom-email-domain.stripe.com.
k6lvijajflsbghbectalzly3lc355wyt._domainkey IN CNAME k6lvijajflsbghbectalzly3lc355wyt.dkim.custom-email-domain.stripe.com.
bounce IN CNAME custom-email-domain.stripe.com.
default._domainkey IN TXT ( "v=DKIM1; k=rsa; "
"p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbrC0G5LTE+laZuKg5yYTLw1C9YgLJ5Ds9wTcQxe152M1dX9y5XfmwHyXV3AYe2j1RnvLMEV03VroEgwgLjJFV65JepSc5efNzy0VZ+ROOey98Gpg9V4abh1aGlbbhNplsoDfyMZnyyWWxZA+5wOANuPyl66OMnAB8ubUvVbL+wwIDAQAB" ) ; ----- DKIM key default for webnetpages.com

View File

@@ -0,0 +1,20 @@
# dns server1 ip
# dns server2 ip
# 68.223.22.17 - 29

View File

@@ -0,0 +1 @@
you are not alone

View File

@@ -0,0 +1,21 @@
set domain_name [lindex $argv 0]
exec ssh root@$dnsserver1 sh /home/master/scripts/create_http_domain.sh $domain_name

View File

@@ -0,0 +1,90 @@
# get commangline args
set domain_name [lindex $argv 0]
set dnsserver1 [lindex $argv 1]
set dnsserver2 [lindex $argv 2]
# copy over new zone files
exec scp -r zonefile1.txt "root@${dnsserver1}:/home/master/scripts/files"
exec scp -r zonefile1.txt "root@${dnsserver2}:/home/master/scripts/files"
# copy over new zone files
exec scp -r zonefile2.txt "root@${dnsserver1}:/home/master/scripts/files"
exec scp -r zonefile2.txt "root@${dnsserver2}:/home/master/scripts/files"
# run setup script on dns servers
exec ssh root@$dnsserver1 sh /home/master/scripts/manage_zone.sh $domain_name
exec ssh root@$dnsserver2 sh /home/master/scripts/manage_zone.sh $domain_name
# scp -r manage_zone.sh root@45.79.23.5:/home/master/scripts
# scp -r manage_zone.sh root@45.79.51.179:/home/master/scripts
# 45.79.23.5 - xgZGm!E2xjEx!LKZ
# 45.79.51.179 - 42RPUEY!KdxZZZ2!
# 45.79.38.89 - ujqU22zs!!jnptGW
# 192.53.167.231 - 9E8P22r!Nxr!RBaL game
# 68.253.22.17
# 20 - hp
# ,21,22 used
# #php request.php true false false domain.com
# #php request.php true true false domain.com
# php request.php true true true \
# "newdomain7.com" \
# "http_ip" \
# "45.79.23.5" \
# "45.79.23.5" \
# "nameserver1" \
# "nameserver2" \
# "soa_contactserver" \
# "45.79.38.89" \
# "45.79.23.5" \
# "45.79.51.179"
php request.php true true true \
"newdomain18.com" \
"http_ip" \
"45.79.23.5" \
"45.79.23.5" \
"ns1.webnetpages.com" \
"ns2.webnetpages.com" \
"soa_contactserver" \
"45.79.38.89" \
"45.79.23.5" \
"45.79.51.179"

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1,8 @@
{
"provider": "Cradle 2 Career",
"domains": ["cradle2careertx.xyz"],
"servers": [
{"name": "server1.cradle2careertx.xyz", "type": "imap"},
{"name": "server1.cradle2careertx.xyz", "type": "smtp"}
]
}

View File

@@ -0,0 +1,11 @@
#CREATE DATABASE IF NOT EXISTS domainsdb;
#CREATE USER 'domains'@'localhost' IDENTIFIED BY 'jdkfjRGfdkE305!fklldgkl';
#GRANT ALL ON domains.* TO 'domainsdb'@'localhost';
ALTER USER 'domains'@'localhost' IDENTIFIED BY 'jdkfjRGfdkE305!fklldgkl';
FLUSH PRIVILEGES;

View File

@@ -0,0 +1,132 @@
<?php
require_once dirname( __DIR__, 5 ) . "/control_panel/admin/includes/core" . "/init_domains.php";
define("RECORD_NS", "NS");
define("RECORD_MX", "MX");
define("RECORD_SOA", "SOA");
define("RECORD_A", "A");
define("RECORD_AAAA", "AAAA");
define("RECORD_DMARC", "DMARC");
define("RECORD_DKIM", "DKIM");
define("RECORD_CNAME", "CNAME");
$enabledDNS = ($argv[1] == "true") ? true : false;
$enabledHttp = ($argv[2] == "true") ? true : false;
$enabledEmail = ($argv[3] == "true") ? true : false;
$isDummy = ($argv[4] == "true") ? true : false;
$domain = $argv[5];
$nameserver1 = $argv[6];
$nameserver2 = $argv[7];
$soa_contactserver = $argv[8];
$httpserver = $argv[9];
$emailserver = $argv[10];
$dnsserver1 = $argv[11];
$dnsserver2 = $argv[12];
$domainuser = $argv[13];
$brainserver = $argv[14];
$emailnameserver = $argv[15];
$tmpdnsfile = "dnsConfig.txt";
$tmpzonefile1 = "zonefile1.txt";
$tmpzonefile2 = "zonefile2.txt";
$defaultPriorty = "10";
$domainsdb = DB::getInstance();
$isDNSEnabled = false;
$isHttpEnabled = false;
$isEmailEnabled = false;
$rows = $domainsdb->query("SELECT * FROM domains WHERE domain_name='".$domain."'");
if($rows->count()>0){
$isDNSEnabled = $rows->results()[0]->dns_enabled;
$isHttpEnabled = $rows->results()[0]->http_enabled;
$isEmailEnabled = $rows->results()[0]->email_enabled;
}else{
$v1 = ($enabledDNS) ? 1 : 0;
$v2 = ($enabledHttp) ? 1 : 0;
$v3 = ($enabledEmail) ? 1 : 0;
$dummy = 0;
if($isDummy){ $dummy = 1; }
$domainsdb->insert('domains',array(
'domain_name' => $domain,
'dns_enabled' => $v1,
'http_enabled' => $v2,
'email_enabled' => $v3,
'dummy' => $dummy
));
}
require_once "handle.php";
require_once "methods.php";
require_once "file_templates.php";
require_once "dns/handleDNSSetup.php";
require_once "http/handleHttpSetup.php";
require_once "email/handleEmailSetup.php";
if($enabledDNS){
EnableDNS();
sleep(5);
echo "Me: Done installing DNS for domain: " . $domain;
echo "\n";
}
if($enabledEmail){
if($enabledDNS==false){
EnableDNS();
sleep(5);
echo "Me: Done installing DNS for domain: " . $domain;
echo "\n";
}
EnableEmail();
sleep(5);
echo "Me: Done installing Email for domain: " . $domain;
echo "\n";
}
if($enabledHttp){
EnableHttp();
echo "Me: Done installing HTTP for domain: " . $domain;
echo "\n";
}

View File

@@ -0,0 +1,95 @@
#!/bin/sh
# $1 username
# $2 password
# $3 domain
# $4 level
# $5 type
# $6 category
# $7 backupEmail
# $8 firstname
# $9 lastname
# $10 token
# $11 verified
#- username VARCHAR(255) NULL,
#- password VARCHAR(255) NULL,
#- domain VARCHAR(255) NULL,
#- level INT DEFAULT 0,
#- type INT DEFAULT 1,
#- backupEmail VARCHAR(255) NULL,
# userid VARCHAR(255) NULL,
# home VARCHAR(255) NULL,
# verified INT DEFAULT 0,
# uid VARCHAR(255) NULL,
# gid INT NULL,
menow=$(date)
#sh create_email_account2.sh "hello90" "mypass84" "cradle2careertx.xyz" 1 3 0 "my@backup.com" "james" "nine" "lkdajsl" "now()"
echo "====================================================" &>> output
printf "Current %s\n" "$menow" &>> output
# mkdir /var/spool/mailbox/$3/$1
# mkdir /var/spool/mailbox/$3/$1/Maildir
# chmod -R 775 /var/spool/mailbox
# chown -R vmail.vmail /var/spool/mailbox
mkdir /mnt/ddd-server1.$3/mailbox &>> output
mkdir /mnt/ddd-server1.$3/mailbox/$3 &>> output
mkdir /mnt/ddd-server1.$3/mailbox/$3/$1 &>> output
mkdir /mnt/ddd-server1.$3/mailbox/$3/$1/Maildir &>> output
chmod -R 775 /mnt/ddd-server1.$3/mailbox &>> output
chown -R vmail.vmail /mnt/ddd-server1.$3/mailbox &>> output
#('testing29','cradle2careertx.xyz','testing29','{plain}mypass84',now(),'10000','10000','/var/spool/mailbox/cradle2careertx.xyz/testing29',0,1,1,'my@backup.com','james','mitchell','d9dfc8de-7fb6-4305-a900-16eeb1f65cee','2023-02-02');
#echo "('$1','$3','$1','{plain}$2',now(),'10000','10000','/var/spool/mailbox/$3/$1',$4,$5,$6,'$7','$8','$9','${10}',${11});" &>> output
echo "('$1','$3','$1','{plain}$2',now(),'10000','10000','/mnt/ddd-server1.$3/mailbox/$3/$1',$4,$5,$6,'$7','$8','$9','${10}',${11});" &>> output
# ('testing38','cradle2careertx.xyz','testing38','{plain}mypass84',now(),'10000','10000','/var/spool/mailbox/cradle2careertx.xyz/testing38',0,1,1,'my@backup.com','james','mitchell','a11eae43-4402-4028-a0e8-1ff94123e987','2023-02-02 12:49:04');
# 22477022809971
# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
mysql -u webnetpages -pjdkfjRGfdkE305!fklldgkl webnetpagesdb -Bse "INSERT INTO email_users (username,domain,userid,password,date,uid,gid,home,level,type,category,backupEmail,firstname,lastname,token,verified) VALUES ('$1','$3','$1','{plain}$2',now(),'10000','10000','/mnt/ddd-server1.$3/mailbox/$3/$1',$4,$5,$6,'$7','$8','$9','${10}',${11});" &>> output
echo "" &>> output
#mysql -u mailman -pgoodnews84 mail -Bse "INSERT INTO users values('','$1','$3','$1','{plain}$2',now(),'10000','10000','/var/spool/mailbox/$3/$1');"
#echo "$1@$3 $3/$1/Maildir/" >> /etc/postfix/webnetpages_vmail/$3/vmailbox
echo "$1@$3 $3/$1/Maildir/" >> /etc/postfix/vmailbox
#postmap /etc/postfix/vmailbox
/usr/sbin/postmap /etc/postfix/vmailbox &>> output
#echo "Welcome $1" | mail -s "Welcome" $1@$3
echo "Welcome $1" | mail -s "Welcome" $1@$3 -aFrom:Me\<info@$3\> $1@e$3 &>> output
#sleep 15
chmod -R 775 /mnt/ddd-server1.$3/mailbox/$3/$1/Maildir/ &>> output
#
# Successfully received certificate.
# Certificate is saved at: /etc/letsencrypt/live/server1.cradle2careertx.xyz/fullchain.pem
# Key is saved at: /etc/letsencrypt/live/server1.cradle2careertx.xyz/privkey.pem
# This certificate expires on 2023-04-29.
# These files will be updated when the certificate renews.
# Certbot has set up a scheduled task to automatically renew this certificate in the background.
# Deploying certificate
# Successfully deployed certificate for server1.cradle2careertx.xyz to /etc/httpd/conf.d/www/cradle2careertx.xyz-vh-le-ssl.conf
# Congratulations! You have successfully enabled HTTPS on https://server1.cradle2careertx.xyz
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# If you like Certbot, please consider supporting our work by:
# * Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
# * Donating to EFF: https://eff.org/donate-le
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@@ -0,0 +1,31 @@
#!/bin/sh
# $1 username
# $2 password
# $3 domain
# $4 level
# $5 type
# $6 category
# $7 backupEmail
#- username VARCHAR(255) NULL,
#- password VARCHAR(255) NULL,
#- domain VARCHAR(255) NULL,
#- level INT DEFAULT 0,
#- type INT DEFAULT 1,
#- backupEmail VARCHAR(255) NULL,
# userid VARCHAR(255) NULL,
# home VARCHAR(255) NULL,
# verified INT DEFAULT 0,
# uid VARCHAR(255) NULL,
# gid INT NULL,
#sh create_through_test.sh "testing" "mypass84" "cradle2careertx.xyz" 1 3 0 "my@backup.com"
mysql -u appfactorystudio -pjdkfjRGfdkE305!fklldgkl appfactorystudiodb -Bse "INSERT INTO email_users (username,domain,userid,password,date,uid,gid,home,level,type,category,backupEmail) values ('$1','$3','$1','{plain}$2',now(),'10000','10000','/var/spool/mailbox/$3/$1',$4,$5,$6,'$7');"

View File

@@ -0,0 +1,12 @@
#!/bin/sh
domain=$1
user=$2
# DELETE FROM email_users WHERE userid="${user}" AND domain="${domain}"
# rm -rf /var/spool/mailbox/${domain}/${user}
# remove postfix stuff

View File

@@ -0,0 +1,64 @@
<?php
function EnableDNS(){
global $isDummy, $domain, $domainsdb, $httpserver, $nameserver1, $nameserver2, $nameserverdomain1, $nameserverdomain2, $soa_nameserver, $soa_contactserver, $dnsserver1, $dnsserver2, $brainserver, $enabledDNS, $enabledHttp, $enabledEmail, $tmpdnsfile, $tmpzonefile1, $tmpzonefile2;
$defaultPriorty = "10";
// get zone file contents
echo "Me: Creating DNS files... \n";
insertIntoDatabaseZoneData($nameserver1, $soa_nameserver, $soa_contactserver, $httpserver, $nameserver1, $nameserver2);
insertIntoDatabaseZoneData($nameserver2, $soa_nameserver, $soa_contactserver, $httpserver, $nameserver1, $nameserver2);
echo "Me: Creating DNS config file... \n";
createDomainZoneFile();
echo "Me: Copying DNS files to remote servers... \n";
exec("expect dns/run_dns.sh " . $domain . " " . $dnsserver1 . " " . $dnsserver2 . " " . $tmpdnsfile . " " . $tmpzonefile1 . " " . $tmpzonefile2);
// set domain_name [lindex $argv 0]
// set dnsserver1 [lindex $argv 1]
// set dnsserver2 [lindex $argv 2]
// set tmpdnsfile [lindex $argv 3]
// set tmpzonefile1 [lindex $argv 4]
// set tmpzonefile2 [lindex $argv 5]
}
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,254 @@
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// See the BIND Administrator's Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
/*
- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
- If you are building a RECURSIVE (caching) DNS server, you need to enable
recursion.
- If your recursive DNS server has a public IP address, you MUST enable access
control to limit queries to your legitimate users. Failing to do so will
cause your server to become part of large scale DNS amplification
attacks. Implementing BCP38 within your network would greatly
reduce such attack surface
*/
recursion no;
dnssec-enable yes;
dnssec-validation yes;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
#additional-from-auth yes;
#additional-from-cache yes;
#additional-from-auth no;
#additional-from-cache no;
};
#logging {
# channel default_debug {
# file "data/named.run";
# severity dynamic;
# };
#};
logging {
channel default_file {
file "/var/log/named/default.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel general_file {
file "/var/log/named/general.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel database_file {
file "/var/log/named/database.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel security_file {
file "/var/log/named/security.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel config_file {
file "/var/log/named/config.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel resolver_file {
file "/var/log/named/resolver.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel xfer-in_file {
file "/var/log/named/xfer-in.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel xfer-out_file {
file "/var/log/named/xfer-out.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel notify_file {
file "/var/log/named/notify.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel client_file {
file "/var/log/named/client.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel unmatched_file {
file "/var/log/named/unmatched.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel queries_file {
file "/var/log/named/queries.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel network_file {
file "/var/log/named/network.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel update_file {
file "/var/log/named/update.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel dispatch_file {
file "/var/log/named/dispatch.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel dnssec_file {
file "/var/log/named/dnssec.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel lame-servers_file {
file "/var/log/named/lame-servers.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
category default { default_file; };
category general { general_file; };
category database { database_file; };
category security { security_file; };
category config { config_file; };
category resolver { resolver_file; };
category xfer-in { xfer-in_file; };
category xfer-out { xfer-out_file; };
category notify { notify_file; };
category client { client_file; };
category unmatched { unmatched_file; };
category queries { queries_file; };
category network { network_file; };
category update { update_file; };
category dispatch { dispatch_file; };
category dnssec { dnssec_file; };
category lame-servers { lame-servers_file; };
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
zone "webnetpages.com" IN {
type master;
file "zones/webnetpages.com";
};
zone "38.79.45.in-addr.arpa" IN {
#zone "84.93.142.in-addr.arpa" IN {
type master;
#file "reverse/142.93.84_in-addr.zone";
file "reverse/38.79.45_in-addr.zone";
};
zone "179.51.79.in-addr.arpa" IN {
#zone "138.68.51.in-addr.arpa" IN {
type master;
#file "reverse/138.68.51_in-addr.zone";
file "reverse/179.51.79_in-addr.zone";
};
zone "2wokegurls.com" IN {
type master;
file "zones/twowokegurlscom.zone";
};
zone "equippedcoding.xyz" IN {
type master;
file "zones/equippedcodingxyz.zone";
};
zone "equippedcoding.net" IN {
type master;
file "zones/equippedcoding.net.zone";
};
zone "appfactoryjs.xyz" IN {
type master;
file "zones/appfactoryjs.com.zone";
};
zone "equippedcoding.org" IN {
type master;
file "zones/equippedcoding.org.zone";
};
zone "equippedcoding.com" IN {
type master;
file "zones/equippedcoding.com.zone";
};
zone "eonofages.com" IN {
type master;
file "zones/eonofages.com.zone";
};
zone "bcmaryanpto.org" IN {
type master;
file "zones/bcmaryanpto.org.zone";
};
zone "bcmaryanpto.com" IN {
type master;
file "zones/bcmaryanpto.com.zone";
};
zone "imminentimagination.com" IN {
type master;
file "zones/imminentimagination.com.zone";
};

View File

@@ -0,0 +1,185 @@
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// See the BIND Administrator's Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
/*
- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
- If you are building a RECURSIVE (caching) DNS server, you need to enable
recursion.
- If your recursive DNS server has a public IP address, you MUST enable access
control to limit queries to your legitimate users. Failing to do so will
cause your server to become part of large scale DNS amplification
attacks. Implementing BCP38 within your network would greatly
reduce such attack surface
*/
recursion no;
dnssec-enable yes;
dnssec-validation yes;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
#additional-from-auth yes;
#additional-from-cache yes;
#additional-from-auth no;
#additional-from-cache no;
};
#logging {
# channel default_debug {
# file "data/named.run";
# severity dynamic;
# };
#};
logging {
channel default_file {
file "/var/log/named/default.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel general_file {
file "/var/log/named/general.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel database_file {
file "/var/log/named/database.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel security_file {
file "/var/log/named/security.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel config_file {
file "/var/log/named/config.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel resolver_file {
file "/var/log/named/resolver.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel xfer-in_file {
file "/var/log/named/xfer-in.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel xfer-out_file {
file "/var/log/named/xfer-out.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel notify_file {
file "/var/log/named/notify.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel client_file {
file "/var/log/named/client.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel unmatched_file {
file "/var/log/named/unmatched.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel queries_file {
file "/var/log/named/queries.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel network_file {
file "/var/log/named/network.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel update_file {
file "/var/log/named/update.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel dispatch_file {
file "/var/log/named/dispatch.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel dnssec_file {
file "/var/log/named/dnssec.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel lame-servers_file {
file "/var/log/named/lame-servers.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
category default { default_file; };
category general { general_file; };
category database { database_file; };
category security { security_file; };
category config { config_file; };
category resolver { resolver_file; };
category xfer-in { xfer-in_file; };
category xfer-out { xfer-out_file; };
category notify { notify_file; };
category client { client_file; };
category unmatched { unmatched_file; };
category queries { queries_file; };
category network { network_file; };
category update { update_file; };
category dispatch { dispatch_file; };
category dnssec { dnssec_file; };
category lame-servers { lame-servers_file; };
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
zone "38.79.45.in-addr.arpa" IN {
type master;
file "reverse/38.79.45_in-addr.zone";
};
zone "179.51.79.in-addr.arpa" IN {
type master;
file "reverse/179.51.79_in-addr.zone";
};

View File

@@ -0,0 +1,45 @@
#!/bin/sh
# $domain . " " . $dnsserver1 . " " . $dnsserver2 . " " . $tmpdnsfile . " " . $tmpzonefile1 . " " . $tmpzonefile2);
# get commangline args
set domain_name [lindex $argv 0]
set dnsserver1 [lindex $argv 1]
set dnsserver2 [lindex $argv 2]
set tmpdnsfile [lindex $argv 3]
set tmpzonefile1 [lindex $argv 4]
set tmpzonefile2 [lindex $argv 5]
exec scp -r $tmpdnsfile "root@${dnsserver1}:/home/master/runnables/scripts/files"
exec scp -r $tmpdnsfile "root@${dnsserver2}:/home/master/runnables/scripts/files"
# copy over new zone files
exec scp -r $tmpzonefile1 "root@${dnsserver1}:/home/master/runnables/scripts/files"
# copy over new zone files
exec scp -r $tmpzonefile2 "root@${dnsserver2}:/home/master/runnables/scripts/files"
sleep 5
# run setup script on dns servers
exec ssh root@$dnsserver1 sh /home/master/runnables/scripts/remote_create_zone.sh $domain_name $tmpdnsfile $tmpzonefile1
exec ssh root@$dnsserver2 sh /home/master/runnables/scripts/remote_create_zone.sh $domain_name $tmpdnsfile $tmpzonefile2

View File

@@ -0,0 +1,33 @@
$TTL 86400
$ORIGIN newdomain7.com.
@ 86400 IN SOA nameserver1. soa_contactserver. (
201700836 ; serial, todays date+todays
3600 ; refresh, seconds
7200 ; retry, seconds
1209600 ; expire, seconds
86400 ) ; minimum, seconds
@ IN NS ns1.webnetpages.com.
@ IN NS ns2.webnetpages.com.
@ IN A 45.79.23.5
ns1 IN A 45.79.23.5
ns2 IN A 45.79.23.5
www IN A 45.79.23.5
dev IN A 45.79.23.5
autoconfig IN A 45.79.23.5
autodiscover IN A 45.79.23.5

View File

@@ -0,0 +1,241 @@
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// See the BIND Administrator's Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
/*
- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
- If you are building a RECURSIVE (caching) DNS server, you need to enable
recursion.
- If your recursive DNS server has a public IP address, you MUST enable access
control to limit queries to your legitimate users. Failing to do so will
cause your server to become part of large scale DNS amplification
attacks. Implementing BCP38 within your network would greatly
reduce such attack surface
*/
recursion no;
dnssec-enable yes;
dnssec-validation yes;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
#additional-from-auth yes;
#additional-from-cache yes;
#additional-from-auth no;
#additional-from-cache no;
};
#logging {
# channel default_debug {
# file "data/named.run";
# severity dynamic;
# };
#};
logging {
channel default_file {
file "/var/log/named/default.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel general_file {
file "/var/log/named/general.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel database_file {
file "/var/log/named/database.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel security_file {
file "/var/log/named/security.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel config_file {
file "/var/log/named/config.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel resolver_file {
file "/var/log/named/resolver.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel xfer-in_file {
file "/var/log/named/xfer-in.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel xfer-out_file {
file "/var/log/named/xfer-out.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel notify_file {
file "/var/log/named/notify.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel client_file {
file "/var/log/named/client.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel unmatched_file {
file "/var/log/named/unmatched.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel queries_file {
file "/var/log/named/queries.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel network_file {
file "/var/log/named/network.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel update_file {
file "/var/log/named/update.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel dispatch_file {
file "/var/log/named/dispatch.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel dnssec_file {
file "/var/log/named/dnssec.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
channel lame-servers_file {
file "/var/log/named/lame-servers.log" versions 3 size 5m;
severity dynamic;
print-time yes;
};
category default { default_file; };
category general { general_file; };
category database { database_file; };
category security { security_file; };
category config { config_file; };
category resolver { resolver_file; };
category xfer-in { xfer-in_file; };
category xfer-out { xfer-out_file; };
category notify { notify_file; };
category client { client_file; };
category unmatched { unmatched_file; };
category queries { queries_file; };
category network { network_file; };
category update { update_file; };
category dispatch { dispatch_file; };
category dnssec { dnssec_file; };
category lame-servers { lame-servers_file; };
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
zone "38.79.45.in-addr.arpa" IN {
type master;
file "reverse/38.79.45_in-addr.zone";
};
zone "179.51.79.in-addr.arpa" IN {
type master;
file "reverse/179.51.79_in-addr.zone";
};
zone "domain.com" IN {
type master;
file "zones/domain.com.zone";
};
zone "newdomain.com" IN {
type master;
file "zones/newdomain.com.zone";
};
zone "newdomain2.com" IN {
type master;
file "zones/newdomain2.com.zone";
};
zone "newdomain3.com" IN {
type master;
file "zones/newdomain3.com.zone";
};
zone "newdomain4.com" IN {
type master;
file "zones/newdomain4.com.zone";
};
zone "newdomain5.com" IN {
type master;
file "zones/newdomain5.com.zone";
};
zone "newdomain6.com" IN {
type master;
file "zones/newdomain6.com.zone";
};
zone "newdomain7.com" IN {
type master;
file "zones/newdomain7.com.zone";
};

View File

@@ -0,0 +1,178 @@
<?php
function EnableEmail(){
global $isDummy, $domain, $domainsdb, $httpserver, $nameserver1, $nameserver2, $nameserverdomain1, $nameserverdomain2, $soa_nameserver, $soa_contactserver, $dnsserver1, $dnsserver2, $brainserver, $enabledDNS, $enabledHttp, $enabledEmail, $tmpdnsfile, $tmpzonefile1, $tmpzonefile2, $emailserver;
$dummy = 0;
if($isDummy){ $dummy = 1; }
$my = array();
exec("sh email/run_email.sh " . $domain . " " . $emailserver . " " . $brainserver . " " . $dnsserver1 . " " . $dnsserver2 , $my);
print_out_errors($my);
sleep(5);
updateZoneRecords($nameserver1, $nameserver2);
buildZoneRecords();
sleep(5);
// restart services
exec("ssh root@$emailserver sh /home/master/runnables/scripts/remote_restart.sh");
}
function print_out_errors($my){
for ($i=0; $i < count($my); $i++) {
echo $my[$i] . "\n\r";
}
}
function updateZoneRecords($thisNameserver1, $thisNameserver2){
// create records for ns1
createMXRecored($thisNameserver1);
createDKIMRecord($thisNameserver1);
createDMARCRecord($thisNameserver1);
createARecord($thisNameserver1);
createCNAMERecords($thisNameserver1);
// create records for ns2
createMXRecored($thisNameserver2);
createDKIMRecord($thisNameserver2);
createDMARCRecord($thisNameserver2);
createARecord($thisNameserver2);
createCNAMERecords($thisNameserver2);
}
function createCNAMERecords($thisNameserver){
global $isDummy, $domain, $domainsdb, $nameserver1, $nameserver2, $soa_nameserver, $soa_contactserver,
$dnsserver1, $dnsserver2, $brainserver, $isDNSEnabled, $isHttpEnabled, $isEmailEnabled, $httpserver, $emailserver, $emailnameserver ;
$param = "imap";
$type = "CNAME";
$value = $emailnameserver . ".";
$defaultPriorty = "10";
$record_type = RECORD_CNAME;
$comment = "";
$dummy = 0;
if($isDummy){ $dummy = 1; }
createRecord($domainsdb, $thisNameserver, $domain, $param, $type, $comment, $value, $record_type, $defaultPriorty, $dummy);
$param = "smtp";
$type = "CNAME";
$value = $emailnameserver . ".";
$defaultPriorty = "10";
$record_type = RECORD_CNAME;
$comment = "";
$dummy = 0;
if($isDummy){ $dummy = 1; }
createRecord($domainsdb, $thisNameserver, $domain, $param, $type, $comment, $value, $record_type, $defaultPriorty, $dummy);
}
function createARecord($thisNameserver){
global $isDummy, $domain, $domainsdb, $nameserver1, $nameserver2, $soa_nameserver, $soa_contactserver,
$dnsserver1, $dnsserver2, $brainserver, $isDNSEnabled, $isHttpEnabled, $isEmailEnabled, $httpserver, $emailserver;
$param = "server";
$type = "A";
$value = $emailserver;
$defaultPriorty = "10";
$record_type = RECORD_A;
$comment = "";
$dummy = 0;
if($isDummy){ $dummy = 1; }
createRecord($domainsdb, $thisNameserver, $domain, $param, $type, $comment, $value, $record_type, $defaultPriorty, $dummy);
}
function createMXRecored($thisNameserver){
global $isDummy, $domain, $domainsdb, $nameserver1, $nameserver2, $soa_nameserver, $soa_contactserver,
$dnsserver1, $dnsserver2, $brainserver, $isDNSEnabled, $isHttpEnabled, $isEmailEnabled, $httpserver, $emailnameserver;
$param = "@";
$type = "MX";
$value = $emailnameserver . ".";
$defaultPriorty = "10";
$record_type = RECORD_MX;
$comment = "";
$dummy = 0;
if($isDummy){ $dummy = 1; }
createRecord($domainsdb, $thisNameserver, $domain, $param, $type, $comment, $value, $record_type, $defaultPriorty, $dummy);
}
function createDMARCRecord($thisNameserver){
global $isDummy, $domain, $domainsdb, $nameserver1, $nameserver2, $soa_nameserver, $soa_contactserver,
$dnsserver1, $dnsserver2, $brainserver, $isDNSEnabled, $isHttpEnabled, $isEmailEnabled, $httpserver, $emailserver;
// $param = "";
// $type = "";
// $value = $dkim_contents;
// $defaultPriorty = "";
// $record_type = RECORD_DMARC;
// $dummy = 0;
// if($isDummy){ $dummy = 1; }
// createRecord($domainsdb, $domain, $param, $type, $comment, $value, $record_type, $defaultPriorty, $dummy);
}
function createDKIMRecord($thisNameserver){
global $isDummy, $domain, $domainsdb, $nameserver1, $nameserver2, $soa_nameserver, $soa_contactserver,
$dnsserver1, $dnsserver2, $brainserver, $isDNSEnabled, $isHttpEnabled, $isEmailEnabled, $httpserver, $emailserver;
$dkim_contents = getFileContents("/home/master/runnables/scripts/files/".$domain.".default.txt");//"/etc/opendkim/keys/bcmaryanpto.org/default.txt");
$comment = "";
$param = "";
$type = "";
$value = $dkim_contents;
$defaultPriorty = "";
$record_type = RECORD_DKIM;
$dummy = 0;
if($isDummy){ $dummy = 1; }
// $domainsdb->updateFields('named_records', array(
// 'name' => 'mine'
// ),
// array('id' => '1'));
createRecord($domainsdb, $thisNameserver, $domain, $param, $type, $comment, $value, $record_type, $defaultPriorty, $dummy);
}

View File

@@ -0,0 +1,40 @@
#!/bin/sh
domain_name=$1
emailserver=$2
brainserver=$3
dnsserver1=$4
dnsserver2=$5
echo "Me: Running remote_create_email_account.sh on host $emailserver "
ssh root@$emailserver sh /home/master/runnables/scripts/remote_create_email_account.sh \
$domain_name \
"/var/named/zones/$domain_name.zone" \
$brainserver \
$dnsserver1 \
$dnsserver2

View File

@@ -0,0 +1,128 @@
<?php
function createZoneInNamedEntry($zoneEntryContents, $contents){
global $domain, $domainsdb, $dns_ip_1, $dns_ip_2, $nameserver1, $nameserver2, $soa_nameserver, $soa_contactserver,
$dnsserver1, $dnsserver2, $brainserver;
$zoneEntryContents = "\n\n
zone \"".$domain."\" IN {
type master;
file \"zones/".$domain.".zone\";
};
";
$contents .= $zoneEntryContents;
return $contents;
}
function configFileTemplate($domain){
$zone = "
zone \"".$domain."\" IN {
type master;
file \"zones/".$domain.".zone\";
};
";
return $zone;
}
function createZoneFile($domain, $nameserver){
$zoneConfig = getZoneConfig($nameserver);
$recordsArray = getZoneReocrds($nameserver);
$all_records = assembleRecords($recordsArray);
$domaininfo = "
\$TTL ".$zoneConfig['ttl']."
\$ORIGIN ".$domain.".
@ 86400 IN SOA ".$zoneConfig['soa_nameserver'].". ".$zoneConfig['soa_contactserver'].". (
".$zoneConfig['serial_num']." ; serial, todays date+todays
".$zoneConfig['refresh']." ; refresh, seconds
".$zoneConfig['retry']." ; retry, seconds
".$zoneConfig['expire']." ; expire, seconds
".$zoneConfig['minimum']." ) ; minimum, seconds
" . $all_records . "
";
return $domaininfo;
}
function assembleRecords($recordsArray){
$all_records = "";
for ($i=0; $i < count($recordsArray); $i++) {
$rec = $recordsArray[$i];
//echo $rec['record_type'] . " - " . $rec['value'] . "\n";
if($rec['record_type'] == RECORD_NS){
//echo $rec['record_type'] . " - " . $rec['value'];
$comment = $rec['comment'] . "\n";
$record = $comment . $rec['param'] . "\t IN " . $rec['type'] . " " . $rec['value'];
$all_records .= "\n" . $record;
}
}
for ($i=0; $i < count($recordsArray); $i++) {
$rec = $recordsArray[$i];
if($rec['record_type'] == RECORD_MX){
$comment = $rec['comment'] . "\n";
$record = $comment . $rec['param'] . "\t IN " . $rec['type'] . " " . $rec['priority'] . " " . $rec['value'];
$all_records .= "\n" . $record;
}
}
for ($i=0; $i < count($recordsArray); $i++) {
$rec = $recordsArray[$i];
if($rec['record_type'] == RECORD_A){
$comment = $rec['comment'] . "\n";
$record = $comment . $rec['param'] . "\t IN " . $rec['type'] . " " . $rec['value'];
$all_records .= "\n" . $record;
}
}
for ($i=0; $i < count($recordsArray); $i++) {
$rec = $recordsArray[$i];
if($rec['record_type'] == RECORD_CNAME){
// echo $rec['record_type'] . " - " . RECORD_CNAME . "\n";
// echo $rec['value'];
$comment = $rec['comment'] . "\n";
$record = $comment . $rec['param'] . "\t IN " . $rec['type'] . " " . $rec['value'];
$all_records .= "\n" . $record;
}
}
for ($i=0; $i < count($recordsArray); $i++) {
$rec = $recordsArray[$i];
//echo $rec['record_type'] . " - " . $rec['type'] . " - " . $rec['value'] . " - " . RECORD_DKIM . "\n";
if($rec['record_type'] == RECORD_DKIM){
//echo $rec['record_type'] . " - " . $rec['record_type'] . " - " . RECORD_DKIM . "\n";
$comment = $rec['comment'] . "\n";
$record = $comment . $rec['value'];
$all_records .= "\n" . $record;
}
}
//echo $all_records . "\n";
//exit;
return $all_records;
}

View File

@@ -0,0 +1,44 @@
<?php
function contains($needle, $haystack)
{
return strpos($haystack, $needle) !== false;
}
function getFileContents($zonefile){
$myfile = fopen($zonefile, "r") or die("Unable to open file!");
$content = fread($myfile,filesize($zonefile));
fclose($myfile);
return $content;
}
function writeFileContents($zonefile, $contents){
$myfile = fopen($zonefile, "w") or die("Unable to open file!");
fwrite($myfile, $contents);
fclose($myfile);
}

View File

@@ -0,0 +1,88 @@
<?php
function EnableHttp(){
global $isDummy, $domain, $domainsdb, $httpserver, $dns_ip_1, $dns_ip_2, $nameserver1, $nameserver2, $soa_nameserver, $soa_contactserver,
$dnsserver1, $dnsserver2, $brainserver, $domainuser;
$dummy = 0;
if($isDummy){ $dummy = 1; }
writeFileContents("http/domain.com-vh.conf", createHttpConfFile());
$http_domain_file = "/home/master/runnables/scripts/files/domain.com-vh.conf";
$passwd = "nowTheWorldIsRound5";
exec("expect http/run_http.sh " . $domain . " " . $domainuser . " " . $httpserver . " " . $http_domain_file . " " . $passwd);
}
function createHttpConfFile(){
global $domain, $domainuser;
$file = "
####### " . $domain . " :80
<VirtualHost *:80>
ServerAdmin www." . $domain . "
DocumentRoot /home/" . $domainuser . "/websites/www
ServerAlias www." . $domain . " " . $domain . "
ServerName www." . $domain . "
<Directory \"/home/" . $domainuser . "/websites/www\">
DirectoryIndex index.html index.php
Options Indexes FollowSymLinks Includes
AllowOverride All
Allow from all
Require all granted
Order allow,deny
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin dev." . $domain . "
DocumentRoot /home/" . $domainuser . "/websites/dev
ServerAlias " . $domain . "
ServerName dev." . $domain . "
<Directory \"/home/" . $domainuser . "/websites/dev\">
DirectoryIndex index.html index.php
Options Indexes FollowSymLinks Includes
AllowOverride All
Allow from all
Require all granted
Order allow,deny
</Directory>
</VirtualHost>
";
return $file;
}

View File

@@ -0,0 +1,30 @@
#!/bin/sh
set domain_name [lindex $argv 0]
set domain_user [lindex $argv 1]
set httpserver [lindex $argv 2]
set http_domain_file [lindex $argv 3]
set password [lindex $argv 4]
exec scp -r http/domain.com-vh.conf "root@${httpserver}:/home/master/runnables/scripts/files"
exec ssh root@$httpserver expect /home/master/runnables/scripts/remote_create_http.sh \
$domain_name \
$domain_user \
$httpserver \
$http_domain_file \
$password

View File

@@ -0,0 +1,375 @@
<?php
function buildZoneRecords(){
global $domain, $domainsdb, $nameserver1, $nameserver2, $soa_nameserver, $soa_contactserver,
$dnsserver1, $dnsserver2, $brainserver, $tmpdnsfile, $tmpzonefile1, $tmpzonefile2;
echo "Me: Creating DNS files \n";
createDomainZoneFile();
sleep(5);
echo "Me: Running DNS script for email creation \n";
exec("expect /home/webnetpagescom/websites/dev/plugins/app/php/create_domains/dns/run_dns.sh " . $domain . " " . $dnsserver1 . " " . $dnsserver2 . " " . $tmpdnsfile . " " . $tmpzonefile1 . " " . $tmpzonefile2);
}
function createDomainZoneFile(){
global $domain, $domainsdb, $nameserver1, $nameserver2, $soa_nameserver, $soa_contactserver,
$dnsserver1, $dnsserver2, $brainserver;
$zonefile1 = "zonefile1.txt";
$filecontents1 = createZoneFile($domain, $nameserver1);
writeFileContents($zonefile1, $filecontents1);
$zonefile2 = "zonefile2.txt";
$filecontents2 = createZoneFile($domain, $nameserver2);
writeFileContents($zonefile2, $filecontents2);
$mainfile = "dnsConfig.txt";
$zones = getzonesArray();
$bindConfigContents = getFileContents("dns/named_template.conf");
$bindConfigContents = addZonesToConfig($zones, $bindConfigContents);
if(contains($domain, $bindConfigContents) == false){
$bindConfigContents .= configFileTemplate($domain);
}
writeFileContents($mainfile, $bindConfigContents);
}
function addZonesToConfig($zones, $bindConfigContents){
for ($i=0; $i < count($zones); $i++) {
$domain = $zones[$i]['domain_name'];
$bindConfigContents .= configFileTemplate($domain);
}
return $bindConfigContents;
}
function updateNamedFile($zonefile){
global $domain, $domainsdb, $nameserver1, $nameserver2, $soa_nameserver, $soa_contactserver,
$dnsserver1, $dnsserver2, $brainserver;
// get zone file contents
$contents = getFileContents($zonefile);
// first check if zone already exit
$doesExist = doesDomainExist($domain);
// if does exist then just replace info
// else create the new zone
if(!$doesExist){
$contents = createZoneInNamedEntry($zoneEntryContents, $contents);
}
$myfile = fopen($zonefile, "w") or die("Unable to open file!");
fwrite($myfile, $contents);
fclose($myfile);
}
function doesDomainExist($domain){
$pattern = "/".$domain."/is";
preg_match($pattern, $contents, $con);
$exist = false;
if(count($con)>0){
// domain exit in zone file
$exist = true;
}
return $exist;
}
function createRecord($domainsdb, $thisNameserver, $domain, $param, $type, $comment, $value, $record_type, $defaultPriorty, $dummy){
//echo $thisNameserver . " - " . $record_type . " - " . $value . "\n";
if($param == "server" && $domain != "webnetpages.com"){
return;
}
// because the value of a record can be a long and complex string that fails to match, such as the DKIM records,
// a double check is made but specificaly for DMIM records the record is just replaced so there can
// only be 1 DKIM record. This key MUST match whats generatied when running this script
$rows = $domainsdb->query("SELECT * FROM zone_records WHERE domain_name='".$domain."' AND this_nameserver='".$thisNameserver."' AND type='".$type."' AND param='".$param."' AND value='".$value."'");
if($rows->count()>0){
}else{
$r = isDkimRecord($domainsdb,$type,$domain,$thisNameserver,$param);
if($r['is_dkim']){
$domainsdb->updateFields('zone_records',array('value' => $value), array('id' => $r['id']));
return;
}
$domainsdb->insert('zone_records',array(
'record_id' => generateRandomString(32) ,
'domain_name' => $domain,
'this_nameserver' => $thisNameserver,
'param' => $param,
'type' => $type,
'comment' => $comment,
'value' => $value,
'record_type' => $record_type,
'priority' => $defaultPriorty,
'dummy' => $dummy
));
}
}
function isDkimRecord($domainsdb,$type,$domain,$thisNameserver,$param){
$results = array(
'is_dkim' => false,
'id' => 0
);
$rows1 = $domainsdb->query("SELECT * FROM zone_records WHERE domain_name='".$domain."' AND this_nameserver='".$thisNameserver."' AND type='".$type."' AND param='".$param."'");
$isDkim = false;
if($rows1->count()>0){
for($n=0; $n < $rows1->count(); $n++){
if($rows1->results()[$n]->record_type == RECORD_DKIM){
$isDkim = true;
$results['is_dkim'] = true;
$results['id'] = $rows1->results()[$n]->id;
break;
}
}
}
return $results;
}
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
function getZoneConfig($thisNameserver){
global $domain, $domainsdb, $nameserver1, $nameserver2, $soa_nameserver, $soa_contactserver,
$dnsserver1, $dnsserver2, $brainserver;
$zoneConfig = array();
$rows = $domainsdb->query("SELECT * FROM zone_config WHERE domain_name='".$domain."' AND this_nameserver='".$thisNameserver."'");
if($rows->count()>0){
$zoneConfig = array(
'domain_name' => $rows->results()[0]->domain_name,
'this_nameserver' => $rows->results()[0]->this_nameserver,
'ttl' => $rows->results()[0]->ttl,
'origin' => $rows->results()[0]->origin,
'soa_nameserver' => $rows->results()[0]->soa_nameserver,
'soa_contactserver' => $rows->results()[0]->soa_contactserver,
'serial_num' => $rows->results()[0]->serial_num,
'refresh' => $rows->results()[0]->refresh,
'retry' => $rows->results()[0]->retry,
'expire' => $rows->results()[0]->expire,
'minimum' => $rows->results()[0]->minimum
);
}
return $zoneConfig;
}
function getZoneReocrds($thisNameserver){
global $domain, $domainsdb, $nameserver1, $nameserver2, $soa_nameserver, $soa_contactserver,
$dnsserver1, $dnsserver2, $brainserver;
$recordsArray = array();
$rows = $domainsdb->query("SELECT * FROM zone_records WHERE domain_name='".$domain."' AND this_nameserver='".$thisNameserver."'");
if($rows->count()>0){
for($i=0; $i < $rows->count(); $i++){
$c = array(
'domain_name' => $rows->results()[$i]->domain_name,
'this_nameserver' => $rows->results()[$i]->this_nameserver,
'param' => $rows->results()[$i]->param,
'type' => $rows->results()[$i]->type,
'comment' => $rows->results()[$i]->comment,
'value' => $rows->results()[$i]->value,
'record_type' => $rows->results()[$i]->record_type,
'priority' => $rows->results()[$i]->priority
);
$recordsArray[$i] = $c;
}
}
return $recordsArray;
}
// default records - soa, at, ns1, ns1, A, AAAA, imap, www, dev, dmarc, autoconfig, autodiscover, dkim
// soa, at, ns1, ns1, A, AAAA, imap, www, dev, dmarc, dkim
function getzonesArray(){
global $domain, $domainsdb, $nameserver1, $nameserver2, $soa_nameserver, $soa_contactserver,
$dnsserver1, $dnsserver2, $brainserver;
$recordsArray = array();
$rows = $domainsdb->query("SELECT * FROM dns_config WHERE active=1");
if($rows->count()>0){
for($i=0; $i < $rows->count(); $i++){
$c = array(
'domain_name' => $rows->results()[$i]->domain_name,
'comment' => $rows->results()[$i]->comment,
'file' => $rows->results()[$i]->file
);
$recordsArray[$i] = $c;
}
}
// echo count($recordsArray) . "\n";
// echo count($rows->count()) . "\n";
return $recordsArray;
}
function insertIntoDatabaseZoneData($thisNameserver, $soa_nameserver, $soa_contactserver, $httpserver, $ns1, $ns2){
global $isDummy, $domain, $domainsdb, $dnsserver1, $dnsserver2, $brainserver, $enabledDNS, $enabledHttp, $enabledEmail, $defaultPriorty;
$dummy = 0;
if($isDummy){ $dummy = 1; }
$rows = $domainsdb->query("SELECT * FROM dns_config WHERE domain_name='".$domain."'");
if($rows->count()>0){
}else{
$domainsdb->insert('dns_config',array(
"domain_name" => $domain,
"file" => "zones/".$domain.".zone",
'dummy' => $dummy
));
}
$rows = $domainsdb->query("SELECT * FROM zone_config WHERE domain_name='".$domain."' AND this_nameserver='".$thisNameserver."'");
if($rows->count()>0){
}else{
// default records - soa, at, ns1, ns1, A, AAAA, imap, www, dev, dmarc, autoconfig, autodiscover, dkim
$domainsdb->insert('zone_config',array(
'domain_name' => $domain,
'this_nameserver' => $thisNameserver,
'ttl' => "86400",
'origin' => $domain,
'soa_nameserver' => $thisNameserver,
'soa_contactserver' => $soa_contactserver,
'serial_num' => "201700836",
'refresh' => "3600",
'retry' => "7200",
'expire' => "1209600",
'minimum' => "86400",
'dummy' => $dummy
));
}
$_ns1 = $ns1 . ".";
$_ns2 = $ns2 . ".";
//echo $_ns1;
$records = array(
'at1' => array( 'NS' => $_ns1),
'at2' => array( 'NS' => $_ns2),
'at3' => array( 'A' => $httpserver),
'ns1' => array( 'A' => $dnsserver1),
'ns2' => array( 'A' => $dnsserver2),
'www' => array( 'A' => $httpserver),
'dev' => array( 'A' => $httpserver),
'autoconfig' => array( 'A' => $httpserver),
'autodiscover' => array( 'A' => $httpserver)
//'aaaa' => array( '' => ''),
//'imap' => array( '' => ''),
//'dmarc' => array( '' => ''),
//'dkim' => array( '' => ''),
//'mx' => array( $mx => $ip_1)
);
// if($enabledEmail){
// $mx = 'MX ' . $defaultPriorty;
// $records['mx'] = array( $mx => $ip_1);
// // DKIM
// $records['default._domainkey' ] = array( '' => $ip_1);
// $records['dmarc'] = array( 'IN TXT' => $ip_1);
// //$records['imap'] = array( '' => $ip_1);
// }
foreach ($records as $key => $value) {
$param = $key;
$type = "";
$value = "";
$record_type = "";
$comment = "";
// the reason why im looping is because I dont know the param
foreach ($records[$key] as $key1 => $value1) {
$type = $key1;
$value = $value1;
$record_type = $key1;
}
if(strpos($key, "at") !== false){
$param = "@";
}
createRecord($domainsdb, $thisNameserver, $domain, $param, $type, $comment, $value, $record_type, $defaultPriorty, $dummy);
// $domainsdb->insert('zone_records',array(
// 'domain_name' => $domain,
// 'param' => $param,
// 'type' => $type,
// 'comment' => "",
// 'value' => $value,
// 'record_type' => $record_type,
// 'priority' => $defaultPriorty,
// 'dummy' => $dummy
// ));
}
}

View File

@@ -0,0 +1,4 @@

View File

@@ -0,0 +1,28 @@
#!/bin/sh
###! NOT USED!!!
named_conf=$1
zone_file=$2
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
new_named_conf=$named_conf.$current_time
new_zone_file=$zone_file.$current_time
mkdir -p /etc/backup/
mkdir -p /var/named/zones/backup/
mv /etc/named.conf /etc/backup/$new_named_conf
mv named.conf /etc/
mv /var/named/zones/$zone_file /var/named/zones/backup/$new_zone_file
mv $zone_file /var/named/zones
systemctl restart named

View File

@@ -0,0 +1,54 @@
#!/bin/sh
#mv files/zonefile2.txt /etc/named.conf
domain_name=$1
tmp_dns_config_file=$2
tmp_zone_file=$3
named_conf="named.conf"
zone_file="${domain_name}.zone"
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
new_named_conf=named.conf.${current_time}
new_zone_file=${zone_file}.${current_time}
mkdir -p /etc/backup/
mkdir -p /var/named/zones/backup/
# move named.conf
FILE1=/etc/named.conf
if [ -f "$FILE1" ]; then
#echo "$FILE exists."
mv /etc/named.conf /etc/backup/$new_named_conf
fi
mv /home/master/runnables/scripts/files/$tmp_dns_config_file /etc/named.conf
restorecon -RFv /etc/named.conf
# move zone file
FILE2=/var/named/zones/$zone_file
if [ -f "$FILE2" ]; then
#echo "$FILE exists."
mv /var/named/zones/$zone_file /var/named/zones/backup/$new_zone_file
fi
mv /home/master/runnables/scripts/files/$tmp_zone_file /var/named/zones/$zone_file
systemctl restart named

View File

@@ -0,0 +1,81 @@
#!/bin/sh
# $1 username
# $2 password
# $3 domain
if [ -e "/var/spool/mailbox/$3/$1" ]; then
echo "Email account exist, quiting";
exit
fi
mkdir -p /var/spool/mailbox/$3/$1
mkdir -p /var/spool/mailbox/$3/$1/Maildir
echo "Starting...."
chmod -R 775 /var/spool/mailbox
chown -R vmail.vmail /var/spool/mailbox
mysql -u mailman -pGOODnews84! mail -Bse "INSERT INTO users (username,domain,userid,password,date,uid,gid,home) values ('$1','$3','$1','{plain}$2',now(),'10000','10000','/var/spool/mailbox/$3/$1');"
echo "$1@$3 $3/$1/Maildir/" >> /etc/postfix/vmailbox
#postmap /etc/postfix/vmailbox
/usr/sbin/postmap /etc/postfix/vmailbox
echo "Welcome $1" | mail -s "Welcome" $1@$3 -aFrom:Me\<info@$3\> $1@e$3
#sleep 5
chmod -R 775 /var/spool/mailbox/$3/$1/Maildir/
echo "Done"
# # $1 username
# # $2 password
# # $3 domain
# mkdir /var/spool/mailbox/$3/$1
# mkdir /var/spool/mailbox/$3/$1/Maildir
# #echo "Starting...."
# chmod -R 775 /var/spool/mailbox
# chown -R vmail.vmail /var/spool/mailbox
# mysql -u mailman -pgoodnews84 mail -Bse "INSERT INTO users (username,domain,userid,password,date,uid,gid,home) values ('$1','$3','$1','{plain}$2',now(),'10000','10000','/var/spool/mailbox/$3/$1');"
# #mysql -u mailman -pgoodnews84 mail -Bse "INSERT INTO users values('','$1','$3','$1','{plain}$2',now(),'10000','10000','/var/spool/mailbox/$3/$1');"
# #echo "$1@$3 $3/$1/Maildir/" >> /etc/postfix/webnetpages_vmail/$3/vmailbox
# echo "$1@$3 $3/$1/Maildir/" >> /etc/postfix/vmailbox
# #postmap /etc/postfix/vmailbox
# /usr/sbin/postmap /etc/postfix/vmailbox
# #echo "Welcome $1" | mail -s "Welcome" $1@$3
# echo "Welcome $1" | mail -s "Welcome" $1@$3 -aFrom:Me\<info@$3\> $1@e$3
# sleep 15
# chmod -R 775 /var/spool/mailbox/$3/$1/Maildir/

View File

@@ -0,0 +1,120 @@
#!/bin/sh
# $1 - domain
# $2 - zone file (full path)
# $3 - executingServer/brainserver
# $4 - dnsserver1
# $5 - dnsserver2
# imminentimagination.com /var/named/zones/imminentimagination.com.zone
### create the relay domain in Postfix ###
echo "Me: Setting up Postfix relay_domains "
if grep -q $1 "/etc/postfix/relay_domains"; then
#Some Actions # SomeString was found
echo "Me: Domain already in relay_domains "
else
echo "$1 lmtp:[127.0.0.1]" >> /etc/postfix/relay_domains
/usr/sbin/postmap /etc/postfix/relay_domains
fi
### create mail folder ###
echo "Me: Setting up Email mailboxes "
if [ ! -e "/var/spool/mailbox/$1" ]; then
echo "Me: Creating Mailbox directory"
mkdir -p /var/spool/mailbox/$1
chmod -R 775 /var/spool/mailbox
chown -R vmail.vmail /var/spool/mailbox
else
echo "Me: Mailbox directory exist skipping"
fi
### OpenDKIM ###
echo "Me: Setting up Email opendkim "
rm -rf /etc/opendkim/keys/$1
mkdir -p /etc/opendkim/keys/$1
cd /etc/opendkim/keys/$1
opendkim-genkey -d $1 -s default
chown -R opendkim.opendkim /etc/opendkim/keys/$1
DomainPrivateKeyEntry="default._domainkey.$1"
if grep -q $DomainPrivateKeyEntry "/etc/opendkim/KeyTable"; then
sed -i '/default._domainkey.$1 $1:default:/etc/opendkim/keys/$1/default.private/g' /etc/opendkim/KeyTable
else
echo "default._domainkey.$1 $1:default:/etc/opendkim/keys/$1/default.private" >> /etc/opendkim/KeyTable
#remove newlines
sed -i '/^$/d' /etc/opendkim/KeyTable
fi
DomainKeyEntry="default._domainkey.$1"
if grep -q "$DomainKeyEntry" "/etc/opendkim/SigningTable"; then
echo "Me: Domain already exist in SigningTable, replacing..."
sed -i '/default._domainkey.$1/d' /etc/opendkim/SigningTable
else
echo "*@$1 default._domainkey.$1" >> /etc/opendkim/SigningTable
#echo "" >> /etc/opendkim/SigningTable
# remove newlines
sed -i '/^$/d' /etc/opendkim/SigningTable
fi
# add public key
cd /etc/opendkim/keys/$1
# do not update zone file, this should be done by another application
# because the other application will overwrite anything thats added
# cat default.txt >> $2
# echo "" >> $2
# systemctl restart opendkim
# systemctl restart named
# systemctl restart postfix
cp -rf /etc/opendkim/keys/$1/default.txt /home/master/runnables/tmp/
mv /home/master/runnables/tmp/default.txt /home/master/runnables/scripts/files/$1.default.txt
echo "Me: Copying over DNS files to remotes servers for email "
# send file back to requesting server to be added to zone file
scp -r /home/master/runnables/scripts/files/$1.default.txt "root@$3:/home/master/runnables/scripts/files"
# send dkim txt file to dns servers
scp -r /home/master/runnables/scripts/files/$1.default.txt "root@$4:/home/master/runnables/scripts/files"
scp -r /home/master/runnables/scripts/files/$1.default.txt "root@$5:/home/master/runnables/scripts/files"
# send dkim key file to dns servers
# scp -r /home/master/runnables/scripts/files/$1.default.txt "root@$3:/home/master/runnables/scripts/files"
# scp -r /home/master/runnables/scripts/files/$1.default.txt "root@$3:/home/master/runnables/scripts/files"

View File

@@ -0,0 +1,12 @@
#!/bin/sh
systemctl restart opendkim
systemctl restart named
systemctl restart postfix

View File

@@ -0,0 +1,45 @@
#!/bin/sh
set domain_name [lindex $argv 0]
set domain_user [lindex $argv 1]
set httpserver [lindex $argv 2]
set http_domain_file [lindex $argv 3]
set password [lindex $argv 4]
spawn adduser $domain_user
sleep 2
exec /home/master/runnables/scripts/remote_create_http2.sh \
$domain_name \
$domain_user \
$httpserver \
$http_domain_file \
$password
sleep 5
spawn passwd $domain_user
expect "password:"
send "${password}\r"
expect "password:"
send "${password}\r"
sleep 1
spawn systemctl restart httpd
expect ".*" { send "server\r" }
interact

View File

@@ -0,0 +1,28 @@
#!/bin/sh
domain_name=$1
domain_user=$2
password=$3
http_domain_file=$4
mkdir -p /home/$domain_user/websites/www
mkdir -p /home/$domain_user/websites/dev
touch /home/$domain_user/websites/www/index.php
touch /home/$domain_user/websites/dev/index.php
echo "<?php echo 'Under Contruction'; ?> " > /home/$domain_user/websites/www/index.php
echo "<?php echo 'Under Contruction'; ?> " > /home/$domain_user/websites/dev/index.php
chown -R $domain_user.apache /home/$domain_user/
chmod -R 775 /home/$domain_user/
mkdir -p /etc/httpd/conf.d/www/$domain_user/
mv $http_domain_file /etc/httpd/conf.d/www/$domain_user/$domain_name-vh.conf
echo "IncludeOptional conf.d/www/$domain_user/*.conf" >> /etc/httpd/conf/httpd.conf

View File

@@ -0,0 +1,132 @@
#!/bin/sh
https://subdomain.appfactory.studio/plugins/app/php/server/create_domains/run.sh
# cd /home/webnetpagescom/websites/dev/plugins/app/php/create_domains
echo "Me: Copying scripts files over to remote servers..."
#
domain=cradle2careertx.xyz
user_directory=cradle2careertxxyz
email_nameserver=imap.cradle2careertx.xyz
#
http_server1=23.239.24.44
#http_server1=45.79.38.89
domain_server1=45.79.23.5
domain_server2=45.79.51.179
name_server_name1=ns1.webnetpages.com
name_server_name2=ns2.webnetpages.com
PASSWORD=GOODnews84!
# dns files
#scp -r remote_files/dns_remote/remote_create_zone.sh root@$domain_server1:/home/master/runnables/scripts
expect <<END_EXPECT
spawn /usr/bin/scp -r remote_files/dns_remote/remote_create_zone.sh root@$domain_server1:/home/master/runnables/scripts
expect {
"*password:*" {
send $PASSWORD\r
interact
}
}
exit
END_EXPECT
#scp -r remote_files/dns_remote/remote_create_zone.sh root@$domain_server2:/home/master/runnables/scripts
expect <<END_EXPECT
spawn /usr/bin/scp -r remote_files/dns_remote/remote_create_zone.sh root@$domain_server2:/home/master/runnables/scripts
expect {
"*password:*" {
send $PASSWORD\r
interact
}
}
exit
END_EXPECT
# http files
#scp -r remote_files/http_remote/remote_create_http.sh root@$http_server1:/home/master/runnables/scripts
expect <<END_EXPECT
spawn /usr/bin/scp -r remote_files/http_remote/remote_create_http.sh root@$http_server1:/home/master/runnables/scripts
expect {
"*password:*" {
send $PASSWORD\r
interact
}
}
exit
END_EXPECT
#scp -r remote_files/http_remote/remote_create_http2.sh root@$http_server1:/home/master/runnables/scripts
expect <<END_EXPECT
spawn /usr/bin/scp -r remote_files/http_remote/remote_create_http2.sh root@$http_server1:/home/master/runnables/scripts
expect {
"*password:*" {
send $PASSWORD\r
interact
}
}
exit
END_EXPECT
# email files
#scp -r remote_files/email_remote/remote_create_email.sh root@$http_server1:/home/master/runnables/scripts
expect <<END_EXPECT
spawn /usr/bin/scp -r remote_files/email_remote/remote_create_email.sh root@$http_server1:/home/master/runnables/scripts
expect {
"*password:*" {
send $PASSWORD\r
interact
}
}
exit
END_EXPECT
#scp -r remote_files/email_remote/remote_create_email_account.sh root@$http_server1:/home/master/runnables/scripts
expect <<END_EXPECT
spawn /usr/bin/scp -r remote_files/email_remote/remote_create_email_account.sh root@$http_server1:/home/master/runnables/scripts
expect {
"*password:*" {
send $PASSWORD\r
interact
}
}
exit
END_EXPECT
#scp -r remote_files/email_remote/remote_restart.sh root@$http_server1:/home/master/runnables/scripts
expect <<END_EXPECT
spawn /usr/bin/scp -r remote_files/email_remote/remote_restart.sh root@$http_server1:/home/master/runnables/scripts
expect {
"*password:*" {
send $PASSWORD\r
interact
}
}
exit
END_EXPECT
sleep 5
echo "Me: Done copying script files to remote servers"
echo "Me: Creating Domain..."
# if email is set to true then dns is ran by default
# DNS HTTP Email Dummy
php create_domain.php true true false false \
$domain \
$name_server_name1 \
$name_server_name2 \
"postmaster.webnetpages.com" \
$http_server1 \
$http_server1 \
$domain_server1 \
$domain_server1 \
$user_directory \
$http_server1 \
$email_nameserver

View File

@@ -0,0 +1,6 @@
delete from domains where domain_name="timeworknotes.com";
delete from dns_config where domain_name="timeworknotes.com";
delete from zone_config where domain_name="timeworknotes.com";
delete from zone_records where domain_name="timeworknotes.com";

View File

@@ -0,0 +1,29 @@
#!/bin/sh
# *@timeworknotes.com default._domainkey.timeworknotes.com
# DomainKeyEntry="default._domainkey.$1"
# if grep -q $DomainKeyEntry "/etc/opendkim/SigningTable2"; then
# #Some Actions # SomeString was found
# echo "Me: Domain already in relay_domains "
# else
# echo "No exist"
# fi
sed -i '/*@$1 default._domainkey.$1/g' /etc/opendkim/SigningTable2
DomainKeyEntry="default._domainkey.$1"
if grep -q $DomainKeyEntry "/etc/opendkim/SigningTable2"; then
echo "Me: Domain already in relay_domains "
sed -i '/*@$1 default._domainkey.$1/g' /etc/opendkim/SigningTable2
else
echo "No exist"
fi

View File

@@ -0,0 +1,243 @@
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
int main (int argc, char *argv[])
{
setuid (0);
/* WARNING: Only use an absolute path to the script to execute,
* a malicious user might fool the binary and execute
* arbitary commands if not.
* */
//system ("php /path/to/php_shell.sh");
// rm -rf run_create_email_account; gcc wrapper.c -o run_create_email_account; chown root run_create_email_account; chmod u=rwx,go=xr,+s run_create_email_account
// rm -rf run_create_email_account
// gcc wrapper.c -o run_create_email_account
// chown root run_create_email_account
// chmod u=rwx,go=xr,+s run_create_email_account
char destination[] = "sh create_email_account2.sh ";
if(argc == 2){// 1
strcat(destination, argv[1]);
}else if(argc == 3){// 2
strcat(destination, argv[1]);
strcat(destination, " ");
strcat(destination, argv[2]);
}else if(argc == 4){// 3
strcat(destination, argv[1]);
strcat(destination, " ");
strcat(destination, argv[2]);
strcat(destination, " ");
strcat(destination, argv[3]);
}else if(argc == 5){// 4
strcat(destination, argv[1]);
strcat(destination, " ");
strcat(destination, argv[2]);
strcat(destination, " ");
strcat(destination, argv[3]);
strcat(destination, " ");
strcat(destination, argv[4]);
}else if(argc == 6){//5
strcat(destination, argv[1]);
strcat(destination, " ");
strcat(destination, argv[2]);
strcat(destination, " ");
strcat(destination, argv[3]);
strcat(destination, " ");
strcat(destination, argv[4]);
strcat(destination, " ");
strcat(destination, argv[5]);
}else if(argc == 7){
strcat(destination, argv[1]);
strcat(destination, " ");
strcat(destination, argv[2]);
strcat(destination, " ");
strcat(destination, argv[3]);
strcat(destination, " ");
strcat(destination, argv[4]);
strcat(destination, " ");
strcat(destination, argv[5]);
strcat(destination, " ");
strcat(destination, argv[6]);
}else if(argc == 8){
strcat(destination, argv[1]);
strcat(destination, " ");
strcat(destination, argv[2]);
strcat(destination, " ");
strcat(destination, argv[3]);
strcat(destination, " ");
strcat(destination, argv[4]);
strcat(destination, " ");
strcat(destination, argv[5]);
strcat(destination, " ");
strcat(destination, argv[6]);
strcat(destination, " ");
strcat(destination, argv[7]);
}else if(argc == 9){
strcat(destination, argv[1]);
strcat(destination, " ");
strcat(destination, argv[2]);
strcat(destination, " ");
strcat(destination, argv[3]);
strcat(destination, " ");
strcat(destination, argv[4]);
strcat(destination, " ");
strcat(destination, argv[5]);
strcat(destination, " ");
strcat(destination, argv[6]);
strcat(destination, " ");
strcat(destination, argv[7]);
strcat(destination, " ");
strcat(destination, argv[8]);
}else if(argc == 10){
strcat(destination, argv[1]);
strcat(destination, " ");
strcat(destination, argv[2]);
strcat(destination, " ");
strcat(destination, argv[3]);
strcat(destination, " ");
strcat(destination, argv[4]);
strcat(destination, " ");
strcat(destination, argv[5]);
strcat(destination, " ");
strcat(destination, argv[6]);
strcat(destination, " ");
strcat(destination, argv[7]);
strcat(destination, " ");
strcat(destination, argv[8]);
strcat(destination, " ");
strcat(destination, argv[9]);
}else if(argc == 11){
strcat(destination, argv[1]);
strcat(destination, " ");
strcat(destination, argv[2]);
strcat(destination, " ");
strcat(destination, argv[3]);
strcat(destination, " ");
strcat(destination, argv[4]);
strcat(destination, " ");
strcat(destination, argv[5]);
strcat(destination, " ");
strcat(destination, argv[6]);
strcat(destination, " ");
strcat(destination, argv[7]);
strcat(destination, " ");
strcat(destination, argv[8]);
strcat(destination, " ");
strcat(destination, argv[9]);
strcat(destination, " ");
strcat(destination, argv[10]);
}else if(argc == 12){
strcat(destination, argv[1]);
strcat(destination, " ");
strcat(destination, argv[2]);
strcat(destination, " ");
strcat(destination, argv[3]);
strcat(destination, " ");
strcat(destination, argv[4]);
strcat(destination, " ");
strcat(destination, argv[5]);
strcat(destination, " ");
strcat(destination, argv[6]);
strcat(destination, " ");
strcat(destination, argv[7]);
strcat(destination, " ");
strcat(destination, argv[8]);
strcat(destination, " ");
strcat(destination, argv[9]);
strcat(destination, " ");
strcat(destination, argv[10]);
strcat(destination, " ");
strcat(destination, argv[11]);
}else if(argc == 13){
strcat(destination, argv[1]);
strcat(destination, " ");
strcat(destination, argv[2]);
strcat(destination, " ");
strcat(destination, argv[3]);
strcat(destination, " ");
strcat(destination, argv[4]);
strcat(destination, " ");
strcat(destination, argv[5]);
strcat(destination, " ");
strcat(destination, argv[6]);
strcat(destination, " ");
strcat(destination, argv[7]);
strcat(destination, " ");
strcat(destination, argv[8]);
strcat(destination, " ");
strcat(destination, argv[9]);
strcat(destination, " ");
strcat(destination, argv[10]);
strcat(destination, " ");
strcat(destination, argv[11]);
strcat(destination, " ");
strcat(destination, argv[12]);
}else if(argc == 14){
strcat(destination, argv[1]);
strcat(destination, " ");
strcat(destination, argv[2]);
strcat(destination, " ");
strcat(destination, argv[3]);
strcat(destination, " ");
strcat(destination, argv[4]);
strcat(destination, " ");
strcat(destination, argv[5]);
strcat(destination, " ");
strcat(destination, argv[6]);
strcat(destination, " ");
strcat(destination, argv[7]);
strcat(destination, " ");
strcat(destination, argv[8]);
strcat(destination, " ");
strcat(destination, argv[9]);
strcat(destination, " ");
strcat(destination, argv[10]);
strcat(destination, " ");
strcat(destination, argv[11]);
strcat(destination, " ");
strcat(destination, argv[12]);
}else if(argc == 15){
strcat(destination, argv[1]);
strcat(destination, " ");
strcat(destination, argv[2]);
strcat(destination, " ");
strcat(destination, argv[3]);
strcat(destination, " ");
strcat(destination, argv[4]);
strcat(destination, " ");
strcat(destination, argv[5]);
strcat(destination, " ");
strcat(destination, argv[6]);
strcat(destination, " ");
strcat(destination, argv[7]);
strcat(destination, " ");
strcat(destination, argv[8]);
strcat(destination, " ");
strcat(destination, argv[9]);
strcat(destination, " ");
strcat(destination, argv[10]);
strcat(destination, " ");
strcat(destination, argv[11]);
strcat(destination, " ");
strcat(destination, argv[12]);
strcat(destination, " ");
strcat(destination, argv[13]);
}
system (destination);
//strcat(destination, "\n");
//printf(destination);
return 0;
}

View File

@@ -0,0 +1,5 @@
{
"require": {
"ddeboer/imap": "^0.5.2"
}
}

View File

@@ -0,0 +1,133 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "f61a7e81674c3b82bca03da383f8f739",
"packages": [
{
"name": "ddeboer/imap",
"version": "0.5.2",
"source": {
"type": "git",
"url": "https://github.com/ddeboer/imap.git",
"reference": "b1939740d62e427a8105312a3fb574deb62dcf68"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ddeboer/imap/zipball/b1939740d62e427a8105312a3fb574deb62dcf68",
"reference": "b1939740d62e427a8105312a3fb574deb62dcf68",
"shasum": ""
},
"require": {
"ddeboer/transcoder": "~1",
"ext-imap": "*",
"php": ">=5.4.0"
},
"require-dev": {
"ext-iconv": "*",
"ext-mbstring": "*",
"phpunit/phpunit": "~4.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Ddeboer\\Imap\\": "src/",
"Ddeboer\\Imap\\Tests\\": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "David de Boer",
"email": "david@ddeboer.nl"
},
{
"name": "Community contributors",
"homepage": "https://github.com/ddeboer/imap/graphs/contributors"
}
],
"description": "Object-oriented IMAP for PHP",
"keywords": [
"email",
"imap",
"mail"
],
"time": "2015-12-03T13:23:36+00:00"
},
{
"name": "ddeboer/transcoder",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/ddeboer/transcoder.git",
"reference": "8781195ad1334add26dca66a4a823b7973639754"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ddeboer/transcoder/zipball/8781195ad1334add26dca66a4a823b7973639754",
"reference": "8781195ad1334add26dca66a4a823b7973639754",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"suggest": {
"ext-iconv": "For using the IconvTranscoder",
"ext-mbstring": "For using the MbTranscoder"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Ddeboer\\Transcoder\\": "src/",
"Ddeboer\\Transcoder\\Tests\\": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "David de Boer",
"email": "david@ddeboer.nl"
},
{
"name": "Community contributors",
"homepage": "https://github.com/ddeboer/transcoder/graphs/contributors"
}
],
"description": "Better encoding conversion for PHP",
"keywords": [
"charset",
"encoding",
"iconv",
"iso",
"mb",
"multibyte",
"utf-8"
],
"time": "2015-01-23T14:32:33+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}

View File

@@ -0,0 +1,7 @@
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit0941f976d889f32b1b964385205ba233::getLoader();

View File

@@ -0,0 +1,445 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see http://www.php-fig.org/psr/psr-0/
* @see http://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
private $fallbackDirsPsr4 = array();
// PSR-0
private $prefixesPsr0 = array();
private $fallbackDirsPsr0 = array();
private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
private $missingClasses = array();
private $apcuPrefix;
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath.'\\';
if (isset($this->prefixDirsPsr4[$search])) {
foreach ($this->prefixDirsPsr4[$search] as $dir) {
$length = $this->prefixLengthsPsr4[$first][$search];
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}

View File

@@ -0,0 +1,21 @@
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,9 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@@ -0,0 +1,9 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@@ -0,0 +1,13 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Ddeboer\\Transcoder\\Tests\\' => array($vendorDir . '/ddeboer/transcoder/tests'),
'Ddeboer\\Transcoder\\' => array($vendorDir . '/ddeboer/transcoder/src'),
'Ddeboer\\Imap\\Tests\\' => array($vendorDir . '/ddeboer/imap/tests'),
'Ddeboer\\Imap\\' => array($vendorDir . '/ddeboer/imap/src'),
);

View File

@@ -0,0 +1,52 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit0941f976d889f32b1b964385205ba233
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit0941f976d889f32b1b964385205ba233', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit0941f976d889f32b1b964385205ba233', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit0941f976d889f32b1b964385205ba233::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
}
$loader->register(true);
return $loader;
}
}

View File

@@ -0,0 +1,46 @@
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInit0941f976d889f32b1b964385205ba233
{
public static $prefixLengthsPsr4 = array (
'D' =>
array (
'Ddeboer\\Transcoder\\Tests\\' => 25,
'Ddeboer\\Transcoder\\' => 19,
'Ddeboer\\Imap\\Tests\\' => 19,
'Ddeboer\\Imap\\' => 13,
),
);
public static $prefixDirsPsr4 = array (
'Ddeboer\\Transcoder\\Tests\\' =>
array (
0 => __DIR__ . '/..' . '/ddeboer/transcoder/tests',
),
'Ddeboer\\Transcoder\\' =>
array (
0 => __DIR__ . '/..' . '/ddeboer/transcoder/src',
),
'Ddeboer\\Imap\\Tests\\' =>
array (
0 => __DIR__ . '/..' . '/ddeboer/imap/tests',
),
'Ddeboer\\Imap\\' =>
array (
0 => __DIR__ . '/..' . '/ddeboer/imap/src',
),
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit0941f976d889f32b1b964385205ba233::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit0941f976d889f32b1b964385205ba233::$prefixDirsPsr4;
}, null, ClassLoader::class);
}
}

View File

@@ -0,0 +1,121 @@
[
{
"name": "ddeboer/transcoder",
"version": "1.0.0",
"version_normalized": "1.0.0.0",
"source": {
"type": "git",
"url": "https://github.com/ddeboer/transcoder.git",
"reference": "8781195ad1334add26dca66a4a823b7973639754"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ddeboer/transcoder/zipball/8781195ad1334add26dca66a4a823b7973639754",
"reference": "8781195ad1334add26dca66a4a823b7973639754",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"suggest": {
"ext-iconv": "For using the IconvTranscoder",
"ext-mbstring": "For using the MbTranscoder"
},
"time": "2015-01-23T14:32:33+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Ddeboer\\Transcoder\\": "src/",
"Ddeboer\\Transcoder\\Tests\\": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "David de Boer",
"email": "david@ddeboer.nl"
},
{
"name": "Community contributors",
"homepage": "https://github.com/ddeboer/transcoder/graphs/contributors"
}
],
"description": "Better encoding conversion for PHP",
"keywords": [
"charset",
"encoding",
"iconv",
"iso",
"mb",
"multibyte",
"utf-8"
]
},
{
"name": "ddeboer/imap",
"version": "0.5.2",
"version_normalized": "0.5.2.0",
"source": {
"type": "git",
"url": "https://github.com/ddeboer/imap.git",
"reference": "b1939740d62e427a8105312a3fb574deb62dcf68"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ddeboer/imap/zipball/b1939740d62e427a8105312a3fb574deb62dcf68",
"reference": "b1939740d62e427a8105312a3fb574deb62dcf68",
"shasum": ""
},
"require": {
"ddeboer/transcoder": "~1",
"ext-imap": "*",
"php": ">=5.4.0"
},
"require-dev": {
"ext-iconv": "*",
"ext-mbstring": "*",
"phpunit/phpunit": "~4.0"
},
"time": "2015-12-03T13:23:36+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"Ddeboer\\Imap\\": "src/",
"Ddeboer\\Imap\\Tests\\": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "David de Boer",
"email": "david@ddeboer.nl"
},
{
"name": "Community contributors",
"homepage": "https://github.com/ddeboer/imap/graphs/contributors"
}
],
"description": "Object-oriented IMAP for PHP",
"keywords": [
"email",
"imap",
"mail"
]
}
]

View File

@@ -0,0 +1,2 @@
vendor
phpunit.xml

View File

@@ -0,0 +1,5 @@
imports:
- php
tools:
external_code_coverage: true

View File

@@ -0,0 +1,20 @@
language: php
php:
- 5.4
- 5.5
- 5.6
env:
global:
- secure: dT+Srfm2l/hI7eXv+Fxy2QsOTTuunCQEhHq9SdX1W8MUafGszbtJhew4NY7ZT5UJzgJ3XN69tkfnEoiZb3vU0jzGVyJOahNkUFo2yRADz8ZWQWwPrfCmZGWCbh7J+cxb9cA0wUh9E3qsmwMoLVpBwnPlolAiGCm1SKxBYw/QrxM=
- secure: "V9m0u6xxjtsHapzm9Yj4jTm+bP5/I9yuElfzZyCP29D4lq9FCra/ygldx9xUfkCkCgroPWfeeDKfoozpoJcrzdH82KCQ9N908y9xM0FeCWLP/KJBCEvPPTVFpv2z+7NouSSOllBEaMXECUCZxOIxhrmhy4/ua42CrUaUtU9rMjU="
before_script:
- composer install --dev
script: phpunit --coverage-clover=coverage.clover
after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover

View File

@@ -0,0 +1,19 @@
Copyright (C) 2013 David de Boer <david@ddeboer.nl>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,211 @@
IMAP library
============
[![Build Status](https://travis-ci.org/ddeboer/imap.svg?branch=master)](https://travis-ci.org/ddeboer/imap)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ddeboer/imap/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ddeboer/imap/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/ddeboer/imap/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/ddeboer/imap/?branch=master)
[![Latest Stable Version](https://poser.pugx.org/ddeboer/imap/v/stable.svg)](https://packagist.org/packages/ddeboer/imap)
A PHP 5.4+ library to read and process e-mails over IMAP.
Installation
------------
Make sure the [PHP IMAP extension](http://php.net/manual/en/book.imap.php)
is installed. For instance on Debian:
```bash
# apt-get install php5-imap
```
The recommended way to install the IMAP library is through [Composer](http://getcomposer.org):
```bash
$ composer require ddeboer/imap
```
This command requires you to have Composer installed globally, as explained
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
of the Composer documentation.
Usage
-----
### Connect and Authenticate
```php
use Ddeboer\Imap\Server;
$server = new Server('imap.gmail.com');
// $connection is instance of \Ddeboer\Imap\Connection
$connection = $server->authenticate('my_username', 'my_password');
```
#### Options
You can specify port, [flags and parameters](http://php.net/manual/en/function.imap-open.php)
to the server:
```php
$server = new Server(
$hostname, // required
$port, // defaults to 993
$flags, // defaults to '/imap/ssl/validate-cert'
$parameters
);
```
### Mailboxes
Retrieve mailboxes (also known as mail folders) from the mail server and iterate
over them:
```php
$mailboxes = $connection->getMailboxes();
foreach ($mailboxes as $mailbox) {
// $mailbox is instance of \Ddeboer\Imap\Mailbox
printf('Mailbox %s has %s messages', $mailbox->getName(), $mailbox->count());
}
```
Or retrieve a specific mailbox:
```php
$mailbox = $connection->getMailbox('INBOX');
```
Delete a mailbox:
```php
$mailbox->delete();
```
### Messages
Retrieve messages (e-mails) from a mailbox and iterate over them:
```php
$messages = $mailbox->getMessages();
foreach ($messages as $message) {
// $message is instance of \Ddeboer\Imap\Message
}
```
#### Searching for Messages
```php
use Ddeboer\Imap\SearchExpression;
use Ddeboer\Imap\Search\Email\To;
use Ddeboer\Imap\Search\Text\Body;
$search = new SearchExpression();
$search->addCondition(new To('me@here.com'))
->addCondition(new Body('contents'))
;
$messages = $mailbox->getMessages($search);
```
#### Message Properties and Operations
Get message number and unique [message id](http://en.wikipedia.org/wiki/Message-ID)
in the form <...>:
```php
$message->getNumber();
$message->getId();
```
Get other message properties:
```php
$message->getSubject();
$message->getFrom();
$message->getTo();
$message->getDate();
$message->isAnswered();
$message->isDeleted();
$message->isDraft();
$message->isSeen();
```
Get message headers as a [\Ddeboer\Imap\Message\Headers](/src/Ddeboer/Imap/Message/Headers.php) object:
```php
$message->getHeaders();
```
Get message body as HTML or plain text:
```php
$message->getBodyHtml();
$message->getBodyText();
```
Reading the message body marks the message as seen. If you want to keep the
message unseen:
```php
$message->keepUnseen()->getBodyHtml();
```
Move a message to another mailbox:
```php
$mailbox = $connection->getMailbox('another-mailbox');
$message->move($mailbox);
```
Deleting messages:
```php
$mailbox->getMessage(1)->delete();
$mailbox->getMessage(2)->delete();
$mailbox->expunge();
```
### Message Attachments
Get message attachments (both inline and attached) and iterate over them:
```php
$attachments = $message->getAttachments();
foreach ($attachments as $attachment) {
// $attachment is instance of \Ddeboer\Imap\Message\Attachment
}
```
Download a message attachment to a local file:
```php
// getDecodedContent() decodes the attachments contents automatically:
file_put_contents(
'/my/local/dir/' . $attachment->getFilename(),
$attachment->getDecodedContent()
);
```
Running the Tests
-----------------
This library is functionally tested on [Travis CI](https://travis-ci.org/ddeboer/imap)
against the Gmail IMAP server.
If you have your own IMAP (test) account, you can run the tests locally by
providing your IMAP (e.g., Gmail) credentials:
```bash
$ composer install --dev
$ EMAIL_USERNAME="your_username" EMAIL_PASSWORD="your_password" vendor/bin/phpunit
```
You can also set an `EMAIL_SERVER` variable, which defaults to `imap.gmail.com`:
```bash
$ EMAIL_USERNAME="your_username" EMAIL_PASSWORD="your_password" EMAIL_SERVER="imap.you.com" vendor/bin/phpunit
```

View File

@@ -0,0 +1,32 @@
{
"name": "ddeboer/imap",
"description": "Object-oriented IMAP for PHP",
"keywords": [ "email", "mail", "imap" ],
"license": "MIT",
"authors": [
{
"name": "David de Boer",
"email": "david@ddeboer.nl"
},
{
"name": "Community contributors",
"homepage": "https://github.com/ddeboer/imap/graphs/contributors"
}
],
"require": {
"php": ">=5.4.0",
"ext-imap": "*",
"ddeboer/transcoder": "~1"
},
"require-dev": {
"ext-mbstring": "*",
"ext-iconv": "*",
"phpunit/phpunit": "~4.0"
},
"autoload": {
"psr-4": {
"Ddeboer\\Imap\\": "src/",
"Ddeboer\\Imap\\Tests\\": "tests/"
}
}
}

View File

@@ -0,0 +1,930 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "a557b6e246bb8081b88f18a0eeb53979",
"packages": [
{
"name": "ddeboer/transcoder",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/ddeboer/transcoder.git",
"reference": "8781195ad1334add26dca66a4a823b7973639754"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ddeboer/transcoder/zipball/8781195ad1334add26dca66a4a823b7973639754",
"reference": "8781195ad1334add26dca66a4a823b7973639754",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"suggest": {
"ext-iconv": "For using the IconvTranscoder",
"ext-mbstring": "For using the MbTranscoder"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Ddeboer\\Transcoder\\": "src/",
"Ddeboer\\Transcoder\\Tests\\": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "David de Boer",
"email": "david@ddeboer.nl"
},
{
"name": "Community contributors",
"homepage": "https://github.com/ddeboer/transcoder/graphs/contributors"
}
],
"description": "Better encoding conversion for PHP",
"keywords": [
"charset",
"encoding",
"iconv",
"iso",
"mb",
"multibyte",
"utf-8"
],
"time": "2015-01-23 14:32:33"
}
],
"packages-dev": [
{
"name": "doctrine/instantiator",
"version": "1.0.4",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
"reference": "f976e5de371104877ebc89bd8fecb0019ed9c119"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119",
"reference": "f976e5de371104877ebc89bd8fecb0019ed9c119",
"shasum": ""
},
"require": {
"php": ">=5.3,<8.0-DEV"
},
"require-dev": {
"athletic/athletic": "~0.1.8",
"ext-pdo": "*",
"ext-phar": "*",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "2.0.*@ALPHA"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-0": {
"Doctrine\\Instantiator\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com",
"homepage": "http://ocramius.github.com/"
}
],
"description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
"homepage": "https://github.com/doctrine/instantiator",
"keywords": [
"constructor",
"instantiate"
],
"time": "2014-10-13 12:58:55"
},
{
"name": "phpunit/php-code-coverage",
"version": "2.0.15",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "34cc484af1ca149188d0d9e91412191e398e0b67"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/34cc484af1ca149188d0d9e91412191e398e0b67",
"reference": "34cc484af1ca149188d0d9e91412191e398e0b67",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"phpunit/php-file-iterator": "~1.3",
"phpunit/php-text-template": "~1.2",
"phpunit/php-token-stream": "~1.3",
"sebastian/environment": "~1.0",
"sebastian/version": "~1.0"
},
"require-dev": {
"ext-xdebug": ">=2.1.4",
"phpunit/phpunit": "~4"
},
"suggest": {
"ext-dom": "*",
"ext-xdebug": ">=2.2.1",
"ext-xmlwriter": "*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
"homepage": "https://github.com/sebastianbergmann/php-code-coverage",
"keywords": [
"coverage",
"testing",
"xunit"
],
"time": "2015-01-24 10:06:35"
},
{
"name": "phpunit/php-file-iterator",
"version": "1.3.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git",
"reference": "acd690379117b042d1c8af1fafd61bde001bf6bb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb",
"reference": "acd690379117b042d1c8af1fafd61bde001bf6bb",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"autoload": {
"classmap": [
"File/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "FilterIterator implementation that filters files based on a list of suffixes.",
"homepage": "https://github.com/sebastianbergmann/php-file-iterator/",
"keywords": [
"filesystem",
"iterator"
],
"time": "2013-10-10 15:34:57"
},
{
"name": "phpunit/php-text-template",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-text-template.git",
"reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a",
"reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"autoload": {
"classmap": [
"Text/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Simple template engine.",
"homepage": "https://github.com/sebastianbergmann/php-text-template/",
"keywords": [
"template"
],
"time": "2014-01-30 17:20:04"
},
{
"name": "phpunit/php-timer",
"version": "1.0.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-timer.git",
"reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c",
"reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"autoload": {
"classmap": [
"PHP/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Utility class for timing",
"homepage": "https://github.com/sebastianbergmann/php-timer/",
"keywords": [
"timer"
],
"time": "2013-08-02 07:42:54"
},
{
"name": "phpunit/php-token-stream",
"version": "1.4.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
"reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/db32c18eba00b121c145575fcbcd4d4d24e6db74",
"reference": "db32c18eba00b121c145575fcbcd4d4d24e6db74",
"shasum": ""
},
"require": {
"ext-tokenizer": "*",
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"description": "Wrapper around PHP's tokenizer extension.",
"homepage": "https://github.com/sebastianbergmann/php-token-stream/",
"keywords": [
"tokenizer"
],
"time": "2015-01-17 09:51:32"
},
{
"name": "phpunit/phpunit",
"version": "4.4.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "2e8580deebb7d1ac92ac878595e6bffe01069c2a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2e8580deebb7d1ac92ac878595e6bffe01069c2a",
"reference": "2e8580deebb7d1ac92ac878595e6bffe01069c2a",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-json": "*",
"ext-pcre": "*",
"ext-reflection": "*",
"ext-spl": "*",
"php": ">=5.3.3",
"phpunit/php-code-coverage": "~2.0",
"phpunit/php-file-iterator": "~1.3.2",
"phpunit/php-text-template": "~1.2",
"phpunit/php-timer": "~1.0.2",
"phpunit/phpunit-mock-objects": "~2.3",
"sebastian/comparator": "~1.0",
"sebastian/diff": "~1.1",
"sebastian/environment": "~1.1",
"sebastian/exporter": "~1.1",
"sebastian/global-state": "~1.0",
"sebastian/recursion-context": "~1.0",
"sebastian/version": "~1.0",
"symfony/yaml": "~2.0"
},
"suggest": {
"phpunit/php-invoker": "~1.1"
},
"bin": [
"phpunit"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.4.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "The PHP Unit Testing framework.",
"homepage": "https://phpunit.de/",
"keywords": [
"phpunit",
"testing",
"xunit"
],
"time": "2015-01-27 16:06:15"
},
{
"name": "phpunit/phpunit-mock-objects",
"version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
"reference": "c63d2367247365f688544f0d500af90a11a44c65"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/c63d2367247365f688544f0d500af90a11a44c65",
"reference": "c63d2367247365f688544f0d500af90a11a44c65",
"shasum": ""
},
"require": {
"doctrine/instantiator": "~1.0,>=1.0.1",
"php": ">=5.3.3",
"phpunit/php-text-template": "~1.2"
},
"require-dev": {
"phpunit/phpunit": "~4.3"
},
"suggest": {
"ext-soap": "*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.3.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Mock Object library for PHPUnit",
"homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/",
"keywords": [
"mock",
"xunit"
],
"time": "2014-10-03 05:12:11"
},
{
"name": "sebastian/comparator",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "1dd8869519a225f7f2b9eb663e225298fade819e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e",
"reference": "1dd8869519a225f7f2b9eb663e225298fade819e",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"sebastian/diff": "~1.2",
"sebastian/exporter": "~1.2"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Volker Dusch",
"email": "github@wallbash.com"
},
{
"name": "Bernhard Schussek",
"email": "bschussek@2bepublished.at"
},
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"description": "Provides the functionality to compare PHP values for equality",
"homepage": "http://www.github.com/sebastianbergmann/comparator",
"keywords": [
"comparator",
"compare",
"equality"
],
"time": "2015-01-29 16:28:08"
},
{
"name": "sebastian/diff",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
"reference": "5843509fed39dee4b356a306401e9dd1a931fec7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/5843509fed39dee4b356a306401e9dd1a931fec7",
"reference": "5843509fed39dee4b356a306401e9dd1a931fec7",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Kore Nordmann",
"email": "mail@kore-nordmann.de"
},
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"description": "Diff implementation",
"homepage": "http://www.github.com/sebastianbergmann/diff",
"keywords": [
"diff"
],
"time": "2014-08-15 10:29:00"
},
{
"name": "sebastian/environment",
"version": "1.2.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
"reference": "6e6c71d918088c251b181ba8b3088af4ac336dd7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6e6c71d918088c251b181ba8b3088af4ac336dd7",
"reference": "6e6c71d918088c251b181ba8b3088af4ac336dd7",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"description": "Provides functionality to handle HHVM/PHP environments",
"homepage": "http://www.github.com/sebastianbergmann/environment",
"keywords": [
"Xdebug",
"environment",
"hhvm"
],
"time": "2014-10-25 08:00:45"
},
{
"name": "sebastian/exporter",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
"reference": "84839970d05254c73cde183a721c7af13aede943"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943",
"reference": "84839970d05254c73cde183a721c7af13aede943",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"sebastian/recursion-context": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Volker Dusch",
"email": "github@wallbash.com"
},
{
"name": "Bernhard Schussek",
"email": "bschussek@2bepublished.at"
},
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
"name": "Adam Harvey",
"email": "aharvey@php.net"
}
],
"description": "Provides the functionality to export PHP variables for visualization",
"homepage": "http://www.github.com/sebastianbergmann/exporter",
"keywords": [
"export",
"exporter"
],
"time": "2015-01-27 07:23:06"
},
{
"name": "sebastian/global-state",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/global-state.git",
"reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01",
"reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
},
"suggest": {
"ext-uopz": "*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"description": "Snapshotting of global state",
"homepage": "http://www.github.com/sebastianbergmann/global-state",
"keywords": [
"global state"
],
"time": "2014-10-06 09:23:50"
},
{
"name": "sebastian/recursion-context",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/recursion-context.git",
"reference": "3989662bbb30a29d20d9faa04a846af79b276252"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252",
"reference": "3989662bbb30a29d20d9faa04a846af79b276252",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
"name": "Adam Harvey",
"email": "aharvey@php.net"
}
],
"description": "Provides functionality to recursively process PHP variables",
"homepage": "http://www.github.com/sebastianbergmann/recursion-context",
"time": "2015-01-24 09:48:32"
},
{
"name": "sebastian/version",
"version": "1.0.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/version.git",
"reference": "a77d9123f8e809db3fbdea15038c27a95da4058b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/version/zipball/a77d9123f8e809db3fbdea15038c27a95da4058b",
"reference": "a77d9123f8e809db3fbdea15038c27a95da4058b",
"shasum": ""
},
"type": "library",
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "Library that helps with managing the version number of Git-hosted PHP projects",
"homepage": "https://github.com/sebastianbergmann/version",
"time": "2014-12-15 14:25:24"
},
{
"name": "symfony/yaml",
"version": "v2.6.3",
"target-dir": "Symfony/Component/Yaml",
"source": {
"type": "git",
"url": "https://github.com/symfony/Yaml.git",
"reference": "82462a90848a52c2533aa6b598b107d68076b018"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Yaml/zipball/82462a90848a52c2533aa6b598b107d68076b018",
"reference": "82462a90848a52c2533aa6b598b107d68076b018",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.6-dev"
}
},
"autoload": {
"psr-0": {
"Symfony\\Component\\Yaml\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
},
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}
],
"description": "Symfony Yaml Component",
"homepage": "http://symfony.com",
"time": "2015-01-03 15:33:07"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=5.4.0",
"ext-imap": "*"
},
"platform-dev": {
"ext-mbstring": "*",
"ext-iconv": "*"
}
}

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="ddeboer/imap">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@@ -0,0 +1,160 @@
<?php
namespace Ddeboer\Imap;
use Ddeboer\Imap\Exception\Exception;
use Ddeboer\Imap\Exception\MailboxDoesNotExistException;
/**
* A connection to an IMAP server that is authenticated for a user
*/
class Connection
{
private $server;
private $resource;
private $mailboxes;
private $mailboxNames;
/**
* Constructor
*
* @param resource $resource
* @param string $server
*
* @throws \InvalidArgumentException
*/
public function __construct($resource, $server)
{
if (!is_resource($resource)) {
throw new \InvalidArgumentException('$resource must be a resource');
}
$this->resource = $resource;
$this->server = $server;
}
/**
* Get a list of mailboxes (also known as folders)
*
* @return Mailbox[]
*/
public function getMailboxes()
{
if (null === $this->mailboxes) {
foreach ($this->getMailboxNames() as $mailboxName) {
$this->mailboxes[] = $this->getMailbox($mailboxName);
}
}
return $this->mailboxes;
}
/**
* Check that a mailbox with the given name exists
*
* @param string $name Mailbox name
*
* @return bool
*/
public function hasMailbox($name)
{
return in_array($name, $this->getMailboxNames());
}
/**
* Get a mailbox by its name
*
* @param string $name Mailbox name
*
* @return Mailbox
* @throws MailboxDoesNotExistException If mailbox does not exist
*/
public function getMailbox($name)
{
if (!$this->hasMailbox($name)) {
throw new MailboxDoesNotExistException($name);
}
return new Mailbox($this->server . imap_utf7_encode($name), $this);
}
/**
* Count number of messages not in any mailbox
*
* @return int
*/
public function count()
{
return imap_num_msg($this->resource);
}
/**
* Create mailbox
*
* @param $name
*
* @return Mailbox
* @throws Exception
*/
public function createMailbox($name)
{
if (imap_createmailbox($this->resource, $this->server . $name)) {
$this->mailboxNames = $this->mailboxes = null;
return $this->getMailbox($name);
}
throw new Exception("Can not create '{$name}' mailbox at '{$this->server}'");
}
/**
* Close connection
*
* @param int $flag
*
* @return bool
*/
public function close($flag = 0)
{
return imap_close($this->resource, $flag);
}
public function deleteMailbox(Mailbox $mailbox)
{
if (false === imap_deletemailbox(
$this->resource,
$this->server . $mailbox->getName()
)) {
throw new Exception('Mailbox ' . $mailbox->getName() . ' could not be deleted');
}
$this->mailboxes = $this->mailboxNames = null;
}
/**
* Get IMAP resource
*
* @return resource
*/
public function getResource()
{
return $this->resource;
}
/**
* Get mailbox names
*
* @return array
*/
private function getMailboxNames()
{
if (null === $this->mailboxNames) {
$mailboxes = imap_getmailboxes($this->resource, $this->server, '*');
foreach ($mailboxes as $mailbox) {
$this->mailboxNames[] = imap_utf7_decode(str_replace($this->server, '', $mailbox->name));
}
}
return $this->mailboxNames;
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Ddeboer\Imap\Exception;
class AuthenticationFailedException extends Exception
{
public function __construct($user, $error = null)
{
parent::__construct(
sprintf(
'Authentication failed for user %s with error %s',
$user,
$error
)
);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Ddeboer\Imap\Exception;
class Exception extends \RuntimeException
{
protected $errors = array();
public function __construct($message, $code = null, $previous = null)
{
parent::__construct($message, $code, $previous);
$this->errors = imap_errors();
}
/**
* Get IMAP errors
*
* @return array
*/
public function getErrors()
{
return $this->errors;
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Ddeboer\Imap\Exception;
class MailboxDoesNotExistException extends Exception
{
public function __construct($mailbox)
{
parent::__construct('Mailbox ' . $mailbox. ' does not exist');
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Ddeboer\Imap\Exception;
class MessageDeleteException extends Exception
{
public function __construct($messageNumber)
{
parent::__construct(sprintf('Message %s cannot be deleted', $messageNumber));
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Ddeboer\Imap\Exception;
class MessageDoesNotExistException extends Exception
{
public function __construct($number, $error)
{
parent::__construct(
sprintf(
'Message %s does not exist: %s',
$number,
$error
)
);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Ddeboer\Imap\Exception;
class MessageMoveException extends Exception
{
public function __construct($messageNumber, $mailbox)
{
parent::__construct(
sprintf(
'Message %s cannot be moved to %s',
$messageNumber,
$mailbox
)
);
}
}

View File

@@ -0,0 +1,143 @@
<?php
namespace Ddeboer\Imap;
/**
* An IMAP mailbox (commonly referred to as a folder)
*
*/
class Mailbox implements \Countable, \IteratorAggregate
{
private $mailbox;
private $name;
private $connection;
/**
* Constructor
*
* @param string $name Mailbox name
* @param Connection $connection IMAP connection
*/
public function __construct($name, Connection $connection)
{
$this->mailbox = $name;
$this->connection = $connection;
$this->name = substr($name, strpos($name, '}')+1);
}
/**
* Get mailbox name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Get number of messages in this mailbox
*
* @return int
*/
public function count()
{
$this->init();
return imap_num_msg($this->connection->getResource());
}
/**
* Get message ids
*
* @param SearchExpression $search Search expression (optional)
*
* @return MessageIterator|Message[]
*/
public function getMessages(SearchExpression $search = null)
{
$this->init();
$query = ($search ? (string) $search : 'ALL');
$messageNumbers = imap_search($this->connection->getResource(), $query, \SE_UID);
if (false == $messageNumbers) {
// imap_search can also return false
$messageNumbers = array();
}
return new MessageIterator($this->connection->getResource(), $messageNumbers);
}
/**
* Get a message by message number
*
* @param int $number Message number
*
* @return Message
*/
public function getMessage($number)
{
$this->init();
return new Message($this->connection->getResource(), $number);
}
/**
* Get messages in this mailbox
*
* @return MessageIterator
*/
public function getIterator()
{
$this->init();
return $this->getMessages();
}
/**
* Delete this mailbox
*
*/
public function delete()
{
$this->connection->deleteMailbox($this);
}
/**
* Delete all messages marked for deletion
*
* @return Mailbox
*/
public function expunge()
{
$this->init();
imap_expunge($this->connection->getResource());
return $this;
}
/**
* Add a message to the mailbox
*
* @param string $message
*
* @return boolean
*/
public function addMessage($message)
{
return imap_append($this->connection->getResource(), $this->mailbox, $message);
}
/**
* If connection is not currently in this mailbox, switch it to this mailbox
*/
private function init()
{
$check = imap_check($this->connection->getResource());
if ($check === false || $check->Mailbox != $this->mailbox) {
imap_reopen($this->connection->getResource(), $this->mailbox);
}
}
}

View File

@@ -0,0 +1,331 @@
<?php
namespace Ddeboer\Imap;
use Ddeboer\Imap\Exception\MessageDoesNotExistException;
use Ddeboer\Imap\Message\EmailAddress;
use Ddeboer\Imap\Exception\MessageDeleteException;
use Ddeboer\Imap\Exception\MessageMoveException;
/**
* An IMAP message (e-mail)
*/
class Message extends Message\Part
{
private $headers;
private $attachments;
/**
* @var boolean
*/
private $keepUnseen = false;
/**
* Constructor
*
* @param resource $stream IMAP stream
* @param int $messageNumber Message number
*/
public function __construct($stream, $messageNumber)
{
$this->stream = $stream;
$this->messageNumber = $messageNumber;
$this->loadStructure();
}
/**
* Get message id
*
* A unique message id in the form <...>
*
* @return string
*/
public function getId()
{
return $this->getHeaders()->get('message_id');
}
/**
* Get message sender (from headers)
*
* @return EmailAddress
*/
public function getFrom()
{
return $this->getHeaders()->get('from');
}
/**
* Get To recipients
*
* @return EmailAddress[] Empty array in case message has no To: recipients
*/
public function getTo()
{
return $this->getHeaders()->get('to') ?: [];
}
/**
* Get Cc recipients
*
* @return EmailAddress[] Empty array in case message has no CC: recipients
*/
public function getCc()
{
return $this->getHeaders()->get('cc') ?: [];
}
/**
* Get message number (from headers)
*
* @return int
*/
public function getNumber()
{
return $this->messageNumber;
}
/**
* Get date (from headers)
*
* @return \DateTime
*/
public function getDate()
{
return $this->getHeaders()->get('date');
}
/**
* Get message size (from headers)
*
* @return int
*/
public function getSize()
{
return $this->getHeaders()->get('size');
}
/**
* Get raw part content
*
* @return string
*/
public function getContent($keepUnseen = false)
{
// Null headers, so subsequent calls to getHeaders() will return
// updated seen flag
$this->headers = null;
return $this->doGetContent($this->keepUnseen ? $this->keepUnseen : $keepUnseen);
}
/**
* Get message answered flag value (from headers)
*
* @return boolean
*/
public function isAnswered()
{
return $this->getHeaders()->get('answered');
}
/**
* Get message deleted flag value (from headers)
*
* @return boolean
*/
public function isDeleted()
{
return $this->getHeaders()->get('deleted');
}
/**
* Get message draft flag value (from headers)
*
* @return boolean
*/
public function isDraft()
{
return $this->getHeaders()->get('draft');
}
/**
* Has the message been marked as read?
*
* @return boolean
*/
public function isSeen()
{
return 'U' != $this->getHeaders()->get('unseen');
}
/**
* Get message subject (from headers)
*
* @return string
*/
public function getSubject()
{
return $this->getHeaders()->get('subject');
}
/**
* Get message headers
*
* @return Message\Headers
*/
public function getHeaders()
{
if (null === $this->headers) {
// imap_header is much faster than imap_fetchheader
// imap_header returns only a subset of all mail headers,
// but it does include the message flags.
$headers = imap_header($this->stream, imap_msgno($this->stream, $this->messageNumber));
$this->headers = new Message\Headers($headers);
}
return $this->headers;
}
/**
* Get body HTML
*
* @return string | null Null if message has no HTML message part
*/
public function getBodyHtml()
{
$iterator = new \RecursiveIteratorIterator($this, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $part) {
if ($part->getSubtype() == 'HTML') {
return $part->getDecodedContent($this->keepUnseen);
}
}
}
/**
* Get body text
*
* @return string
*/
public function getBodyText()
{
$iterator = new \RecursiveIteratorIterator($this, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $part) {
if ($part->getSubtype() == 'PLAIN') {
return $part->getDecodedContent($this->keepUnseen);
}
}
// If message has no parts, return content of message itself.
return $this->getDecodedContent($this->keepUnseen);
}
/**
* Get attachments (if any) linked to this e-mail
*
* @return Message\Attachment[]
*/
public function getAttachments()
{
if (null === $this->attachments) {
$this->attachments = array();
foreach ($this->getParts() as $part) {
if ($part instanceof Message\Attachment) {
$this->attachments[] = $part;
}
if ($part->hasChildren()) {
foreach ($part->getParts() as $child_part) {
if ($child_part instanceof Message\Attachment) {
$this->attachments[] = $child_part;
}
}
}
}
}
return $this->attachments;
}
/**
* Does this message have attachments?
*
* @return bool
*/
public function hasAttachments()
{
return count($this->getAttachments()) > 0;
}
/**
* Delete message
*
* @throws MessageDeleteException
*/
public function delete()
{
// 'deleted' header changed, force to reload headers, would be better to set deleted flag to true on header
$this->headers = null;
if (!imap_delete($this->stream, $this->messageNumber, \FT_UID)) {
throw new MessageDeleteException($this->messageNumber);
}
}
/**
* Move message to another mailbox
* @param Mailbox $mailbox
*
* @throws MessageMoveException
* @return Message
*/
public function move(Mailbox $mailbox)
{
if (!imap_mail_move($this->stream, $this->messageNumber, $mailbox->getName(), \CP_UID)) {
throw new MessageMoveException($this->messageNumber, $mailbox->getName());
}
return $this;
}
/**
* Prevent the message from being marked as seen
*
* Defaults to true, so messages that are read will be still marked as unseen.
*
* @param bool $bool
*
* @return Message
*/
public function keepUnseen($bool = true)
{
$this->keepUnseen = (bool) $bool;
return $this;
}
/**
* Load message structure
*/
private function loadStructure()
{
set_error_handler(
function ($nr, $error) {
throw new MessageDoesNotExistException(
$this->messageNumber,
$error
);
}
);
$structure = imap_fetchstructure(
$this->stream,
$this->messageNumber,
\FT_UID
);
restore_error_handler();
$this->parseStructure($structure);
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Ddeboer\Imap\Message;
/**
* An e-mail attachment
*/
class Attachment extends Part
{
/**
* Get attachment filename
*
* @return string
*/
public function getFilename()
{
return $this->parameters->get('filename')
?: $this->parameters->get('name');
}
/**
* Get attachment file size
*
* @return int Number of bytes
*/
public function getSize()
{
return $this->parameters->get('size');
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Ddeboer\Imap\Message;
/**
* An e-mail address
*/
class EmailAddress
{
private $mailbox;
private $hostname;
private $name;
private $address;
public function __construct($mailbox, $hostname = null, $name = null)
{
$this->mailbox = $mailbox;
$this->hostname = $hostname;
$this->name = $name;
if ($hostname) {
$this->address = $mailbox . '@' . $hostname;
}
}
public function getAddress()
{
return $this->address;
}
/**
* Returns address with person name
*
* @return string
*/
public function getFullAddress()
{
if ($this->name) {
$address = sprintf("%s <%s@%s>", $this->name, $this->mailbox, $this->hostname);
} else {
$address = sprintf("%s@%s", $this->mailbox, $this->hostname);
}
return $address;
}
public function getMailbox()
{
return $this->mailbox;
}
public function getHostname()
{
return $this->hostname;
}
public function getName()
{
return $this->name;
}
public function __toString()
{
return $this->getAddress();
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace Ddeboer\Imap\Message;
use Ddeboer\Imap\Parameters;
/**
* Collection of message headers
*/
class Headers extends Parameters
{
/**
* Constructor
*
* @param \stdClass $headers
*/
public function __construct(\stdClass $headers)
{
// Store all headers as lowercase
$headers = array_change_key_case((array) $headers);
foreach ($headers as $key => $value) {
$this->parameters[$key] = $this->parseHeader($key, $value);
}
}
/**
* Get header
*
* @param string $key
*
* @return string
*/
public function get($key)
{
return parent::get(strtolower($key));
}
private function parseHeader($key, $value)
{
switch ($key) {
case 'msgno':
return (int)$value;
case 'answered':
// no break
case 'deleted':
// no break
case 'draft':
// no break
case 'unseen':
return (bool)trim($value);
case 'date':
$value = $this->decode($value);
$value = preg_replace('/([^\(]*)\(.*\)/', '$1', $value);
return new \DateTime($value);
case 'from':
return $this->decodeEmailAddress(current($value));
case 'to':
// no break
case 'cc':
$emails = [];
foreach ($value as $address) {
$emails[] = $this->decodeEmailAddress($address);
}
return $emails;
case 'subject':
return $this->decode($value);
default:
return $value;
}
}
private function decodeEmailAddress($value)
{
return new EmailAddress(
$value->mailbox,
isset($value->host) ? $value->host : null,
isset($value->personal) ? $this->decode($value->personal) : null
);
}
}

View File

@@ -0,0 +1,354 @@
<?php
namespace Ddeboer\Imap\Message;
use Ddeboer\Imap\Parameters;
use Ddeboer\Transcoder\Transcoder;
/**
* A message part
*/
class Part implements \RecursiveIterator
{
const TYPE_TEXT = 'text';
const TYPE_MULTIPART = 'multipart';
const TYPE_MESSAGE = 'message';
const TYPE_APPLICATION = 'application';
const TYPE_AUDIO = 'audio';
const TYPE_IMAGE = 'image';
const TYPE_VIDEO = 'video';
const TYPE_OTHER = 'other';
const TYPE_UNKNOWN = 'unknown';
const ENCODING_7BIT = '7bit';
const ENCODING_8BIT = '8bit';
const ENCODING_BINARY = 'binary';
const ENCODING_BASE64 = 'base64';
const ENCODING_QUOTED_PRINTABLE = 'quoted-printable';
const ENCODING_UNKNOWN = 'unknown';
const SUBTYPE_TEXT = 'TEXT';
const SUBTYPE_HTML = 'HTML';
protected $typesMap = array(
0 => self::TYPE_TEXT,
1 => self::TYPE_MULTIPART,
2 => self::TYPE_MESSAGE,
3 => self::TYPE_APPLICATION,
4 => self::TYPE_AUDIO,
5 => self::TYPE_IMAGE,
6 => self::TYPE_VIDEO,
7 => self::TYPE_OTHER
);
protected $encodingsMap = array(
0 => self::ENCODING_7BIT,
1 => self::ENCODING_8BIT,
2 => self::ENCODING_BINARY,
3 => self::ENCODING_BASE64,
4 => self::ENCODING_QUOTED_PRINTABLE,
5 => self::ENCODING_UNKNOWN
);
protected $type;
protected $subtype;
protected $encoding;
protected $bytes;
protected $lines;
/**
* @var Parameters
*/
protected $parameters;
protected $stream;
protected $messageNumber;
protected $partNumber;
protected $structure;
protected $content;
protected $decodedContent;
protected $parts = array();
protected $key = 0;
protected $disposition;
/**
* Constructor
*
* @param resource $stream IMAP stream
* @param int $messageNumber Message number
* @param int $partNumber Part number (optional)
* @param \stdClass $structure Part structure
*/
public function __construct(
$stream,
$messageNumber,
$partNumber = null,
\stdClass $structure = null
) {
$this->stream = $stream;
$this->messageNumber = $messageNumber;
$this->partNumber = $partNumber;
$this->structure = $structure;
$this->parseStructure($structure);
}
public function getCharset()
{
return $this->parameters->get('charset');
}
public function getType()
{
return $this->type;
}
public function getSubtype()
{
return $this->subtype;
}
public function getEncoding()
{
return $this->encoding;
}
public function getBytes()
{
return $this->bytes;
}
public function getLines()
{
return $this->lines;
}
public function getParameters()
{
return $this->parameters;
}
/**
* Get raw part content
*
* @return string
*/
public function getContent($keepUnseen = false)
{
if (null === $this->content) {
$this->content = $this->doGetContent($keepUnseen);
}
return $this->content;
}
/**
* Get decoded part content
*
* @return string
*/
public function getDecodedContent($keepUnseen = false)
{
if (null === $this->decodedContent) {
switch ($this->getEncoding()) {
case self::ENCODING_BASE64:
$this->decodedContent = base64_decode($this->getContent($keepUnseen));
break;
case self::ENCODING_QUOTED_PRINTABLE:
$this->decodedContent = quoted_printable_decode($this->getContent($keepUnseen));
break;
case self::ENCODING_7BIT:
case self::ENCODING_8BIT:
case self::ENCODING_BINARY:
$this->decodedContent = $this->getContent($keepUnseen);
break;
default:
throw new \UnexpectedValueException('Cannot decode ' . $this->getEncoding());
}
// If this part is a text part, try to convert its encoding to UTF-8.
// We don't want to convert an attachment's encoding.
if ($this->getType() === self::TYPE_TEXT
&& strtolower($this->getCharset()) != 'utf-8'
) {
$this->decodedContent = Transcoder::create()->transcode(
$this->decodedContent,
$this->getCharset()
);
}
}
return $this->decodedContent;
}
public function getStructure()
{
return $this->structure;
}
protected function fetchStructure($partNumber = null)
{
if (null === $this->structure) {
$this->loadStructure();
}
if ($partNumber) {
return $this->structure->parts[$partNumber];
}
return $this->structure;
}
protected function parseStructure(\stdClass $structure)
{
if (isset($this->typesMap[$structure->type])) {
$this->type = $this->typesMap[$structure->type];
} else {
$this->type = self::TYPE_UNKNOWN;
}
$this->encoding = $this->encodingsMap[$structure->encoding];
$this->subtype = $structure->subtype;
if (isset($structure->bytes)) {
$this->bytes = $structure->bytes;
}
foreach (array('disposition', 'bytes', 'description') as $optional) {
if (isset($structure->$optional)) {
$this->$optional = $structure->$optional;
}
}
$this->parameters = new Parameters();
if (is_array($structure->parameters)) {
$this->parameters->add($structure->parameters);
}
if (isset($structure->dparameters)) {
$this->parameters->add($structure->dparameters);
}
if (isset($structure->parts)) {
foreach ($structure->parts as $key => $partStructure) {
if (null === $this->partNumber) {
$partNumber = ($key + 1);
} else {
$partNumber = (string) ($this->partNumber . '.' . ($key+1));
}
if ($this->isAttachment($partStructure)) {
$this->parts[] = new Attachment($this->stream, $this->messageNumber, $partNumber, $partStructure);
} else {
$this->parts[] = new Part($this->stream, $this->messageNumber, $partNumber, $partStructure);
}
}
}
}
/**
* Get an array of all parts for this message
*
* @return self[]
*/
public function getParts()
{
return $this->parts;
}
public function current()
{
return $this->parts[$this->key];
}
public function getChildren()
{
return $this->current();
}
public function hasChildren()
{
return count($this->parts) > 0;
}
public function key()
{
return $this->key;
}
public function next()
{
++$this->key;
}
public function rewind()
{
$this->key = 0;
}
public function valid()
{
return isset($this->parts[$this->key]);
}
public function getDisposition()
{
return $this->disposition;
}
/**
* Get raw message content
*
* @param bool $keepUnseen Whether to keep the message unseen.
* Default behaviour is set set the seen flag when
* getting content.
*
* @return string
*/
protected function doGetContent($keepUnseen = false)
{
return imap_fetchbody(
$this->stream,
$this->messageNumber,
$this->partNumber ?: 1,
\FT_UID | ($keepUnseen ? \FT_PEEK : null)
);
}
private function isAttachment($part)
{
// Attachment with correct Content-Disposition header
if (isset($part->disposition)) {
if (('attachment' === strtolower($part->disposition)
|| 'inline' === strtolower($part->disposition))
&& strtoupper($part->subtype) != "PLAIN"
) {
return true;
}
}
// Attachment without Content-Disposition header
if (isset($part->parameters)) {
foreach ($part->parameters as $parameter) {
if ('name' === strtolower($parameter->attribute)
|| 'filename' === strtolower($parameter->attribute)
) {
return true;
}
}
}
return false;
}
}

Some files were not shown because too many files have changed in this diff Show More