Merge pull request #1656 from laf/upgrade-scripts

This commit is contained in:
Søren Rosiak
2015-08-11 22:38:05 +02:00
4 changed files with 0 additions and 390 deletions

View File

@@ -1,87 +0,0 @@
<?php
// MYSQL Check - FIXME
// 1 DROP
// 1 CREATE
// 25 ALTERS
include("includes/defaults.inc.php");
include("config.php");
echo("Updating Billing...");
$create_sql = "CREATE TABLE IF NOT EXISTS `bill_history` (
`bill_hist_id` int(11) NOT NULL AUTO_INCREMENT,
`bill_id` int(11) NOT NULL,
`updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`bill_datefrom` datetime NOT NULL,
`bill_dateto` datetime NOT NULL,
`bill_type` text NOT NULL,
`bill_allowed` bigint(20) NOT NULL,
`bill_used` bigint(20) NOT NULL,
`bill_overuse` bigint(20) NOT NULL,
`bill_percent` decimal(10,2) NOT NULL,
`rate_95th_in` bigint(20) NOT NULL,
`rate_95th_out` bigint(20) NOT NULL,
`rate_95th` bigint(20) NOT NULL,
`dir_95th` varchar(3) NOT NULL,
`rate_average` bigint(20) NOT NULL,
`rate_average_in` bigint(20) NOT NULL,
`rate_average_out` bigint(20) NOT NULL,
`traf_in` bigint(20) NOT NULL,
`traf_out` bigint(20) NOT NULL,
`traf_total` bigint(20) NOT NULL,
`pdf` longblob,
PRIMARY KEY (`bill_hist_id`),
UNIQUE KEY `unique_index` (`bill_id`,`bill_datefrom`,`bill_dateto`),
KEY `bill_id` (`bill_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;";
mysql_query("DROP TABLE `bill_history`");
mysql_query($create_sql);
mysql_query("ALTER TABLE `bills` ADD `bill_quota` bigint(20) NOT NULL AFTER `bill_gb`;");
mysql_query("ALTER TABLE `bills` DROP `rate_95th_in`;");
mysql_query("ALTER TABLE `bills` DROP `rate_95th_out`;");
mysql_query("ALTER TABLE `bills` DROP `rate_95th`;");
mysql_query("ALTER TABLE `bills` DROP `dir_95th`;");
mysql_query("ALTER TABLE `bills` DROP `total_data`;");
mysql_query("ALTER TABLE `bills` DROP `total_data_in`;");
mysql_query("ALTER TABLE `bills` DROP `total_data_out`;");
mysql_query("ALTER TABLE `bills` DROP `rate_average_in`;");
mysql_query("ALTER TABLE `bills` DROP `rate_average_out`;");
mysql_query("ALTER TABLE `bills` DROP `rate_average`;");
mysql_query("ALTER TABLE `bills` DROP `bill_last_calc`;");
mysql_query("ALTER TABLE `bills` ADD `rate_95th_in` bigint(20) NOT NULL;");
mysql_query("ALTER TABLE `bills` ADD `rate_95th_out` bigint(20) NOT NULL;");
mysql_query("ALTER TABLE `bills` ADD `rate_95th` bigint(20) NOT NULL;");
mysql_query("ALTER TABLE `bills` ADD `dir_95th` varchar(3) NOT NULL;");
mysql_query("ALTER TABLE `bills` ADD `total_data` bigint(20) NOT NULL;");
mysql_query("ALTER TABLE `bills` ADD `total_data_in` bigint(20) NOT NULL;");
mysql_query("ALTER TABLE `bills` ADD `total_data_out` bigint(20) NOT NULL;");
mysql_query("ALTER TABLE `bills` ADD `rate_average_in` bigint(20) NOT NULL;");
mysql_query("ALTER TABLE `bills` ADD `rate_average_out` bigint(20) NOT NULL;");
mysql_query("ALTER TABLE `bills` ADD `rate_average` bigint(20) NOT NULL;");
mysql_query("ALTER TABLE `bills` ADD `bill_last_calc` datetime NOT NULL;");
mysql_query("ALTER TABLE `bills` CHANGE `bill_cdr` bigint(20) NOT NULL;");
foreach (dbFetchRows("SELECT * FROM `bills`") as $bill_data) {
echo("Bill ".$bill['bill_id']." ".$bill['bill_name']);
if($bill_data['bill_gb'] > 0) {
$bill_data['bill_quota'] = $bill_data['bill_gb'] * $config['billing']['base'] * $config['billing']['base'];
dbUpdate(array('bill_quota' => $bill_data['bill_quota']), 'bills', '`bill_id` = ?', array($bill_data['bill_id']));
echo("Quota -> ".$bill_data['bill_quota']);
}
if($bill_data['bill_cdr'] > 0) {
$bill_data['bill_cdr'] = $bill_data['bill_cdr'] * 1000;
dbUpdate(array('bill_cdr' => $bill_data['bill_cdr']), 'bills', '`bill_id` = ?', array($bill_data['bill_id']));
echo("CDR -> ".$bill_data['bill_cdr']);
}
echo("\n");
}
mysql_query("ALTER TABLE `bills` DROP `bill_gb`");
?>

