index.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. include_once ('includes/checklogin.php');
  3. include_once ('includes/head.php');
  4. include_once ('tools/htpasswd.php');
  5. include_once ('tools/util.php');
  6. $ini = read_config ();
  7. include_once ('includes/nav.php');
  8. $htpasswd = new htpasswd ( $ini ['secure_path'] . ".htpasswd" ); // path to your .htpasswd file
  9. ?>
  10. <div class="container box">
  11. <div class="row">
  12. <div class="col-xs-12">
  13. <?php
  14. echo "<h2>" . $ini ['app_title'] . "</h2>";
  15. if (isset ( $_POST ['user'] )) {
  16. $username = $_POST ['user'];
  17. $passwd = $_POST ['pwd'];
  18. if (!check_username($username) || !check_password_quality($passwd)) {
  19. ?>
  20. <div class="alert alert-danger">
  21. <?php
  22. echo "<p>User <em>" . htmlspecialchars ( $username ) . "</em> is invalid!.</p>";
  23. } else {
  24. ?>
  25. <div class="alert alert-info">
  26. <?php
  27. if (! $htpasswd->user_exists ( $username )) {
  28. $htpasswd->user_add ( $username, $passwd );
  29. echo "<p>User <em>" . htmlspecialchars ( $username ) . "</em> created.</p>";
  30. } else {
  31. $htpasswd->user_update ( $username, $passwd );
  32. echo "<p>User <em>" . htmlspecialchars ( $username ) . "</em> changed.</p>";
  33. }
  34. }
  35. ?>
  36. </div>
  37. <?php
  38. }
  39. ?>
  40. <div class="result alert alert-info" style="display: none;"></div>
  41. </div>
  42. </div>
  43. <div class=row>
  44. <div class="col-xs-12 col-md-4">
  45. <h3>Create or change user and password:</h3>
  46. <form class="navbar-form navbar-left" action="index.php"
  47. method="post">
  48. <div class="form-group">
  49. <input type="text" class="userfield form-control"
  50. placeholder="Username" name="user">
  51. </p>
  52. <p>
  53. <input class="passwordfield form-control" type="password"
  54. name="pwd" placeholder="Password" />
  55. </p>
  56. <button type="submit" class="btn btn-default">Submit</button>
  57. </div>
  58. </form>
  59. </div>
  60. <div class="col-xs-12 col-md-6">
  61. <h3>Users found:</h3>
  62. <ul class="list-group">
  63. <?php
  64. $users = $htpasswd->get_users ();
  65. foreach ( $users as $user ) {
  66. echo "<li class='list-group-item list-item-with-button id-" . htmlspecialchars ( $user ) . "' onclick=\"setUserField('" . $user . "');\">" . htmlspecialchars ( $user ) . "<a class='btn btn-danger btn-list-item pull-right' " . "onclick=\"deleteUser('" . $user . "');\"" . "href='#' >Delete</a>" . "</li>\n";
  67. }
  68. ?>
  69. </ul>
  70. </div>
  71. </div>
  72. <div class=row>
  73. <br/><br/>
  74. <div class="col-xs-12 col-md-10 well">
  75. <p>Create new users for the htpasswd file here. A user can change his/her password with this <a href="selfservice.php">self service link.</a><br/>
  76. You can fill the username in the form if you add the url parameter user=&lt;username&gt;</p>
  77. </div>
  78. </div>
  79. </div>
  80. <?php
  81. include_once ('includes/footer.php');
  82. ?>