Browse Source

Add RSS/ATOM notification feeds, close #12

tags/v2.1
Skylar Ittner 7 months ago
parent
commit
39ccaa2f2d
11 changed files with 318 additions and 269 deletions
  1. 4
    0
      action.php
  2. 2
    2
      composer.json
  3. 100
    264
      composer.lock
  4. BIN
      database.mwb
  5. 35
    0
      database_upgrade/2.0_2.1.sql
  6. 89
    0
      feed.php
  7. 3
    1
      langs/en/notifications.json
  8. 4
    1
      langs/en/sync.json
  9. 4
    0
      langs/messages.php
  10. 31
    0
      lib/RandomString.lib.php
  11. 46
    1
      pages/sync.php

+ 4
- 0
action.php View File

@@ -113,4 +113,8 @@ switch ($VARS['action']) {
113 113
             returnToSender("invalid_parameters#notifications");
114 114
         }
115 115
         break;
116
+    case "resetfeedkey":
117
+        $database->delete('userkeys', ['AND' => ['uid' => $_SESSION['uid'], 'typeid' => 1]]);
118
+        returnToSender("feed_key_reset");
119
+        break;
116 120
 }

+ 2
- 2
composer.json View File

@@ -6,10 +6,10 @@
6 6
         "catfan/medoo": "^1.5",
7 7
         "spomky-labs/otphp": "^8.3",
8 8
         "endroid/qr-code": "^3.2",
9
-        "ldaptools/ldaptools": "^0.24.0",
10 9
         "guzzlehttp/guzzle": "^6.2",
11 10
         "phpmailer/phpmailer": "^5.2",
12
-        "christian-riesen/base32": "^1.3"
11
+        "christian-riesen/base32": "^1.3",
12
+        "mibe/feedwriter": "^1.1"
13 13
     },
14 14
     "license": "MPL-2.0",
15 15
     "authors": [

+ 100
- 264
composer.lock View File

@@ -4,8 +4,7 @@
4 4
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5 5
         "This file is @generated automatically"
6 6
     ],
7
-    "hash": "872ba5f8bcf571aca66346a439e5b40d",
8
-    "content-hash": "49c0c56036b215998ff212564e9c2fd3",
7
+    "content-hash": "eca0497dbaf6b15cbe0ced496dec0712",
9 8
     "packages": [
10 9
         {
11 10
             "name": "bacon/bacon-qr-code",
@@ -51,7 +50,7 @@
51 50
             ],
52 51
             "description": "BaconQrCode is a QR code generator for PHP.",
53 52
             "homepage": "https://github.com/Bacon/BaconQrCode",
54
-            "time": "2017-10-17 09:59:25"
53
+            "time": "2017-10-17T09:59:25+00:00"
55 54
         },
56 55
         {
57 56
             "name": "beberlei/assert",
@@ -106,7 +105,7 @@
106 105
                 "assertion",
107 106
                 "validation"
108 107
             ],
109
-            "time": "2018-04-09 14:40:28"
108
+            "time": "2018-04-09T14:40:28+00:00"
110 109
         },
111 110
         {
112 111
             "name": "catfan/medoo",
@@ -165,7 +164,7 @@
165 164
                 "sql",
166 165
                 "sqlite"
167 166
             ],
168
-            "time": "2018-03-26 17:54:24"
167
+            "time": "2018-03-26T17:54:24+00:00"
169 168
         },
170 169
         {
171 170
             "name": "christian-riesen/base32",
@@ -219,7 +218,7 @@
219 218
                 "encode",
220 219
                 "rfc4648"
221 220
             ],
222
-            "time": "2016-05-05 11:49:03"
221
+            "time": "2016-05-05T11:49:03+00:00"
223 222
         },
224 223
         {
225 224
             "name": "endroid/qr-code",
@@ -279,7 +278,7 @@
279 278
                 "qr",
280 279
                 "qrcode"
281 280
             ],
282
-            "time": "2018-02-27 21:35:30"
281
+            "time": "2018-02-27T21:35:30+00:00"
283 282
         },
284 283
         {
285 284
             "name": "guzzlehttp/guzzle",
@@ -344,7 +343,7 @@
344 343
                 "rest",
345 344
                 "web service"
346 345
             ],
347
-            "time": "2018-03-26 16:33:04"
346
+            "time": "2018-03-26T16:33:04+00:00"
348 347
         },
