From 2031a7240cae35dbfbc3e1aa749ae9157250b033 Mon Sep 17 00:00:00 2001 From: Keith Fernie Date: Fri, 18 May 2012 09:12:02 +0100 Subject: [PATCH] new file: public_server.tgz add public_server plugin new file: public_server/README.md add public_server plugin new file: public_server/public_server.php add public_server plugin modified: testdrive.tgz puts content in notification emails modified: testdrive/testdrive.php puts content in notification emails --- public_server.tgz | Bin 0 -> 2158 bytes public_server/README.md | 29 +++++++ public_server/public_server.php | 140 ++++++++++++++++++++++++++++++++ testdrive.tgz | Bin 1879 -> 1882 bytes testdrive/testdrive.php | 3 + 5 files changed, 172 insertions(+) create mode 100755 public_server.tgz create mode 100644 public_server/README.md create mode 100644 public_server/public_server.php mode change 100644 => 100755 testdrive.tgz diff --git a/public_server.tgz b/public_server.tgz new file mode 100755 index 0000000000000000000000000000000000000000..c9a67fe35ef2c182f781b00ff0ee0d637f0314cc GIT binary patch literal 2158 zcmV-!2$A<6iwFQT0=7>81ML}UbK5r7U(H|fR->3wD(mo-t`obX#&+x3I?cpNIvK~K zLL?-iCJB}V?PzxV-}gO$q)1)16SuqF8l#Z}@ZsGTz%Utj!s*96y5>=9?GG7k94~fv z^)HUuU;V$+L5Q7pr`_IOYj?JGIy-By`^T_T9!acN1h5uKsaC<=_53e7!jk<a zV-d~|Jc>2GPP0w(ZlcCA+J}E}LUh8TKyY|9Rw~?YwT6b~6>Iu@rzun`jO0*wymdv; zhq%9G(a7kRMd*tFjqG`~I{e$R)+0U=vBKrClvg!7pEAdhNucZo*jl949kD@xWjb@H z>M!TWIgt#$f`s0VXdxXl*m)q87*6cQm*US5Ea2ReqY-yenP0&^;t-nu+vV0ug0j7m z;7_*L9KlDn*&O~ywb~r^$F|!Nv(2iqR%MOqz?iU_2p0~ZI(SJFmrY`vjkxMNG8l?c ztxOH|z(0o~;smH=(p&nWjMe=%YDm3P3~T=Yy}fR&qerVG3N#ZDBKo~ndH?pP+dGB? z5ny&wkTTylc;Y^ac>wma7*%4HaQe)Jn=!|~Mk<_o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@80*Mm8Hb$hA55=rfLqI^7PTRWTbN3syG(eF+LT zEDA^ux+6tN^i3i)z1ZzV^0UBv#l6Y2FGUzSZE2hZy3%oy2%FZE9L{4D00dS@1?C>j k1xHd=B+RHt>=>WAou~0Mp2pL78vi5XKRSO`vH&Om05@GA1poj5 literal 0 HcmV?d00001 diff --git a/public_server/README.md b/public_server/README.md new file mode 100644 index 000000000..44b29f8e5 --- /dev/null +++ b/public_server/README.md @@ -0,0 +1,29 @@ +Public Server +============= + + +Public Server is a Friendica plugin which implements automatic account & post expiration so that a site may be used as a public +test bed with reduced data retention. + +This is a modified version of the testdrive plugin, DO NOT ACTIVATE AT THE SAME TIME AS THE TESTDRIVE PLUGIN. + +//When an account is created on the site, it is given a hard expiration date of +$a->config['public_server']['expiredays'] = 30; +//Set the default days for posts to expire here +$a->config['public_server']['expireposts'] = 30; +//Remove users who have never logged in after nologin days +$a->config['public_server']['nologin'] = 30; +//Remove users who last logged in over flagusers days ago +$a->config['public_server']['flagusers'] = 146; +//For users who last logged in over flagposts days ago set post expiry days to flagpostsexpire +$a->config['public_server']['flagposts'] = 90; +$a->config['public_server']['flagpostsexpire'] = 146; + +Set these in your .htconfig.php file. By default nothing is defined in case the plugin is activated accidentally. +They can be ommitted or set to 0 to disable each option. +The default values are those used by friendica.eu, change these as desired. + +The expiration date is updated when the user logs in. + +An email warning will be sent out approximately five days before the expiration occurs. Five days later the account is removed completely. + diff --git a/public_server/public_server.php b/public_server/public_server.php new file mode 100644 index 000000000..9d4698291 --- /dev/null +++ b/public_server/public_server.php @@ -0,0 +1,140 @@ + + */ + + + + +function public_server_install() { + + register_hook('register_account', 'addon/public_server/public_server.php', 'public_server_register_account'); + register_hook('cron', 'addon/public_server/public_server.php', 'public_server_cron'); + register_hook('enotify','addon/public_server/public_server.php', 'public_server_enotify'); + register_hook('logged_in', 'addon/public_server/public_server.php', 'public_server_login'); +} + + +function public_server_uninstall() { + + unregister_hook('register_account', 'addon/public_server/public_server.php', 'public_server_register_account'); + unregister_hook('cron', 'addon/public_server/public_server.php', 'public_server_cron'); + unregister_hook('enotify','addon/public_server/public_server.php', 'public_server_enotify'); + unregister_hook('logged_in', 'addon/public_server/public_server.php', 'public_server_login'); +} + +function public_server_register_account($a,$b) { + + $uid = $b; + + $days = get_config('public_server','expiredays'); + $days_posts = get_config('public_server','expireposts'); + if(! $days) + return; + + $r = q("UPDATE user set account_expires_on = '%s', expire = %d where uid = %d limit 1", + dbesc(datetime_convert('UTC','UTC','now +' . $days . ' days')), + intval($days_posts), + intval($uid) + ); + +}; + + +function public_server_cron($a,$b) { + require_once('include/enotify.php'); + $r = q("select * from user where account_expires_on < UTC_TIMESTAMP() + INTERVAL 5 DAY and account_expires_on > '0000-00-00 00:00:00' and + expire_notification_sent = '0000-00-00 00:00:00' "); + + if(count($r)) { + foreach($r as $rr) { + notification(array( + 'uid' => $rr['uid'], + 'type' => NOTIFY_SYSTEM, + 'system_type' => 'public_server_expire', + 'language' => $rr['language'], + 'to_name' => $rr['username'], + 'to_email' => $rr['email'], + 'source_name' => t('Administrator'), + 'source_link' => $a->get_baseurl(), + 'source_photo' => $a->get_baseurl() . '/images/person-80.jpg', + )); + + q("update user set expire_notification_sent = '%s' where uid = %d limit 1", + dbesc(datetime_convert()), + intval($rr['uid']) + ); + } + } + + $r = q("select * from user where account_expired = 1 and account_expires_on < UTC_TIMESTAMP() - INTERVAL 5 DAY and account_expires_on > '0000-00-00 00:00:00'"); + if(count($r)) { + require_once('include/Contact.php'); + foreach($r as $rr) + user_remove($rr['uid']); + + } + $nologin = get_config('public_server','nologin'); + if($nologin) { + $r = q("select uid from user where account_expired = 0 and login_date = '0000-00-00 00:00:00' and register_date < UTC_TIMESTAMP() - INTERVAL %d DAY and account_expires_on = '0000-00-00 00:00:00'",intval($nologin)); + if(count($r)) { + foreach($r as $rr) + q("update user set account_expires_on = '%s' where uid = %d limit 1", + dbesc(datetime_convert('UTC','UTC','now +' . '6 days')), + intval($rr['uid']) + ); + } + } + + + $flagusers = get_config('public_server','flagusers'); + if($flagusers) { + $r = q("select uid from user where account_expired = 0 and login_date < UTC_TIMESTAMP() - INTERVAL %d DAY and account_expires_on = '0000-00-00 00:00:00' and `page-flags` = 0",intval($flagusers)); + if(count($r)) { + foreach($r as $rr) + q("update user set account_expires_on = '%s' where uid = %d limit 1", + dbesc(datetime_convert('UTC','UTC','now +' . '6 days')), + intval($rr['uid']) + ); + } + } + + $flagposts = get_config('public_server','flagposts'); + $flagpostsexpire = get_config('public_server','flagpostsexpire'); + if ($flagposts && $flagpostsexpire) { + $r = q("select uid from user where account_expired = 0 and login_date < UTC_TIMESTAMP() - INTERVAL %d DAY and account_expires_on = '0000-00-00 00:00:00' and expire = 0 and 'page-flags' = 0",intval(flagposts)); + if(count($r)) { + foreach($r as $rr) + q("update user set expire = %d where uid = %d limit 1", + intval($flagpostsexpire), + intval($rr['uid']) + ); + } + } + + +} + +function public_server_enotify(&$a, &$b) { + if (x($b, 'params') && $b['params']['type'] == NOTIFY_SYSTEM + && x($b['params'], 'system_type') && $b['params']['system_type'] === 'public_server_expire') { + $b['itemlink'] = $a->get_baseurl(); + $b['epreamble'] = $b['preamble'] = sprintf( t('Your account on %s will expire in a few days.'), get_config('system','sitename')); + $b['subject'] = t('Your Friendica account is about to expire.'); + $b['body'] = sprintf( t("Hi %1\$s,\n\nYour account on %2\$s will expire in less than five days. You may keep your account by logging in at least once every 30 days"), $b['params']['to_name'], "[url=" . $app->config["system"]["url"] . "]" . $app->config["sitename"] . "[/url]"); + } +} + +function public_server_login($a,$b) { + $days = get_config('public_server','expiredays'); + if(! $days) + return; + $r = q("UPDATE user set account_expires_on = '%s' where uid = %d and account_expires_on > '0000-00-00 00:00:00' limit 1", + dbesc(datetime_convert('UTC','UTC','now +' . $days . ' days')), + local_user() + ); +} diff --git a/testdrive.tgz b/testdrive.tgz old mode 100644 new mode 100755 index 7d314ea28fedfdfdd21653a06b8e1cd1e00457bd..3369481c589e4399200e2afd0e3ae89dd24dd4f4 GI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