View File

@@ -1,20 +0,0 @@
<?php
// MYSQL Check - FIXME
// 3 ALTERS
// 1 SELECT
// 1 UPDATE
mysql_query('ALTER TABLE `eventlog` DROP `id`');
mysql_query('ALTER TABLE `eventlog` ADD `event_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST');
$s = 'SELECT * FROM eventlog';
$q = mysql_query($s);
while ($event = mysql_fetch_assoc($q)) {
if ($event['interface']) {
mysql_query("UPDATE `eventlog` SET `interface` = NULL, `type` = 'interface', `reference` = '".$event['interface']."' WHERE `event_id` = '".$event['event_id']."'");
}
$i++;
}
mysql_query('ALTER TABLE `eventlog` DROP `interface`');

View File

@@ -1,202 +0,0 @@
<?php
require 'includes/defaults.inc.php';
require 'config.php';
$basepath = $config['rrd_dir'].'/';
$files = (getDirectoryTree($basepath));
$count = count($files);
if ($config['rrdcached']) {
$rrdcached = ' --daemon '.$config['rrdcached'];
}
echo $count." Files \n";
$start = date('U');
$i = 0;
foreach ($files as $file) {
fixRdd($file);
$i++;
if ((date('U') - $start) > 1) {
echo (round((($i / $count) * 100), 2)."% \r");
}
}
function getDirectoryTree($outerDir, &$files=array())
{
$dirs = array_diff(scandir($outerDir), array( '.', '..' ));
foreach ($dirs as $d) {
if (is_dir($outerDir.'/'.$d)) {
getDirectoryTree($outerDir.'/'.$d, $files);
}
else {
if (preg_match('/^[\d]+.rrd$/', $d)) {
array_push($files, preg_replace('/\/+/', '/', $outerDir.'/'.$d));
}
}
}
return $files;
}//end getDirectoryTree()
function fixRdd($file)
{
global $config;
global $rrdcached;
$fileC = shell_exec("{$config['rrdtool']} dump $file $rrdcached");
// ---------------------------------------------------------------------------------------------------------
$first = <<<FIRST
<ds>
<name> INDISCARDS </name>
<type> DERIVE </type>
<minimal_heartbeat> 600 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> 1.2500000000e+10 </max>
<!-- PDP Status -->
<last_ds> UNKN </last_ds>
<value> 0.0000000000e+00 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
<ds>
<name> OUTDISCARDS </name>
<type> DERIVE </type>
<minimal_heartbeat> 600 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> 1.2500000000e+10 </max>
<!-- PDP Status -->
<last_ds> UNKN </last_ds>
<value> 0.0000000000e+00 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
<ds>
<name> INUNKNOWNPROTOS </name>
<type> DERIVE </type>
<minimal_heartbeat> 600 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> 1.2500000000e+10 </max>
<!-- PDP Status -->
<last_ds> UNKN </last_ds>
<value> 0.0000000000e+00 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
<ds>
<name> INBROADCASTPKTS </name>
<type> DERIVE </type>
<minimal_heartbeat> 600 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> 1.2500000000e+10 </max>
<!-- PDP Status -->
<last_ds> UNKN </last_ds>
<value> 0.0000000000e+00 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
<ds>
<name> OUTBROADCASTPKTS </name>
<type> DERIVE </type>
<minimal_heartbeat> 600 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> 1.2500000000e+10 </max>
<!-- PDP Status -->
<last_ds> UNKN </last_ds>
<value> 0.0000000000e+00 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
<ds>
<name> INMULTICASTPKTS </name>
<type> DERIVE </type>
<minimal_heartbeat> 600 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> 1.2500000000e+10 </max>
<!-- PDP Status -->
<last_ds> UNKN </last_ds>
<value> 0.0000000000e+00 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
<ds>
<name> OUTMULTICASTPKTS </name>
<type> DERIVE </type>
<minimal_heartbeat> 600 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> 1.2500000000e+10 </max>
<!-- PDP Status -->
<last_ds> UNKN </last_ds>
<value> 0.0000000000e+00 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
<!-- Round Robin Archives -->
FIRST;
$second = <<<SECOND
<ds>
<primary_value> 0.0000000000e+00 </primary_value>
<secondary_value> NaN </secondary_value>
<value> NaN </value>
<unknown_datapoints> 0 </unknown_datapoints>
</ds>
<ds>
<primary_value> 0.0000000000e+00 </primary_value>
<secondary_value> NaN </secondary_value>
<value> NaN </value>
<unknown_datapoints> 0 </unknown_datapoints>
</ds>
<ds>
<primary_value> 0.0000000000e+00 </primary_value>
<secondary_value> NaN </secondary_value>
<value> NaN </value>
<unknown_datapoints> 0 </unknown_datapoints>
</ds>
<ds>
<primary_value> 0.0000000000e+00 </primary_value>
<secondary_value> NaN </secondary_value>
<value> NaN </value>
<unknown_datapoints> 0 </unknown_datapoints>
</ds>
<ds>
<primary_value> 0.0000000000e+00 </primary_value>
<secondary_value> NaN </secondary_value>
<value> NaN </value>
<unknown_datapoints> 0 </unknown_datapoints>
</ds>
<ds>
<primary_value> 0.0000000000e+00 </primary_value>
<secondary_value> NaN </secondary_value>
<value> NaN </value>
<unknown_datapoints> 0 </unknown_datapoints>
</ds>
<ds>
<primary_value> 0.0000000000e+00 </primary_value>
<secondary_value> NaN </secondary_value>
<value> NaN </value>
<unknown_datapoints> 0 </unknown_datapoints>
</ds>
</cdp_prep>
SECOND;
$third = <<<THIRD
<v> NaN </v><v> NaN </v><v> NaN </v><v> NaN </v><v> NaN </v><v> NaN </v><v> NaN </v></row>
THIRD;
// ---------------------------------------------------------------------------------------------------------
if (!preg_match('/DISCARDS/', $fileC)) {
$fileC = str_replace('<!-- Round Robin Archives -->', $first, $fileC);
$fileC = str_replace('</cdp_prep>', $second, $fileC);
$fileC = str_replace('</row>', $third, $fileC);
$tmpfname = tempnam('/tmp', 'OBS');
file_put_contents($tmpfname, $fileC);
@unlink($file);
$newfile = preg_replace('/(\d+)\.rrd/', 'port-\\1.rrd', $file);
@unlink($newfile);
shell_exec($config['rrdtool']." restore $tmpfname $newfile");
unlink($tmpfname);
}
}//end fixRdd()
echo "\n";