349 348
         {
350 349
             "name": "guzzlehttp/promises",
@@ -395,7 +394,7 @@
395 394
             "keywords": [
396 395
                 "promise"
397 396
             ],
398
-            "time": "2016-12-20 10:07:11"
397
+            "time": "2016-12-20T10:07:11+00:00"
399 398
         },
400 399
         {
401 400
             "name": "guzzlehttp/psr7",
@@ -460,7 +459,7 @@
460 459
                 "uri",
461 460
                 "url"
462 461
             ],
463
-            "time": "2017-03-20 17:10:46"
462
+            "time": "2017-03-20T17:10:46+00:00"
464 463
         },
465 464
         {
466 465
             "name": "khanamiryan/qrcode-detector-decoder",
@@ -510,67 +509,104 @@
510 509
                 "qr",
511 510
                 "zxing"
512 511
             ],
513
-            "time": "2018-04-01 20:25:53"
512
+            "time": "2018-04-01T20:25:53+00:00"
514 513
         },
515 514
         {
516
-            "name": "ldaptools/ldaptools",
517
-            "version": "v0.24.0",
515
+            "name": "mibe/feedwriter",
516
+            "version": "v1.1.1",
518 517
             "source": {
519 518
                 "type": "git",
520
-                "url": "https://github.com/ldaptools/ldaptools.git",
521
-                "reference": "31e05ae6082fc7e61afc666e2c773ee8cb0e47b5"
519
+                "url": "https://github.com/mibe/FeedWriter.git",
520
+                "reference": "f4cc748ad8700e36663f08cfeebe7fd39b00eea2"
522 521
             },
523 522
             "dist": {
524 523
                 "type": "zip",
525
-                "url": "https://api.github.com/repos/ldaptools/ldaptools/zipball/31e05ae6082fc7e61afc666e2c773ee8cb0e47b5",
526
-                "reference": "31e05ae6082fc7e61afc666e2c773ee8cb0e47b5",
524
+                "url": "https://api.github.com/repos/mibe/FeedWriter/zipball/f4cc748ad8700e36663f08cfeebe7fd39b00eea2",
525
+                "reference": "f4cc748ad8700e36663f08cfeebe7fd39b00eea2",
527 526
                 "shasum": ""
528 527
             },
529 528
             "require": {
530
-                "ext-ldap": "*",
531
-                "php": ">=5.6",
532
-                "ramsey/uuid": ">=3.0",
533
-                "symfony/event-dispatcher": ">=2.0",
534
-                "symfony/yaml": ">=2.0"
535
-            },
536
-            "require-dev": {
537
-                "doctrine/cache": "~1.0",
538
-                "friendsofphp/php-cs-fixer": "~1.0",
539
-                "phpspec/phpspec": "~3.0",
540
-                "tedivm/stash": ">=0.14.1"
541
-            },
542
-            "suggest": {
543
-                "doctrine/cache": "Provides the cache_type 'doctrine' to help increase performance.",
544
-                "ext-intl": "Better UTF-8 handling.",
545
-                "ext-mbstring": "Better UTF-8 handling.",
546
-                "tedivm/stash": "Provides the cache_type 'stash' to help increase performance."
529
+                "php": ">=5.3.0"
547 530
             },
548 531
             "type": "library",
532
+            "extra": {
533
+                "branch-alias": {
534
+                    "dev-master": "1.1.x-dev"
535
+                }
536
+            },
549 537
             "autoload": {
550 538
                 "psr-4": {
551
-                    "LdapTools\\": "src/LdapTools"
539
+                    "FeedWriter\\": ""
552 540
                 }
553 541
             },
554 542
             "notification-url": "https://packagist.org/downloads/",
555 543
             "license": [
556
-                "MIT"
544
+                "GPL-3.0"
557 545
             ],
558 546
             "authors": [
559 547
                 {
560
-                    "name": "Chad Sikorra",
561
-                    "email": "Chad.Sikorra@gmail.com",
562
-                    "homepage": "http://www.chadsikorra.com"
548
+                    "name": "Michael Bemmerl",
549
+                    "email": "mail@mx-server.de"
550
+                },
551
+                {
552
+                    "name": "Phil Freo"
553
+                },
554
+                {
555
+                    "name": "Paul Ferrett"
556
+                },
557
+                {
558
+                    "name": "Brennen Bearnes"
559
+                },
560
+                {
561
+                    "name": "Michael Robinson",
562
+                    "email": "mike@pagesofinterest.net"
563
+                },
564
+                {
565
+                    "name": "Baptiste Fontaine"
566
+                },
567
+                {
568
+                    "name": "Kristián Valentín"
569
+                },
570
+                {
571
+                    "name": "Brandtley McMinn"
572
+                },
573
+                {
574
+                    "name": "Julian Bogdani"
575
+                },
576
+                {
577
+                    "name": "Anis Uddin Ahmad",
578
+                    "email": "anis.programmer@gmail.com"
579
+                },
580
+                {
581
+                    "name": "Cedric Gampert"
582
+                },
583
+                {
584
+                    "name": "Yamek"
585
+                },
586
+                {
587
+                    "name": "thielj"
588
+                },
589
+                {
590
+                    "name": "Pavel Khakhlou"
591
+                },
592
+                {
593
+                    "name": "Daniel"
594
+                },
595
+                {
596
+                    "name": "Tino Goratsch"
563 597
                 }
564 598
             ],
565
-            "description": "LdapTools is a feature-rich LDAP library for PHP 5.6+.",
566
-            "homepage": "http://www.phpldaptools.com",
599
+            "description": "Generate feeds in either RSS 1.0, RSS 2.0 or ATOM formats",
600
+            "homepage": "https://github.com/mibe/FeedWriter",
567 601
             "keywords": [
568
-                "Microsoft Exchange",
569
-                "active directory",
570
-                "ldap",
571
-                "openldap"
572
-            ],
573
-            "time": "2017-04-09 23:39:51"
602
+                "RSS 1.0",
603
+                "atom",
604
+                "feed",
605
+                "rss",
606
+                "rss 2.0",
607
+                "rss2"
608
+            ],
609
+            "time": "2016-11-19T20:47:44+00:00"
574 610
         },
