Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.42 KB | None | 0 0
  1. <?php
  2. echo "<h3> PHP List All Session Variables</h3>";
  3. foreach ($_SESSION as $key=>$val)
  4. echo $key." => ".$val."<br/>";
  5. session_start();
  6. $message = '';
  7.  
  8. if(isset($_POST['connect'])) {
  9. $adress = 'localhost';
  10. $mysql = $_POST['mysql'];
  11. $dbuser = $_POST['dbuser'];
  12. $dbpass = $_POST['dbpass'];
  13.  
  14. $dbtest= new PDO("mysql:host=$adress;dbname=$mysql", $dbuser, $dbpass);
  15. $dbtest->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  16.  
  17. $_SESSION['install'] = '1';
  18.  
  19. if ($dbtest) {
  20. echo '
  21. <script>
  22. $(document).ready(function(){
  23. $("#step1").toggle(function(){
  24. $("#step1").hide();
  25. });
  26. $("#step2").toggle(function(){
  27. $("#step2").show();
  28. });
  29. });
  30. </script>
  31. ';
  32. } else {
  33. $message = 'Connection Failed. Please try agian';
  34. }
  35. }
  36.  
  37. if (isset($_POST['settings'])) {
  38.  
  39. $_SESSION['settingsname'] = $_POST['name'];
  40. $_SESSION['settingsicon'] = $_POST['icon'];
  41. $_SESSION['settingsmetadesc'] = $_POST['metadesc'];
  42. $_SESSION['settingsmetakey'] = $_POST['metakey'];
  43. $_SESSION['settingsfacebook'] = $_POST['facebook'];
  44. $_SESSION['settingstwitter'] = $_POST['twitter'];
  45. $_SESSION['settingsinstagram'] = $_POST['instagram'];
  46. $_SESSION['settingsgoogle'] = $_POST['google'];
  47.  
  48. $_SESSION['install'] = '2';
  49.  
  50. echo "<h3> PHP List All Session Variables</h3>";
  51. foreach ($_SESSION as $key=>$val)
  52. echo $key." => ".$val."<br/>";
  53.  
  54. echo '
  55. <script>
  56. $(document).ready(function(){
  57. $("#step2").toggle(function(){
  58. $("#step1").hide();
  59. $("#step2").hide();
  60. });
  61. $("#step3").toggle(function(){
  62. $("#step3").show();
  63. });
  64. </script>
  65. ';
  66.  
  67. }
  68.  
  69. if(isset($_POST['users'])) {
  70. $userusername = $_POST['username'];
  71. $userpassword = $_POST['password'];
  72. $useremail = $_POST['email'];
  73. $userrank = $_POST['rank'];
  74. $userdate = date("d/m/Y");
  75.  
  76. $_SESSION['userusername'] = $userusername;
  77. $_SESSION['userpassword'] = $userpassword;
  78. $_SESSION['useremail'] = $useremail;
  79. $_SESSION['userrank'] = $userrank;
  80. $_SESSION['userdate'] = $userdate;
  81.  
  82. $_SESSION['install'] = '3';
  83.  
  84. echo '
  85. <script>
  86. $(document).ready(function(){
  87. $("#step3").toggle(function(){
  88. $("#step1").hide();
  89. $("#step2").hide();
  90. $("#step3").hide();
  91. });
  92. $("#step4").toggle(function(){
  93. $("#step4").show();
  94. });
  95. });
  96. </script>
  97. ';
  98. }
  99.  
  100. if (isset($_GET['install'])) {
  101. $complete = $_GET['install'];
  102. if ($complete == 'complete') {
  103. $filename = (getenv("DOCUMENT_ROOT")."/inc/db.php");
  104. $data = '
  105. <?php
  106.  
  107. $servername = "localhost";
  108. $username = "test";
  109. $password = "";
  110. $dbname = "clientcp";
  111.  
  112. $db = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  113. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  114.  
  115. ?>
  116. ';
  117. if(!is_file($filename)) {
  118. $fp = fopen($filename,"x");
  119. fwrite($fp,$data);
  120. fclose($fp);
  121.  
  122. } else {
  123. $fp = fopen($filename,"w");
  124. fwrite($fp,$data);
  125. fclose($fp);
  126. }
  127. }
  128. if (file_exists($filename)) {
  129. require_once(getenv("DOCUMENT_ROOT")."/inc/db.php");
  130. try { // CREATE ALL TABLES
  131. $stmt1 = $db->prepare("
  132. CREATE TABLE settings (
  133. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  134. tag VARCHAR(128) NOT NULL,
  135. name VARCHAR(30) NOT NULL,
  136. favicon BLOB NOT NULL,
  137. metadesc VARCHAR(160) NOT NULL,
  138. metakey VARCHAR(256) NOT NULL,
  139. facebook VARCHAR(256) NOT NULL,
  140. twitter VARCHAR(256) NOT NULL,
  141. instagram VARCHAR(256) NOT NULL,
  142. google VARCHAR(256) NOT NULL
  143. )
  144. ");
  145. $stmt1->execute();
  146. $stmt2 = $db->prepare("
  147. CREATE TABLE contenttags (
  148. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  149. name VARCHAR(256) NOT NULL,
  150. tag VARCHAR(256) NOT NULL
  151. )
  152. ");
  153. $stmt2->execute();
  154. $stmt3 = $db->prepare("
  155. CREATE TABLE content (
  156. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  157. tag VARCHAR(128) NOT NULL,
  158. title VARCHAR(30) NOT NULL,
  159. image BLOB NOT NULL,
  160. tag VARCHAR(256) NOT NULL,
  161. page VARCHAR(256) NOT NULL
  162. )
  163. ");
  164. $stmt3->execute();
  165. $stmt4 = $db->prepare("
  166. CREATE TABLE users (
  167. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  168. name VARCHAR(30) NOT NULL,
  169. password VARCHAR(256) NOT NULL,
  170. email VARCHAR(256) NOT NULL,
  171. rank VARCHAR(256) NOT NULL,
  172. date VARCHAR(256) NOT NULL
  173. )
  174. ");
  175. $stmt4->execute();
  176. }
  177. catch(PDOException $e) {
  178. $message = "Something went wrong when creating tables: " . $e->getMessage();
  179. }
  180. try { // PUT CONTENT INTO TABLES
  181. $stmt1 = $db->prepare("
  182. INSERT into settings
  183. (tag, name, favicon, metadesc, metakey, facebook, twitter, instagram, google)
  184. VALUES
  185. (:tag, :name, :icon, :metadesc, :metakey, facebook, :twitter, :instagram, :google);
  186. ");
  187. $stmt1->execute(array(
  188. ':name' => $_SESSION['settingsname'],
  189. ':tag' => $_SESSION['settingstag'],
  190. ':icon' => $_SESSION['settingsicon'],
  191. ':metadesc' => $_SESSION['settingsmetadesc'],
  192. ':metakey' => $_SESSION['settingsmetakey'],
  193. ':facebook' => $_SESSION['settingsfacebook'],
  194. ':twitter' => $_SESSION['settingstwitter'],
  195. ':instagram' => $_SESSION['settingsinstagram'],
  196. ':google' => $_SESSION['settingsgoogle']
  197. ));
  198. $stmt2 = $db->prepare("
  199. INSERT INTO contenttags
  200. (name, tag)
  201. VALUES
  202. ('carousel', 'image'),
  203. ('image', 'image'),
  204. ('video', 'link'),
  205. ('header', 'text'),
  206. ('title', 'text'),
  207. ('post', 'text'),
  208. ('date', 'text'),
  209. ('link', 'text'),
  210. ('page', 'text')
  211. ");
  212. $stmt2->execute();
  213.  
  214. $contenttitle = 'First post';
  215. $contenttext = 'This is an example of your first post';
  216. $contenttag = 'text';
  217. $contentpage = 'home';
  218. $contentimage = '';
  219. $contentdate = date(d/n/Y);
  220.  
  221. $stmt3 = $db->prepare("
  222. INSERT INTO content
  223. (title, text, image, tag, page, date)
  224. VALUES
  225. (:title, :text, :image, :tag, :page, :date)
  226. ");
  227. $stmt3->execute(array(
  228. ':name' => $contenttitle,
  229. ':text' => $contenttext,
  230. ':image' => $contentimage,
  231. ':tag' => $contenttag,
  232. ':page' => $contentpage,
  233. ':date' => $contentdate
  234. ));
  235.  
  236. $stmt4 = $db->prepare("
  237. INSERT into users
  238. (name, password, email, rank, date)
  239. VALUES
  240. (:name, :password, :email, :rank, :date)
  241. ");
  242. $stmt4->execute(array(
  243. ':name' => $_SESSION['userusername'],
  244. ':password' => $_SESSION['userpassword'],
  245. ':email' => $_SESSION['useremail'],
  246. ':rank' => $_SESSION['userrank'],
  247. ':date' => $_SESSION['userdate']
  248. ));
  249.  
  250. }
  251. catch(PDOException $e) {
  252. $message = "Something went wrong while populating tables: " . $e->getMessage();
  253. }
  254. } else {
  255. $message = "Something went wrong when creating database file. ";
  256. }
  257. $_SESSION['install'] = '5';
  258.  
  259. header('Location: /');
  260. }
  261.  
  262.  
  263. ?>
  264. <!DOCTYPE html>
  265. <html>
  266. <head>
  267. <title>Client Panel</title>
  268. <meta charset="utf-8">
  269. <meta name="description" content="">
  270. <meta name="keywords" content="">
  271. <meta name="author" content="">
  272. <meta content="width=device-width, initial-scale=1" name="viewport"/>
  273. <link rel="shortcut icon" href="template/images/favicon.ico" type="image/x-icon"/>
  274. <link rel="stylesheet" href="/template/css/style.css">
  275. <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
  276. <script type='text/javascript' src='template/js/installation.js'></script>
  277. <script type='text/javascript' src='template/js/jquery-3.3.1.js'></script>
  278. </head>
  279. <body>
  280. <div class="installcms">
  281. <div id="step1" style="display:block;">
  282. <div class="installheader">
  283. <img src="template/images/logo.png">
  284. <h4>Please follow the next steps to install your website.</h4>
  285. </div>
  286. <div class="installbody">
  287. <h3>Connect to Database:</h3>
  288. <form name="connect" action="" method="post">
  289. <label for="mysql">MySQL Database:</label>
  290. <input type="text" name="mysql" required>
  291. <label for="dbuser">MySQL Username:</label>
  292. <input type="text" name="dbuser" required>
  293. <label for="dbpass">MySQL Password:</label>
  294. <input type="password" name="dbpass">
  295. <button type="submit" name="connect" class="button">Next Step</button>
  296. </form>
  297. </div>
  298. <?php if (!$message == '') {
  299. echo '
  300. <div class="under">
  301. <h4>'.$message.'</h4>
  302. </div>
  303. ';
  304. }
  305. ?>
  306.  
  307. </div>
  308.  
  309. <div id="step2" style="display:none;">
  310. <div class="installheader">
  311. <img src="template/images/logo.png">
  312. <h2>Website Settings and Social Media:</h2>
  313. </div>
  314. <div class="installbody">
  315. <h3></h3>
  316. <form name="settings" action="" method="post">
  317. <label for="name">Website Name: </label>
  318. <input type="text" name="name" placeholder="Website Name">
  319. <label for="icon">Favicon:</label>
  320. <input type="file" name="icon" id="icon">
  321. <label for="metadesc">Meta Description: <i class="far fa-question-circle" title="A description of your site in a clear sense. Maximum of 160 Charachters."></i></label>
  322. <input type="text" name="metadesc" placeholder="Meta Description">
  323. <label for="metakey">Meta Keywords: <i class="far fa-question-circle" title="A summary of the most important keywords or keywords that you use on a page. Maximum of 10 keyword phrases."></i></label>
  324. <input type="text" name="metakey" placeholder="Meta Keywords">
  325. <label for="facebook">Facebook:</label>
  326. <input type="text" name="facebook" placeholder="Facebook">
  327. <label for="twitter">Twitter:</label>
  328. <input type="text" name="twitter" placeholder="Twitter">
  329. <label for="instagram">Instagram:</label>
  330. <input type="text" name="instagram" placeholder="Instagram">
  331. <label for="google">Google+:</label>
  332. <input type="text" name="google" placeholder="Google+">
  333. <button type="submit" name="settings" class="button">Next Step</button>
  334. </form>
  335. </div>
  336. <?php if (!$message == '') {
  337. echo '
  338. <div class="under">
  339. <h4>'.$message.'</h4>
  340. </div>
  341. ';
  342. }
  343. ?>
  344.  
  345. </div>
  346.  
  347. <div id="step3" style="display:none;">
  348. <div class="installheader">
  349. <img src="template/images/logo.png">
  350. <h2>Add a user to your CMS:</h2>
  351. </div>
  352. <div class="installbody">
  353. <h3></h3>
  354. <p>*This is not required</p>
  355. <form name="users" action="" method="post">
  356. <label for="username">Username:</label>
  357. <input type="text" name="username">
  358. <label for="password">Password:</label>
  359. <input type="password" name="password">
  360. <label for="email">Email:</label>
  361. <input type="text" name="email">
  362. <div id="rank">
  363. <label for="rank">Rank: <i class="far fa-question-circle" title="
  364. Editor: Can manage content such as media files and heading texts.
  365. Admin: Grants full access to the CMS and can edit everything. Be cautious when giving this rank."></i></label>
  366. <select name="rank">
  367. <option value="editor">Editor</option>
  368. <option value="admin">Admin</option>
  369. </select>
  370. </div>
  371. <button type="submit" name="users" class="button">Last Step</button>
  372. </form>
  373. </div>
  374. <?php if (!$message == '') {
  375. echo '
  376. <div class="under">
  377. <h4>'.$message.'</h4>
  378. </div>
  379. ';
  380. }
  381. ?>
  382.  
  383. </div>
  384.  
  385. <div id="step4" style="display:none;">
  386. <div class="installheader">
  387. <img src="template/images/logo.png">
  388. <h2>Congratulations!</h2>
  389. <h3>You made it!</h3>
  390. </div>
  391. <div class="installbody">
  392. <h4>Your website CMS is not ready to de used!<br>
  393. You can now login and start creating content!</h4>
  394. <button href="?file=install&install=complete" type="submit" name="users" class="button">Complete Installation</button>
  395. </div>
  396. </div>
  397. </div>
  398. </body>
  399. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement