1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21:
22: function emptyLogFile() {
23: global $cfg, $notification, $auth;
24:
25: if (strpos($auth->auth["perm"], "sysadmin") === false) {
26: return $notification->returnNotification("error", i18n("Can't clear error log : Access is denied!"));
27: }
28:
29: $tmp_notification = false;
30:
31:
32: $filename = $cfg['path']['contenido_logs'] . 'errorlog.txt';
33:
34: if (cFileHandler::exists($filename) && is_writeable($filename)) {
35: cFileHandler::truncate($filename);
36: $tmp_notification = $notification->returnNotification("info", i18n("Error log successfully cleared!"));
37: } else if (cFileHandler::exists($filename) && !is_writeable($filename)) {
38: $tmp_notification = $notification->returnNotification("error", i18n("Can't clear error log : Access is denied!"));
39: }
40:
41: return $tmp_notification;
42: }
43:
44: 45: 46: 47: 48:
49: function phpInfoToHtml() {
50:
51: ob_start();
52: phpinfo();
53: $phpInfoToHtml = ob_get_contents();
54: ob_end_clean();
55:
56: return $phpInfoToHtml;
57: }
58:
59: 60: 61: 62: 63: 64:
65: function systemHavePerm($client) {
66: global $auth;
67:
68: if (!isset($auth->perm['perm'])) {
69: $auth->perm['perm'] = '';
70: }
71:
72: $userPerm = explode(',', $auth->auth['perm']);
73:
74: if (in_array('sysadmin', $userPerm)) {
75: return true;
76: } elseif (in_array('admin[' . $client . ']', $userPerm)) {
77: return true;
78: } elseif (in_array('client[' . $client . ']', $userPerm)) {
79: return true;
80: }
81: return false;
82: }
83:
84: 85: 86: 87: 88: 89:
90: function isIPv4($strHostAdress) {
91:
92: $ipPattern = "([0-9]|1?\d\d|2[0-4]\d|25[0-5])";
93: if (preg_match("/^$ipPattern\.$ipPattern\.$ipPattern\.$ipPattern?$/", $strHostAdress)) {
94: return true;
95: }
96: return false;
97: }
98:
99: 100: 101: 102: 103: 104: 105:
106: function checkPathInformation($strConUrl, $strBrowserUrl) {
107:
108: $arrConUrl = parse_url($strConUrl);
109: $arrBrowserUrl = parse_url($strBrowserUrl);
110:
111: if (isIPv4($arrConUrl['host'])) {
112: if (isIPv4($arrBrowserUrl['host'])) {
113: if (compareUrlStrings($arrConUrl, $arrBrowserUrl)) {
114: return '1';
115: }
116:
117: return '2';
118: } else {
119: $arrBrowserUrl['host'] = gethostbyname($arrBrowserUrl['host']);
120: if (!isIPv4($arrBrowserUrl['host'])) {
121: return '3';
122: }
123:
124: if (compareUrlStrings($arrConUrl, $arrBrowserUrl)) {
125: return '1';
126: }
127:
128: return '2';
129: }
130: } else {
131: if (isIPv4($arrBrowserUrl['host'])) {
132: $tmpAddr = gethostbyaddr($arrBrowserUrl['host']);
133: $arrBrowserUrl['host'] = str_replace('-', '.', substr($tmpAddr, 0, strpos($tmpAddr, ".")));
134:
135: if (isIPv4($arrBrowserUrl['host'])) {
136: return '3';
137: }
138:
139: if (compareUrlStrings($arrConUrl, $arrBrowserUrl, true)) {
140: return '1';
141: }
142:
143: return '2';
144: } else {
145: if (compareUrlStrings($arrConUrl, $arrBrowserUrl)) {
146: return '1';
147: }
148:
149: return '2';
150: }
151: }
152: }
153:
154: 155: 156: 157: 158:
159: function compareUrlStrings($arrConUrl, $arrBrowserUrl, $isIP = false) {
160:
161:
162: if (strpos($arrConUrl['host'], 'www.') == 0 || strpos($arrBrowserUrl['host'], 'www.') == 0) {
163: $arrConUrl['host'] = str_replace('www.', '', $arrConUrl);
164: $arrBrowserUrl['host'] = str_replace('www.', '', $arrBrowserUrl);
165: }
166:
167: $strConUrl = $arrConUrl['scheme'] . '://' . $arrConUrl['host'] . $arrConUrl['path'];
168: $strBrowserUrl = $arrBrowserUrl['scheme'] . '://' . $arrBrowserUrl['host'] . $arrBrowserUrl['path'];
169:
170: if (strcmp($strConUrl, $strBrowserUrl) != 0) {
171: return false;
172: }
173: return true;
174: }
175: