/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
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
<?php
$mysql = new mysqli("localhost", "adei", "adei", "adei");


function resolve($postfix) {
    global $mysql;

    $res = $mysql->query("SELECT hash FROM md5 WHERE `postfix` LIKE \"%$postfix\"");
    if (($res)&&($res->num_rows > 0)) {
	$row = $res->fetch_assoc();
	return $row["hash"];
    }

    return $postfix;
}


function get_caches($postfix) {
    global $mysql;

    $list = array();

    $res = $mysql->query("SHOW TABLES LIKE \"cache%{$postfix}\";");
    if (($res)&&($res->num_rows > 0)) {
	$res->data_seek(0);
	while ($row = $res->fetch_array()) {
	    array_push($list, $row[0]);
	}
    }
    return $list;
}


$done = array();

$f = fopen("/var/spool/mail/root", "r");
while (!feof($f)) {
    $line = fgets($f);
    if (preg_match('/Server: "(.*)" Database: "?(.*)" Group: "(.*)"/', $line, $m)) {
	$postfix=resolve("__{$m[1]}__{$m[2]}__{$m[3]}");
	
	if (!in_array($postfix, $done)) {
	    echo "Fixing: $postfix\n";
	    $caches = get_caches($postfix);
	    foreach ($caches as $cache) {
		system("mysqlcheck -r adei $cache\n");
	    }

	    array_push($done, $postfix);
	}
    }
}


?>