index.php 2.8 KB

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