575 611
         {
576 612
             "name": "myclabs/php-enum",
@@ -614,7 +650,7 @@
614 650
             "keywords": [
615 651
                 "enum"
616 652
             ],
617
-            "time": "2017-06-28 16:24:08"
653
+            "time": "2017-06-28T16:24:08+00:00"
618 654
         },
619 655
         {
620 656
             "name": "paragonie/constant_time_encoding",
@@ -676,20 +712,20 @@
676 712
                 "hex2bin",
677 713
                 "rfc4648"
678 714
             ],
679
-            "time": "2018-03-10 19:47:49"
715
+            "time": "2018-03-10T19:47:49+00:00"
680 716
         },
681 717
         {
682 718
             "name": "paragonie/random_compat",
683
-            "version": "v2.0.12",
719
+            "version": "v2.0.17",
684 720
             "source": {
685 721
                 "type": "git",
686 722
                 "url": "https://github.com/paragonie/random_compat.git",
687
-                "reference": "258c89a6b97de7dfaf5b8c7607d0478e236b04fb"
723
+                "reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d"
688 724
             },
689 725
             "dist": {
690 726
                 "type": "zip",
691
-                "url": "https://api.github.com/repos/paragonie/random_compat/zipball/258c89a6b97de7dfaf5b8c7607d0478e236b04fb",
692
-                "reference": "258c89a6b97de7dfaf5b8c7607d0478e236b04fb",
727
+                "url": "https://api.github.com/repos/paragonie/random_compat/zipball/29af24f25bab834fcbb38ad2a69fa93b867e070d",
728
+                "reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d",
693 729
                 "shasum": ""
694 730
             },
695 731
             "require": {
@@ -721,10 +757,11 @@
721 757
             "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
722 758
             "keywords": [
723 759
                 "csprng",
760
+                "polyfill",
724 761
                 "pseudorandom",
725 762
                 "random"
726 763
             ],
727
-            "time": "2018-04-04 21:24:14"
764
+            "time": "2018-07-04T16:31:37+00:00"
728 765
         },
729 766
         {
730 767
             "name": "phpmailer/phpmailer",
@@ -801,7 +838,7 @@
801 838
                 }
802 839
             ],
803 840
             "description": "PHPMailer is a full-featured email creation and transfer class for PHP",
804
-            "time": "2017-11-04 09:26:05"
841
+            "time": "2017-11-04T09:26:05+00:00"
805 842
         },
806 843
         {
807 844
             "name": "psr/http-message",
@@ -851,87 +888,7 @@
851 888
                 "request",
852 889
                 "response"
853 890
             ],
