New Backup Restore System
This commit is contained in:
parent
90cfc3e6d9
commit
c8d19a859f
@ -280,7 +280,7 @@ ALTER TABLE `tbl_voucher`
|
|||||||
|
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
`tbl_appconfig` (`id`, `setting`, `value`)
|
`tbl_appconfig` (`id`, `setting`, `value`)
|
||||||
VALUES (1, 'CompanyName', 'PHPNuxBill'), (2, 'currency_code', 'Rp.'), (3, 'language', 'indonesia'), (4, 'show-logo', '1'), (5, 'nstyle', 'blue'), (6, 'timezone', 'Asia/Jakarta'), (7, 'dec_point', ','), (8, 'thousands_sep', '.'), (9, 'rtl', '0'), (10, 'address', ''), (11, 'phone', ''), (12, 'date_format', 'd M Y'), (13, 'note', 'Thank you...');
|
VALUES (1, 'CompanyName', 'PHPNuxBill'), (2, 'currency_code', 'Rp.'), (3, 'language', 'english'), (4, 'show-logo', '1'), (5, 'nstyle', 'blue'), (6, 'timezone', 'Asia/Jakarta'), (7, 'dec_point', ','), (8, 'thousands_sep', '.'), (9, 'rtl', '0'), (10, 'address', ''), (11, 'phone', ''), (12, 'date_format', 'd M Y'), (13, 'note', 'Thank you...');
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($cn == '1') {
|
if ($cn == '1') {
|
||||||
if ($_POST['radius'] == 'yes') {
|
if (isset($_POST['radius']) && $_POST['radius'] == 'yes') {
|
||||||
$input = '<?php
|
$input = '<?php
|
||||||
|
|
||||||
define(\'APP_URL\', \'' . $appurl . '\');
|
define(\'APP_URL\', \'' . $appurl . '\');
|
||||||
@ -83,7 +83,7 @@ if($_app_stage!=\'Live\'){
|
|||||||
fclose($fh);
|
fclose($fh);
|
||||||
$sql = file_get_contents('phpnuxbill.sql');
|
$sql = file_get_contents('phpnuxbill.sql');
|
||||||
$qr = $dbh->exec($sql);
|
$qr = $dbh->exec($sql);
|
||||||
if ($_POST['radius'] == 'yes') {
|
if (isset($_POST['radius']) && $_POST['radius'] == 'yes') {
|
||||||
$sql = file_get_contents('radius.sql');
|
$sql = file_get_contents('radius.sql');
|
||||||
$qrs = $dbh->exec($sql);
|
$qrs = $dbh->exec($sql);
|
||||||
}
|
}
|
||||||
|
@ -126,9 +126,15 @@ function _notify($msg, $type = 'e')
|
|||||||
$_SESSION['ntype'] = $type;
|
$_SESSION['ntype'] = $type;
|
||||||
$_SESSION['notify'] = $msg;
|
$_SESSION['notify'] = $msg;
|
||||||
}
|
}
|
||||||
|
if(empty($config['language'])){
|
||||||
|
$config['language'] = 'english';
|
||||||
|
}
|
||||||
$lan_file = File::pathFixer('system/lan/' . $config['language'] . '/common.lan.php');
|
$lan_file = File::pathFixer('system/lan/' . $config['language'] . '/common.lan.php');
|
||||||
require $lan_file;
|
if(file_exists($lan_file)){
|
||||||
|
require $lan_file;
|
||||||
|
}else{
|
||||||
|
die("$lan_file not found");
|
||||||
|
}
|
||||||
|
|
||||||
$ui = new Smarty();
|
$ui = new Smarty();
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ switch ($action) {
|
|||||||
$logo = 'system/uploads/logo.default.png';
|
$logo = 'system/uploads/logo.default.png';
|
||||||
}
|
}
|
||||||
$ui->assign('logo', $logo);
|
$ui->assign('logo', $logo);
|
||||||
if ( $_c['radius_enable'] && empty($_c['radius_client'])) {
|
if ($_c['radius_enable'] && empty($_c['radius_client'])) {
|
||||||
try {
|
try {
|
||||||
$_c['radius_client'] = Radius::getClient();
|
$_c['radius_client'] = Radius::getClient();
|
||||||
$ui->assign('_c', $_c);
|
$ui->assign('_c', $_c);
|
||||||
@ -675,20 +675,12 @@ switch ($action) {
|
|||||||
|
|
||||||
$dbc = new mysqli($db_host, $db_user, $db_password, $db_name);
|
$dbc = new mysqli($db_host, $db_user, $db_password, $db_name);
|
||||||
if ($result = $dbc->query('SHOW TABLE STATUS')) {
|
if ($result = $dbc->query('SHOW TABLE STATUS')) {
|
||||||
$size = 0;
|
|
||||||
$decimals = 2;
|
|
||||||
$tables = array();
|
$tables = array();
|
||||||
while ($row = $result->fetch_array()) {
|
while ($row = $result->fetch_array()) {
|
||||||
$size += $row["Data_length"] + $row["Index_length"];
|
$tables[$row['Name']]['rows'] = ORM::for_table($row["Name"])->count();
|
||||||
$total_size = ($row["Data_length"] + $row["Index_length"]) / 1024;
|
|
||||||
$tables[$row['Name']]['size'] = number_format($total_size, '0');
|
|
||||||
$tables[$row['Name']]['rows'] = $row["Rows"];
|
|
||||||
$tables[$row['Name']]['name'] = $row["Name"];
|
$tables[$row['Name']]['name'] = $row["Name"];
|
||||||
}
|
}
|
||||||
$mbytes = number_format($size / (1024 * 1024), $decimals, $config['dec_point'], $config['thousands_sep']);
|
|
||||||
|
|
||||||
$ui->assign('tables', $tables);
|
$ui->assign('tables', $tables);
|
||||||
$ui->assign('dbsize', $mbytes);
|
|
||||||
run_hook('view_database'); #HOOK
|
run_hook('view_database'); #HOOK
|
||||||
$ui->display('dbstatus.tpl');
|
$ui->display('dbstatus.tpl');
|
||||||
}
|
}
|
||||||
@ -698,92 +690,52 @@ switch ($action) {
|
|||||||
if ($admin['user_type'] != 'Admin') {
|
if ($admin['user_type'] != 'Admin') {
|
||||||
r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
|
r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
|
||||||
}
|
}
|
||||||
|
$tables = $_POST['tables'];
|
||||||
try {
|
set_time_limit(-1);
|
||||||
run_hook('backup_database'); #HOOK
|
header('Pragma: public');
|
||||||
$mysqli = new mysqli($db_host, $db_user, $db_password, $db_name);
|
header('Expires: 0');
|
||||||
if ($mysqli->connect_errno) {
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||||
throw new Exception("Failed to connect to MySQL: " . $mysqli->connect_error);
|
header('Content-Type: application/force-download');
|
||||||
}
|
header('Content-Type: application/octet-stream');
|
||||||
|
header('Content-Type: application/download');
|
||||||
header('Pragma: public');
|
header('Content-Disposition: attachment;filename="phpnuxbill_' . count($tables) . '_tables_' . date('Y-m-d_H_i') . '.json"');
|
||||||
header('Expires: 0');
|
header('Content-Transfer-Encoding: binary');
|
||||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
$array = [];
|
||||||
header('Content-Type: application/force-download');
|
foreach ($tables as $table) {
|
||||||
header('Content-Type: application/octet-stream');
|
$array[$table] = ORM::for_table($table)->find_array();
|
||||||
header('Content-Type: application/download');
|
}
|
||||||
header('Content-Disposition: attachment;filename="backup_' . date('Y-m-d_h_i_s') . '.sql"');
|
echo json_encode($array);
|
||||||
header('Content-Transfer-Encoding: binary');
|
break;
|
||||||
|
case 'dbrestore':
|
||||||
ob_start();
|
if ($admin['user_type'] != 'Admin') {
|
||||||
$f_output = fopen("php://output", 'w');
|
r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
|
||||||
|
}
|
||||||
print("-- pjl SQL Dump\n");
|
if (file_exists($_FILES['json']['tmp_name'])) {
|
||||||
print("-- Server version:" . $mysqli->server_info . "\n");
|
$suc = 0;
|
||||||
print("-- Generated: " . date('Y-m-d h:i:s') . "\n");
|
$fal = 0;
|
||||||
print('-- Current PHP version: ' . phpversion() . "\n");
|
$json = json_decode(file_get_contents($_FILES['json']['tmp_name']), true);
|
||||||
print('-- Host: ' . $db_host . "\n");
|
foreach ($json as $table => $records) {
|
||||||
print('-- Database:' . $db_name . "\n");
|
ORM::raw_execute("TRUNCATE $table;");
|
||||||
|
foreach ($records as $rec) {
|
||||||
$aTables = array();
|
$t = ORM::for_table($table)->create();
|
||||||
$strSQL = 'SHOW TABLES';
|
foreach ($rec as $k => $v) {
|
||||||
if (!$res_tables = $mysqli->query($strSQL))
|
if ($k != 'id') {
|
||||||
throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: ' . $strSQL);
|
$t->set($k, $v);
|
||||||
|
}
|
||||||
while ($row = $res_tables->fetch_array()) {
|
}
|
||||||
$aTables[] = $row[0];
|
if ($t->save()) {
|
||||||
}
|
$suc++;
|
||||||
|
} else {
|
||||||
$res_tables->free();
|
$fal++;
|
||||||
|
}
|
||||||
foreach ($aTables as $table) {
|
}
|
||||||
print("-- --------------------------------------------------------\n");
|
}
|
||||||
print("-- Structure for '" . $table . "'\n");
|
if (file_exists($_FILES['json']['tmp_name'])) unlink($_FILES['json']['tmp_name']);
|
||||||
print("--\n\n");
|
r2(U . "settings/dbstatus", 's', "Restored $suc success $fal failed");
|
||||||
|
} else {
|
||||||
$strSQL = 'SHOW CREATE TABLE ' . $table;
|
r2(U . "settings/dbstatus", 'e', 'Upload failed');
|
||||||
if (!$res_create = $mysqli->query($strSQL))
|
|
||||||
throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: ' . $strSQL);
|
|
||||||
$row_create = $res_create->fetch_assoc();
|
|
||||||
|
|
||||||
print("\n" . $row_create['Create Table'] . ";\n");
|
|
||||||
print("-- --------------------------------------------------------\n");
|
|
||||||
print('-- Dump Data for `' . $table . "`\n");
|
|
||||||
print("--\n\n");
|
|
||||||
$res_create->free();
|
|
||||||
|
|
||||||
$strSQL = 'SELECT * FROM ' . $table;
|
|
||||||
if (!$res_select = $mysqli->query($strSQL))
|
|
||||||
throw new Exception("MySQL Error: " . $mysqli->error . 'SQL: ' . $strSQL);
|
|
||||||
|
|
||||||
$fields_info = $res_select->fetch_fields();
|
|
||||||
|
|
||||||
while ($values = $res_select->fetch_assoc()) {
|
|
||||||
$strFields = '';
|
|
||||||
$strValues = '';
|
|
||||||
foreach ($fields_info as $field) {
|
|
||||||
if ($strFields != '') $strFields .= ',';
|
|
||||||
$strFields .= "`" . $field->name . "`";
|
|
||||||
|
|
||||||
if ($strValues != '') $strValues .= ',';
|
|
||||||
$strValues .= '"' . preg_replace('/[^(\x20-\x7F)\x0A]*/', '', $values[$field->name] . '"');
|
|
||||||
}
|
|
||||||
print("INSERT INTO " . $table . " (" . $strFields . ") VALUES (" . $strValues . ");\n");
|
|
||||||
}
|
|
||||||
print("\n\n\n");
|
|
||||||
$res_select->free();
|
|
||||||
}
|
|
||||||
_log('[' . $admin['username'] . ']: ' . $_L['Download_Database_Backup'], 'Admin', $admin['id']);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
print($e->getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($f_output);
|
|
||||||
print(ob_get_clean());
|
|
||||||
$mysqli->close();
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'language':
|
case 'language':
|
||||||
if ($admin['user_type'] != 'Admin') {
|
if ($admin['user_type'] != 'Admin') {
|
||||||
r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
|
r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
|
||||||
|
@ -1,41 +1,58 @@
|
|||||||
{include file="sections/header.tpl"}
|
{include file="sections/header.tpl"}
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-7">
|
||||||
<div class="panel mb20 panel-primary">
|
<div class="panel panel-primary">
|
||||||
<div class="panel-heading">{$_L['Database_Status']}</div>
|
<div class="panel-heading">Backup Database</div>
|
||||||
<div class="panel-body">
|
<form method="post" action="{$_url}settings/dbbackup">
|
||||||
|
<div class="table-responsive">
|
||||||
<div class="row">
|
<table class="table table-bordered">
|
||||||
<div class="col-md-12 col-sm-12 col-xs-12">
|
<thead>
|
||||||
<div class="col-md-9">{$_L['Total_Database_Size']}: {$dbsize} MB </div>
|
<tr>
|
||||||
<div class="col-md-3 text-right">
|
<th width="50%">{$_L['Table_Name']}</th>
|
||||||
<a href="{$_url}settings/dbbackup/" class="btn btn-primary btn-xs"><i class="fa fa-download"></i> {$_L['Download_Database_Backup']}</a>
|
<th>{$_L['Rows']}</th>
|
||||||
</div>
|
<th>Select</th>
|
||||||
<div class="table-responsive">
|
</tr>
|
||||||
<table class="table table-bordered">
|
</thead>
|
||||||
<thead>
|
<tbody>
|
||||||
<tr>
|
{foreach $tables as $tbl}
|
||||||
<th width="50%">{$_L['Table_Name']}</th>
|
<tr>
|
||||||
<th>{$_L['Rows']}</th>
|
<td>{$tbl['name']}</td>
|
||||||
<th>{$_L['Size']}</th>
|
<td>{$tbl['rows']}</td>
|
||||||
</tr>
|
<td><input type="checkbox" checked name="tables[]" value="{$tbl['name']}"></td>
|
||||||
</thead>
|
</tr>
|
||||||
<tbody>
|
{/foreach}
|
||||||
{foreach $tables as $tbl}
|
</tbody>
|
||||||
<tr>
|
</table>
|
||||||
<td>{$tbl['name']}</td>
|
</div>
|
||||||
<td>{$tbl['rows']}</td>
|
<div class="panel-body">
|
||||||
<td>{$tbl['size']} Kb</td>
|
<div class="row">
|
||||||
</tr>
|
<div class="col-md-6">Dont select logs if it failed</div>
|
||||||
{/foreach}
|
<div class="col-md-4 text-right">
|
||||||
</tbody>
|
<button type="submit" class="btn btn-primary btn-xs btn-block"><i
|
||||||
</table>
|
class="fa fa-download"></i>
|
||||||
</div>
|
{$_L['Download_Database_Backup']}</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-5">
|
||||||
|
<div class="panel panel-primary">
|
||||||
|
<div class="panel-heading">Restore Database</div>
|
||||||
|
<form method="post" action="{$_url}settings/dbrestore" enctype="multipart/form-data">
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-7"><input type="file" name="json" accept="application/json"></div>
|
||||||
|
<div class="col-md-5 text-right">
|
||||||
|
<button type="submit" class="btn btn-primary btn-block btn-xs"><i class="fa fa-upload"></i>
|
||||||
|
Restore Dabase</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -38,8 +38,8 @@
|
|||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<img src="./ui/ui/images/error.png" class="img-responsive hidden-sm hidden-xs">
|
<img src="./ui/ui/images/error.png" class="img-responsive hidden-sm hidden-xs">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-9">
|
||||||
<div class="box box-danger box-solid text-center">
|
<div class="box box-danger box-solid">
|
||||||
|
|
||||||
<section class="content-header">
|
<section class="content-header">
|
||||||
<h1 class="text-center">
|
<h1 class="text-center">
|
||||||
|
@ -252,8 +252,8 @@
|
|||||||
href="{$_url}settings/notifications">{Lang::T('User Notification')}</a></li>
|
href="{$_url}settings/notifications">{Lang::T('User Notification')}</a></li>
|
||||||
<li {if $_routes[1] eq 'users'}class="active" {/if}><a
|
<li {if $_routes[1] eq 'users'}class="active" {/if}><a
|
||||||
href="{$_url}settings/users">{$_L['Administrator_Users']}</a></li>
|
href="{$_url}settings/users">{$_L['Administrator_Users']}</a></li>
|
||||||
{* <li {if $_routes[1] eq 'dbstatus'}class="active" {/if}><a
|
<li {if $_routes[1] eq 'dbstatus'}class="active" {/if}><a
|
||||||
href="{$_url}settings/dbstatus">{$_L['Backup_Restore']}</a></li> *}
|
href="{$_url}settings/dbstatus">{$_L['Backup_Restore']}</a></li>
|
||||||
<li {if $_routes[0] eq 'pluginmanager'}class="active" {/if}>
|
<li {if $_routes[0] eq 'pluginmanager'}class="active" {/if}>
|
||||||
<a href="{$_url}pluginmanager">{Lang::T('Plugin Manager')}</a>
|
<a href="{$_url}pluginmanager">{Lang::T('Plugin Manager')}</a>
|
||||||
</li>
|
</li>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user