index.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 ($use_metadata) {
  18. $meta_model = new meta_model ();
  19. $meta_model->user = $username;
  20. $meta_model->email = $_POST ['email'];
  21. $meta_model->name = $_POST ['name'];
  22. $meta_model->mailkey = random_password(16);
  23. }
  24. if (! check_username ( $username ) || ! check_password_quality ( $passwd )) {
  25. ?>
  26. <div class="alert alert-danger">
  27. <?php
  28. echo "<p>User <em>" . htmlspecialchars ( $username ) . "</em> is invalid!.</p>";
  29. } else {
  30. ?>
  31. <div class="alert alert-info">
  32. <?php
  33. if (! $htpasswd->user_exists ( $username )) {
  34. $htpasswd->user_add ( $username, $passwd );
  35. echo "<p>User <em>" . htmlspecialchars ( $username ) . "</em> created.</p>";
  36. } else {
  37. $htpasswd->user_update ( $username, $passwd );
  38. echo "<p>User <em>" . htmlspecialchars ( $username ) . "</em> changed.</p>";
  39. }
  40. if ($use_metadata) {
  41. if (! $htpasswd->meta_exists ( $username )) {
  42. $htpasswd->meta_add ( $meta_model );
  43. } else {
  44. $htpasswd->meta_update ( $meta_model );
  45. }
  46. }
  47. }
  48. ?>
  49. </div>
  50. <?php
  51. }
  52. ?>
  53. <div class="result alert alert-info" style="display: none;"></div>
  54. </div>
  55. </div>
  56. <div class=row>
  57. <div class="col-xs-12 col-md-4">
  58. <h3>Create or update user:</h3>
  59. <form class="navbar-form navbar-left" action="index.php"
  60. method="post">
  61. <div class="form-group">
  62. <p>
  63. <input type="text" class="userfield form-control"
  64. placeholder="Username" name="user">
  65. </p>
  66. <?php
  67. if ($use_metadata) {
  68. ?>
  69. <p>
  70. <input class="emailfield form-control" type="email" name="email"
  71. placeholder="Email" />
  72. </p>
  73. <p>
  74. <input class="namefield form-control" type="text" name="name"
  75. placeholder="Real Name" />
  76. </p>
  77. <?php
  78. }
  79. ?>
  80. <p>
  81. <input class="passwordfield form-control" type="password"
  82. name="pwd" placeholder="Password" />
  83. </p>
  84. <button type="submit" class="btn btn-default">Submit</button>
  85. </div>
  86. </form>
  87. </div>
  88. <div class="col-xs-12 col-md-6">
  89. <h3>Users:</h3>
  90. <?php
  91. $users = $htpasswd->get_users ();
  92. if ($use_metadata) {
  93. $meta_map = $htpasswd->get_metadata ();
  94. }
  95. include_once ("includes/user_table.php");
  96. ?>
  97. </div>
  98. </div>
  99. <div class=row>
  100. <br /> <br />
  101. <div class="col-xs-12 col-md-10 well">
  102. <p>
  103. Create new users for the htpasswd file here. A user can change
  104. his/her password with this <a href="selfservice.php">self service
  105. link.</a><br /> You can fill the username in the form if you add
  106. the url parameter user=&lt;username&gt;
  107. </p>
  108. </div>
  109. </div>
  110. </div>
  111. <?php
  112. include_once ('includes/footer.php');
  113. ?>