mirror of
https://github.com/loewexy/pdnsmanager.git
synced 2025-01-16 03:02:22 +01:00
Added installer
This commit is contained in:
parent
520234c424
commit
4e753118b9
3 changed files with 298 additions and 0 deletions
114
api/install.php
Normal file
114
api/install.php
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2016 Lukas Metzger <developer@lukas-metzger.com>.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
if(file_exists("../config/config-user.php")) {
|
||||
echo "Permission denied!";
|
||||
exit();
|
||||
}
|
||||
|
||||
//Get input
|
||||
$input = json_decode(file_get_contents('php://input'));
|
||||
|
||||
//Database command
|
||||
$sql = "
|
||||
CREATE TABLE IF NOT EXISTS domains (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
name varchar(255) NOT NULL,
|
||||
master varchar(128) DEFAULT NULL,
|
||||
last_check int(11) DEFAULT NULL,
|
||||
type varchar(6) NOT NULL,
|
||||
notified_serial int(11) DEFAULT NULL,
|
||||
account varchar(40) DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY name_index (name)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS permissions (
|
||||
user int(11) NOT NULL,
|
||||
domain int(11) NOT NULL,
|
||||
PRIMARY KEY (user,domain),
|
||||
KEY domain (domain)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS records (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
domain_id int(11) DEFAULT NULL,
|
||||
name varchar(255) DEFAULT NULL,
|
||||
type varchar(6) DEFAULT NULL,
|
||||
content varchar(255) DEFAULT NULL,
|
||||
ttl int(11) DEFAULT NULL,
|
||||
prio int(11) NOT NULL DEFAULT '0',
|
||||
change_date int(11) DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY rec_name_index (name),
|
||||
KEY nametype_index (name,type),
|
||||
KEY domain_id (domain_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
name varchar(50) NOT NULL,
|
||||
password varchar(200) NOT NULL,
|
||||
type varchar(20) NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
||||
ALTER TABLE permissions
|
||||
ADD CONSTRAINT permissions_ibfk_2 FOREIGN KEY (domain) REFERENCES domains (id),
|
||||
ADD CONSTRAINT permissions_ibfk_1 FOREIGN KEY (user) REFERENCES user (id);
|
||||
|
||||
";
|
||||
|
||||
|
||||
$db = @new mysqli($input->host, $input->user, $input->password, $input->database, $input->port);
|
||||
|
||||
|
||||
if($db->connect_error) {
|
||||
$retval['status'] = "error";
|
||||
$retval['message'] = $db->connect_error;
|
||||
} else {
|
||||
$passwordHash = password_hash($input->userPassword, PASSWORD_DEFAULT);
|
||||
|
||||
$db->multi_query($sql);
|
||||
while ($db->next_result()) {;}
|
||||
|
||||
$stmt = $db->prepare("INSERT INTO user(name,password,type) VALUES (?,?,'admin')");
|
||||
$stmt->bind_param("ss", $input->userName, $passwordHash);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
$configFile = Array();
|
||||
|
||||
$configFile[] = '<?php';
|
||||
$configFile[] = '$config[\'db_host\'] = \'' . addslashes($input->host) . "';";
|
||||
$configFile[] = '$config[\'db_user\'] = \'' . addslashes($input->user) . "';";
|
||||
$configFile[] = '$config[\'db_password\'] = \'' . addslashes($input->password) . "';";
|
||||
$configFile[] = '$config[\'db_name\'] = \'' . addslashes($input->database) . "';";
|
||||
$configFile[] = '$config[\'db_port\'] = ' . addslashes($input->port) . ";";
|
||||
|
||||
file_put_contents("../config/config-user.php", implode("\n", $configFile));
|
||||
|
||||
$retval['status'] = "success";
|
||||
}
|
||||
|
||||
|
||||
if(isset($retval)) {
|
||||
echo json_encode($retval);
|
||||
} else {
|
||||
echo "{}";
|
||||
}
|
113
install.php
Normal file
113
install.php
Normal file
|
@ -0,0 +1,113 @@
|
|||
<!DOCTYPE html>
|
||||
<!--
|
||||
Copyright 2016 Lukas Metzger <developer@lukas-metzger.com>.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<?php
|
||||
if(file_exists("config/config-user.php")) {
|
||||
Header("Location: index.php");
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>PDNS Manager - Domains</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<link href="include/bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="include/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet">
|
||||
<link href="include/custom.css" rel="stylesheet">
|
||||
|
||||
<script src="include/jquery.js"></script>
|
||||
<script src="include/bootstrap/js/bootstrap.min.js"></script>
|
||||
|
||||
<script src="js/install.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-inverse navbar-static-top">
|
||||
<div class="container">
|
||||
<div class="navbar-brand">
|
||||
PDNS Manager
|
||||
</div>
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="#">Install</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<row>
|
||||
<h2 id="domain-name">Install PDNS Manager</h2>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<div class="alert alert-danger defaulthidden" id="alertFailed" role="alert">
|
||||
Error
|
||||
</div>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
|
||||
<form>
|
||||
<div class="container col-md-3">
|
||||
<h3>Database</h3>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="dbHost" class="control-label">Host</label>
|
||||
<input type="text" class="form-control" id="dbHost" placeholder="Host" autocomplete="off">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="dbUser" class="control-label">User</label>
|
||||
<input type="text" class="form-control" id="dbUser" placeholder="User" autocomplete="off">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="dbPassword" class="control-label">Password</label>
|
||||
<input type="password" class="form-control" id="dbPassword" placeholder="Password" autocomplete="off">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="dbDatabase" class="control-label">Database</label>
|
||||
<input type="text" class="form-control" id="dbDatabase" placeholder="Database" autocomplete="off">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="dbPort" class="control-label">Port</label>
|
||||
<input type="text" class="form-control" id="dbPort" value="3306" autocomplete="off">
|
||||
</div>
|
||||
<button id="buttonInstall" class="btn btn-primary">Install</button>
|
||||
</div>
|
||||
|
||||
<div class="container col-md-3">
|
||||
<h3>Admin</h3>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="adminName" class="control-label">Name</label>
|
||||
<input type="text" class="form-control" id="adminName" placeholder="Name" autocomplete="off">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="adminPassword" class="control-label">Password</label>
|
||||
<input type="password" class="form-control" id="adminPassword" placeholder="Password" autocomplete="off">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="adminPassword2" class="control-label">Password repeated</label>
|
||||
<input type="password" class="form-control" id="adminPassword2" placeholder="Password repeated" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</row>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
71
js/install.js
Normal file
71
js/install.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright 2016 Lukas Metzger <developer@lukas-metzger.com>.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
$('#buttonInstall').click(function(evt){
|
||||
evt.preventDefault();
|
||||
checkSettings();
|
||||
});
|
||||
|
||||
$('#adminPassword2').bind("change keyup paste", function() {
|
||||
if($('#adminPassword').val() == $('#adminPassword2').val()) {
|
||||
$(this).parent().removeClass("has-error");
|
||||
} else {
|
||||
$(this).parent().addClass("has-error");
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
function checkSettings() {
|
||||
|
||||
if($('#adminPassword').val() != $('#adminPassword2').val()) {
|
||||
$('#adminPassword2').parent().addClass("has-error");
|
||||
}
|
||||
|
||||
if($('#adminPassword').val().length <= 0) {
|
||||
$('#adminPassword').parent().addClass("has-error");
|
||||
}
|
||||
|
||||
if($('#adminName').val().length <= 0) {
|
||||
$('#adminName').parent().addClass("has-error");
|
||||
}
|
||||
|
||||
var data = {
|
||||
host: $('#dbHost').val(),
|
||||
user: $('#dbUser').val(),
|
||||
password: $('#dbPassword').val(),
|
||||
database: $('#dbDatabase').val(),
|
||||
port: $('#dbPort').val(),
|
||||
userName: $('#adminName').val(),
|
||||
userPassword: $('#adminPassword').val()
|
||||
};
|
||||
|
||||
$.post(
|
||||
"api/install.php",
|
||||
JSON.stringify(data),
|
||||
function(data) {
|
||||
if(data.status == "error") {
|
||||
$('#alertFailed').text(data.message);
|
||||
$('#alertFailed').slideDown(600);
|
||||
} else if(data.status == "success") {
|
||||
location.assign("index.php");
|
||||
}
|
||||
},
|
||||
"json"
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in a new issue