854
-            "time": "2016-08-06 14:39:51"
855
-        },
856
-        {
857
-            "name": "ramsey/uuid",
858
-            "version": "3.7.3",
859
-            "source": {
860
-                "type": "git",
861
-                "url": "https://github.com/ramsey/uuid.git",
862
-                "reference": "44abcdad877d9a46685a3a4d221e3b2c4b87cb76"
863
-            },
864
-            "dist": {
865
-                "type": "zip",
866
-                "url": "https://api.github.com/repos/ramsey/uuid/zipball/44abcdad877d9a46685a3a4d221e3b2c4b87cb76",
867
-                "reference": "44abcdad877d9a46685a3a4d221e3b2c4b87cb76",
868
-                "shasum": ""
869
-            },
870
-            "require": {
871
-                "paragonie/random_compat": "^1.0|^2.0",
872
-                "php": "^5.4 || ^7.0"
873
-            },
874
-            "replace": {
875
-                "rhumsaa/uuid": "self.version"
876
-            },
877
-            "require-dev": {
878
-                "codeception/aspect-mock": "^1.0 | ~2.0.0",
879
-                "doctrine/annotations": "~1.2.0",
880
-                "goaop/framework": "1.0.0-alpha.2 | ^1.0 | ^2.1",
881
-                "ircmaxell/random-lib": "^1.1",
882
-                "jakub-onderka/php-parallel-lint": "^0.9.0",
883
-                "mockery/mockery": "^0.9.9",
884
-                "moontoast/math": "^1.1",
885
-                "php-mock/php-mock-phpunit": "^0.3|^1.1",
886
-                "phpunit/phpunit": "^4.7|^5.0",
887
-                "squizlabs/php_codesniffer": "^2.3"
888
-            },
889
-            "suggest": {
890
-                "ext-libsodium": "Provides the PECL libsodium extension for use with the SodiumRandomGenerator",
891
-                "ext-uuid": "Provides the PECL UUID extension for use with the PeclUuidTimeGenerator and PeclUuidRandomGenerator",
892
-                "ircmaxell/random-lib": "Provides RandomLib for use with the RandomLibAdapter",
893
-                "moontoast/math": "Provides support for converting UUID to 128-bit integer (in string form).",
894
-                "ramsey/uuid-console": "A console application for generating UUIDs with ramsey/uuid",
895
-                "ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type."
896
-            },
897
-            "type": "library",
898
-            "extra": {
899
-                "branch-alias": {
900
-                    "dev-master": "3.x-dev"
901
-                }
902
-            },
903
-            "autoload": {
904
-                "psr-4": {
905
-                    "Ramsey\\Uuid\\": "src/"
906
-                }
907
-            },
908
-            "notification-url": "https://packagist.org/downloads/",
909
-            "license": [
910
-                "MIT"
911
-            ],
912
-            "authors": [
913
-                {
914
-                    "name": "Marijn Huizendveld",
915
-                    "email": "marijn.huizendveld@gmail.com"
916
-                },
917
-                {
918
-                    "name": "Thibaud Fabre",
919
-                    "email": "thibaud@aztech.io"
920
-                },
921
-                {
922
-                    "name": "Ben Ramsey",
923
-                    "email": "ben@benramsey.com",
924
-                    "homepage": "https://benramsey.com"
925
-                }
926
-            ],
927
-            "description": "Formerly rhumsaa/uuid. A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID).",
928
-            "homepage": "https://github.com/ramsey/uuid",
929
-            "keywords": [
930
-                "guid",
931
-                "identifier",
932
-                "uuid"
933
-            ],
934
-            "time": "2018-01-20 00:28:24"
891
+            "time": "2016-08-06T14:39:51+00:00"
935 892
         },
936 893
         {
937 894
             "name": "spomky-labs/otphp",
@@ -995,70 +952,7 @@
995 952
                 "otp",
996 953
                 "totp"
997 954
             ],
