From e3c04b1fd0f441e0042e218f47696b1bfad26c73 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 26 Sep 2018 22:24:36 +0200 Subject: guest access app --- Zotlabs/Module/Permcats.php | 4 +- Zotlabs/Module/Settings/Tokens.php | 173 --------------------------------- Zotlabs/Module/Tokens.php | 193 +++++++++++++++++++++++++++++++++++++ Zotlabs/Widget/Settings_menu.php | 8 -- app/tokens.apd | 6 ++ include/features.php | 15 --- view/tpl/settings_tokens.tpl | 72 -------------- view/tpl/tokens.tpl | 72 ++++++++++++++ 8 files changed, 272 insertions(+), 271 deletions(-) delete mode 100644 Zotlabs/Module/Settings/Tokens.php create mode 100644 Zotlabs/Module/Tokens.php create mode 100644 app/tokens.apd delete mode 100644 view/tpl/settings_tokens.tpl create mode 100644 view/tpl/tokens.tpl diff --git a/Zotlabs/Module/Permcats.php b/Zotlabs/Module/Permcats.php index 97090067b..3d068862a 100644 --- a/Zotlabs/Module/Permcats.php +++ b/Zotlabs/Module/Permcats.php @@ -14,8 +14,7 @@ class Permcats extends Controller { return; if(! Apps::system_app_installed(local_channel(), 'Permission Categories')) - return - + return; $channel = App::get_channel(); @@ -67,7 +66,6 @@ class Permcats extends Controller { $channel = App::get_channel(); - if(argc() > 1) $name = hex2bin(argv(1)); diff --git a/Zotlabs/Module/Settings/Tokens.php b/Zotlabs/Module/Settings/Tokens.php deleted file mode 100644 index e59cf8d1c..000000000 --- a/Zotlabs/Module/Settings/Tokens.php +++ /dev/null @@ -1,173 +0,0 @@ -= $max_tokens) { - notice( sprintf( t('This channel is limited to %d tokens'), $max_tokens) . EOL); - return; - } - } - } - if($token_errs) { - notice( t('Name and Password are required.') . EOL); - return; - } - if($atoken_id) { - $r = q("update atoken set atoken_name = '%s', atoken_token = '%s', atoken_expires = '%s' - where atoken_id = %d and atoken_uid = %d", - dbesc($name), - dbesc($token), - dbesc($expires), - intval($atoken_id), - intval($channel['channel_id']) - ); - } - else { - $r = q("insert into atoken ( atoken_aid, atoken_uid, atoken_name, atoken_token, atoken_expires ) - values ( %d, %d, '%s', '%s', '%s' ) ", - intval($channel['channel_account_id']), - intval($channel['channel_id']), - dbesc($name), - dbesc($token), - dbesc($expires) - ); - } - - $atoken_xchan = substr($channel['channel_hash'],0,16) . '.' . $name; - - $all_perms = \Zotlabs\Access\Permissions::Perms(); - - if($all_perms) { - foreach($all_perms as $perm => $desc) { - if(array_key_exists('perms_' . $perm, $_POST)) { - set_abconfig($channel['channel_id'],$atoken_xchan,'my_perms',$perm,intval($_POST['perms_' . $perm])); - } - else { - set_abconfig($channel['channel_id'],$atoken_xchan,'my_perms',$perm,0); - } - } - } - - - info( t('Token saved.') . EOL); - return; - } - - - function get() { - - $channel = \App::get_channel(); - - $atoken = null; - $atoken_xchan = ''; - - if(argc() > 2) { - $id = argv(2); - - $atoken = q("select * from atoken where atoken_id = %d and atoken_uid = %d", - intval($id), - intval(local_channel()) - ); - - if($atoken) { - $atoken = $atoken[0]; - $atoken_xchan = substr($channel['channel_hash'],0,16) . '.' . $atoken['atoken_name']; - } - - if($atoken && argc() > 3 && argv(3) === 'drop') { - atoken_delete($id); - $atoken = null; - $atoken_xchan = ''; - } - } - - $t = q("select * from atoken where atoken_uid = %d", - intval(local_channel()) - ); - - $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:'); - - $global_perms = \Zotlabs\Access\Permissions::Perms(); - $their_perms = []; - - $existing = get_all_perms(local_channel(),(($atoken_xchan) ? $atoken_xchan : ''),false); - - if($atoken_xchan) { - $theirs = q("select * from abconfig where chan = %d and xchan = '%s' and cat = 'their_perms'", - intval(local_channel()), - dbesc($atoken_xchan) - ); - if($theirs) { - foreach($theirs as $t) { - $their_perms[$t['k']] = $t['v']; - } - } - } - foreach($global_perms as $k => $v) { - $thisperm = get_abconfig(local_channel(),$contact['abook_xchan'],'my_perms',$k); -//fixme - - $checkinherited = \Zotlabs\Access\PermissionLimits::Get(local_channel(),$k); - - if($existing[$k]) - $thisperm = "1"; - - $perms[] = array('perms_' . $k, $v, ((array_key_exists($k,$their_perms)) ? intval($their_perms[$k]) : ''),$thisperm, 1, (($checkinherited & PERMS_SPECIFIC) ? '' : '1'), '', $checkinherited); - } - - - - $tpl = get_markup_template("settings_tokens.tpl"); - $o .= replace_macros($tpl, array( - '$form_security_token' => get_form_security_token("settings_tokens"), - '$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)), ''), - '$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']) : ''), ''), - '$them' => t('Their Settings'), - '$me' => t('My Settings'), - '$perms' => $perms, - '$inherited' => t('inherited'), - '$notself' => 1, - '$self' => 0, - '$permlbl' => t('Individual Permissions'), - '$permnote' => t('Some permissions may be inherited from your channel\'s privacy settings, which have higher priority than individual settings. You can not change those settings here.'), - '$submit' => t('Submit') - )); - return $o; - } - -} diff --git a/Zotlabs/Module/Tokens.php b/Zotlabs/Module/Tokens.php new file mode 100644 index 000000000..a791d3f63 --- /dev/null +++ b/Zotlabs/Module/Tokens.php @@ -0,0 +1,193 @@ += $max_tokens) { + notice( sprintf( t('This channel is limited to %d tokens'), $max_tokens) . EOL); + return; + } + } + } + if($token_errs) { + notice( t('Name and Password are required.') . EOL); + return; + } + if($atoken_id) { + $r = q("update atoken set atoken_name = '%s', atoken_token = '%s', atoken_expires = '%s' + where atoken_id = %d and atoken_uid = %d", + dbesc($name), + dbesc($token), + dbesc($expires), + intval($atoken_id), + intval($channel['channel_id']) + ); + } + else { + $r = q("insert into atoken ( atoken_aid, atoken_uid, atoken_name, atoken_token, atoken_expires ) + values ( %d, %d, '%s', '%s', '%s' ) ", + intval($channel['channel_account_id']), + intval($channel['channel_id']), + dbesc($name), + dbesc($token), + dbesc($expires) + ); + } + + $atoken_xchan = substr($channel['channel_hash'],0,16) . '.' . $name; + + $all_perms = \Zotlabs\Access\Permissions::Perms(); + + if($all_perms) { + foreach($all_perms as $perm => $desc) { + if(array_key_exists('perms_' . $perm, $_POST)) { + set_abconfig($channel['channel_id'],$atoken_xchan,'my_perms',$perm,intval($_POST['perms_' . $perm])); + } + else { + set_abconfig($channel['channel_id'],$atoken_xchan,'my_perms',$perm,0); + } + } + } + + + info( t('Token saved.') . EOL); + return; + } + + + function get() { + + if(! local_channel()) + return; + + if(! Apps::system_app_installed(local_channel(), 'Guest Access')) { + //Do not display any associated widgets at this point + App::$pdl = ''; + + $o = 'Guest Access App (Not Installed):
'; + $o .= t('Create access tokens so that non-members can access private content'); + return $o; + } + + $channel = App::get_channel(); + + $atoken = null; + $atoken_xchan = ''; + + if(argc() > 2) { + $id = argv(2); + + $atoken = q("select * from atoken where atoken_id = %d and atoken_uid = %d", + intval($id), + intval(local_channel()) + ); + + if($atoken) { + $atoken = $atoken[0]; + $atoken_xchan = substr($channel['channel_hash'],0,16) . '.' . $atoken['atoken_name']; + } + + if($atoken && argc() > 3 && argv(3) === 'drop') { + atoken_delete($id); + $atoken = null; + $atoken_xchan = ''; + } + } + + $t = q("select * from atoken where atoken_uid = %d", + intval(local_channel()) + ); + + $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:'); + + $global_perms = \Zotlabs\Access\Permissions::Perms(); + $their_perms = []; + + $existing = get_all_perms(local_channel(),(($atoken_xchan) ? $atoken_xchan : ''),false); + + if($atoken_xchan) { + $theirs = q("select * from abconfig where chan = %d and xchan = '%s' and cat = 'their_perms'", + intval(local_channel()), + dbesc($atoken_xchan) + ); + if($theirs) { + foreach($theirs as $t) { + $their_perms[$t['k']] = $t['v']; + } + } + } + foreach($global_perms as $k => $v) { + $thisperm = get_abconfig(local_channel(),$contact['abook_xchan'],'my_perms',$k); +//fixme + + $checkinherited = \Zotlabs\Access\PermissionLimits::Get(local_channel(),$k); + + if($existing[$k]) + $thisperm = "1"; + + $perms[] = array('perms_' . $k, $v, ((array_key_exists($k,$their_perms)) ? intval($their_perms[$k]) : ''),$thisperm, 1, (($checkinherited & PERMS_SPECIFIC) ? '' : '1'), '', $checkinherited); + } + + + + $tpl = get_markup_template("tokens.tpl"); + $o .= replace_macros($tpl, array( + '$form_security_token' => get_form_security_token("tokens"), + '$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)), ''), + '$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']) : ''), ''), + '$them' => t('Their Settings'), + '$me' => t('My Settings'), + '$perms' => $perms, + '$inherited' => t('inherited'), + '$notself' => 1, + '$self' => 0, + '$permlbl' => t('Individual Permissions'), + '$permnote' => t('Some permissions may be inherited from your channel\'s privacy settings, which have higher priority than individual settings. You can not change those settings here.'), + '$submit' => t('Submit') + )); + return $o; + } + +} diff --git a/Zotlabs/Widget/Settings_menu.php b/Zotlabs/Widget/Settings_menu.php index 781f3b145..ecf93ec78 100644 --- a/Zotlabs/Widget/Settings_menu.php +++ b/Zotlabs/Widget/Settings_menu.php @@ -79,14 +79,6 @@ class Settings_menu { 'selected' => '' ); - if(feature_enabled(local_channel(),'access_tokens')) { - $tabs[] = array( - 'label' => t('Guest Access Tokens'), - 'url' => z_root() . '/settings/tokens', - 'selected' => ((argv(1) === 'tokens') ? 'active' : ''), - ); - } - if($role === false || $role === 'custom') { $tabs[] = array( 'label' => t('Connection Default Permissions'), diff --git a/app/tokens.apd b/app/tokens.apd new file mode 100644 index 000000000..6cb66cbd7 --- /dev/null +++ b/app/tokens.apd @@ -0,0 +1,6 @@ +version: 1 +url: $baseurl/tokens +requires: local_channel +name: Guest Access +photo: icon:user-secret +categories: Access Control diff --git a/include/features.php b/include/features.php index a264ae289..8dcf4517d 100644 --- a/include/features.php +++ b/include/features.php @@ -71,21 +71,6 @@ function get_features($filtered = true, $level = (-1)) { $arr = [ - 'access_control' => [ - t('Access Control and Permissions'), - - [ - 'access_tokens', - t('Access Tokens'), - t('Create access tokens so that non-members can access private content.'), - false, - get_config('feature_lock','access_tokens'), - feature_level('access_tokens',2), - ], - - ], - - // Item tools 'tools' => [ diff --git a/view/tpl/settings_tokens.tpl b/view/tpl/settings_tokens.tpl deleted file mode 100644 index 48190c00c..000000000 --- a/view/tpl/settings_tokens.tpl +++ /dev/null @@ -1,72 +0,0 @@ -
-
-

{{$title}}

-
-
-
- - -
- - {{if $atoken}}{{/if}} - {{include file="field_input.tpl" field=$name}} - {{include file="field_input.tpl" field=$token}} - {{include file="field_input.tpl" field=$expires}} -
- -
-
- -
- -
-
-
- {{$permnote}} -
- - - - - - {{foreach $perms as $prm}} - {{include file="field_acheckbox.tpl" field=$prm}} - {{/foreach}} -
{{$me}}
- -
- -
-
-
-
- - -
{{$desc2}}
- - - {{if $tokens}} -
- - {{foreach $tokens as $t}} - - - - - {{/foreach}} -
{{$t.atoken_name}}
- -
- {{/if}} -
diff --git a/view/tpl/tokens.tpl b/view/tpl/tokens.tpl new file mode 100644 index 000000000..ccb1f8c61 --- /dev/null +++ b/view/tpl/tokens.tpl @@ -0,0 +1,72 @@ +
+
+

{{$title}}

+
+
+
+ + +
+ + {{if $atoken}}{{/if}} + {{include file="field_input.tpl" field=$name}} + {{include file="field_input.tpl" field=$token}} + {{include file="field_input.tpl" field=$expires}} +
+ +
+
+ +
+ +
+
+
+ {{$permnote}} +
+ + + + + + {{foreach $perms as $prm}} + {{include file="field_acheckbox.tpl" field=$prm}} + {{/foreach}} +
{{$me}}
+ +
+ +
+
+
+
+ + +
{{$desc2}}
+ + + {{if $tokens}} +
+ + {{foreach $tokens as $t}} + + + + + {{/foreach}} +
{{$t.atoken_name}}
+ +
+ {{/if}} +
-- cgit v1.2.3