settings.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. if((!isset($_COOKIE["logged"]))){
  3. echo "<!DOCTYPE html>";
  4. echo "<head>";
  5. echo "<title>Form submitted</title>";
  6. echo "<script type='text/javascript'>window.location.replace('setup.php');</script>";
  7. echo "</head>";
  8. echo "<body></body></html>";
  9. die;
  10. }
  11. if(isset($_GET["action"])){$action = $_GET["action"];}
  12. function write_ini_file($content, $path) {
  13. if (!$handle = fopen($path, 'w')) {
  14. return false;
  15. }
  16. $success = fwrite($handle, $content);
  17. fclose($handle);
  18. return $success;
  19. }
  20. //ini_set('display_errors',1); error_reporting(E_ALL);
  21. $configfile = 'settings.ini.php';
  22. try {
  23. $config = parse_ini_file('settings.ini.php', true);
  24. } catch(Exception $e) {
  25. die('<b>Unable to read config.ini.php. Did you rename it from settings.ini.php-example?</b><br><br>Error message: ' .$e->getMessage());
  26. }
  27. //Password crap
  28. if(array_key_exists('category-0', $_POST) == true){
  29. foreach ($config as $keyname => $section) { if(($keyname == "general")) { $nopass = $section["password"]; } }
  30. $salt = substr(str_replace('+','.',base64_encode(md5(mt_rand(), true))),0,16);
  31. $rounds = 10000;
  32. if(empty($_POST["password-0"])){ $_POST["password-0"] = $nopass;}
  33. if(strlen($_POST["password-0"]) < 50){ $_POST["password-0"] = crypt($_POST["password-0"], sprintf('$5$rounds=%d$%s$', $rounds, $salt)); }
  34. setcookie("test1", "test", time() + (86400 * 1), "/");
  35. setcookie("test2", $_POST["password-0"], time() + (86400 * 7), "/");
  36. //password crap
  37. //Gather Config Write Info
  38. $sampleData .= '; <?php die("Access denied"); ?>' . "\r\n";
  39. foreach ($_POST as $parameter => $value) {
  40. $splitParameter = explode('-', $parameter);
  41. if ($value == "on")
  42. $value = "true";
  43. if($splitParameter[0] == "category"){ $sampleData .= "[" . $value . "]\r\n"; }else{ $sampleData .= $splitParameter[0] . " = \"" . $value . "\"\r\n"; }
  44. }
  45. if($action == "write"){
  46. write_ini_file($sampleData, $configfile);
  47. sleep(.5);
  48. echo "<!DOCTYPE html>";
  49. echo "<head>";
  50. echo "<title>Form submitted</title>";
  51. echo "<script type='text/javascript'>window.location.replace('settings.php');</script>";
  52. echo "</head>";
  53. echo "<body></body></html>";
  54. }
  55. }
  56. ?>
  57. <!doctype html>
  58. <html>
  59. <head>
  60. <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css'>
  61. <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'>
  62. <!-- Bootstrap -->
  63. <link rel="stylesheet" href="css/bootstrap.min.css"/>
  64. <!-- Font Awesome -->
  65. <link rel="stylesheet" href="css/font-awesome.min.css"/>
  66. <!-- Bootstrap-Iconpicker -->
  67. <link rel="stylesheet" href="css/bootstrap-iconpicker.min.css"/>
  68. <style>
  69. body {
  70. margin: 50px;
  71. }
  72. .fa {
  73. min-width: 14px;
  74. }
  75. .form-inline .form-control,
  76. .form-inline .btn {
  77. margin-bottom: 8px;
  78. }
  79. .form-group {
  80. width: 100%;
  81. }
  82. input[type=checkbox].css-checkbox {
  83. position:absolute; z-index:-1000; left:-1000px; overflow: hidden; clip: rect(0 0 0 0); height:1px; width:1px; margin:-1px; padding:0; border:0;
  84. }
  85. input[type=checkbox].css-checkbox + label.css-label {
  86. padding-left:55px;
  87. height:30px;
  88. display:inline-block;
  89. line-height:30px;
  90. background-repeat:no-repeat;
  91. background-position: 0 0;
  92. font-size:30px;
  93. vertical-align:middle;
  94. cursor:pointer;
  95. }
  96. input[type=checkbox].css-checkbox:checked + label.css-label {
  97. background-position: 0 -30px;
  98. }
  99. label.css-label {
  100. background-image:url(img/check.png);
  101. -webkit-touch-callout: none;
  102. -webkit-user-select: none;
  103. -khtml-user-select: none;
  104. -moz-user-select: none;
  105. -ms-user-select: none;
  106. user-select: none;
  107. }
  108. hr {
  109. display: block;
  110. height: 1px;
  111. border: 0;
  112. border-top: 1px solid #ccc;
  113. margin: 1em 0 auto;
  114. padding: 0;
  115. }
  116. </style>
  117. </head>
  118. <body>
  119. <form action="?action=write" method="post" name="adminForm" class="form-inline">
  120. <?foreach ($config as $keyname => $section) {
  121. setcookie("test3", "test", time() + (86400 * 1), "/");
  122. setcookie("test4", $_POST["password-0"], time() + (86400 * 7), "/");
  123. if(($keyname == "general")) {
  124. echo '<div class="form-group clearfix">';
  125. echo '<input type="hidden" name="category-0" class="form-control" value="general">';
  126. echo '<span class="btn btn-inactive " type="button"><span class="fa fa-cog"></span></span> ';
  127. echo '<input type="text" name="title-0" class="form-control" value="'. $section["title"] .'"> ';
  128. echo '<input type="text" name="password-0" class="form-control" placeholder="Leave Blank if no change" value=""> ';
  129. if($section['useicons'] == "true"){echo '<input type="checkbox" name="useicons-0" id="useicons-0" class="css-checkbox" checked> ';}else {echo '<input type="checkbox" name="useicons-0" id="useicons-0" class="css-checkbox"> ';}
  130. echo '<label for="useicons-0" class="css-label">Icons</label></div><br/><hr/><br/> ';
  131. }
  132. }?>
  133. <div id="tagsForm" class="sortable">
  134. <?$i = 0;
  135. foreach ($config as $keyname => $section) {
  136. if(($keyname !== "general")) {?>
  137. <div class="form-group clearfix">
  138. <span class="btn btn-default move" type="button"><span class="fa fa-arrows"></span></span>
  139. <input type="text" name="category-<?=$i;?>" class="form-control" value="<?=$keyname;?>">
  140. <input type="text" name="url-<?=$i;?>" class="form-control" placeholder="url" value="<?=$section['url']?>">
  141. <button data-placement="left" data-cols="5" data-rows="5" class="btn btn-default" name="icon-<?=$i;?>" role="iconpicker" data-iconset="fontawesome" data-icon="<?=$section['icon']?>"></button>
  142. <?if($section['enabled'] == "true"){echo '<input type="checkbox" name="enabled-' . $i .'" id="enabled-' . $keyname . '" class="css-checkbox" checked>';}else {echo '<input type="checkbox" name="enabled-' . $i .'" id="enabled-' . $keyname . '" class="css-checkbox">';}?>
  143. <label for="enabled-<?=$keyname;?>" class="css-label">Enabled</label>
  144. <?if($section['guest'] == "true"){echo '<input type="checkbox" name="guest-' . $i .'" id="guest-' . $keyname . '" class="css-checkbox" checked>';}else {echo '<input type="checkbox" name="guest-' . $i .'" id="guest-' . $keyname . '" class="css-checkbox">';}?>
  145. <label for="guest-<?=$keyname;?>" class="css-label">Guest</label> <button class="btn btn-danger deleteGroup" id="remScnt" type="button"><span class="fa fa-trash"></span></button>
  146. </div>
  147. <?}
  148. $i++;
  149. }?>
  150. </div>
  151. <div class="form-group clearfix">
  152. <button class="btn btn-primary" id="addScnt" type="button"><span class="fa fa-plus"></span></button>
  153. <button class="btn btn-success" type="submit"> Save Settings </button>
  154. </div>
  155. </form>
  156. <script type="text/javascript" src="https://code.jquery.com/jquery-1.4.3.min.js"></script>
  157. <script type='text/javascript'>
  158. $(function() {
  159. var scntDiv = $('#tagsForm');
  160. var i = <?=$i?>;
  161. $('#addScnt').on('click', function() {
  162. $('<div class="form-group clearfix ui-sortable-handle"> <span class="btn btn-default move" type="button"><span class="fa fa-arrows"></span></span> <input type="text" name="category-' + i +'" class="form-control" placeholder="Tag" value="New Tab"> <input type="text" name="url-' + i +'" class="form-control" placeholder="url" value="Add URL"> <button class="btn btn-default" name="icon-' + i +'" role="iconpicker" data-iconset="fontawesome" data-icon="fa-question"></button> <input type="checkbox" name="enabled-' + i +'" id="enabled-' + i +'" class="css-checkbox"> <label for="enabled-' + i +'" class="css-label">Enabled</label> <input type="checkbox" name="guest-' + i +'" id="guest-' + i +'" class="css-checkbox"> <label for="guest-' + i +'" class="css-label">Guest</label> <button class="btn btn-danger deleteGroup" id="remScnt" type="button"><span class="fa fa-trash"></span></button></div>').appendTo(scntDiv);
  163. i++;
  164. return false;
  165. });
  166. $(document).on('click','#remScnt', function() {
  167. $(this).closest('div').remove();
  168. i--;
  169. return false;
  170. });
  171. });
  172. </script>
  173. <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
  174. <script src='https://code.jquery.com/ui/1.11.2/jquery-ui.min.js'></script>
  175. <script>$( "#tagsForm" ).sortable({connectWith: ".sortable"});</script>
  176. <!-- jQuery -->
  177. <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
  178. <!-- Bootstrap -->
  179. <script type="text/javascript" src="js/bootstrap.min.js"></script>
  180. <!-- Bootstrap-Iconpicker Iconset for Font Awesome -->
  181. <script type="text/javascript" src="js/iconset-fontawesome-4.2.0.min.js"></script>
  182. <!-- Bootstrap-Iconpicker -->
  183. <script type="text/javascript" src="js/bootstrap-iconpicker.min.js"></script>
  184. </body>
  185. </html>