Subversion Repositories oidplus

Rev

Rev 116 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
115 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
 
20
if (!defined('IN_OIDPLUS')) die();
21
 
22
class OIDplusLogger {
23
 
24
        public function log($maskcodes, $event) {
25
 
26
                $users = array();
27
                $objects = array();
28
 
29
                /*
30
                \\ras3\daten\htdocs\oidplus_dev\ajax.php(116): OIDplus::logger()->log("RA($email)?/A?", "RA '$email' deleted");
31
                \\ras3\daten\htdocs\oidplus_dev\ajax.php(136): OIDplus::logger()->log("OID($id)+SUPOIDRA($id)?/A?", "Object '$id' (recursively) deleted");
32
                \\ras3\daten\htdocs\oidplus_dev\ajax.php(186): OIDplus::logger()->log("OID($id)+SUPOIDRA($id)?/A?", "RA of object '$id' changed from '$current_ra' to '$new_ra'");
33
                \\ras3\daten\htdocs\oidplus_dev\ajax.php(187): OIDplus::logger()->log("RA($current_ra)!", "Lost ownership of object '$id' due to RA transfer of superior RA / admin.");
34
                \\ras3\daten\htdocs\oidplus_dev\ajax.php(188): OIDplus::logger()->log("RA($new_ra)!", "Gained ownership of object '$id' due to RA transfer of superior RA / admin.");
35
                \\ras3\daten\htdocs\oidplus_dev\ajax.php(192): OIDplus::logger()->log("OID($id)+SUPOIDRA($id)?/A?", "Identifiers/Confidential flag of object '$id' updated"); // TODO: Check if they were ACTUALLY updated!
36
                \\ras3\daten\htdocs\oidplus_dev\ajax.php(235): OIDplus::logger()->log("OID($id)+SUPOIDRA($id)?/A?", "Title/Description of object '$id' updated");
37
                \\ras3\daten\htdocs\oidplus_dev\ajax.php(273): OIDplus::logger()->log("OID($parent)+OIDRA($parent)?/A?", "Created child object '$id'");
38
                \\ras3\daten\htdocs\oidplus_dev\ajax.php(274): OIDplus::logger()->log("OID($id)+SUPOIDRA($id)?/A?",      "OIDP/A", "Object '$id' created, given to RA '".(empty($ra_email) ? '(undefined)' : $ra_email)."'");
39
                \\ras3\daten\htdocs\oidplus_dev\plugins\publicPages\200_viathinksoft_freeoid\plugin.inc.php(60): OIDplus::logger()->log("OID($root_oid)+RA($email)!", "Requested a free OID for email '$email' to be placed into root '$root_oid'");
40
                \\ras3\daten\htdocs\oidplus_dev\plugins\publicPages\200_viathinksoft_freeoid\plugin.inc.php(120): OIDplus::logger()->log("OID($root_oid)+OIDRA($root_oid)!", "Child OID '$new_oid' added automatically by '$email' (RA Name: '$ra_name')");
41
                \\ras3\daten\htdocs\oidplus_dev\plugins\publicPages\200_viathinksoft_freeoid\plugin.inc.php(121): OIDplus::logger()->log("OID($new_oid)+RA($email)!",        "Free OID '$new_oid' activated (RA Name: '$ra_name')");
42
                \\ras3\daten\htdocs\oidplus_dev\plugins\publicPages\091_forgot_password\plugin.inc.php(51): OIDplus::logger()->log("RA($email)!", "A new password for '$email' was requested (forgot password)");
43
                \\ras3\daten\htdocs\oidplus_dev\plugins\publicPages\091_forgot_password\plugin.inc.php(89): OIDplus::logger()->log("RA($email)!", "RA '$email' has reset his password (forgot passwort)");
44
                \\ras3\daten\htdocs\oidplus_dev\plugins\publicPages\090_login\plugin.inc.php(50): OIDplus::logger()->log("RA(".$_POST['email'].")!", "RA '".$_POST['email']."' logged in");
45
                \\ras3\daten\htdocs\oidplus_dev\plugins\publicPages\090_login\plugin.inc.php(65): OIDplus::logger()->log("RA(".$_POST['email'].")!", "RA '".$_POST['email']."' logged out");
46
                \\ras3\daten\htdocs\oidplus_dev\plugins\publicPages\090_login\plugin.inc.php(86): OIDplus::logger()->log("A!", "Admin logged in");
47
                \\ras3\daten\htdocs\oidplus_dev\plugins\publicPages\090_login\plugin.inc.php(95): OIDplus::logger()->log("A!", "Admin logged out");
48
                \\ras3\daten\htdocs\oidplus_dev\plugins\publicPages\092_invite\plugin.inc.php(53): OIDplus::logger()->log("RA($email)!", "RA '$email' has been invited");
49
                \\ras3\daten\htdocs\oidplus_dev\plugins\publicPages\092_invite\plugin.inc.php(91): OIDplus::logger()->log("RA($email)!", "RA '$email' has been registered due to invitation");
50
                \\ras3\daten\htdocs\oidplus_dev\plugins\raPages\102_change_email\plugin.inc.php(60): OIDplus::logger()->log("RA($old_email)!+RA($new_email)!", "Requested email change from '$old_email' to '$new_email'");
51
                \\ras3\daten\htdocs\oidplus_dev\plugins\raPages\102_change_email\plugin.inc.php(123): OIDplus::logger()->log("RA($old_email)!", "Changed email address from '$old_email' to '$new_email'");
52
                \\ras3\daten\htdocs\oidplus_dev\plugins\raPages\102_change_email\plugin.inc.php(124): OIDplus::logger()->log("RA($new_email)!", "RA '$old_email' has changed its email address to '$new_email'");
53
                \\ras3\daten\htdocs\oidplus_dev\plugins\raPages\101_change_password\plugin.inc.php(62): OIDplus::logger()->log("RA($email)?/A?", "Password of RA '$email' changed");
54
                \\ras3\daten\htdocs\oidplus_dev\plugins\raPages\100_edit_contact_data\plugin.inc.php(46): OIDplus::logger()->log("RA($email)?/A?", "Changed RA '$email' contact data/details");
55
                \\ras3\daten\htdocs\oidplus_dev\plugins\adminPages\110_system_config\plugin.inc.php(49): OIDplus::logger()->log("A?", "Changed system config setting '$name' to '$value'");
56
                */
57
 
58
                $maskcodes = str_replace('/', '+', $maskcodes);
59
                $maskcodes = explode('+', $maskcodes);
60
                foreach ($maskcodes as $maskcode) {
61
                        // OID(x)       Save log entry into the logbook of: Object "x"
62
                        if (preg_match('@^OID\((.+)\)$@ismU', $maskcode, $m)) {
63
                                $object_id = $m[1];
64
                                $objects[] = $object_id;
65
                        }
66
 
67
                        // OIDRA(x)?    Save log entry into the logbook of: Logged in RA of object "x"
68
                        // Replace ? by ! if the entity does not need to be logged in
69
                        else if (preg_match('@^OIDRA\((.+)\)([\?\!])$@ismU', $maskcode, $m)) {
70
                                $object_id         = $m[1];
71
                                $ra_need_login     = $m[2];
72
                                $obj = OIDplusObject::parse($object_id);
73
                                if ($ra_need_login) {
74
                                        foreach (OIDplus::authUtils()->loggedInRaList() as $ra) {
75
                                                if ($obj->hasWriteRights($ra)) $users[] = $ra->raEmail();
76
                                        }
77
                                } else {
78
                                        // $users[] = $obj->getRa()->raEmail();
79
                                        foreach (OIDplusRA::getAllRAs() as $ra) {
80
                                                if ($obj->hasWriteRights($ra)) $users[] = $ra->raEmail();
81
                                        }
82
                                }
83
                        }
84
 
85
                        // SUPOIDRA(x)? Save log entry into the logbook of: Logged in RA that owns the superior object of "x"
86
                        // Replace ? by ! if the entity does not need to be logged in
87
                        else if (preg_match('@^SUPOIDRA\((.+)\)([\?\!])$@ismU', $maskcode, $m)) {
88
                                $object_id         = $m[1];
89
                                $ra_need_login     = $m[2];
90
                                $obj = OIDplusObject::parse($object_id);
91
                                if ($ra_need_login) {
92
                                        foreach (OIDplus::authUtils()->loggedInRaList() as $ra) {
93
                                                if ($obj->hasParentalWriteRights($ra)) $users[] = $ra->raEmail();
94
                                        }
95
                                } else {
96
                                        // $users[] = $obj->getParent()->getRa()->raEmail();
97
                                        foreach (OIDplusRA::getAllRAs() as $ra) {
98
                                                if ($obj->hasParentalWriteRights($ra)) $users[] = $ra->raEmail();
99
                                        }
100
                                }
101
                        }
102
 
103
                        // RA(x)?       Save log entry into the logbook of: Logged in RA "x"
104
                        // Replace ? by ! if the entity does not need to be logged in
105
                        else if (preg_match('@^RA\((.+)\)([\?\!])$@ismU', $maskcode, $m)) {
106
                                $ra_email          = $m[1];
107
                                $ra_need_login     = $m[2];
108
                                if ($ra_need_login && OIDplus::authUtils()->isRaLoggedIn($ra_email)) {
109
                                        $users[] = $ra_email;
110
                                } else if (!$ra_need_login) {
111
                                        $users[] = $ra_email;
112
                                }
113
                        }
114
 
115
                        // A?   Save log entry into the logbook of: A logged in admin
116
                        // Replace ? by ! if the entity does not need to be logged in
117
                        else if (preg_match('@^A([\?\!])$@ismU', $maskcode, $m)) {
118
                                $admin_need_login = $m[1];
119
                                if ($admin_need_login && OIDplus::authUtils()->isAdminLoggedIn()) {
120
                                        $users[] = 'admin';
121
                                } else if (!$admin_need_login) {
122
                                        $users[] = 'admin';
123
                                }
124
                        }
125
 
126
                        // Unexpected
127
                        else {
128
                                throw new Exception("Unexpected logger mask code '$maskcode'");
129
                        }
130
 
131
                        // TODO: Log to database
132
                        $users = implode(';', $users);
133
                        if ($users == '') $users = '-';
134
                        $objects = implode(';', $objects);
135
                        if ($objects == '') $objects = '-';
136
                        file_put_contents(__DIR__ . '/../../logtest.log', "$objects / $users / $event\n", FILE_APPEND);
137
                }
138
        }
139
}