998
-            "time": "2017-07-24 10:27:40"
999
-        },
1000
-        {
1001
-            "name": "symfony/event-dispatcher",
1002
-            "version": "v4.0.8",
1003
-            "source": {
1004
-                "type": "git",
1005
-                "url": "https://github.com/symfony/event-dispatcher.git",
1006
-                "reference": "63353a71073faf08f62caab4e6889b06a787f07b"
1007
-            },
1008
-            "dist": {
1009
-                "type": "zip",
1010
-                "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/63353a71073faf08f62caab4e6889b06a787f07b",
1011
-                "reference": "63353a71073faf08f62caab4e6889b06a787f07b",
1012
-                "shasum": ""
1013
-            },
1014
-            "require": {
1015
-                "php": "^7.1.3"
1016
-            },
1017
-            "conflict": {
1018
-                "symfony/dependency-injection": "<3.4"
1019
-            },
1020
-            "require-dev": {
1021
-                "psr/log": "~1.0",
1022
-                "symfony/config": "~3.4|~4.0",
1023
-                "symfony/dependency-injection": "~3.4|~4.0",
1024
-                "symfony/expression-language": "~3.4|~4.0",
1025
-                "symfony/stopwatch": "~3.4|~4.0"
1026
-            },
1027
-            "suggest": {
1028
-                "symfony/dependency-injection": "",
1029
-                "symfony/http-kernel": ""
1030
-            },
1031
-            "type": "library",
1032
-            "extra": {
1033
-                "branch-alias": {
1034
-                    "dev-master": "4.0-dev"
1035
-                }
1036
-            },
1037
-            "autoload": {
1038
-                "psr-4": {
1039
-                    "Symfony\\Component\\EventDispatcher\\": ""
1040
-                },
1041
-                "exclude-from-classmap": [
1042
-                    "/Tests/"
1043
-                ]
1044
-            },
1045
-            "notification-url": "https://packagist.org/downloads/",
1046
-            "license": [
1047
-                "MIT"
1048
-            ],
1049
-            "authors": [
1050
-                {
1051
-                    "name": "Fabien Potencier",
1052
-                    "email": "fabien@symfony.com"
1053
-                },
1054
-                {
1055
-                    "name": "Symfony Community",
1056
-                    "homepage": "https://symfony.com/contributors"
1057
-                }
1058
-            ],
1059
-            "description": "Symfony EventDispatcher Component",
1060
-            "homepage": "https://symfony.com",
1061
-            "time": "2018-04-06 07:35:43"
955
+            "time": "2017-07-24T10:27:40+00:00"
1062 956
         },
1063 957
         {
1064 958
             "name": "symfony/inflector",
@@ -1115,7 +1009,7 @@
1115 1009
                 "symfony",
1116 1010
                 "words"
1117 1011
             ],
1118
-            "time": "2018-01-03 17:15:19"
1012
+            "time": "2018-01-03T17:15:19+00:00"
1119 1013
         },
1120 1014
         {
1121 1015
             "name": "symfony/options-resolver",
@@ -1169,7 +1063,7 @@
1169 1063
                 "configuration",
1170 1064
                 "options"
1171 1065
             ],
1172
-            "time": "2018-01-18 22:19:33"
1066
+            "time": "2018-01-18T22:19:33+00:00"
1173 1067
         },
1174 1068
         {
1175 1069
             "name": "symfony/polyfill-mbstring",
@@ -1228,7 +1122,7 @@
1228 1122
                 "portable",
1229 1123
                 "shim"
1230 1124
             ],
1231
-            "time": "2018-01-30 19:27:44"
1125
+            "time": "2018-01-30T19:27:44+00:00"
1232 1126
         },
1233 1127
         {
1234 1128
             "name": "symfony/polyfill-php56",
@@ -1284,7 +1178,7 @@
1284 1178
                 "portable",
1285 1179
                 "shim"
1286 1180
             ],
1287
-            "time": "2018-01-30 19:27:44"
1181
+            "time": "2018-01-30T19:27:44+00:00"
1288 1182
         },
1289 1183
         {
1290 1184
             "name": "symfony/polyfill-util",
@@ -1336,7 +1230,7 @@
1336 1230
                 "polyfill",
1337 1231
                 "shim"
1338 1232
             ],
1339
-            "time": "2018-01-31 18:08:44"
1233
+            "time": "2018-01-31T18:08:44+00:00"
1340 1234
         },
1341 1235
         {
1342 1236
             "name": "symfony/property-access",
@@ -1403,65 +1297,7 @@
1403 1297
                 "property path",
1404 1298
                 "reflection"
1405 1299
             ],