View File

@@ -1,81 +0,0 @@
<?php
require 'includes/defaults.inc.php';
require 'config.php';
$basepath = $config['rrd_dir'].'/';
$files = (sensor_getDirectoryTree($basepath));
$count = count($files);
echo $count." Files \n";
$start = date('U');
$i = 0;
foreach ($files as $file) {
sensor_fixRdd($file);
$i++;
if ((date('U') - $start) > 1) {
echo (round((($i / $count) * 100), 2)."% \r");
}
}
function sensor_getDirectoryTree($outerDir, &$files=array())
{
$dirs = array_diff(scandir($outerDir), array( '.', '..' ));
foreach ($dirs as $d) {
if (is_dir($outerDir.'/'.$d)) {
sensor_getDirectoryTree($outerDir.'/'.$d, $files);
}
else {
if ((preg_match('/^fan-.*.rrd$/', $d))
|| (preg_match('/^current-.*.rrd$/', $d))
|| (preg_match('/^freq-.*.rrd$/', $d))
|| (preg_match('/^humidity-.*.rrd$/', $d))
|| (preg_match('/^volt-.*.rrd$/', $d))
|| (preg_match('/^temp-.*.rrd$/', $d))
) {
array_push($files, preg_replace('/\/+/', '/', $outerDir.'/'.$d));
}
}
}
return $files;
}
function sensor_fixRdd($file)
{
global $config;
global $rrdcached;
$fileC = shell_exec("{$config['rrdtool']} dump $file $rrdcached");
if (preg_match('/<name> fan/', $fileC)) {
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r fan:sensor");
rename($file, str_replace('/fan-', '/fanspeed-', $file));
}
else if (preg_match('/<name> volt/', $fileC)) {
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r volt:sensor");
rename($file, str_replace('/volt-', '/voltage-', $file));
}
else if (preg_match('/<name> current/', $fileC)) {
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r current:sensor");
}
else if (preg_match('/<name> freq/', $fileC)) {
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r freq:sensor");
rename($file, str_replace('/freq-', '/frequency-', $file));
}
else if (preg_match('/<name> humidity/', $fileC)) {
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r humidity:sensor");
}
else if (preg_match('/<name> temp/', $fileC)) {
shell_exec("{$config['rrdtool']} tune $file $rrdcached -r temp:sensor");
rename($file, str_replace('/temp-', '/temperature-', $file));
}
}
echo "\n";