From: <chr...@us...> - 2018-06-29 01:26:32
|
Revision: 13378 http://sourceforge.net/p/xoops/svn/13378 Author: chronolabscoop Date: 2018-06-29 01:26:22 +0000 (Fri, 29 Jun 2018) Log Message: ----------- API's AuthKey/XoopsKey (prealpha) ~ almost there! Modified Paths: -------------- XoopsModules/authkey/trunk/modules/authkey/api/index.php XoopsModules/authkey/trunk/modules/authkey/apis.php XoopsModules/authkey/trunk/modules/authkey/class/apis.php XoopsModules/authkey/trunk/modules/authkey/class/keys.php XoopsModules/authkey/trunk/modules/authkey/class/users.php XoopsModules/authkey/trunk/modules/authkey/include/functions.php XoopsModules/authkey/trunk/modules/authkey/index.php XoopsModules/authkey/trunk/modules/authkey/language/english/main.php XoopsModules/authkey/trunk/modules/authkey/language/english/modinfo.php XoopsModules/authkey/trunk/modules/authkey/preloads/reports.php XoopsModules/authkey/trunk/modules/authkey/sql/mysql.sql XoopsModules/authkey/trunk/modules/authkey/templates/authkeys_apis.html XoopsModules/authkey/trunk/modules/authkey/xoops_version.php Added Paths: ----------- XoopsModules/authkey/trunk/modules/authkey/preloads/checking.php Modified: XoopsModules/authkey/trunk/modules/authkey/api/index.php =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/api/index.php 2018-06-28 21:12:26 UTC (rev 13377) +++ XoopsModules/authkey/trunk/modules/authkey/api/index.php 2018-06-29 01:26:22 UTC (rev 13378) @@ -119,8 +119,8 @@ if (empty($return)) { $apisHandler = xoops_getModuleHandler('apis', basename(dirname(__DIR__))); - $criteria = new CriteriaCompo(new Criteria('`api-http`', $inner['api-url'], 'LIKE')); - $criteria->add(new Criteria('`api-https`', $inner['api-url'], 'LIKE'), 'OR'); + $criteria = new CriteriaCompo(new Criteria('`api-http`', $GLOBALS['xoopsDB']->escape($inner['api-url']), 'LIKE')); + $criteria->add(new Criteria('`api-https`', $GLOBALS['xoopsDB']->escape($inner['api-url']), 'LIKE'), 'OR'); if ($apisHandler->getCount($criteria)==0) $return = array('code' => 501, 'errors' => array(114 => 'Variable passed but not found on the with the api in the field element: "api-url" ~ "'.$inner['api-url'].'" not found on resource!')); else { @@ -197,7 +197,7 @@ $token[$api->getVar('api-type')][$inner['api-url']] = 1; $token['polling'] = $token['polling'] + 1; $token['polled-last'] = $token['polled']; - $token['polled'] = time() + $authkeyConfigsList['polling-seconds']; + $token['polled'] = time() + $GLOBALS['authkeyConfigsList']['polling-seconds']; XoopsCache::write("xoopskey_".md5($inner['xoopskey']), $token, 3600 * 24 * 7 * 4 * 36); $key = $keysHandler->get($token['id']); @@ -234,7 +234,7 @@ $token['polling'] = 0; $overlimit = false; - if ($authkeyConfigsList['limited']==true) + if ($GLOBALS['authkeyConfigsList']['limited']==true) { if ($key->getVar('limit-hour') < $key->getVar('calls-hour')) { @@ -352,13 +352,13 @@ $data = $key->getValues(array_keys($key->vars)); $data[$api->getVar('api-type')][$inner['api-url']] = 0; $data['polling'] = 0; - $data['polled'] = time() + $authkeyConfigsList['polling-seconds']; + $data['polled'] = time() + $GLOBALS['authkeyConfigsList']['polling-seconds']; XoopsCache::write("xoopskey_".md5($key->getVar('key')), $data, 3600 * 24 * 7 * 4 * 36); XoopsCache::write("xoopskey_".md5(md5($key->getVar('key'))), $data, 3600 * 24 * 7 * 4 * 36); XoopsCache::write("xoopskey_".md5(sha1($key->getVar('key'))), $data, 3600 * 24 * 7 * 4 * 36); } @$apisHandler->insert($api, true); - if ($authkeyConfigsList['limited'] == true && $overlimit == true && !authkeys_checkperm(_MI_AUTHKEY_PERM_UNLIMITEDCALLS, $key->getVar('id'), $key->getVar('uid')) == false) + if ($GLOBALS['authkeyConfigsList']['limited'] == true && $overlimit == true && !authkeys_checkperm(_MI_AUTHKEY_PERM_UNLIMITEDCALLS, $key->getVar('id'), $key->getVar('uid')) == false) $return = array('code'=>501, 'passed' => false, 'errors' => array(110 => 'Over Limit of Calling Polls to API\'s')); } } Modified: XoopsModules/authkey/trunk/modules/authkey/apis.php =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/apis.php 2018-06-28 21:12:26 UTC (rev 13377) +++ XoopsModules/authkey/trunk/modules/authkey/apis.php 2018-06-29 01:26:22 UTC (rev 13378) @@ -21,15 +21,47 @@ require_once __DIR__ . DIRECTORY_SEPARATOR . 'header.php'; -$xoopsOption['template_main'] = 'authkeys_key.html'; +if ($GLOBALS['authkeyConfigsList']['htaccess']) + if (strpos($_SERVER['REQUEST_URI'], 'odules/')>0) { + header('HTTP/1.1 301 Moved Permanently'); + header('Location: ' . XOOPS_URL . '/' . $GLOBALS['authkeyConfigsList']['baseurl'] . '/apis' . $GLOBALS['authkeyConfigsList']['endofurl']); + exit(0); + } + +$xoopsOption['template_main'] = 'authkeys_apis.html'; require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'header.php'; +$GLOBALS['xoopsTpl']->assign('moddirname', basename(dirname(__DIR__))); -$GLOBALS['xoopsTpl']->assign('authkeys_module_version', $authkeyModule->getVar('version')); -$GLOBALS['xoopsTpl']->assign('authkeys_module_namings', $authkeyModule->getVar('name')); +$criteria = new Criteria('1', '1'); +$criteria->setSort('`api-type` ASC, `api-http` ASC, `api-https`'); +$criteria->setOrder('ASC'); -$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/module/' . basename(dirname(__DIR__)) . '/assets/css/api-style.css'); -if (is_file(XOOPS_ROOT_PATH . '/module/' . basename(dirname(__DIR__)) . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/style.css')) - $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/module/' . basename(dirname(__DIR__)) . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/style.css'); - else - $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/module/' . basename(dirname(__DIR__)) . '/language/english/style.css'); - \ No newline at end of file +foreach(xoops_getModuleHandler('apis', basename(__DIR__))->getObjects($criteria) as $api) +{ + $apiarr = array(); + foreach($api->getValues(array_keys($api->vars)) as $field => $value) + { + if (substr($field, 0, 5) == 'calls') { + $apiarr[str_replace("-", "_", $field)] = number_format($value, 0); + } elseif (in_array($field, array('online', 'offline'))) { + if ($value = $api->getVar('status')) + $apiarr[str_replace("-", "_", $field)] = authkey_getTimePeriod($value + (time() - $api->getVar('checked'))); + else + $apiarr[str_replace("-", "_", $field)] = authkey_getTimePeriod($value); + } elseif (in_array($field, array('stats-hour', 'stats-day', 'stats-week', 'stats-month', 'stats-quarter', 'stats-year', 'report-month', 'report-quarter', 'report-year', 'report-biannual', 'created', 'checked', 'checking', 'emailed'))) { + $apiarr[str_replace("-", "_", $field)] = date("Y/m/d H:i:s", $value); + } else { + $apiarr[str_replace("-", "_", $field)] = $value; + } + } + $apiarr['url'] = $api->getVar('api-'.$api->getVar('mode')); + $GLOBALS['xoopsTpl']->append('apis', $apiarr); +} + +$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/module/' . basename(__DIR__) . '/assets/css/style.css'); +if (is_file(XOOPS_ROOT_PATH . '/module/' . basename(__DIR__) . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/style.css')) + $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/module/' . basename(__DIR__) . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/style.css'); +else + $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/module/' . basename(__DIR__) . '/language/english/style.css'); + +require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'footer.php'; \ No newline at end of file Modified: XoopsModules/authkey/trunk/modules/authkey/class/apis.php =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/class/apis.php 2018-06-28 21:12:26 UTC (rev 13377) +++ XoopsModules/authkey/trunk/modules/authkey/class/apis.php 2018-06-29 01:26:22 UTC (rev 13378) @@ -60,9 +60,9 @@ $this->initVar('stats-month', XOBJ_DTYPE_INT, null, false); $this->initVar('stats-quarter', XOBJ_DTYPE_INT, null, false); $this->initVar('stats-year', XOBJ_DTYPE_INT, null, false); - $this->initVar('report-month', XOBJ_DTYPE_INT, null, false); - $this->initVar('report-quarter', XOBJ_DTYPE_INT, null, false); - $this->initVar('report-year', XOBJ_DTYPE_INT, null, false); + $this->initVar('report-monthly', XOBJ_DTYPE_INT, null, false); + $this->initVar('report-halfyear', XOBJ_DTYPE_INT, null, false); + $this->initVar('report-fullyear', XOBJ_DTYPE_INT, null, false); $this->initVar('report-biannual', XOBJ_DTYPE_INT, null, false); $this->initVar('created', XOBJ_DTYPE_INT, null, false); $this->initVar('emailed', XOBJ_DTYPE_INT, null, false); @@ -91,19 +91,20 @@ if (!$read = XoopsCache::read('xoopskeys_apis')) { - $csv = array_map('str_getcsv', getURIData($this->_csv_resources, 120, 120)); + $csv = array_map('str_getcsv', file($this->_csv_resources)); array_walk($csv, function(&$a) use ($csv) { $a = array_combine($csv[0], $a); }); array_shift($csv); - + foreach($csv as $line => $values) { - $criteria = new CriteriaCompo(new Criteria('`api-http`', $values['API HTTP'])); - $criteria->add(new Criteria('`api-https`', $values['API HTTPS'])); - $criteria->add(new Criteria('`api-type`', $values['API Type'])); + $criteria = new CriteriaCompo(new Criteria('`api-http`', $this->db->escape($values['API HTTP']))); + $criteria->add(new Criteria('`api-https`', $this->db->escape($values['API HTTPS']))); + $criteria->add(new Criteria('`api-type`', $this->db->escape($values['API Type']))); - if ($this->count($criteria) == 0 && ((isset($values['API Authenticate Write'])?$values['API Authenticate Write']:$values['API Authicate Write']) == 'xoopskey' || (isset($values['API Authenticate Read'])?$values['API Authenticate Read']:$values['API Authicate Read']) == 'xoopskey')) + + if ($this->getCount($criteria) == 0 && ((isset($values['API Authenticate Write'])?$values['API Authenticate Write']:$values['API Authicate Write']) == 'xoopskey' || (isset($values['API Authenticate Read'])?$values['API Authenticate Read']:$values['API Authicate Read']) == 'xoopskey')) { $object = $this->create(); $object->setVar('api-name', $values['API Name']); @@ -119,7 +120,7 @@ $object->setVar('checked', time() + mt_rand(1800, 3600*mt_rand(2,7))); $object->setVar('checking', $object->getVar('checked')); @$this->insert($object, true); - } elseif ($this->count($criteria) != 0) { + } elseif ($this->getCount($criteria) != 0) { $objects = $this->getObjects($criteria); if (!empty($objects[0])) { Modified: XoopsModules/authkey/trunk/modules/authkey/class/keys.php =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/class/keys.php 2018-06-28 21:12:26 UTC (rev 13377) +++ XoopsModules/authkey/trunk/modules/authkey/class/keys.php 2018-06-29 01:26:22 UTC (rev 13378) @@ -65,9 +65,9 @@ $this->initVar('stats-month', XOBJ_DTYPE_INT, null, false); $this->initVar('stats-quarter', XOBJ_DTYPE_INT, null, false); $this->initVar('stats-year', XOBJ_DTYPE_INT, null, false); - $this->initVar('report-month', XOBJ_DTYPE_INT, null, false); - $this->initVar('report-quarter', XOBJ_DTYPE_INT, null, false); - $this->initVar('report-year', XOBJ_DTYPE_INT, null, false); + $this->initVar('report-monthly', XOBJ_DTYPE_INT, null, false); + $this->initVar('report-halfyear', XOBJ_DTYPE_INT, null, false); + $this->initVar('report-fullyear', XOBJ_DTYPE_INT, null, false); $this->initVar('report-biannual', XOBJ_DTYPE_INT, null, false); $this->initVar('created', XOBJ_DTYPE_INT, null, false); $this->initVar('issuing', XOBJ_DTYPE_INT, null, false); @@ -206,7 +206,7 @@ $mailer->setFromEmail($GLOBALS['xoopsConfig']['adminemail']); $mailer->setFromName($GLOBALS['xoopsConfig']['sitename']); - $mailer->assign('APIS', xoops_getModuleHandler('apis', basename(dirname(__DIR__)))->getAPIsText()); + $mailer->assign('APIS', xoops_getModuleHandler('apis', basename(dirname(__DIR__)))->getAPIsText("\t * ")); $mailer->assign('KEY', $object->getVar('key')); $mailer->assign('MD5KEY', md5($object->getVar('key'))); $mailer->assign('SHA1KEY', sha1($object->getVar('key'))); Modified: XoopsModules/authkey/trunk/modules/authkey/class/users.php =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/class/users.php 2018-06-28 21:12:26 UTC (rev 13377) +++ XoopsModules/authkey/trunk/modules/authkey/class/users.php 2018-06-29 01:26:22 UTC (rev 13378) @@ -59,9 +59,9 @@ $this->initVar('stats-month', XOBJ_DTYPE_INT, null, false); $this->initVar('stats-quarter', XOBJ_DTYPE_INT, null, false); $this->initVar('stats-year', XOBJ_DTYPE_INT, null, false); - $this->initVar('report-month', XOBJ_DTYPE_INT, null, false); - $this->initVar('report-quarter', XOBJ_DTYPE_INT, null, false); - $this->initVar('report-year', XOBJ_DTYPE_INT, null, false); + $this->initVar('report-monthly', XOBJ_DTYPE_INT, null, false); + $this->initVar('report-halfyear', XOBJ_DTYPE_INT, null, false); + $this->initVar('report-fullyear', XOBJ_DTYPE_INT, null, false); $this->initVar('report-biannual', XOBJ_DTYPE_INT, null, false); $this->initVar('created', XOBJ_DTYPE_INT, null, false); $this->initVar('emailed', XOBJ_DTYPE_INT, null, false); Modified: XoopsModules/authkey/trunk/modules/authkey/include/functions.php =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/include/functions.php 2018-06-28 21:12:26 UTC (rev 13377) +++ XoopsModules/authkey/trunk/modules/authkey/include/functions.php 2018-06-29 01:26:22 UTC (rev 13378) @@ -20,6 +20,54 @@ require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'xcp' . DIRECTORY_SEPARATOR . 'xcp.class.php'; + +if (!function_exists("authkey_getTimePeriod")) { + + /* function eightbit_loadConfig() + * + * Converts Seconds to Staggered United Display + * + * @author Simon Roberts (Chronolabs) si...@la... + * + * @return array() + */ + function authkey_getTimePeriod($seconds = 0) + { + $result = array(); + $months = 3600 * 24 * 7 * 4; + $weeks = 3600 * 24 * 7; + $days = 3600 * 24; + $hours = 3600; + $minutes = 3600 / 60; + $seconds = 60; + if (floor($seconds / $months) != 0) { + $result[] = floor($seconds / $months) . 'mth'; + $seconds = $seconds - (floor($seconds / $months) * $months); + } + if (floor($seconds / $weeks) != 0) { + $result[] = floor($seconds / $weeks) . 'wk'; + $seconds = $seconds - (floor($seconds / $weeks) * $weeks); + } + if (floor($seconds / $days) != 0) { + $result[] = floor($seconds / $days) . 'd'; + $seconds = $seconds - (floor($seconds / $days) * $days); + } + if (floor($seconds / $hours) != 0) { + $result[] = floor($seconds / $hours) . 'h'; + $seconds = $seconds - (floor($seconds / $hours) * $hours); + } + if (floor($seconds / $minutes) != 0) { + $result[] = floor($seconds / $minutes) . 'm'; + $seconds = $seconds - (floor($seconds / $minutes) * $minutes); + } + if (floor($seconds) != 0) { + $result[] = floor($seconds) . 's'; + $seconds = $seconds - (floor($seconds)); + } + return implode(" ", $result); + } +} + function getHTMLForm($mode = '') { Modified: XoopsModules/authkey/trunk/modules/authkey/index.php =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/index.php 2018-06-28 21:12:26 UTC (rev 13377) +++ XoopsModules/authkey/trunk/modules/authkey/index.php 2018-06-29 01:26:22 UTC (rev 13378) @@ -23,7 +23,7 @@ if (!is_object($GLOBALS['xoopsUser'])) { - redirect_header(XOOPS_URL . '/user.php', 8, _MN_AUTHKEY_LOGINREQUIRED); + require_once __DIR__ . DS . 'apis.php'; exit(0); } @@ -36,7 +36,7 @@ $xoopsOption['template_main'] = 'authkeys_index.html'; require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'header.php'; -$GLOBALS['xoopsTpl']->assign('moddirname', basename(dirname(__DIR__))); +$GLOBALS['xoopsTpl']->assign('moddirname', basename(__DIR__)); $criteria = new Criteria('uid', $GLOBALS['xoopsUser']->getVar('uid')); $criteria->setSort('`title` ASC, `name` ASC, `company`'); @@ -47,7 +47,7 @@ $keyarr = array(); foreach($key->getValues(array_keys($key->vars)) as $field => $value) { - if (substr($field, 0, 5) == 'calls' || substr($field, 0, 5) == 'limit' ) { + if (substr($field, 0, 5) == 'calls' || substr($field, 0, 5) == 'limit' || substr($field, 0, 5) == 'overs') { $keyarr[str_replace("-", "_", $field)] = number_format($value, 0); } elseif (in_array($field, array('stats-hour', 'stats-day', 'stats-week', 'stats-month', 'stats-quarter', 'stats-year', 'report-month', 'report-quarter', 'report-year', 'report-biannual', 'created', 'issuing', 'quoting', 'emailed'))) { $keyarr[str_replace("-", "_", $field)] = date("Y/m/d H:i:s", $value); Modified: XoopsModules/authkey/trunk/modules/authkey/language/english/main.php =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/language/english/main.php 2018-06-28 21:12:26 UTC (rev 13377) +++ XoopsModules/authkey/trunk/modules/authkey/language/english/main.php 2018-06-29 01:26:22 UTC (rev 13378) @@ -33,4 +33,22 @@ define('_MN_AUTHKEY_INDEX_TDE', 'Weekly Pollings'); define('_MN_AUTHKEY_INDEX_TDF', 'Monthly Pollings'); define('_MN_AUTHKEY_INDEX_TDG', 'Actions'); + +// apis.html - language constants +define('_MN_AUTHKEY_APIS_PA', 'Below is the listing of the api\'s that require the XoopsKey/Authkey and there status online as well as a few other statistics!'); +define('_MN_AUTHKEY_APIS_H2A', 'API\'s Requiring Key\'s'); + +//table headers +define('_MN_AUTHKEY_APIS_TDA', 'Icon'); +define('_MN_AUTHKEY_APIS_TDB', 'Name'); +define('_MN_AUTHKEY_APIS_TDC', 'URL'); +define('_MN_AUTHKEY_APIS_TDD', 'Status'); +define('_MN_AUTHKEY_APIS_TDE', 'Write Permission'); +define('_MN_AUTHKEY_APIS_TDF', 'Read Permission'); +define('_MN_AUTHKEY_APIS_TDG', 'API Uptime'); +define('_MN_AUTHKEY_APIS_TDH', 'API Downtime'); +define('_MN_AUTHKEY_APIS_TDI', 'Calls Today'); +define('_MN_AUTHKEY_APIS_TDJ', 'Today Ends'); +define('_MN_AUTHKEY_APIS_TDK', 'Calls this Month'); +define('_MN_AUTHKEY_APIS_TDL', 'Month Ends'); ?> \ No newline at end of file Modified: XoopsModules/authkey/trunk/modules/authkey/language/english/modinfo.php =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/language/english/modinfo.php 2018-06-28 21:12:26 UTC (rev 13377) +++ XoopsModules/authkey/trunk/modules/authkey/language/english/modinfo.php 2018-06-29 01:26:22 UTC (rev 13378) @@ -61,9 +61,11 @@ define('_MI_AUTHKEY_ADMENU4_ICON','assets/images/32x32/about.png'); define('_MI_AUTHKEY_ADMENU5_ICON','assets/images/32x32/exec.png'); - // LANGUAGE DESCRIPTIONS + // LANGUAGE DESCRIPTIONS define('_MI_AUTHKEY_API_REPORTING','Send API Overall Reports to these groups!'); define('_MI_AUTHKEY_API_REPORTING_DESC','The API Reports will be sent to these groups when they are made monthly, 6 monthly, yearly or biannually!'); + define('_MI_AUTHKEY_MINUMUM_LINES','Minimum lines of data sent in *.csv report'); + define('_MI_AUTHKEY_MINUMUM_LINES_DESC','This is the minimum lines of data that have to exist in a report to be sent to API, User or Owner Reports!'); define('_MI_AUTHKEY_TMP_PATH','Temporary Write Path'); define('_MI_AUTHKEY_TMP_PATH_DESC','This is the full path to your temporary write path'); define('_MI_AUTHKEY_DELETE_SECONDS','Deleting statistical data when it is!'); Added: XoopsModules/authkey/trunk/modules/authkey/preloads/checking.php =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/preloads/checking.php (rev 0) +++ XoopsModules/authkey/trunk/modules/authkey/preloads/checking.php 2018-06-29 01:26:22 UTC (rev 13378) @@ -0,0 +1,91 @@ +<?php +/** + * Authkey API Authentication Keys for xoops.org + * + * You may not change or alter any portion of this comment or credits + * of supporting developers from this source code or any supporting source code + * which is considered copyrighted (c) material of the original comment or credit authors. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * @copyright (c) 2000-2019 Chronolabs Cooperative (8Bit.snails.email) + * @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html) + * @package authkey + * @since 1.0.7 + * @author Simon Antony Roberts <wis...@us...> + * @link https://sourceforge.net/p/xoops/svn/HEAD/tree/XoopsModules/authkey + */ + + + + +/** + * Profile core preloads + * + * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) + * @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html) + * @author trabis <lus...@gm...> + */ +class AuthkeyCheckingPreload extends XoopsPreloadItem +{ + + /** + * @param $args + */ + public static function eventCoreIncludeCommonEnd($args) + { + xoops_loadLanguage('modinfo', basename(dirname(__DIR__))); + xoops_load('XoopsCache'); + + global $authkeyModule, $authkeyConfigsList, $authkeyConfigs, $authkeyConfigsOptions; + require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'header.php'; + + if (!$rtt = XoopsCache::read('authkey_checking')) + { + $criteria = new CriteriaCompo(new Criteria('`checking`', time(), "<=")); + foreach(xoops_getModuleHandler('apis', basename(dirname(__DIR__)))->getObjects($criteria) as $api) + { + $status = $api->getVar('status'); + $json = json_decode(getURLData($api->getVar('api-https') . '/' . $api->getVar('api-version') . '/test.api', 30, 30)); + if (isset($json['api-type']) && !empty($json['api-type']) && $json['api-type'] == $api->getVar('api-type')) + { + $api->setVar('mode', 'https'); + $api->setVar('status', 'online'); + if ($status == 'offline') + $api->setVar('online', 0); + else + $api->setVar('online', $api->getVar('online') + $api->getVar('checking') - $api->getVar('checked')); + $api->setVar('checked', $api->getVar('checking')); + $api->setVar('checking', time() + (3600 * mt_rand(8, 24))); + @xoops_getModuleHandler('apis', basename(dirname(__DIR__)))->insert($api, true); + } else { + $json = json_decode(getURLData($api->getVar('api-http') . '/' . $api->getVar('api-version') . '/test.api', 30, 30)); + if (isset($json['api-type']) && !empty($json['api-type']) && $json['api-type'] == $api->getVar('api-type')) + { + $api->setVar('mode', 'http'); + $api->setVar('status', 'online'); + if ($status == 'offline') + $api->setVar('online', 0); + else + $api->setVar('online', $api->getVar('online') + $api->getVar('checking') - $api->getVar('checked')); + $api->setVar('checked', $api->getVar('checking')); + $api->setVar('checking', time() + (3600 * mt_rand(8, 24))); + @xoops_getModuleHandler('apis', basename(dirname(__DIR__)))->insert($api, true); + } else { + $api->setVar('mode', 'http'); + $api->setVar('status', 'offline'); + if ($status == 'online') + $api->setVar('offline', 0); + else + $api->setVar('offline', $api->getVar('offline') + $api->getVar('checking') - $api->getVar('checked')); + $api->setVar('checked', $api->getVar('checking')); + $api->setVar('checking', time() + (3600 * mt_rand(2, 7))); + @xoops_getModuleHandler('apis', basename(dirname(__DIR__)))->insert($api, true); + } + } + } + XoopsCache::write('authkey_checking', array('time'=>time()), $authkeyConfigsList['preload-seconds']); + } + } +} Property changes on: XoopsModules/authkey/trunk/modules/authkey/preloads/checking.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Modified: XoopsModules/authkey/trunk/modules/authkey/preloads/reports.php =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/preloads/reports.php 2018-06-28 21:12:26 UTC (rev 13377) +++ XoopsModules/authkey/trunk/modules/authkey/preloads/reports.php 2018-06-29 01:26:22 UTC (rev 13378) @@ -27,7 +27,7 @@ * @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html) * @author trabis <lus...@gm...> */ -class AuthkeyPollingPreload extends XoopsPreloadItem +class AuthkeyReportsPreload extends XoopsPreloadItem { /** @@ -41,7 +41,7 @@ global $authkeyModule, $authkeyConfigsList, $authkeyConfigs, $authkeyConfigsOptions; require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'header.php'; - if (!$rtt = XoopsCache::read('authkey_polling')) + if (!$rtt = XoopsCache::read('authkey_reporting')) { $criteria = new CriteriaCompo(new Criteria('`stats-hour`', time(), "<="), 'OR'); $criteria->add(new Criteria('`stats-day`', time(), "<="), 'OR'); @@ -51,145 +51,9 @@ $criteria->add(new Criteria('`stats-year`', time(), "<="), 'OR'); foreach(xoops_getModuleHandler('keys', basename(dirname(__DIR__)))->getObjects($criteria) as $key) { - if ($key->getVar('stats-hour') <= time()) - $key->setVar('stats-hour', time() + (3600)); - if ($key->getVar('stats-day') <= time()) - $key->setVar('stats-day', time() + (3600 * 24)); - if ($key->getVar('stats-week') <= time()) - $key->setVar('stats-week', time() + (3600 * 24 * 7)); - if ($key->getVar('stats-month') <= time()) - $key->setVar('stats-month', time() + (3600 * 24 * 7 * 4)); - if ($key->getVar('stats-quarter') <= time()) - $key->setVar('stats-quarter', time() + (3600 * 24 * 7 * 4 * 3)); - if ($key->getVar('stats-year') <= time()) - $key->setVar('stats-year', time() + (3600 * 24 * 7 * 4 * 12)); - - $user = xoops_getModuleHandler('users', basename(dirname(__DIR__)))->get($key->getVar('uid')); - if ($user->getVar('stats-hour') <= time()) - $user->setVar('stats-hour', time() + (3600)); - if ($user->getVar('stats-day') <= time()) - $user->setVar('stats-day', time() + (3600 * 24)); - if ($user->getVar('stats-week') <= time()) - $user->setVar('stats-week', time() + (3600 * 24 * 7)); - if ($user->getVar('stats-month') <= time()) - $user->setVar('stats-month', time() + (3600 * 24 * 7 * 4)); - if ($user->getVar('stats-quarter') <= time()) - $user->setVar('stats-quarter', time() + (3600 * 24 * 7 * 4 * 3)); - if ($user->getVar('stats-year') <= time()) - $user->setVar('stats-year', time() + (3600 * 24 * 7 * 4 * 12)); - - foreach(array(md5($key->getVar('key')), md5(md5($key->getVar('key'))), md5(sha1($key->getVar('key')))) as $keyy) { - if ($token = XoopsCache::read("xoopskey_".$keyy)) { - - foreach(xoops_getModuleHandler('apis', basename(dirname(__DIR__)))->getURLSArray() as $apitype => $urls) - foreach($urls as $apiurl => $apiname) - if (isset($token[$apitype][$apiurl]) && !empty($token[$apitype][$apiurl])) - { - $criteria = new CriteriaCompo(new Criteria('`api-http`', $apiurl, 'LIKE')); - $criteria->add(new Criteria('`api-https`', $apiurl, 'LIKE'), 'OR'); - $criteria->add(new Criteria('`api-type`', $apitype, 'LIKE'), 'AND'); - $apis = xoops_getModuleHandler('apis', basename(dirname(__DIR__)))->getObjects($criteria); - if (!empty($apis[0])) - { - $apis[0]->setVar('calls-hour', $apis[0]->getVar('calls-hour') + $token[$apitype][$apiurl]); - $apis[0]->setVar('calls-day', $apis[0]->getVar('calls-day') + $token[$apitype][$apiurl]); - $apis[0]->setVar('calls-week', $apis[0]->getVar('calls-week') + $token[$apitype][$apiurl]); - $apis[0]->setVar('calls-month', $apis[0]->getVar('calls-month') + $token[$apitype][$apiurl]); - $apis[0]->setVar('calls-quarter', $apis[0]->getVar('calls-quarter') + $token[$apitype][$apiurl]); - $apis[0]->setVar('calls-year', $apis[0]->getVar('calls-year') + $token[$apitype][$apiurl]); - if (xoops_getModuleHandler('apis', basename(dirname(__DIR__)))->insert($apis[0], true)) - $token[$apitype][$apiurl] = 0; - } - } - - $key->setVar('calls-hour', $key->getVar('calls-hour') + $token['polling']); - $key->setVar('calls-day', $key->getVar('calls-day') + $token['polling']); - $key->setVar('calls-week', $key->getVar('calls-week') + $token['polling']); - $key->setVar('calls-month', $key->getVar('calls-month') + $token['polling']); - $key->setVar('calls-quarter', $key->getVar('calls-quarter') + $token['polling']); - $key->setVar('calls-year', $key->getVar('calls-year') + $token['polling']); - - $user->setVar('calls-hour', $user->getVar('calls-hour') + $token['polling']); - $user->setVar('calls-day', $user->getVar('calls-day') + $token['polling']); - $user->setVar('calls-week', $user->getVar('calls-week') + $token['polling']); - $user->setVar('calls-month', $user->getVar('calls-month') + $token['polling']); - $user->setVar('calls-quarter', $user->getVar('calls-quarter') + $token['polling']); - $user->setVar('calls-year', $user->getVar('calls-year') + $token['polling']); - - $token['polling'] = 0; - - $overlimit = false; - if ($authkeyConfigsList['limited']==true) - { - if ($key->getVar('limit-hour') < $key->getVar('calls-hour')) - { - $overlimit = true; - $key->setVar('overs-hour', $key->getVar('calls-hour') - $key->getVar('limit-hour')); - } - if ($key->getVar('limit-day') < $key->getVar('calls-day')) - { - $overlimit = true; - $key->setVar('overs-day', $key->getVar('calls-day') - $key->getVar('limit-day')); - } - if ($key->getVar('limit-week') < $key->getVar('calls-week')) - { - $overlimit = true; - $key->setVar('overs-week', $key->getVar('calls-week') - $key->getVar('limit-week')); - } - if ($key->getVar('limit-month') < $key->getVar('calls-month')) - { - $overlimit = true; - $key->setVar('overs-month', $key->getVar('calls-month') - $key->getVar('limit-month')); - } - if ($key->getVar('limit-quarter') < $key->getVar('calls-quarter')) - { - $overlimit = true; - $key->setVar('overs-quarter', $key->getVar('calls-quarter') - $key->getVar('limit-quarter')); - } - if ($key->getVar('limit-year') < $key->getVar('calls-year')) - { - $overlimit = true; - $key->setVar('overs-year', $key->getVar('calls-year') - $key->getVar('limit-year')); - } - if ($user->getVar('limit-hour') < $user->getVar('calls-hour')) - { - $overlimit = true; - $user->setVar('overs-hour', $user->getVar('calls-hour') - $user->getVar('limit-hour')); - } - if ($user->getVar('limit-day') < $user->getVar('calls-day')) - { - $overlimit = true; - $user->setVar('overs-day', $user->getVar('calls-day') - $user->getVar('limit-day')); - } - if ($user->getVar('limit-week') < $user->getVar('calls-week')) - { - $overlimit = true; - $user->setVar('overs-week', $user->getVar('calls-week') - $user->getVar('limit-week')); - } - if ($user->getVar('limit-month') < $user->getVar('calls-month')) - { - $overlimit = true; - $user->setVar('overs-month', $user->getVar('calls-month') - $user->getVar('limit-month')); - } - if ($user->getVar('limit-quarter') < $user->getVar('calls-quarter')) - { - $overlimit = true; - $user->setVar('overs-quarter', $user->getVar('calls-quarter') - $user->getVar('limit-quarter')); - } - if ($user->getVar('limit-year') < $user->getVar('calls-year')) - { - $overlimit = true; - $user->setVar('overs-year', $user->getVar('calls-year') - $user->getVar('limit-year')); - } - } - - XoopsCache::write("xoopskey_".$keyy, $token, 3600 * 24 * 7 * 4 * 36); - } - } - @xoops_getModuleHandler('users', basename(dirname(__DIR__)))->insert($user, true); - @xoops_getModuleHandler('keys', basename(dirname(__DIR__)))->insert($key, true); } + XoopsCache::write('authkey_reporting', array('time'=>time()), $authkeyConfigsList['preload-seconds']); } - XoopsCache::write('authkey_polling', array('time'=>time()), $authkeyConfigsList['preload-seconds']); + } } Modified: XoopsModules/authkey/trunk/modules/authkey/sql/mysql.sql =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/sql/mysql.sql 2018-06-28 21:12:26 UTC (rev 13377) +++ XoopsModules/authkey/trunk/modules/authkey/sql/mysql.sql 2018-06-29 01:26:22 UTC (rev 13378) @@ -39,7 +39,7 @@ `emailed` INT(12) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `apitypestatus` (`api-type`,`status`), - KEY `search` (`api-name`,`api-type`,`api-version`,`api-http`,`api-https`), + KEY `search` (`api-name`,`api-type`,`api-version`,`api-http`,`api-https`) ) ENGINE=INNODB DEFAULT CHARSET=utf8; # Table structure for table authkey_keys Modified: XoopsModules/authkey/trunk/modules/authkey/templates/authkeys_apis.html =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/templates/authkeys_apis.html 2018-06-28 21:12:26 UTC (rev 13377) +++ XoopsModules/authkey/trunk/modules/authkey/templates/authkeys_apis.html 2018-06-29 01:26:22 UTC (rev 13378) @@ -1,39 +1,36 @@ <h1><{$authkeys_module_namings}> ~ v<{$authkeys_module_version}></h1> -<p><{$smarty.const._MN_AUTHKEY_INDEX_PA}></p> -<{if $authkeys_count == 0 || ($authkeys_count >= 1 && $allow_creating == true)}> -<h2><{$smarty.const._MN_AUTHKEY_INDEX_H2A}></h2> -<div style="margin-left: 17.1831%; margin-right: 17.1831%; margin-bottom: 25px; margin-top: 17px; font-size: 67%;"> - <div style="padding: 6px; border: 3px dashed black;"> - <{$authkeys_newkey_form}> - </div> -</div> -<{/if}> -<{if $authkeys_count > 0}> -<h2><{$smarty.const._MN_AUTHKEY_INDEX_H2B}></h2> +<p><{$smarty.const._MN_AUTHKEY_APIS_PA}></p> +<{if $apis_count > 0}> +<h2><{$smarty.const._MN_AUTHKEY_APIS_H2A}></h2> <table> <tr class='head'> - <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_INDEX_TDA}></td> - <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_INDEX_TDB}></td> - <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_INDEX_TDC}></td> - <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_INDEX_TDD}></td> - <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_INDEX_TDE}></td> - <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_INDEX_TDF}></td> - <td style='text-align: right;'><{$smarty.const._MN_AUTHKEY_INDEX_TDG}></td> + <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_APIS_TDA}></td> + <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_APIS_TDB}></td> + <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_APIS_TDC}></td> + <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_APIS_TDD}></td> + <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_APIS_TDE}></td> + <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_APIS_TDF}></td> + <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_APIS_TDG}></td> + <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_APIS_TDH}></td> + <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_APIS_TDI}></td> + <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_APIS_TDJ}></td> + <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_APIS_TDK}></td> + <td style='text-align: center;'><{$smarty.const._MN_AUTHKEY_APIS_TDL}></td> </tr> - <{foreach from=$authkeys item=key}> + <{foreach from=$apis item=api}> <tr class='<{cycle values='even,odd'}>'> - <td style='text-align: center; font-weight: 700; width: auto !important;'><{$key.key}></td> - <td style='text-align: center; width: auto !important;'><{$key.title}></td> - <td style='text-align: center; width: auto !important;'><{$key.name}></td> - <td style='text-align: center; width: 125px !important;'><{$key.calls_day}> / <strong><{$key.limit_day}></strong><{if $key.overs_day > 0}> <font style='color: red; font-weight: 900;'>( <{$key.overs_day}> )</font><{/if}></td> - <td style='text-align: center; width: 125px !important;'><{$key.calls_week}> / <strong><{$key.limit_week}></strong><{if $key.overs_week > 0}> <font style='color: red; font-weight: 900;'>( <{$key.overs_week}> )</font><{/if}></td> - <td style='text-align: center; width: 125px !important;'><{$key.calls_month}> / <strong><{$key.limit_month}></strong><{if $key.overs_month > 0}> <font style='color: red; font-weight: 900;'>( <{$key.overs_month}> )</font><{/if}></td> - <td style='text-align: right; width: 120px !important;'> - <{if $allow_viewing}><a href="<{$xoops_url}>/modules/authkey/key.php?id=<{$key.id}>&op=view" ><img src="<{$xoops_url}>/modules/authkey/assets/images/16x16/view.png" /></a><{/if}> - <{if $allow_editing}><a href="<{$xoops_url}>/modules/authkey/key.php?id=<{$key.id}>&op=edit" ><img src="<{$xoops_url}>/modules/authkey/assets/images/16x16/edit.png" /></a><{/if}> - <{if $allow_reissued}><a href="<{$xoops_url}>/modules/authkey/key.php?id=<{$key.id}>&op=reissue" ><img src="<{$xoops_url}>/modules/authkey/assets/images/16x16/issue.png" /></a><{/if}> - <{if $allow_deleting}><a href="<{$xoops_url}>/modules/authkey/key.php?id=<{$key.id}>&op=delete" ><img src="<{$xoops_url}>/modules/authkey/assets/images/16x16/delete.png" /></a><{/if}> - </td> + <td style='text-align: center; width: 28px !important;'><img src="<{$api.api_icon}>" /></td> + <td style='text-align: center; width: auto !important;'><{$api.api_name}></td> + <td style='text-align: center; width: auto !important;'><a href="<{$api.url}>" target="_blank"><{$api.url}></a></td> + <td style='text-align: center; width: auto !important;'><{$api.status}></td> + <td style='text-align: center; width: 45px !important;'><{$api.api_write}></td> + <td style='text-align: center; width: 45px !important;'><{$api.api_read}></td> + <td style='text-align: center; width: 55px !important;'><{$api.online}></td> + <td style='text-align: center; width: 55px !important;'><{$api.offline}></td> + <td style='text-align: center; width: 75px !important;'><{$api.calls_day}></td> + <td style='text-align: center; width: 95px !important;'><{$api.stats_day}></td> + <td style='text-align: center; width: 75px !important;'><{$api.calls_month}></td> + <td style='text-align: center; width: 95px !important;'><{$api.stats_month}></td> </tr> <{/foreach}> </table> Modified: XoopsModules/authkey/trunk/modules/authkey/xoops_version.php =================================================================== --- XoopsModules/authkey/trunk/modules/authkey/xoops_version.php 2018-06-28 21:12:26 UTC (rev 13377) +++ XoopsModules/authkey/trunk/modules/authkey/xoops_version.php 2018-06-29 01:26:22 UTC (rev 13378) @@ -100,12 +100,12 @@ $modversion['templates'][$i]['description'] = 'authkeys migrate to token purchases'; // Module Submenus -$i=1; -$modversion['sub'][$i]['name'] = _MI_AUTHKEY_APIS; -$modversion['sub'][$i]['url'] = "apis.php"; - if (is_object($GLOBALS['xoopsUser'])) -{ +{ + $i=1; + $modversion['sub'][$i]['name'] = _MI_AUTHKEY_APIS; + $modversion['sub'][$i]['url'] = "apis.php"; + // Submenu Items $keys_handler =& xoops_getmodulehandler('keys', 'authkey'); $criteria = new CriteriaCompo(new Criteria('uid', $GLOBALS['xoopsUser']->getVar('uid'))); @@ -139,6 +139,15 @@ $modversion['config'][$i]['default'] = array(XOOPS_GROUP_ADMIN=>XOOPS_GROUP_ADMIN); $i++; +$modversion['config'][$i]['name'] = 'minimum-lines'; +$modversion['config'][$i]['title'] = "_MI_AUTHKEY_MINUMUM_LINES"; +$modversion['config'][$i]['description'] = "_MI_AUTHKEY_MINUMUM_LINES_DESC"; +$modversion['config'][$i]['formtype'] = 'select'; +$modversion['config'][$i]['valuetype'] = 'int'; +$modversion['config'][$i]['default'] = mt_rand(2, 6); +$modversion['config'][$i]['options'] = array('1 Line of Data' => 1, '2 Lines of Data' => 2, '3 Lines of Data' => 3, '4 Lines of Data' => 4, '5 Lines of Data' => 5, '6 Lines of Data' => 6, '7 Lines of Data' => 7, '8 Lines of Data' => 8, '9 Lines of Data' => 9, '10 Lines of Data' => 10); + +$i++; $modversion['config'][$i]['name'] = 'tmp-path'; $modversion['config'][$i]['title'] = "_MI_AUTHKEY_TMP_PATH"; $modversion['config'][$i]['description'] = "_MI_AUTHKEY_TMP_PATH_DESC"; |