File: log-db.php3

package info (click to toggle)
php3 3%3A3.0.18-0potato1.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,736 kB
  • ctags: 11,198
  • sloc: ansic: 108,120; sh: 2,512; php: 2,024; yacc: 1,887; makefile: 1,038; perl: 537; pascal: 238; awk: 90; cpp: 28; sql: 11
file content (82 lines) | stat: -rw-r--r-- 1,489 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/* $Id: log-db.php3,v 1.3 1998/01/19 03:08:03 jim Exp $ */

function _log_db_filename() {
	global $_log_logas;
	$ret = get_cfg_var("logging.directory");
	if ($ret) {
		$uid = getmyuid();
		$ret .= "/$uid/" . ereg_replace("/", "_", $_log_logas);
	}
	return $ret;
}

function _log_db_mkdir() {
	$dir = get_cfg_var("logging.directory");
	if ($dir) {
		@mkdir($dir, 0777);
		@mkdir($dir . "/" . getmyuid(), 0777);
	}
}

function _log_db_getlast() {
	$ret = new log_last_hit;

	/* we handle an error with opening the log file, so suppress messages */
	$file = _log_db_filename();
	if ($file) {
		$db = @dbmopen($file, "r");
	}

	if ($db) {
		$str = dbmfetch($db, "last");
		if ($str) {
			$ret->set_from_string($str);
		}
		dbmclose($db);
	}

	return $ret;
}
$_log_getlastfunc = '_log_db_getlast';

function _log_db_setlast($hit) {
	$file = _log_db_filename();
	_log_db_mkdir();
	if ($file) {
		$db = @dbmopen($file, "w");
		if (!$db) {
			$db = @dbmopen($file, "n");
		}
	}

	if ($db) {
		dbmreplace($db, "last", $hit->as_string());
		dbmclose($db);
	}
}
$_log_setlastfunc = '_log_db_setlast';

function _log_db_loghit($hit) {
	$file = _log_db_filename();
	_log_db_mkdir();

	if ($file) {
		$db = @dbmopen($file, "w");
		if (!$db) {
			$db = @dbmopen($file, "n");
		}
	}
	if ($db) {
		$retry = 0;
		while ($retry < 20) {
			if(dbminsert($db, $hit->time . $retry, $hit->as_string())) {
				$retry = 100;
			}
			$retry++;
		}
		dbmclose($db);
	}
}
$_log_loghitfunc = '_log_db_loghit';
?>