1406
-            "time": "2018-01-03 07:38:00"
1407
-        },
1408
-        {
1409
-            "name": "symfony/yaml",
1410
-            "version": "v4.0.8",
1411
-            "source": {
1412
-                "type": "git",
1413
-                "url": "https://github.com/symfony/yaml.git",
1414
-                "reference": "8b34ebb5989df61cbd77eff29a02c4db9ac1069c"
1415
-            },
1416
-            "dist": {
1417
-                "type": "zip",
1418
-                "url": "https://api.github.com/repos/symfony/yaml/zipball/8b34ebb5989df61cbd77eff29a02c4db9ac1069c",
1419
-                "reference": "8b34ebb5989df61cbd77eff29a02c4db9ac1069c",
1420
-                "shasum": ""
1421
-            },
1422
-            "require": {
1423
-                "php": "^7.1.3"
1424
-            },
1425
-            "conflict": {
1426
-                "symfony/console": "<3.4"
1427
-            },
1428
-            "require-dev": {
1429
-                "symfony/console": "~3.4|~4.0"
1430
-            },
1431
-            "suggest": {
1432
-                "symfony/console": "For validating YAML files using the lint command"
1433
-            },
1434
-            "type": "library",
1435
-            "extra": {
1436
-                "branch-alias": {
1437
-                    "dev-master": "4.0-dev"
1438
-                }
1439
-            },
1440
-            "autoload": {
1441
-                "psr-4": {
1442
-                    "Symfony\\Component\\Yaml\\": ""
1443
-                },
1444
-                "exclude-from-classmap": [
1445
-                    "/Tests/"
1446
-                ]
1447
-            },
1448
-            "notification-url": "https://packagist.org/downloads/",
1449
-            "license": [
1450
-                "MIT"
1451
-            ],
1452
-            "authors": [
1453
-                {
1454
-                    "name": "Fabien Potencier",
1455
-                    "email": "fabien@symfony.com"
1456
-                },
1457
-                {
1458
-                    "name": "Symfony Community",
1459
-                    "homepage": "https://symfony.com/contributors"
1460
-                }
1461
-            ],
1462
-            "description": "Symfony Yaml Component",
1463
-            "homepage": "https://symfony.com",
1464
-            "time": "2018-04-03 05:24:00"
1300
+            "time": "2018-01-03T07:38:00+00:00"
1465 1301
         }
1466 1302
     ],
1467 1303
     "packages-dev": [],

BIN
database.mwb View File


+ 35
- 0
database_upgrade/2.0_2.1.sql View File

@@ -0,0 +1,35 @@
1
+/*
2
+ * This Source Code Form is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ */
6
+
7
+CREATE TABLE IF NOT EXISTS `userkeys` (
8
+  `uid` INT(11) NOT NULL,
9
+  `key` VARCHAR(100) NOT NULL,
10
+  `created` DATETIME NULL DEFAULT NULL,
11
+  `typeid` INT(11) NOT NULL,
12
+  PRIMARY KEY (`uid`),
13
+  INDEX `fk_userkeys_userkeytypes1_idx` (`typeid` ASC),
14
+  CONSTRAINT `fk_userkeys_accounts1`
15
+    FOREIGN KEY (`uid`)
16
+    REFERENCES `accounthub`.`accounts` (`uid`)
17
+    ON DELETE NO ACTION
18
+    ON UPDATE NO ACTION,
19
+  CONSTRAINT `fk_userkeys_userkeytypes1`
20
+    FOREIGN KEY (`typeid`)
21
+    REFERENCES `accounthub`.`userkeytypes` (`typeid`)
22
+    ON DELETE NO ACTION
23
+    ON UPDATE NO ACTION)
24
+ENGINE = InnoDB
25
+DEFAULT CHARACTER SET = utf8;
26
+
27
+CREATE TABLE IF NOT EXISTS `userkeytypes` (
28
+  `typeid` INT(11) NOT NULL,
29
+  `typename` VARCHAR(45) NOT NULL,
30
+  PRIMARY KEY (`typeid`, `typename`))
31
+ENGINE = InnoDB
32
+DEFAULT CHARACTER SET = utf8;
33
+
34
+INSERT INTO `userkeytypes` (`typeid`, `typename`) VALUES (1, 'RSSAtomFeed');
35
+INSERT INTO `userkeytypes` (`typeid`, `typename`) VALUES (2, 'Other');

+ 89
- 0
feed.php View File

