paedml.rb 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. require 'sinatra'
  2. require 'mailgun-ruby'
  3. require 'envyable'
  4. # env.yml mit den unten verwendeten ENV anleg
  5. Envyable.load("#{File.dirname(__FILE__)}/config/env.yml")
  6. helpers do
  7. def repost(adresse)
  8. mg_client = Mailgun::Client.new(ENV['MG_API_KEY'])
  9. message_params = {
  10. from: ENV['MG_SENDER'],
  11. to: adresse,
  12. subject: 'Zugangsdaten für PaedML/NextCloud',
  13. text: "Jemand hat die Zugangsdaten zum Intranet für diese Adresse angefordert.\n\nBenutzername und Passwort:\nZeile1\nZeile2\n\nAber Achtung, wenn das Passwort in PaedML geändert wurde, dann hilft das o.a. Passwort leider auch nicht weiter. Dann bitte bei HOB melden.\n\nEinen schönen Tag noch und bis zum nächsten Mal."
  14. }
  15. mg_client.send_message(ENV['MG_DOMAIN'], message_params).to_h!
  16. puts "Nachricht an #{adresse} verschickt"
  17. end
  18. end
  19. get '/' do
  20. <<-eos
  21. <html>
  22. <head>
  23. <meta charset="utf-8">
  24. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  25. <title>Zugangsdaten vergessen</title>
  26. <style media="screen" type="text/css">
  27. *, *:before, *:after {
  28. -moz-box-sizing: border-box;
  29. -webkit-box-sizing: border-box;
  30. box-sizing: border-box;
  31. }
  32. form {
  33. max-width: 300px;
  34. margin: 10px auto;
  35. padding: 10px 20px;
  36. background: #f4f7f8;
  37. border-radius: 8px;
  38. }
  39. h1 {
  40. margin: 0 0 30px 0;
  41. text-align: center;
  42. }
  43. input[type="email"],
  44. textarea,
  45. select {
  46. background: rgba(255,255,255,0.1);
  47. border: none;
  48. font-size: 16px;
  49. height: auto;
  50. margin: 0;
  51. outline: 0;
  52. padding: 15px;
  53. width: 100%;
  54. background-color: #e8eeef;
  55. color: #8a97a0;
  56. box-shadow: 0 1px 0 rgba(0,0,0,0.03) inset;
  57. margin-bottom: 30px;
  58. }
  59. button {
  60. padding: 19px 39px 18px 39px;
  61. color: #FFF;
  62. background-color: #4bc970;
  63. font-size: 18px;
  64. text-align: center;
  65. font-style: normal;
  66. border-radius: 5px;
  67. width: 100%;
  68. border: 1px solid #3ac162;
  69. border-width: 1px 1px 3px;
  70. box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset;
  71. margin-bottom: 10px;
  72. }
  73. fieldset {
  74. margin-bottom: 30px;
  75. border: none;
  76. }
  77. label {
  78. display: block;
  79. margin-bottom: 8px;
  80. }
  81. @media screen and (min-width: 480px) {
  82. form {
  83. max-width: 480px;
  84. }
  85. }
  86. </style>
  87. </head>
  88. <body>
  89. <form action="/repost" method="post">
  90. <h1>Zugangsdaten für PaedML/NextCloud vergessen?</h1>
  91. <fieldset>
  92. <label for="mail">Email angeben</label>
  93. <input type="email" id="mail" name="email" placeholder="Mein_Name@fvbschulen.de">
  94. </fieldset>
  95. <button type="submit">Zuschicken</button>
  96. </form>
  97. </body>
  98. </html>
  99. eos
  100. end
  101. post "/repost" do
  102. adresse = params["email"]
  103. domain = adresse.scan(/(?<=@)([^\s]+)(?=\s|$)/).join
  104. if ENV['MG_ZUL_DOMAIN']== domain
  105. repost(adresse)
  106. puts "Nachricht an #{adresse} verschickt"
  107. <<-eos
  108. <html>
  109. <head>
  110. <meta charset="utf-8">
  111. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  112. <title>Zugangsdaten verschickt</title>
  113. <style media="screen" type="text/css">
  114. *, *:before, *:after {
  115. -moz-box-sizing: border-box;
  116. -webkit-box-sizing: border-box;
  117. box-sizing: border-box;
  118. }
  119. h1 {
  120. margin: 0 0 30px 0;
  121. text-align: center;
  122. }
  123. </style>
  124. </head>
  125. <body>
  126. <h1>Zugangsdaten verschickt, bis zum nächsten Mal</h1>
  127. </body>
  128. </html>
  129. eos
  130. else
  131. puts "Fehler: #{adresse} unzulässig"
  132. <<-eos
  133. <html>
  134. <head>
  135. <meta charset="utf-8">
  136. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  137. <title>Fehler!</title>
  138. <style media="screen" type="text/css">
  139. h1 {
  140. margin: 0 0 30px 0;
  141. text-align: center;
  142. }
  143. </style>
  144. </head>
  145. <body>
  146. <h1>Nur Dienstadressen sind zulässig.</h1>
  147. </body>
  148. </html>
  149. eos
  150. end
  151. end