1+ <?php
2+ if (!is_writable (__DIR__ . '/../config/ ' )) {
3+ echo "Error! no permissions on /config! " ;
4+ exit ();
5+ }
6+ if (isset ($ _POST ['submit ' ])) {
7+ $ dbhost = $ _POST ['dbhost ' ];
8+ $ dbuser = $ _POST ['dbuser ' ];
9+ $ dbpass = $ _POST ['dbpass ' ];
10+ $ dbname = $ _POST ['dbname ' ];
11+ $ url = substr ($ _POST ['url ' ], -1 ) !== '/ ' ? $ _POST ['url ' ] . '/ ' : $ _POST ['url ' ];
12+ $ keywords = $ _POST ['keywords ' ];
13+ $ description = $ _POST ['description ' ];
14+ $ title = $ _POST ['title ' ];
15+ $ slogan = $ _POST ['slogan ' ];
16+
17+ $ config = "<?php
18+ // database
19+ define('DB_HOST', ' " .$ dbhost ."');
20+ define('DB_USER', ' " .$ dbuser ."');
21+ define('DB_PASS', ' " .$ dbpass ."');
22+ define('DB_NAME', ' " .$ dbname ."');
23+
24+ // page settings
25+ define('ROOT_PATH', ' " .$ url ."'); // domain (must end with a \"/ \"!)
26+ define('DEFAULT_KEYWORDS', ' " .$ keywords ."');
27+ define('DESCRIPTION', ' " .$ description ."');
28+ define('PAGE_TITLE', ' " .$ title ."');
29+ define('PAGE_SLOGAN', ' " .$ slogan ."');
30+
31+ define('ITEMS_PER_PAGE', 4); " ;
32+
33+ $ conn = new mysqli ($ dbhost , $ dbuser , $ dbpass , $ dbname );
34+
35+ if (mysqli_connect_errno ()) {
36+ echo "Connection to database failed " ;
37+ exit ();
38+ }
39+
40+ $ sql = "SHOW TABLES IN $ dbname " ;
41+ $ result = $ conn ->query ($ sql );
42+
43+ if ($ result ->num_rows !== 0 ) {
44+ echo "Database is not empty, delete all tables! " ;
45+ exit ();
46+ }
47+
48+ mysqli_select_db ($ conn , $ dbname );
49+
50+ $ templine = '' ;
51+ $ lines = file (__DIR__ . '/blog.sql ' );
52+
53+ foreach ($ lines as $ line ) {
54+ if (substr ($ line , 0 , 2 ) == '-- ' || $ line == '' ) {
55+ continue ;
56+ }
57+ $ templine .= $ line ;
58+ if (substr (trim ($ line ), -1 , 1 ) == '; ' ) {
59+ mysqli_query ($ conn , $ templine );
60+ $ templine = '' ;
61+ }
62+
63+ }
64+
65+ file_put_contents (__DIR__ . '/../config/config.php ' , $ config );
66+
67+ file_put_contents (__DIR__ . '/../install/.installed ' , 'true ' );
68+ header ('Location: ' . $ url );
69+ }
70+ ?>
71+ <!DOCTYPE html>
72+ <html lang="en">
73+ <head>
74+ <meta charset="UTF-8">
75+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
76+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
77+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
78+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
79+
80+ <title>Installation</title>
81+ </head>
82+ <body>
83+
84+ <div class="container">
85+ <h1>Installation</h1>
86+ <form method="post">
87+ <span>Please Create the Database!</span>
88+ <div class="mb-3">
89+ <label class="form-label">DB Host*</label>
90+ <input name="dbhost" type="text" value="localhost" class="form-control">
91+ </div>
92+ <div class="mb-3">
93+ <label class="form-label">DB User*</label>
94+ <input name="dbuser" type="text" class="form-control">
95+ </div>
96+ <div class="mb-3">
97+ <label class="form-label">DB Password*</label>
98+ <input name="dbpass" type="password" class="form-control">
99+ </div>
100+ <div class="mb-3">
101+ <label class="form-label">DB Name*</label>
102+ <input name="dbname" type="text" class="form-control">
103+ </div>
104+ <hr>
105+ <div class="mb-3">
106+ <label class="form-label">Title*</label>
107+ <input name="title" type="text" class="form-control">
108+ </div>
109+ <div class="mb-3">
110+ <label class="form-label">URL/Path*</label>
111+ <input name="url" value="<?= $ _SERVER ['HTTPS ' ] ? 'https:// ' : 'http:// ' ?> <?= $ _SERVER ['HTTP_HOST ' ]?> /" type="text" class="form-control">
112+ </div>
113+ <div class="mb-3">
114+ <label class="form-label">Keywords*</label>
115+ <input name="keywords" type="text" class="form-control">
116+ <div class="form-text">Separate with ","</div>
117+ </div>
118+ <div class="mb-3">
119+ <label class="form-label">Description*</label>
120+ <input name="description" type="text" class="form-control">
121+ </div>
122+ <div class="mb-3">
123+ <label class="form-label">Slogan*</label>
124+ <input name="slogan" type="text" class="form-control">
125+ </div>
126+
127+ <button name="submit" type="submit" class="btn btn-primary">Submit</button>
128+ </form>
129+ </div>
130+
131+ </body>
132+ </html>
0 commit comments