-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.php
More file actions
168 lines (148 loc) · 5.73 KB
/
Copy pathsetup.php
File metadata and controls
168 lines (148 loc) · 5.73 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
157
158
159
160
161
162
163
164
165
166
167
168
<?php
require_once('config.php');
require_once('lib/misc.php');
if(isset($config) && !logged_in()) {
$error = "Your server is already configured";
require_once('index.php');
exit();
}
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(!isset($config)) {
$config = array();
$config['password-salt'] = sha1(date('l jS \of F Y h:i:s A').mt_rand().mt_rand());
if($_REQUEST['db'] == 'sqlite') {
$dir = dirname(__FILE__)."/db";
$config['connect-string'] = "sqlite:/".$dir."/nabaztag.sqlite3";
} else {
$config['connect-string'] = $_REQUEST['connect-string'];
$config['db-user'] = $_REQUEST['db-user'];
$config['db-password'] = $_REQUEST['db-password'];
}
if($_POST['password'] != $_REQUEST['confirm']) {
$error = "Password and password confirmation do not match";
}
}
$config['server-timezone'] = $_REQUEST['server-timezone'];
foreach($_POST as $key => $value) {
if(strpos($key, 'app-') === 0) {
$config[$key] = $value;
}
}
require_once('lib/db.php');
if(isset($error)) {
unset($config);
} else {
if(install_database_tables($db)) {
save_config($config);
if(!logged_in()) {
create_user($db, $config, $_REQUEST['username'], $_REQUEST['password'], true);
}
$info = "Configuration successful";
}
}
} else {
require_once('lib/db.php');
}
$dir = dirname(__FILE__);
require('header.php'); ?>
<header class="jumbotron masthead">
<div class="inner">
<h1>Nabaztag Server</h1>
<p>Welcome to the simple Nabaztag Server</p>
<p class="download-info">
<a href="https://github.com/dparnell/nabaztag-php/" class="btn btn-primary btn-large">View project on GitHub</a>
</p>
</div>
</header>
<hr class="soften">
<div class="marketing">
<?php if(logged_in()) { ?>
<h1>Reconfigure your Nabaztag Server.</h1>
<p class="marketing-byline">Time to make some changes!</p>
<?php } else { ?>
<h1>Your Nabaztag Server is not yet configured.</h1>
<p class="marketing-byline">Let's get ready to rock!</p>
<?php } ?>
<?php if(is_writable($dir)) { ?>
<form method="post" action="setup.php" id="setup-form" data-ajax="false" class="ui-body ui-body-b ui-corner-all">
<?php if(!logged_in()) { ?>
<fieldset data-role="controlgroup">
<legend>Where do you want to store your data:</legend>
<?php if(is_writable($dir."/db")) { ?>
<input type="radio" name="db" value="sqlite" id="use-sqlite" checked="checked"/>
<label for="use-sqlite">Use auto-configured SQlite database</label>
<?php } else { ?>
<input type="radio" name="db" value="sqlite-not-available" id="use-sqlite" disabled="disabled"/>
<label for="use-sqlite" class="error">Use auto-configured SQlite database - not available as <?php echo $dir."/db" ?> is not writable</label>
<?php } ?>
<input type="radio" name="db" value="other" id="use-other"/><label for="use-other">Configure database connection manually</label>
</fieldset>
<fieldset data-role="controlgroup" id="pdo-settings" style="display: none">
<legend>Advanced database details:</legend>
<label for="connect-string">PDO Connect String (<a href="http://www.electrictoolbox.com/php-pdo-dsn-connection-string/" target="_blank">Help</a>):</label>
<input type="text" name="connect-string" id="connect-string" />
<label for="db-user">Database Username:</label>
<input type="text" name="db-user" id="db-user" value="<?php echo $_REQUEST['db-user']; ?>" />
<label for="db-password">Database Password:</label>
<input type="password" name="db-password" id="db-password" />
</fieldset>
<fieldset data-role="controlgroup">
<legend>Administrator User Details:</legend>
<div data-role="fieldcontain">
<label for="username">Username:</label>
<input type="text" name="username" id="username" class="required"/>
</div>
<div data-role="fieldcontain">
<label for="password">Password:</label>
<input type="password" name="password" id="password" class="required"/>
</div>
<div data-role="fieldcontain">
<label for="confirm">Confirm:</label>
<input type="password" name="confirm" id="confirm" class="required"/>
</div>
</fieldset>
<?php } ?>
<fieldset data-role="controlgroup">
<legend>Server Timezone:</legend>
<?php timezone_select('server-timezone', config_value('server-timezone')); ?>
</fieldset>
<fieldset data-role="controlgroup">
<legend>Media:</legend>
<div data-role="fieldcontain">
<label for="app-media-base">Base URL for media files:</label>
<input type="text" name="app-media-base" id="app-media-base" value="<?php echo config_value('app-media-base', 'http://karotz.s3.amazonaws.com/applications/'); ?>"/>
</div>
</fieldset>
<?php
$dir = dirname(__FILE__)."/apps";
$setup_files = scandir($dir);
foreach($setup_files as $file) {
if(preg_match("/_setup.php$/i", $file) == 1) {
require($dir.'/'.$file);
}
} ?>
<fieldset data-role="controlgroup">
<input type="submit" name="submit" value="Save" id="submit" data-role="none" class="btn button"/>
</fieldset>
</form>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#setup-form').validate();
$('#use-other, #use-sqlite').click(function(e) {
if($('#use-sqlite').prop('checked')) {
$('#pdo-settings').slideUp();
} else {
$('#pdo-settings').slideDown();
}
});
});
</script>
<?php } else { ?>
<div class="alert alert-error">
<h2>Error</h2>
<p>Please make sure that <?php echo $dir; ?> is writable by your web server.</p>
<p>Until this is done it is not possible to configure your simple nabaztag server.</p>
</div>
<?php } ?>
<?php require('footer.php'); ?>