@@ -0,0 +1,89 @@
1
+<?php
2
+
3
+/*
4
+ * This Source Code Form is subject to the terms of the Mozilla Public
5
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
6
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
+ */
8
+
9
+require __DIR__ . "/required.php";
10
+
11
+date_default_timezone_set('UTC');
12
+
13
+use \FeedWriter\RSS1;
14
+use \FeedWriter\RSS2;
15
+use \FeedWriter\ATOM;
16
+
17
+if (empty($_GET['key']) || empty($_GET['type'])) {
18
+    http_response_code(400);
19
+    die("400 Bad Request: please send a user key and a feed type");
20
+}
21
+
22
+if (!$database->has('userkeys', ['key' => $_GET['key']])) {
23
+    http_response_code(403);
24
+    die("403 Forbidden: provide valid key");
25
+}
26
+
27
+$uid = $database->get('userkeys', 'uid', ['key' => $_GET['key']]);
28
+$user = new User($uid);
29
+switch ($user->getStatus()->get()) {
30
+    case AccountStatus::NORMAL:
31
+    case AccountStatus::CHANGE_PASSWORD:
32
+    case AccountStatus::ALERT_ON_ACCESS:
33
+        break;
34
+    default:
35
+        http_response_code(403);
36
+        die("403 Forbidden: user account not active");
37
+}
38
+
39
+$notifications = Notifications::get($user);
40
+
41
+switch ($_GET['type']) {
42
+    case "rss1":
43
+        $feed = new RSS1();
44
+        break;
45
+    case "rss":
46
+    case "rss2":
47
+        $feed = new RSS2();
48
+        break;
49
+    case "atom":
50
+        $feed = new ATOM();
51
+        break;
52
+    default:
53
+        http_response_code(400);
54
+        die("400 Bad Request: feed parameter must have a value of \"rss\", \"rss1\", \"rss2\" or \"atom\".");
55
+}
56
+
57
+$feed->setTitle($Strings->build("Notifications from server for user", ['server' => SITE_TITLE, 'user' => $user->getName()], false));
58
+
59
+if (strpos(URL, "http") === 0) {
60
+    $url = URL;
61
+} else {
62
+    $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . (($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) ? ":" . $_SERVER['SERVER_PORT'] : "") . URL;
63
+}
64
+
65
+$feed->setLink($url);
66
+
67
+foreach ($notifications as $n) {
68
+    $item = $feed->createNewItem();
69
+    $item->setTitle($n['title']);
70
+    if (empty($n['url'])) {
71
+        $item->setLink($url);
72
+    } else {
73
+        $item->setLink($n['url']);
74
+    }
75
+    $item->setDate(strtotime($n['timestamp']));
76
+    if ($n['sensitive']) {
77
+        $content = $Strings->get("Sensitive content hidden", false);
78
+    } else {
79
+        $content = $n['content'];
80
+    }
81
+    if ($_GET['type'] == "atom") {
82
+        $item->setContent($content);
83
+    } else {
84
+        $item->setDescription($content);
85
+    }
86
+    $feed->addItem($item);
87
+}
88
+
89
+$feed->printFeed();

+ 3
- 1
langs/en/notifications.json View File

@@ -3,5 +3,7 @@
3 3
     "Notification deleted.": "Notification deleted.",
4 4
     "Mark as read": "Mark as read",
5 5
     "Delete": "Delete",
6
-    "All caught up!": "All caught up!"
6
+    "All caught up!": "All caught up!",
7
+    "Notifications from server for user": "Notifications from {server} for {user}",
8
+    "Sensitive content hidden": "Sensitive content hidden"
7 9
 }

+ 4
- 1
langs/en/sync.json View File

@@ -9,5 +9,8 @@
9 9
     "manual setup": "Manual Setup:",
10 10
     "sync key": "Sync key:",
11 11
     "url": "URL:",
12
-    "sync code name": "Device nickname"
12
+    "sync code name": "Device nickname",
13
+    "notification feed explained": "You can receive notifications via a RSS or ATOM news reader by clicking one of the buttons or manually adding a URL.  Click the Reset button if you think someone else might know your feed URL (you'll need to delete and re-add the feed on all your devices).",
14
+    "Reset": "Reset",
15
+    "Feed key reset.": "Feed key reset."
13 16
 }

+ 4
- 0
langs/messages.php View File

@@ -72,5 +72,9 @@ define("MESSAGES", [
72 72
     "notification_deleted" => [
73 73
         "string" => "Notification deleted.",
74 74
         "type" => "success"
75
+    ],
76
+    "feed_key_reset" => [
77
+        "string" => "Feed key reset.",
78
+        "type" => "success"
75 79
     ]
76 80
 ]);

+ 31
- 0
lib/RandomString.lib.php View File

