Initial commit

This commit is contained in:
2010-12-31 01:05:08 -07:00
commit 84d3b511a0
330 changed files with 71369 additions and 0 deletions
+428
View File
@@ -0,0 +1,428 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Dynect API SOAP Library
*
* Interfaces with the Dynect DNS service to query and modfiy DNS records.
*
* @category Libraries
* @author Will Bradley, based on Dynect API examples.
* @link http://www.zyphon.com
*/
class Dynect_API {
//private
var $CI;
var $base_url = 'https://api2.dynect.net/wsdl/2.0.0/Dynect.wsdl'; // The Base Dynect API2 URL
var $client; // The SOAP client
var $token; // Dynect login token
var $user_name = 'jstrebel'; // set by config
var $customer_name = 'demo-pagely'; // set by config
var $password = '1234test'; // set by config
/**
* Constructor
*
* @access public
*/
function Dynect_API() {
$this->CI =& get_instance();
$this->client = new SoapClient($this->base_url, array('cache_wsdl' => 0)); //Connect to the WSDL
log_message('debug', 'Dynect_API Class Initialized');
}
// --------------------------------------------------------------------
function login() {
/* ##########################
Logging In
------------
To log in to the dynect API you must call SessionLogin with customer name, username and password
Some Returned Values
status - success or failure
data->token - to be used with all other commands
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
if(!isset($this->user_name) || !isset($this->customer_name) || !isset($this->password)) {
show_error('You must set your username, customer name, and password in application/config/dynect_api.php in order to login.');
}
else {
$parameters = array(
'parameters' => array(
'user_name'=> $this->user_name,
'customer_name' => $this->customer_name,
'password' => $this->password
)
);
$result = $this->client->__soapCall('SessionLogin',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
if($result->status == 'success'){
$this->token = $result->data->token;
return true;
} else {
log_message('error', 'Dynect_API could not log in. Result status: '.$result->status);
die();
}
} // end if isset user_name
} // end login
function get_all_records($zone, $fqdn) {
/* ##########################
Getting All Records on a zone
------------
To get a list of all records send a GetANYRecords command with the token, zone, and fqdn as paramters
Some Returned Values
status - success or failure
data - object containing a list record type containers each with the rdata, fqdn, record_type, ttl and zone
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $this->token,
'zone' => $zone,
'fqdn' => $fqdn
)
);
echo '<b>Retrieving all Records</b><br/>';
echo '--------------------------<br/>';
$result = $this->client->__soapCall('GetANYRecords',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
if($result->status == 'success'){
return $result->data;
} else {
die('Unable to Get records');
}
} // end get_record
/**
* Create a Zone
*
* @access public
* @param Name of the zone
* @param Administrative contact for this zone
* @param Default TTL (in seconds) for records in the zone
* @return void
*/
function create_zone($zone, $rname, $ttl = 3600) {
$parameters = array(
'parameters' => array(
'token'=> $this->token,
'zone' => $zone,
'rname' => $rname,
'ttl' => $ttl
)
);
try{
$result = $this->client->__soapCall('CreateZone',$parameters);
}
catch (SoapFault $ex) {
trigger_error("SOAP Fault: ( ".var_export($ex->detail,true)." )", E_USER_ERROR);
die();
}
if($result->status == 'success'){
return $result->data;
} else {
die('Unable to create zone');
}
} // end create_zone
/**
* Delete a Zone
*
* @access public
* @param Name of the zone
* @return boolean (true = success)
*/
function delete_zone($zone) {
$parameters = array(
'parameters' => array(
'token'=> $this->token,
'zone' => $zone
)
);
try{
$result = $this->client->__soapCall('DeleteOneZone',$parameters);
}
catch (SoapFault $ex) {
trigger_error("SOAP Fault: ( ".var_export($ex->detail,true)." )", E_USER_ERROR);
die();
}
if($result->status == 'success'){
return true;
} else {
die('Unable to delete zone');
}
} // end delete_zone
/**
* Publish a Zone
*
* @access public
* @param Name of the zone
* @return boolean (true = success)
*/
function publish_zone($zone) {
$parameters = array(
'parameters' => array(
'token'=> $this->token,
'zone' => $zone
)
);
try{
$result = $this->client->__soapCall('PublishZone',$parameters);
}
catch (SoapFault $ex) {
trigger_error("SOAP Fault: ( ".var_export($ex->detail,true)." )", E_USER_ERROR);
die();
}
if($result->status == 'success'){
return true;
} else {
die('Unable to publish zone');
}
} // end publish_zone
/**
* Delete Records - Deletes all records at fqdn of type
*
* @access public
* @param Type of record to delete (A, AAAA, CNAME, DNSKEY, DS, KEY, LOC, MX, NS, PTR, RP, SOA, SRV, TXT)
* @param Name of zone to delete records from
* @param Name of node to delete records from
* @return bool (true=success)
*/
function delete_records($type, $zone, $fqdn) {
if(in_array($type, array('A', 'AAAA', 'CNAME', 'DNSKEY', 'DS', 'KEY', 'LOC', 'MX', 'NS', 'PTR', 'RP', 'SOA', 'SRV', 'TXT'))) {
$parameters = array(
'parameters' => array(
'token'=> $this->token,
'fqdn' => $fqdn,
'zone' => $zone
)
);
try{
$result = $this->client->__soapCall('Delete'.$type.'Records',$parameters);
}
catch (SoapFault $ex) {
trigger_error("SOAP Fault: ( ".var_export($ex->detail,true)." )", E_USER_ERROR);
die();
}
if($result->status == 'success'){
return true;
} else {
die('Unable to create '.$type.' record.');
}
}
} // end delete_records
/**
* Create Record
*
* @access public
* @param Type of record to create (A, AAAA, CNAME, DNSKEY, DS, KEY, LOC, MX, NS, PTR, RP, SOA, SRV, TXT)
* @param Name of zone to add the record to
* @param Name of node to add the record to
* @param RData defining the record to add
* @return array data
string fqdn Fully qualified domain name of a node in the zone
hash rdata RData defining the record
(response data)
string record_type The RRType of the record
string ttl TTL for the record.
string zone Name of the zone
*/
function create_record($type, $zone, $fqdn, $rdata) {
if(in_array($type, array('A', 'AAAA', 'CNAME', 'DNSKEY', 'DS', 'KEY', 'LOC', 'MX', 'NS', 'PTR', 'RP', 'SOA', 'SRV', 'TXT'))) {
$parameters = array(
'parameters' => array(
'token'=> $this->token,
'fqdn' => $fqdn,
'zone' => $zone,
'rdata' => $rdata
)
);
try{
$result = $this->client->__soapCall('Create'.$type.'Record',$parameters);
}
catch (SoapFault $ex) {
trigger_error("SOAP Fault: ( ".var_export($ex->detail,true)." )", E_USER_ERROR);
die();
}
if($result->status == 'success'){
return $result->data;
} else {
die('Unable to create '.$type.' record.');
}
}
} // end create_record
/**
* Get Records
*
* @access public
* @param Type of record to get (A, AAAA, CNAME, DNSKEY, DS, KEY, LOC, MX, NS, PTR, RP, SOA, SRV, TXT)
* @param Name of zone to get the record of
* @param Name of node to get the record of
* @return array data
string fqdn Fully qualified domain name of a node in the zone
hash rdata RData defining the record
(response data)
string record_type The RRType of the record
string ttl TTL for the record.
string zone Name of the zone
*/
function get_records($type, $zone, $fqdn) {
if(in_array($type, array('A', 'AAAA', 'CNAME', 'DNSKEY', 'DS', 'KEY', 'LOC', 'MX', 'NS', 'PTR', 'RP', 'SOA', 'SRV', 'TXT'))) {
$parameters = array(
'parameters' => array(
'token'=> $this->token,
'fqdn' => $fqdn,
'zone' => $zone
)
);
try{
$result = $this->client->__soapCall('Get'.$type.'Records',$parameters);
}
catch (SoapFault $ex) {
trigger_error("SOAP Fault: ( ".var_export($ex->faultstring,true)." )", E_USER_ERROR);
die();
}
if($result->status == 'success'){
return $result->data;
} else {
die('Unable to get '.$type.' records.');
}
}
} // end get_records
/**
* Get all Zones
*
* @access public
* @return zone data
*/
function get_zones() {
$parameters = array(
'parameters' => array(
'token'=> $this->token
)
);
$result = $this->client->__soapCall('GetZones',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
if($result->status == 'success'){
return $result->data;
} else {
die('Unable to get zones');
}
} // end get_zones
function logout() {
/* ##########################
Logging Out
------------
To log in to the dynect API you must call SessionLogout with the token received at login
Some Returned Values
status - success or failure
** Complete Documentations can be found at
https://manage.dynect.net/help/docs/api2/soap/
########################## */
$parameters = array(
'parameters' => array(
'token'=> $this->token
)
);
$result = $this->client->__soapCall('SessionLogout',$parameters);
if(is_soap_fault($result)){
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
die();
}
$message = $result->msgs;
if($result->status != 'success'){
log_message('error','Dynect_API unable to log out.');
}
} // end logout
} // end class
+452
View File
@@ -0,0 +1,452 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Postmark Email Library
*
* Permits email to be sent using Postmarkapp.com's Servers
*
* @category Libraries
* @author Based on work by János Rusiczki & Markus Hedlunds.
* @modified Heavily Modified by Zack Kitzmiller
* @link http://www.github.com/zackkitzmiller/postmark-codeigniter
*/
class Postmark {
//private
var $CI;
var $api_key = '';
var $validation = FALSE;
var $strip_html = FALSE;
var $develop = FALSE;
var $from_name;
var $from_address;
var $_reply_to_name;
var $_reply_to_address;
var $_to_name;
var $_to_address;
var $_cc_name;
var $_cc_address;
var $_subject;
var $_message_plain;
var $_message_html;
var $_tag;
/**
* Constructor
*
* @access public
* @param array initialization parameters
*/
function Postmark($params = array())
{
$this->CI =& get_instance();
if (count($params) > 0)
{
$this->initialize($params);
}
if ($this->develop == TRUE)
{
$this->api_key = 'POSTMARK_API_TEST';
}
log_message('debug', 'Postmark Class Initialized');
}
// --------------------------------------------------------------------
/**
* Initialize Preferences
*
* @access public
* @param array initialization parameters
* @return void
*/
function initialize($params)
{
$this->clear();
if (count($params) > 0)
{
foreach ($params as $key => $value)
{
if (isset($this->$key))
{
$this->$key = $value;
}
}
}
}
// --------------------------------------------------------------------
/**
* Clear the Email Data
*
* @access public
* @return void
*/
function clear() {
$this->from_name = '';
$this->from_address = '';
$this->_to_name = '';
$this->_to_address = '';
$this->_cc_name = '';
$this->_cc_address = '';
$this->_subject = '';
$this->_message_plain = '';
$this->_message_html = '';
$this->_tag = '';
}
// --------------------------------------------------------------------
/**
* Set Email FROM address
*
* This could also be set in the config file
*
* TODO:
* Validate Email Addresses ala CodeIgniter's Email Class
*
* @access public
* @return void
*/
function from($address, $name = null)
{
if ( ! $this->validation == TRUE)
{
$this->from_address = $address;
$this->from_name = $name;
}
else
{
if ($this->_validate_email($address))
{
$this->from_address = $address;
$this->from_name = $name;
}
else
{
show_error('You have entered an invalid sender address.');
}
}
}
// --------------------------------------------------------------------
/**
* Set Email TO address
*
* TODO:
* Validate Email Addresses ala CodeIgniter's Email Class
*
* @access public
* @return void
*/
function to($address, $name = null)
{
if ( ! $this->validation == TRUE)
{
$this->_to_address = $address;
$this->_to_name = $name;
}
else
{
if ($this->_validate_email($address))
{
$this->_to_address = $address;
$this->_to_name = $name;
}
else
{
show_error('You have entered an invalid recipient address.');
}
}
}
// --------------------------------------------------------------------
/**
* Set Email ReplyTo address
*
* TODO:
* Validate Email Addresses ala CodeIgniter's Email Class
*
* @access public
* @return void
*/
function reply_to($address, $name = null)
{
if ( ! $this->validation == TRUE)
{
$this->_reply_to_address = $address;
$this->_reply_to_name = $name;
}
else
{
if ($this->_validate_email($address))
{
$this->_reply_to_address = $address;
$this->_reply_to_name = $name;
}
else
{
show_error('You have entered an invalid reply to address.');
}
}
}
// --------------------------------------------------------------------
/**
* Set Email CC address
*
* TODO:
* Validate Email Addresses ala CodeIgniter's Email Class
*
* @access public
* @return void
*/
function cc($address, $name = null)
{
if ( ! $this->validation == TRUE)
{
$this->_cc_address = $address;
$this->_cc_name = $name;
}
else
{
if ($this->_validate_email($address))
{
$this->_cc_address = $address;
$this->_cc_name = $name;
}
else
{
show_error('You have entered an invalid recipient address.');
}
}
}
// --------------------------------------------------------------------
/**
* Set Email Subject
*
* @access public
* @return void
*/
function subject($subject)
{
$this->_subject = $subject;
}
// --------------------------------------------------------------------
/**
* Set Tag
*
* @access public
* @return void
*/
function tag($tag)
{
$this->_tag = $tag;
}
// --------------------------------------------------------------------
/**
* Set Email Message in Plain Text
*
* @access public
* @return void
*/
function message_plain($message)
{
if ( ! $this->strip_html )
{
$this->_message_plain = $message;
}
else
{
$this->_message_plain = $this->_strip_html($message);
}
}
// --------------------------------------------------------------------
/**
* Set Email Message in HTML
*
* @access public
* @return void
*/
function message_html($message)
{
$this->_message_html = $message;
}
// --------------------------------------------------------------------
/**
* Private Function to prepare and send email
*/
function _prepare_data()
{
$data = array();
$data['Subject'] = $this->_subject;
$data['From'] = is_null($this->from_name) ? $this->from_address : "{$this->from_name} <{$this->from_address}>";
$data['To'] = is_null($this->_to_name) ? $this->_to_address : "{$this->_to_name} <{$this->_to_address}>";
if (!is_null($this->_cc_address) && ($this->_cc_address != '')) {
$data['Cc'] = is_null($this->_cc_name) ? $this->_cc_address : "{$this->_cc_name} <{$this->_cc_address}>";
}
if (!is_null($this->_reply_to_address) && ($this->_reply_to_address != '')) {
$data['ReplyTo'] = is_null($this->_reply_to_name) ? $this->_reply_to_address : "{$this->_reply_to_name} <{$this->_reply_to_address}>";
}
if (!is_null($this->_tag) && ($this->_tag != '')) {
$data['tag'] = $this->_tag;
}
if (!is_null($this->_message_html)) {
$data['HtmlBody'] = $this->_message_html;
}
if (!is_null($this->_message_plain)) {
$data['TextBody'] = $this->_message_plain;
}
return $data;
}
function send($from_address = null, $from_name = null, $to_address = null, $to_name = null, $subject = null, $message_plain = null, $message_html = null)
{
if (!function_exists('curl_init'))
{
if(function_exists('log_message'))
{
log_message('error', 'Postmark - PHP was not built with cURL enabled. Rebuild PHP with --with-curl to use cURL.');
}
return false;
}
if (!is_null($from_address)) $this->from($from_address, $from_name);
if (!is_null($to_address)) $this->to($to_address, $to_name);
if (!is_null($subject)) $this->subject($subject);
if (!is_null($message_plain)) $this->message_plain($message_plain);
if (!is_null($message_html)) $this->message_html($message_html);
if (is_null($this->api_key)) {
show_error("Postmark API key is not set!");
}
if (is_null($this->from_address)) {
show_error("From address is not set!");
}
if (is_null($this->_to_address)) {
show_error("To address is not set!");
}
if (is_null($this->_subject)) {
show_error("Subject is not set!");
}
if (is_null($this->_message_plain) && is_null($this->_message_html)) {
show_error("Please either set plain message, HTML message or both!");
}
$encoded_data = json_encode($this->_prepare_data());
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
'X-Postmark-Server-Token: ' . $this->api_key
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.postmarkapp.com/email');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$return = curl_exec($ch);
log_message('debug', 'POSTMARK JSON: ' . $encoded_data . "\nHeaders: \n\t" . implode("\n\t", $headers) . "\nReturn:\n$return");
if (curl_error($ch) != '') {
show_error(curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
log_message('debug', 'POSTMARK http code:' . $httpCode);
if (intval($httpCode / 100) != 2) {
$message = json_decode($return)->Message;
show_error('Error while mailing. Postmark returned HTTP code ' . $httpCode . ' with message "'.$message.'"');
}
}
// --------------------------------------------------------------------
/**
* Email Validation
*
* @access public
* @param string
* @return bool
*/
function _validate_email($address)
{
$addresses = explode(',', $address);
foreach($addresses as $k => $v) {
if ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", trim($v))) {
return FALSE;
}
}
return TRUE;
}
// --------------------------------------------------------------------
/**
* Strip Html
*
* @access public
* @param string
* @return string
*/
function _strip_html($message)
{
$message = preg_replace('/\<br(\s*)?\/?\>/i', "\n", $message);
return strip_tags($message);
}
}
+10
View File
@@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>