public function Check_dansguardian_events_table($table = null) { if ($table == null) { $table = "dansguardian_events_" . date('Ymd'); } $sql = "CREATE TABLE IF NOT EXISTS `{$table}` (\n\t`sitename` varchar(90) NOT NULL,\n\t`ID` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t`uri` varchar(255) NOT NULL,\n\t`TYPE` varchar(50) NOT NULL,\n\t`REASON` varchar(255) NOT NULL,\n\t`CLIENT` varchar(50) NOT NULL DEFAULT '',\n\t`hostname` varchar(120) NOT NULL DEFAULT '',\n\t`account` INT UNSIGNED NOT NULL,\n\t`zDate` datetime NOT NULL,\n\t`zMD5` CHAR(32) NOT NULL,\n\t`uid` varchar(128) NOT NULL,\n\t`remote_ip` varchar(20) NOT NULL,\n\t`country` varchar(20) NOT NULL,\n\t`QuerySize` BIGINT UNSIGNED NOT NULL,\n\t`hits` INT UNSIGNED NOT NULL,\n `category` VARCHAR(60) NULL,\n\t`cached` smallint(1) NOT NULL DEFAULT '0',\n\t`MAC` varchar(20) NOT NULL,\n\tPRIMARY KEY (`ID`),\n\tUNIQUE KEY `zMD5` (`zMD5`),\n\tKEY `sitename` (`sitename`,`TYPE`,`CLIENT`,`uri`),\n\tKEY `zDate` (`zDate`),\n\tKEY `category` (`category`),\n\tKEY `hostname` (`hostname`),KEY `account` (`account`),\n\tKEY `cached` (`cached`),\n\tKEY `uri` (`uri`),\n\tKEY `hits` (`hits`),\n\tKEY `remote_ip` (`remote_ip`),\n\tKEY `uid` (`uid`),\n\tKEY `country` (`country`),\n\tKEY `MAC` (`MAC`)\n\t) ENGINE = MYISAM;"; $this->QUERY_SQL($sql, $this->database); if (!$this->ok) { if (function_exists("events_repair")) { events_repair("{$this->mysql_error} in " . __CLASS__ . '/' . __FUNCTION__ . " line:" . __LINE__); } writelogs("{$this->mysql_error}\n{$sql}", __CLASS__ . '/' . __FUNCTION__, __FILE__, __LINE__); $this->mysql_error = $this->mysql_error . "\n{$sql}"; return false; } if (!$this->FIELD_EXISTS("{$table}", "category")) { $this->QUERY_SQL("ALTER TABLE `{$table}` ADD `category` VARCHAR( 60 ) NOT NULL ,ADD INDEX ( `category` )"); } if (!$this->FIELD_EXISTS("{$table}", "hostname")) { $this->QUERY_SQL("ALTER TABLE `{$table}` ADD `hostname` VARCHAR( 120 ) NOT NULL ,ADD INDEX ( `hostname` )"); } if (!$this->FIELD_EXISTS("{$table}", "hits")) { $this->QUERY_SQL("ALTER TABLE `{$table}` ADD `hits` INT UNSIGNED NOT NULL,ADD KEY `hits` (`hits`)"); } return true; }
function change_date_popup(){ $q=new mysql_squid_builder(); $tables=$q->LIST_TABLES_HOURS_TEMP(); while (list ($table, $none) = each ($tables) ){ if(!preg_match("#squidhour_([0-9]+)#",$table,$re)){events_repair("No match `$table` abort... L: ".__LINE__);continue;} $hour=$re[1]; $year=substr($hour,0,4); $month=substr($hour,4,2); $day=substr($hour,6,2); $hour=substr($hour,8,2); $time=strtotime("$year-$month-$day $hour:00:00"); } }
function backup_hourly_table($tablename) { $q = new mysql_squid_builder(); $unix = new unix(); $mysqldump = $unix->find_program("mysqldump"); $tar = $unix->find_program("tar"); $mysqldump_prefix = "{$mysqldump} {$q->MYSQL_CMDLINES} --skip-add-locks --insert-ignore --quote-names --skip-add-drop-table --verbose --force {$q->database} "; $container = "/home/artica/squid/backup-statistics/{$tablename}.sql"; if (is_file($container)) { return; } $cmdline = "{$mysqldump_prefix}{$tablename} >{$container}"; events_repair($cmdline); if ($GLOBALS["VERBOSE"]) { echo "\n*******\n{$cmdline}\n*******\n"; } exec($cmdline, $resultsZ); if (!$unix->Mysql_TestDump($resultsZ, $container)) { events_repair("Fatal Error: day: Dump failed {$tablename}"); ufdbguard_admin_events("Fatal Error: day: Dump failed {$tablename}", __FUNCTION__, __FILE__, __LINE__, "backup"); return; } $size = @filesize($container); chdir("/home/artica/squid/backup-statistics"); $cmdline = "{$tar} cfz {$container}.tar.gz {$container} 2>&1"; $resultsZ = array(); exec($cmdline, $resultsZ); if ($GLOBALS["VERBOSE"]) { while (list($a, $b) = each($resultsZ)) { echo "Compress: `{$b}`\n"; } } if (!$unix->TARGZ_TEST_CONTAINER("{$container}.tar.gz")) { @unlink($container); @unlink("{$container}.tar.gz"); return; } @unlink($container); }