-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.php
More file actions
executable file
·156 lines (149 loc) · 5.92 KB
/
setup.php
File metadata and controls
executable file
·156 lines (149 loc) · 5.92 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* Provides interface for initial system setup and dean account registration.
* @author Avin E.M; Kunal Dahiya
*/
if (file_exists('config.php'))
include('config.php');
require('functions.php');
if(empty($config))
$config = $_POST;
if($config)
{
try
{
$db = new PDO("mysql:host={$config['db_host']}", $config['db_user'], $config['db_pswd'],
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_FOUND_ROWS => true
]);
$conf = "<?php\n \$config = " . var_export($config,true) . ";\n?>";
$db->exec('CREATE DATABASE IF NOT EXISTS '.$config['db_name']);
$db->exec('USE '.$config['db_name']);
file_put_contents('config.php',$conf);
// If the system already has an admin configured, we redirect to login page instead.
$query = $db->query("SELECT count(*) FROM faculty where level='dean'");
if($query->fetch()[0])
{
if($_POST)
postResponse('redirect','login.php');
header("Location: ./");
die();
}
if($_POST)
postResponse('redirect','setup.php');
}
catch(PDOException $e)
{
if($e->getCode()=='42S02')
{
$db->exec(file_get_contents('create_tables.sql'));
if($_POST)
postResponse('redirect','setup.php');
}
if($_POST)
{
if($e->getCode()==1045)
postResponse('error',"Cannot connect to the database: Invalid username or password");
else if($e->getCode()==1044)
postResponse('error',$e->getMessage());
else
{
postResponse('error',$e->getMessage());
}
}
else
{
copy('config.php','tmp/config.old_invalid.php');
file_put_contents('config.php','');
}
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" type="image/png" href="images/favicon.png"/>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<link href="css/chosen.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.min.js" ></script>
<script type="text/javascript" src="js/form.js"></script>
<script type="text/javascript" src="js/chosen.js"></script>
<script>
$(function()
{
$("select").chosen({
create_option: function(term){
if(term.length < 6 || term.length>50)
{
var message = $(".info").addClass('error');
message.hide();
message.html('<b>✖ </b> Department name should be between 6 to 50 characters');
message.show(400);
return false;
}
$("#newdpt").show();
$("#newdpt input").prop("disabled", false);
this.append_option({
value: term,
text: term
});
},
create_option_text: 'Add Department ',
persistent_create_option: true});
})
</script>
<title>QuickSlots | Setup</title>
</head>
<body class="center">
<div class="vspacer"></div>
<div class="box" style="vertical-align: middle">
<div class="boxbg"></div>
<?php if(empty($db)): ?>
<div class="db"></div>
<div class="title">Setup a databse for quickslots to use</div>
<div class="elements">
<form method="post" action="setup.php">
<input type="text" name="db_host" class="styled details" required title="Please enter database host" placeholder="Database host" />
<input type="text" name="db_name" class="styled details" required title="Please enter database name" placeholder="Database Name" />
<input type="text" name="db_user" class="styled username" required title="Please enter database username" placeholder="Database User" />
<input type="password" name="db_pswd" class="styled pswd" required title="Please enter database password" placeholder="Database Password" />
<input type="text" name="ldap_host" class="styled details" placeholder="LDAP Server" />
<input type="text" name="ldap_dn" class="styled uInfo" placeholder="LDAP DN" />
<div class="blocktext info"></div>
<div class="center button">
<button>Continue</button>
</div>
</form>
</div>
<?php else:?>
<div class="avatar"><div class="add icon"></div></div>
<div class="title">To start using the system,<br /> create an admin/dean account...</div>
<div class="elements">
<form method="post" action="register.php?action=addUser">
<input type="text" name="uName" class="styled username" required pattern="[^ ]{4,25}" title="4 to 25 characters without spaces" placeholder="Username" />
<input type="text" name="fullName" class="styled uInfo" required pattern=".{6,50}" title="6 to 50 characters" placeholder="Full Name" />
<select name="dept" class="stretch" data-placeholder="Choose Department..." required>
<option label="Choose Department..."></option>
<?php
require_once ('connect_db.php');
foreach($db->query('SELECT * FROM depts') as $dept)
echo "<option value=\"{$dept['dept_code']}\">{$dept['dept_name']} ({$dept['dept_code']})</option>"
?>
</select>
<div id="newdpt" style="display: none;">
<input type="text" name="newDpt" class="styled uInfo" disabled autocomplete="off" required pattern=".{2,5}" title="2 to 5 characters" placeholder="Dept. Code" />
</div>
<input type="password" name="pswd" class="styled pswd" required pattern="[^ ]{8,32}" title="8 to 32 characters without spaces" placeholder="Password" />
<input type="password" class="styled pswd" required pattern="[^ ]{8,32}" title="8 to 32 characters without spaces" placeholder="Confirm password" />
<div class="blocktext info"></div>
<div class="center button">
<button>Register</button>
</div>
</form>
</div>
<?php endif;?>
</div>
</body>
</html>