From df8bb0596a2a657cb2b0be951e2bc713f2b5e89d Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 2 Jan 2022 20:45:25 +0000 Subject: port new_token from zap, fixes and more cleanup --- Zotlabs/Daemon/Notifier.php | 2 +- Zotlabs/Module/Tokens.php | 10 ++-------- include/text.php | 22 +++++++++++++++++++++- view/tpl/tokens.tpl | 36 ------------------------------------ 4 files changed, 24 insertions(+), 46 deletions(-) diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php index 76c17545a..7964621c7 100644 --- a/Zotlabs/Daemon/Notifier.php +++ b/Zotlabs/Daemon/Notifier.php @@ -240,7 +240,7 @@ class Notifier { $target_item = $r[0]; - if (in_array($target_item['author']['xchan_network'], ['rss', 'anon'])) { + if (in_array($target_item['author']['xchan_network'], ['rss', 'anon', 'token'])) { logger('notifier: target item author is not a fetchable actor', LOGGER_DEBUG); return; } diff --git a/Zotlabs/Module/Tokens.php b/Zotlabs/Module/Tokens.php index b1c8bb4bf..1b074171e 100644 --- a/Zotlabs/Module/Tokens.php +++ b/Zotlabs/Module/Tokens.php @@ -250,9 +250,6 @@ class Tokens extends Controller { $desc = t('Use this form to create temporary access identifiers to share things with non-members. These identities may be used in Access Control Lists and visitors may login using these credentials to access private content.'); - $desc2 = t('You may also provide dropbox style access links to friends and associates by adding the Login Password to any specific site URL as shown. Examples:'); - - //TODO: assign role $pcat = new Permcat(local_channel()); $pcatlist = $pcat->listing(); @@ -266,7 +263,7 @@ class Tokens extends Controller { if (!$current_permcat) { - notice(t('Please select a role for this contact!') . EOL); + notice(t('Please select a role for this guest!') . EOL); $permcats[] = ''; } @@ -282,13 +279,10 @@ class Tokens extends Controller { '$permcat' => ['permcat', t('Select a role for this token'), $current_permcat, '', $permcats], '$title' => t('Guest Access Tokens'), '$desc' => $desc, - '$desc2' => $desc2, '$tokens' => $t, '$atoken' => $atoken, - '$url1' => z_root() . '/channel/' . $channel['channel_address'], - '$url2' => z_root() . '/photos/' . $channel['channel_address'], '$name' => array('name', t('Login Name') . ' *', (($atoken) ? $atoken['atoken_name'] : ''),''), - '$token'=> array('token', t('Login Password') . ' *',(($atoken) ? $atoken['atoken_token'] : autoname(8)), ''), + '$token'=> array('token', t('Login Password') . ' *',(($atoken) ? $atoken['atoken_token'] : new_token()), ''), '$expires'=> array('expires', t('Expires (yyyy-mm-dd)'), (($atoken['atoken_expires'] && $atoken['atoken_expires'] > NULL_DATE) ? datetime_convert('UTC',date_default_timezone_get(),$atoken['atoken_expires']) : ''), ''), '$submit' => t('Submit') )); diff --git a/include/text.php b/include/text.php index 0522dd3c9..29b9d039c 100644 --- a/include/text.php +++ b/include/text.php @@ -2586,7 +2586,7 @@ function xchan_query(&$items, $abook = true, $effective_uid = 0) { $chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") and hubloc_primary = 1"); } - $xchans = q("select * from xchan where xchan_hash in (" . protect_sprintf(implode(',',$arr)) . ") and xchan_network in ('rss','unknown', 'anon')"); + $xchans = q("select * from xchan where xchan_hash in (" . protect_sprintf(implode(',',$arr)) . ") and xchan_network in ('rss','unknown', 'anon', 'token')"); if(! $chans) $chans = $xchans; else @@ -3888,6 +3888,26 @@ function array_path_exists($str,$arr) { } +/** + * @brief provide psuedo random token (string) consisting entirely of US-ASCII letters/numbers + * and with possibly variable length + * + * @return string + */ +function new_token($minlen = 36, $maxlen = 48) { + $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; + $str = EMPTY_STR; + + $len = (($minlen === $maxlen) ? $minlen : mt_rand($minlen, $maxlen)); + + for ($a = 0; $a < $len; $a++) { + $str .= $chars[mt_rand(0, 62)]; + } + + return $str; +} + + /** * @brief Generate a random v4 UUID. * diff --git a/view/tpl/tokens.tpl b/view/tpl/tokens.tpl index 51cd4a6cf..443fb5392 100644 --- a/view/tpl/tokens.tpl +++ b/view/tpl/tokens.tpl @@ -21,42 +21,6 @@ - - -
{{$desc2}}
- - {{if $tokens}}
-- cgit v1.2.3