@@ -0,0 +1,31 @@
1
+<?php
2
+
3
+/*
4
+ * This Source Code Form is subject to the terms of the Mozilla Public
5
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
6
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
+ */
8
+
9
+class RandomString {
10
+
11
+    /**
12
+     * Generate a random string, using a cryptographically secure
13
+     * pseudorandom number generator (random_int)
14
+     *
15
+     * From https://stackoverflow.com/a/31107425
16
+     *
17
+     * @param int $length      How many characters do we want?
18
+     * @param string $keyspace A string of all possible characters
19
+     *                         to select from
20
+     * @return string
21
+     */
22
+    public static function generate(int $length, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'): string {
23
+        $pieces = [];
24
+        $max = mb_strlen($keyspace, '8bit') - 1;
25
+        for ($i = 0; $i < $length; ++$i) {
26
+            $pieces [] = $keyspace[random_int(0, $max)];
27
+        }
28
+        return implode('', $pieces);
29
+    }
30
+
31
+}

+ 46
- 1
pages/sync.php View File

@@ -29,7 +29,7 @@ if (!empty($_GET['delsynccode'])) {
29 29
                         $desc = htmlspecialchars($_POST['desc']);
30 30
                         $database->insert('mobile_codes', ['uid' => $_SESSION['uid'], 'code' => $code, 'description' => $desc]);
31 31
                     }
32
-                    if (strpos(URL, "http") !== FALSE) {
32
+                    if (strpos(URL, "http") === 0) {
33 33
                         $url = URL . "mobile/index.php";
34 34
                     } else {
35 35
                         $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . (($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) ? ":" . $_SERVER['SERVER_PORT'] : "") . URL . "mobile/index.php";
@@ -124,4 +124,49 @@ if (!empty($_GET['delsynccode'])) {
124 124
     </div>
125 125
 </div>
126 126
 
127
+<div class="col-sm-10 col-md-6 col-lg-4 col-xl-4">
128
+    <div class="card">
129
+        <div class="card-body">
130
+            <h5 class="card-title"><i class="fas fa-rss-square"></i> <?php $Strings->get("Notifications"); ?></h5>
131
+            <hr />
132
+            <p class="card-text">
133
+                <?php $Strings->get("notification feed explained"); ?>
134
+            </p>
135
+            <?php
136
+            if ($database->has('userkeys', ['AND' => ['uid' => $_SESSION['uid'], 'typeid' => 1]])) {
137
+                $key = $database->get('userkeys', 'key', ['AND' => ['uid' => $_SESSION['uid'], 'typeid' => 1]]);
138
+            } else {
139
+                $key = RandomString::generate(50);
140
+                while ($database->has('userkeys', ['key' => $key])) {
141
+                    $key = RandomString::generate(50);
142
+                }
143
+                $database->insert('userkeys', ['uid' => $_SESSION['uid'], 'typeid' => 1, 'created' => date('Y-m-d H:i:s'), 'key' => $key]);
144
+            }
145
+
146
+            if (strpos(URL, "http") === 0) {
147
+                $url = URL;
148
+            } else {
149
+                $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . (($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) ? ":" . $_SERVER['SERVER_PORT'] : "") . URL;
150
+            }
151
+            $url = $url . "feed.php?key=$key";
152
+            ?>
153
+            <a href="<?php echo $url; ?>&type=rss2" target="_BLANK" class="btn btn-orange mr-2"><i class="fas fa-rss"></i> RSS 2.0</a>
154
+            <a href="<?php echo $url; ?>&type=rss1" target="_BLANK" class="btn btn-orange mr-2"><i class="fas fa-rss"></i> RSS 1.0</a>
155
+            <a href="<?php echo $url; ?>&type=atom" target="_BLANK" class="btn btn-blue"><i class="fas fa-atom"></i> ATOM</a>
156
+            <hr />
157
+            RSS 2.0: <input type="text" readonly class="form-control" value="<?php echo $url; ?>&type=rss2" />
158
+            <br />
159
+            RSS 1.0: <input type="text" readonly class="form-control" value="<?php echo $url; ?>&type=rss1" />
160
+            <br />
161
+            ATOM: <input type="text" readonly class="form-control" value="<?php echo $url; ?>&type=atom" />
162
+            <hr />
163
+            <form action="action.php" method="POST">
164
+                <input type="hidden" name="source" value="sync" />
165
+                <input type="hidden" name="action" value="resetfeedkey" />
166
+                <button type="submit" class="btn btn-danger"><i class="fas fa-sync"></i> <?php $Strings->get('Reset'); ?></button>
167
+            </form>
168
+        </div>
169
+    </div>
170
+</div>
171
+
127 172
 </div>

Loading…
Cancel
Save