Subversion Repositories oidplus

Rev

Rev 116 | Rev 119 | Go to most recent revision | Details | Compare with Previous | 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'");
116 daniel-mar 38
                \\ras3\daten\htdocs\oidplus_dev\ajax.php(274): OIDplus::logger()->log("OID($id)+SUPOIDRA($id)?/A?", "Object '$id' created, given to RA '".(empty($ra_email) ? '(undefined)' : $ra_email)."'");
115 daniel-mar 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;
116 daniel-mar 65
                                if ($object_id == '') throw new Exception("OID logger mask requires OID");
115 daniel-mar 66
                        }
67
 
68
                        // OIDRA(x)?    Save log entry into the logbook of: Logged in RA of object "x"
69
                        // Replace ? by ! if the entity does not need to be logged in
70
                        else if (preg_match('@^OIDRA\((.+)\)([\?\!])$@ismU', $maskcode, $m)) {
71
                                $object_id         = $m[1];
116 daniel-mar 72
                                $ra_need_login     = $m[2] == '?';
73
                                if ($object_id == '') throw new Exception("OIDRA logger mask requires OID");
115 daniel-mar 74
                                $obj = OIDplusObject::parse($object_id);
116 daniel-mar 75
                                if ($obj) {
76
                                        if ($ra_need_login) {
77
                                                foreach (OIDplus::authUtils()->loggedInRaList() as $ra) {
78
                                                        if ($obj->userHasWriteRights($ra)) $users[] = $ra->raEmail();
79
                                                }
80
                                        } else {
81
                                                // $users[] = $obj->getRa()->raEmail();
82
                                                foreach (OIDplusRA::getAllRAs() as $ra) {
83
                                                        if ($obj->userHasWriteRights($ra)) $users[] = $ra->raEmail();
84
                                                }
115 daniel-mar 85
                                        }
86
                                }
87
                        }
88
 
89
                        // SUPOIDRA(x)? Save log entry into the logbook of: Logged in RA that owns the superior object of "x"
90
                        // Replace ? by ! if the entity does not need to be logged in
91
                        else if (preg_match('@^SUPOIDRA\((.+)\)([\?\!])$@ismU', $maskcode, $m)) {
92
                                $object_id         = $m[1];
116 daniel-mar 93
                                $ra_need_login     = $m[2] == '?';
94
                                if ($object_id == '') throw new Exception("SUPOIDRA logger mask requires OID");
115 daniel-mar 95
                                $obj = OIDplusObject::parse($object_id);
116 daniel-mar 96
                                if ($obj) {
97
                                        if ($ra_need_login) {
98
                                                foreach (OIDplus::authUtils()->loggedInRaList() as $ra) {
99
                                                        if ($obj->userHasParentalWriteRights($ra)) $users[] = $ra->raEmail();
100
                                                }
101
                                        } else {
102
                                                // $users[] = $obj->getParent()->getRa()->raEmail();
103
                                                foreach (OIDplusRA::getAllRAs() as $ra) {
104
                                                        if ($obj->userHasParentalWriteRights($ra)) $users[] = $ra->raEmail();
105
                                                }
115 daniel-mar 106
                                        }
107
                                }
108
                        }
109
 
110
                        // RA(x)?       Save log entry into the logbook of: Logged in RA "x"
111
                        // Replace ? by ! if the entity does not need to be logged in
112
                        else if (preg_match('@^RA\((.+)\)([\?\!])$@ismU', $maskcode, $m)) {
113
                                $ra_email          = $m[1];
116 daniel-mar 114
                                $ra_need_login     = $m[2] == '?';
115 daniel-mar 115
                                if ($ra_need_login && OIDplus::authUtils()->isRaLoggedIn($ra_email)) {
116
                                        $users[] = $ra_email;
117
                                } else if (!$ra_need_login) {
118
                                        $users[] = $ra_email;
119
                                }
120
                        }
121
 
122
                        // A?   Save log entry into the logbook of: A logged in admin
123
                        // Replace ? by ! if the entity does not need to be logged in
124
                        else if (preg_match('@^A([\?\!])$@ismU', $maskcode, $m)) {
116 daniel-mar 125
                                $admin_need_login = $m[1] == '?';
115 daniel-mar 126
                                if ($admin_need_login && OIDplus::authUtils()->isAdminLoggedIn()) {
127
                                        $users[] = 'admin';
128
                                } else if (!$admin_need_login) {
129
                                        $users[] = 'admin';
130
                                }
131
                        }
132
 
133
                        // Unexpected
134
                        else {
135
                                throw new Exception("Unexpected logger mask code '$maskcode'");
136
                        }
116 daniel-mar 137
                }
115 daniel-mar 138
 
117 daniel-mar 139
                // Now write the log message
140
 
141
                $addr = isset($_SERVER['REMOTE_ADDR']) ? "'".OIDplus::db()->real_escape_string($_SERVER['REMOTE_ADDR'])."'" : "null";
142
                OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."log (addr, unix_ts, event) values ($addr, UNIX_TIMESTAMP(), '".OIDplus::db()->real_escape_string($event)."')");
143
                $log_id = OIDplus::db()->insert_id();
144
 
145
                foreach ($objects as $object) {
146
                        OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."log_object (log_id, object) values ($log_id, '".OIDplus::db()->real_escape_string($object)."')");
147
                }
148
 
149
                foreach ($users as $user) {
150
                        OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."log_user (log_id, user) values ($log_id, '".OIDplus::db()->real_escape_string($user)."')");
151
                }
152
 
115 daniel-mar 153
        }
154
}