Subversion Repositories oidplus

Rev

Rev 1116 | Rev 1131 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1116 Rev 1130
Line 23... Line 23...
23
\defined('INSIDE_OIDPLUS') or die;
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusPagePublicAttachments extends OIDplusPagePluginPublic {
26
class OIDplusPagePublicAttachments extends OIDplusPagePluginPublic {
27
 
27
 
-
 
28
        /**
-
 
29
         *
-
 
30
         */
28
        const DIR_UNLOCK_FILE = 'oidplus_upload.dir';
31
        const DIR_UNLOCK_FILE = 'oidplus_upload.dir';
29
 
32
 
30
        /**
33
        /**
31
         * @param $dir
34
         * @param string $dir
32
         * @return void
35
         * @return void
33
         * @throws OIDplusException
36
         * @throws OIDplusException
34
         */
37
         */
35
        private static function checkUploadDir($dir) {
38
        private static function checkUploadDir(string $dir) {
36
                if (!is_dir($dir)) {
39
                if (!is_dir($dir)) {
37
                        throw new OIDplusException(_L('The attachment directory "%1" is not existing.', $dir));
40
                        throw new OIDplusException(_L('The attachment directory "%1" is not existing.', $dir));
38
                }
41
                }
39
 
42
 
40
                $realdir = realpath($dir);
43
                $realdir = realpath($dir);
Line 88... Line 91...
88
                        // the owner. We don't want to over-complicate it to the Windows admin.
91
                        // the owner. We don't want to over-complicate it to the Windows admin.
89
                }
92
                }
90
        }
93
        }
91
 
94
 
92
        /**
95
        /**
93
         * @param $dir
96
         * @param string $dir
94
         * @return bool
97
         * @return bool
95
         */
98
         */
96
        private static function isCriticalWindowsDirectory($dir): bool {
99
        private static function isCriticalWindowsDirectory(string $dir): bool {
97
                $dir .= '\\';
100
                $dir .= '\\';
98
                $windir = isset($_SERVER['SystemRoot']) ? $_SERVER['SystemRoot'].'\\' : 'C:\\Windows\\';
101
                $windir = isset($_SERVER['SystemRoot']) ? $_SERVER['SystemRoot'].'\\' : 'C:\\Windows\\';
99
                if (stripos($dir,$windir) === 0) return true;
102
                if (stripos($dir,$windir) === 0) return true;
100
                return false;
103
                return false;
101
        }
104
        }
102
 
105
 
103
        /**
106
        /**
104
         * @param $dir
107
         * @param string $dir
105
         * @return bool
108
         * @return bool
106
         */
109
         */
107
        private static function isCriticalLinuxDirectory($dir): bool {
110
        private static function isCriticalLinuxDirectory(string $dir): bool {
108
                if ($dir == '/') return true;
111
                if ($dir == '/') return true;
109
                $dir .= '/';
112
                $dir .= '/';
110
                if (strpos($dir,'/bin/') === 0) return true;
113
                if (strpos($dir,'/bin/') === 0) return true;
111
                if (strpos($dir,'/boot/') === 0) return true;
114
                if (strpos($dir,'/boot/') === 0) return true;
112
                if (strpos($dir,'/dev/') === 0) return true;
115
                if (strpos($dir,'/dev/') === 0) return true;
Line 135... Line 138...
135
                if (strpos($dir,'/var/tmp/') === 0) return true;
138
                if (strpos($dir,'/var/tmp/') === 0) return true;
136
                return false;
139
                return false;
137
        }
140
        }
138
 
141
 
139
        /**
142
        /**
140
         * @param $id
143
         * @param string|null $id
141
         * @return string
144
         * @return string
142
         * @throws OIDplusException
145
         * @throws OIDplusException
143
         */
146
         */
