From: <chr...@us...> - 2018-10-26 18:38:19
|
Revision: 13393 http://sourceforge.net/p/xoops/svn/13393 Author: chronolabscoop Date: 2018-10-26 18:38:15 +0000 (Fri, 26 Oct 2018) Log Message: ----------- Email API Rest 1.0.3! Modified Paths: -------------- *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/crons/find-mx-services.php *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/crons/import-generated-keys.php *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/crons/port-encryption-keys.php *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/include/version.php *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/install/include/config.php *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/install/page_extrasettings.php Modified: *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/crons/find-mx-services.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/crons/find-mx-services.php 2018-10-26 18:17:07 UTC (rev 13392) +++ *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/crons/find-mx-services.php 2018-10-26 18:38:15 UTC (rev 13393) @@ -55,7 +55,7 @@ $seconds = 1800; } -$sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix('domains') . "` WHERE `mxcheck` < UNIX_TIMESTAMP()"; +$sql = "SELECT * FROM `" . $GLOBALS['APIDB']->prefix('domains') . "` WHERE `mxcheck` > UNIX_TIMESTAMP()"; $result = $GLOBALS['APIDB']->queryF($sql); while($domain = $GLOBALS['APIDB']->fetchArray($result)) { $found = false; @@ -62,15 +62,18 @@ $priority = 10; foreach(getMXByNamel($domain['domain']) as $key => $mxrecord) { if ($found == false) - if ($priority < $mxrecord['pri']) + if ($priority > $mxrecord['pri']) $priority = $mxrecord['pri']; if ($mxrecord['target'] == parse_url(API_URL, PHP_URL_HOST)) - $found = true; + if ($found == false) + if ($mxhost = $mxrecord['host']) + if ($found = true) + continue; } if ($found == false) { - list($count) = $GLOBALS['APIDB']->fetchRow($GLOBALS['APIDB']->queryF("SELECT count(*) FROM `" . $GLOBALS['APIDB']->prefix('mxs') . "` WHERE `mx` LIKE 'mx.".$domain['domain']."' AND `target` LIKE '".parse_url(API_URL, PHP_URL_HOST)."'")); + list($count) = $GLOBALS['APIDB']->fetchRow($GLOBALS['APIDB']->queryF("SELECT count(*) FROM `" . $GLOBALS['APIDB']->prefix('mxs') . "` WHERE `mx` LIKE '".$domain['domain']."' AND `target` LIKE '".parse_url(API_URL, PHP_URL_HOST)."'")); if ($count == 0) { - if (!$GLOBALS['APIDB']->queryF($sql = "INSERT INTO `" . $GLOBALS['APIDB']->prefix('mxs') . "` (`domainid`, `uid`, `pid`, `mx`, `target`, `pirority`, `mxcheck`) VALUES('".$domain['id']."', '".$domain['uid']."','".$domain['pid']."','mx.".$domain['domain']."','".parse_url(API_URL, PHP_URL_HOST)."','".($pirority+10)."', UNIX_TIMESTAMP() + $seconds)")) + if (!$GLOBALS['APIDB']->queryF($sql = "INSERT INTO `" . $GLOBALS['APIDB']->prefix('mxs') . "` (`domainid`, `uid`, `pid`, `mx`, `target`, `pirority`, `mxcheck`) VALUES('".$domain['id']."', '".$domain['uid']."','".$domain['pid']."','".domain['domain']."','".parse_url(API_URL, PHP_URL_HOST)."','".($pirority+10)."', UNIX_TIMESTAMP() + $seconds)")) die("SQL Failed: $sql;"); else echo("\nSQL Success: $sql;"); @@ -96,10 +99,13 @@ $priority = 10; foreach(getMXByNamel($domain['domain']) as $key => $mxrecord) { if ($found == false) - if ($priority < $mxrecord['pri']) + if ($priority > $mxrecord['pri']) $priority = $mxrecord['pri']; if ($mxrecord['target'] == $mx['target'] && $mxrecord['host'] == $mx['mx'] ) - $found = true; + if ($found == false) + if ($mxhost = $mxrecord['host']) + if ($found = true) + continue; } if ($found == false) { if (!$GLOBALS['APIDB']->queryF($sql = "UPDATE `" . $GLOBALS['APIDB']->prefix('mxs') . "` SET `mxcheck` = UNIX_TIMESTAMP() + " . ($seconds * 2) . " WHERE `id` = " . $mx['id'])) Modified: *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/crons/import-generated-keys.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/crons/import-generated-keys.php 2018-10-26 18:17:07 UTC (rev 13392) +++ *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/crons/import-generated-keys.php 2018-10-26 18:38:15 UTC (rev 13393) @@ -67,7 +67,7 @@ foreach($names as $name => $email) if ($email == $addy['email']) unset($emails[$key]); - + foreach($emails as $emailkey => $names) foreach($names as $name => $email) { $domainid = 0; @@ -76,21 +76,22 @@ $domain = $parts[1]; $domainpath = implode(DS, array_reverse(explode('.', $domain))); $result = $GLOBALS['APIDB']->queryF("SELECT `domain`, `id`, md5(concat(`id`, '" . API_URL . "', 'domain')) as `key` FROM `" . $GLOBALS['APIDB']->prefix('domains') . "`"); - while($domain = $GLOBALS['APIDB']->fetchArray($result)) { - if (empty($domainid) && empty($domainkey) && $domain['domain'] == $domain) + while($record = $GLOBALS['APIDB']->fetchArray($result)) { + if (empty($domainid) && empty($domainkey) && $record['domain'] == $domain) { - $domainid = $domain['id']; - $domainkey = $domain['key']; + $domainid = $record['id']; + $domainkey = $record['key']; continue; } } - $mfile = mfiletime($keyfile = API_MAILDIR_PATH . DS . $domainpath . DS . '.pgp-keys' . DS . "$email.asc"); + $keyfile = API_MAILDIR_PATH . DS . $domainpath . DS . '.pgp-keys' . DS . "$email.asc"; if (file_exists($keyfile)) { - $sql = "INSERT INTO `" . $GLOBALS['APIDB']->prefix('pgpkeys') . "` (`typal`, `domainid`, `name`, `email`, `key`, `created`, `imported`) VALUES('internal', '$domainid', '" . $GLOBALS['APIDB']->escape($name) . "', '$email', '". $GLOBALS['APIDB']->escape($pgpkey = file_get_contents($keyfile)) . "', UNIX_TIMESTAMP(), '$mtime')"; + $ctime = filectime($keyfile); + $sql = "INSERT INTO `" . $GLOBALS['APIDB']->prefix('pgpkeys') . "` (`typal`, `domainid`, `name`, `email`, `key`, `created`, `imported`) VALUES('internal', '$domainid', '" . $GLOBALS['APIDB']->escape($name) . "', '$email', '". $GLOBALS['APIDB']->escape($pgpkey = file_get_contents($keyfile)) . "', UNIX_TIMESTAMP(), '$ctime')"; if ($GLOBALS['APIDB']->queryF($sql)) { $from = $GLOBALS['APIDB']->fetchArray($GLOBALS['APIDB']->queryF("SELECT * FROM `" . $GLOBALS['APIDB']->prefix('users') . "` WHERE `uid` = '" . API_PRIMARY_SYSOP_UID . "'")); - $todomain = $GLOBALS['APIDB']->fetchArray($GLOBALS['APIDB']->queryF("SELECT *, AES_DECRYPT(`password`, `email`) as `depassword` FROM `" . $GLOBALS['APIDB']->prefix('mail_users') . "` WHERE `email` = '" . $email . "'")); + $todomain = $GLOBALS['APIDB']->fetchArray($GLOBALS['APIDB']->queryF("SELECT *, DES_DECRYPT(`password`, `email`) as `depassword` FROM `" . $GLOBALS['APIDB']->prefix('mail_users') . "` WHERE `email` = '" . $email . "'")); $to = array($todomain['notify']); $cc = array($todomain['email']); $mailers = new APIMailer($from['email'], $from['name']); @@ -119,6 +120,8 @@ } if (strlen($todomain['callback']) > 0) addCallback($todomain['callback'], array("op" => 'email-activation', "emailkey" => $emailkey, "email" => $email, "name" => $todomain['name'], 'pgpkey' => $pgpkey, 'activation-link' => API_URL . '/v2/' . $emailkey . "/" . $todomain['actkey'] . '/activation.html')); + } else { + die("SQL Error: $sql;"); } } } Modified: *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/crons/port-encryption-keys.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/crons/port-encryption-keys.php 2018-10-26 18:17:07 UTC (rev 13392) +++ *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/crons/port-encryption-keys.php 2018-10-26 18:38:15 UTC (rev 13393) @@ -26,8 +26,8 @@ */ require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'apiconfig.php'; -require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'apimailer.php'; + $start = time(); if ($staters = APICache::read('port-encryption-keys')) { @@ -47,8 +47,8 @@ if (count($avg) > 0 ) { foreach($avg as $average) $seconds += $average; - $seconds = $seconds / count($avg); - } else + $seconds = $seconds / count($avg); + } else $seconds = 1800; } else { APICache::write('port-encryption-keys', array(0=>$start), 3600 * 24 * 7 * 4 * 6); @@ -55,7 +55,7 @@ $seconds = 1800; } -$authkey = json_decode(getURIData(API_ZONES_API_URL . "/v1/authkey.api", 200, 200, array("username" => API_ZONES_API_USER, "password" => API_ZONES_API_PASS)), true); +$authkey = json_decode(getURIData(API_ZONES_API_URL . "/v1/authkey.api?" . http_build_query(array("username" => API_ZONES_API_USER, "password" => API_ZONES_API_PASS, 'format' => 'json')), 200, 200, array("username" => API_ZONES_API_USER, "password" => API_ZONES_API_PASS, 'format' => 'json')), true); if (count($authkey['errors']) == 0) $domains = json_decode(getURIData(API_ZONES_API_URL . "/v1/".$authkey['authkey']."/domains/json.api", 200, 200), true); else @@ -71,18 +71,24 @@ $domain['zonekey'] = $zone['domainkey']; if (!$GLOBALS['APIDB']->queryF($sql = "UPDATE `" . $GLOBALS['APIDB']->prefix('domains') . "` SET `zonekey` = '" . $domain['zonekey'] . "' WHERE `id` = '" . $pgpkey['domainid'] . "'")) { die("SQL Failed: $sql;"); + } else { + echo ("SQL Success: $sql;"); } } } } if (!empty($domain['zonekey'])) { - $record = json_decode(getURIData(API_ZONES_API_URL . "/v1/".$authkey['authkey']."/zones.api", 200, 200, array('domain' => $domain['zonekey'], 'type' => 'OPENPGPKEY', 'name' => $pgpkey['email'], 'content' => $pgpkey['key'], 'ttl' => 6000, 'prio' => 5)), true); + $record = json_decode(getURIData(API_ZONES_API_URL . "/v1/".$authkey['authkey']."/zones.api?" . http_build_query(array('domain' => $domain['zonekey'], 'type' => 'OPENPGPKEY', 'name' => $pgpkey['email'], 'content' => $pgpkey['key'], 'ttl' => 6000, 'prio' => 5, 'format' => 'json')), 200, 200, array('domain' => $domain['zonekey'], 'type' => 'OPENPGPKEY', 'name' => $pgpkey['email'], 'content' => $pgpkey['key'], 'ttl' => 6000, 'prio' => 5, 'format' => 'json')), true); if (count($record['errors']) == 0) { - $GLOBALS['APIDB']->queryF("UPDATE `" . $GLOBALS['APIDB']->prefix('pgpkeys') . "` SET `zonekey` = '" . $record['recordkey'] . "', `zoned` = UNIX_TIMESTAMP() WHERE `kid` = '" . $pgpkey['kid'] . "'"); + if (!$GLOBALS['APIDB']->queryF($sql = "UPDATE `" . $GLOBALS['APIDB']->prefix('pgpkeys') . "` SET `zonekey` = '" . $record['recordkey'] . "', `zoned` = UNIX_TIMESTAMP() WHERE `kid` = '" . $pgpkey['kid'] . "'")) { + die("SQL Failed: $sql;"); + } else { + echo ("SQL Success: $sql;"); + } } } } - $authkey = json_decode(getURIData(API_ZONES_API_URL . "/v1/authkey.api", 200, 200, array("username" => API_ZONES_API_USER, "password" => API_ZONES_API_PASS)), true); + $authkey = json_decode(getURIData(API_ZONES_API_URL . "/v1/authkey.api?" . http_build_query(array("username" => API_ZONES_API_USER, "password" => API_ZONES_API_PASS, 'format' => 'json')), 200, 200, array("username" => API_ZONES_API_USER, "password" => API_ZONES_API_PASS, 'format' => 'json')), true); } ?> Modified: *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/include/version.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/include/version.php 2018-10-26 18:17:07 UTC (rev 13392) +++ *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/include/version.php 2018-10-26 18:38:15 UTC (rev 13393) @@ -41,5 +41,5 @@ /** * Define API version */ -define('API_VERSION', 'Emails Propogation REST Services API 1.0.2'); +define('API_VERSION', 'Emails Propogation REST Services API 1.0.3'); define('API_TYPE', 'emails-api'); Modified: *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/install/include/config.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/install/include/config.php 2018-10-26 18:17:07 UTC (rev 13392) +++ *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/install/include/config.php 2018-10-26 18:38:15 UTC (rev 13393) @@ -75,7 +75,6 @@ $configs['api_url'] = array( 'strata' => 'http://strata.snails.email', 'whois' => 'http://whois.snails.email', - 'zones' => 'http://zones.snails.email', 'masterhost' => $_SESSION['settings']['URL'], ); @@ -95,7 +94,11 @@ 'zones' => '', ); -$configs['api_paths'] = array( +$configs['api_urls'] = array( + 'zones' => 'http://zones.snails.email', +); + +$configs['path'] = array( 'maildir' => '/mailboxs', 'homedir' => '/var/www/homes', ); Modified: *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/install/page_extrasettings.php =================================================================== --- *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/install/page_extrasettings.php 2018-10-26 18:17:07 UTC (rev 13392) +++ *.xoops.org (Subdomain APIs & Sites)/email.xoops.org/install/page_extrasettings.php 2018-10-26 18:38:15 UTC (rev 13393) @@ -46,18 +46,22 @@ { $_SESSION['constants']['api_url'][$setting] = $_POST[$setting]; } - foreach($wizard->configs['api_paths'] as $setting => $values) + foreach($wizard->configs['path'] as $setting => $values) { - $_SESSION['constants']['paths'][$setting] = $_POST[$setting]; + $_SESSION['constants']['path'][$setting] = $_POST[$setting]; } foreach($wizard->configs['api_user'] as $setting => $values) { - $_SESSION['constants']['api_user'][$setting] = $_POST[$setting]; + $_SESSION['constants']['api_user'][$setting] = $_POST['api_user_' . $setting]; } foreach($wizard->configs['api_pass'] as $setting => $values) { - $_SESSION['constants']['api_pass'][$setting] = $_POST[$setting]; + $_SESSION['constants']['api_pass'][$setting] = $_POST['api_pass_' . $setting]; } + foreach($wizard->configs['api_urls'] as $setting => $values) + { + $_SESSION['constants']['api_url'][$setting] = $_POST['api_url_' . $setting]; + } foreach($wizard->configs['pgp_keys'] as $setting => $values) { $_SESSION['constants']['pgp_keys'][$setting] = $_POST[$setting]; @@ -105,19 +109,25 @@ <div class="xoform-help alert alert-info"><?php echo constant("API_".strtoupper($setting) . "_HELP"); ?></div> <input type="text" class="form-control" name="<?php echo $setting; ?>" id="<?php echo $setting; ?>" value="<?php echo $default; ?>"/> <?php } + foreach($wizard->configs['api_urls'] as $setting => $default) + {?> + <label for="<?php echo $setting; ?>"><?php echo constant("API_".strtoupper($setting) . "_LABEL"); ?></label> + <div class="xoform-help alert alert-info"><?php echo constant("API_".strtoupper($setting) . "_HELP"); ?></div> + <input type="text" class="form-control" name="<?php echo 'api_url_' . $setting; ?>" id="<?php echo $setting; ?>" value="<?php echo $default; ?>"/> + <?php } foreach($wizard->configs['api_user'] as $setting => $default) {?> <label for="<?php echo $setting; ?>"><?php echo constant("API_".strtoupper($setting) . "_USER_LABEL"); ?></label> <div class="xoform-help alert alert-info"><?php echo constant("API_".strtoupper($setting) . "_USER_HELP"); ?></div> - <input type="text" class="form-control" name="<?php echo $setting; ?>" id="<?php echo $setting; ?>" value="<?php echo $default; ?>"/> + <input type="text" class="form-control" name="<?php echo 'api_user_' . $setting; ?>" id="<?php echo $setting; ?>" value="<?php echo $default; ?>"/> <?php } foreach($wizard->configs['api_pass'] as $setting => $default) {?> <label for="<?php echo $setting; ?>"><?php echo constant("API_".strtoupper($setting) . "_PASS_LABEL"); ?></label> <div class="xoform-help alert alert-info"><?php echo constant("API_".strtoupper($setting) . "_PASS_HELP"); ?></div> - <input type="password" class="form-control" name="<?php echo $setting; ?>" id="<?php echo $setting; ?>" value="<?php echo $default; ?>"/> + <input type="password" class="form-control" name="<?php echo 'api_pass_' . $setting; ?>" id="<?php echo $setting; ?>" value="<?php echo $default; ?>"/> <?php } - foreach($wizard->configs['api_paths'] as $setting => $default) + foreach($wizard->configs['path'] as $setting => $default) {?> <label for="<?php echo $setting; ?>"><?php echo constant("API_".strtoupper($setting) . "_LABEL"); ?></label> <div class="xoform-help alert alert-info"><?php echo constant("API_".strtoupper($setting) . "_HELP"); ?></div> |