144
        public static function getUploadDir($id=null): string {
147
        public static function getUploadDir(string $id=null): string {
145
                // Get base path
148
                // Get base path
146
                $cfg = OIDplus::config()->getValue('attachment_upload_dir', '');
149
                $cfg = OIDplus::config()->getValue('attachment_upload_dir', '');
147
                $cfg = trim($cfg);
150
                $cfg = trim($cfg);
148
                if ($cfg === '') {
151
                if ($cfg === '') {
149
                        $basepath = OIDplus::localpath() . 'userdata' . DIRECTORY_SEPARATOR . 'attachments';
152
                        $basepath = OIDplus::localpath() . 'userdata' . DIRECTORY_SEPARATOR . 'attachments';
Line 515... Line 518...
515
                if ($doshow) $text .= $output;
518
                if ($doshow) $text .= $output;
516
        }
519
        }
517
 
520
 
518
        /**
521
        /**
519
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
522
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
520
         * @param $id
523
         * @param string $id
521
         * @return void
524
         * @return void
522
         */
525
         */
523
        public function beforeObjectDelete($id) {}
526
        public function beforeObjectDelete(string $id) {}
524
 
527
 
525
        /**
528
        /**
526
         * Delete the attachment folder including all files in it (note: Subfolders are not possible)
529
         * Delete the attachment folder including all files in it (note: Subfolders are not possible)
527
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
530
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
528
         * @param $id
531
         * @param string $id
529
         * @return void
532
         * @return void
530
         * @throws OIDplusException
533
         * @throws OIDplusException
531
         */
534
         */
532
        public function afterObjectDelete($id) {
535
        public function afterObjectDelete(string $id) {
533
                $uploaddir = self::getUploadDir($id);
536
                $uploaddir = self::getUploadDir($id);
534
                if ($uploaddir != '') {
537
                if ($uploaddir != '') {
535
                        $ary = @glob($uploaddir . DIRECTORY_SEPARATOR . '*');
538
                        $ary = @glob($uploaddir . DIRECTORY_SEPARATOR . '*');
536
                        if ($ary) foreach ($ary as $a) @unlink($a);
539
                        if ($ary) foreach ($ary as $a) @unlink($a);
537
                        @rmdir($uploaddir);
540
                        @rmdir($uploaddir);
Line 541... Line 544...
541
                }
544
                }
542
        }
545
        }
543
 
546
 
544
        /**
547
        /**
545
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
548
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
546
         * @param $id
549
         * @param string $id
547
         * @param $params
550
         * @param array $params
548
         * @return void
551
         * @return void
549
         */
552
         */
550
        public function beforeObjectUpdateSuperior($id, &$params) {}
553
        public function beforeObjectUpdateSuperior(string $id, array &$params) {}
551
 
554
 
552
        /**
555
        /**
553
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
556
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
554
         * @param $id
557
         * @param string $id
555
         * @param $params
558
         * @param array $params
556
         * @return void
559
         * @return void
557
         */
560
         */
558
        public function afterObjectUpdateSuperior($id, &$params) {}
561
        public function afterObjectUpdateSuperior(string $id, array &$params) {}
559
 
562
 
560
        /**
563
        /**
561
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
564
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
562
         * @param $id
565
         * @param string $id
563
         * @param $params
566
         * @param array $params
564
         * @return void
567
         * @return void
565
         */
568
         */
566
        public function beforeObjectUpdateSelf($id, &$params) {}
569
        public function beforeObjectUpdateSelf(string $id, array &$params) {}
567
 
570
 
568
        /**
571
        /**
569
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
572
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
570
         * @param $id
573
         * @param string $id
571
         * @param $params
574
         * @param array $params
572
         * @return void
575
         * @return void
573
         */
576
         */
574
        public function afterObjectUpdateSelf($id, &$params) {}
577
        public function afterObjectUpdateSelf(string $id, array &$params) {}
575
 
578
 
576
        /**
579
        /**
577
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
580
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
578
         * @param $id
581
         * @param string $id
579
         * @param $params
582
         * @param array $params
580
         * @return void
583
         * @return void
581
         */
584
         */
582
        public function beforeObjectInsert($id, &$params) {}
585
        public function beforeObjectInsert(string $id, array &$params) {}
583
 
586
 
584
        /**
587
        /**
585
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
588
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.3
586
         * @param $id
589
         * @param string $id
587
         * @param $params
590
         * @param array $params
588
         * @return void
591
         * @return void
589
         */
592
         */
590
        public function afterObjectInsert($id, &$params) {}
593
        public function afterObjectInsert(string $id, array &$params) {}
591
 
594
 
592
        /**
595
        /**
593
         * @param string $request
596
         * @param string $request
594
         * @return array|false
597
         * @return array|false
595
         */
598
         */
Line 597... Line 600...
597
                return false;
600
                return false;
598
        }
601
        }
599
 
602
 
600
        /**
603
        /**
601
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.4
604
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.4
602
         * @param $id
605
         * @param string $id
603
         * @param $out
606
         * @param array $out
604
         * @return void
607
         * @return void
605
         * @throws OIDplusException
608
         * @throws OIDplusException
606
         */
609
         */
607
        public function whoisObjectAttributes($id, &$out) {
610
        public function whoisObjectAttributes(string $id, array &$out) {
608
                $xmlns = 'oidplus-attachment-plugin';
611
                $xmlns = 'oidplus-attachment-plugin';
609
                $xmlschema = 'urn:oid:1.3.6.1.4.1.37476.2.5.2.4.1.95.1';
612
                $xmlschema = 'urn:oid:1.3.6.1.4.1.37476.2.5.2.4.1.95.1';
610
                $xmlschemauri = OIDplus::webpath(__DIR__.'/attachments.xsd',OIDplus::PATH_ABSOLUTE);
613
                $xmlschemauri = OIDplus::webpath(__DIR__.'/attachments.xsd',OIDplus::PATH_ABSOLUTE);
611
 
614
 
612
                $files = @glob(self::getUploadDir($id) . DIRECTORY_SEPARATOR . '*');
615
                $files = @glob(self::getUploadDir($id) . DIRECTORY_SEPARATOR . '*');
Line 632... Line 635...
632
 
635
 
633
        }
636
        }
634
 
637
 
635
        /**
638
        /**
636
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.4
639
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.4
637
         * @param $email
640
         * @param string $email
638
         * @param $out
641
         * @param array $out
639
         * @return void
642
         * @return void
640
         */
643
         */
641
        public function whoisRaAttributes($email, &$out) {}
644
        public function whoisRaAttributes(string $email, array &$out) {}
642
}
645
}