intranet.rb 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 zum Intranet',
  13. text: "Jemand hat die Zugangsdaten zum Intranet für diese Adresse angefordert.\n\nBenutzername und Passwort:\n#{ENV['MG_USER']}\n#{ENV['MG_PASSWORD']}\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. <title>Zugangsdaten vergessen</title>
  25. <style media="screen" type="text/css">
  26. *, *:before, *:after {
  27. -moz-box-sizing: border-box;
  28. -webkit-box-sizing: border-box;
  29. box-sizing: border-box;
  30. }
  31. form {
  32. max-width: 400px;
  33. margin: 10px auto;
  34. padding: 10px 20px;
  35. background: #f4f7f8;
  36. border-radius: 8px;
  37. }
  38. h1 {
  39. margin: 0 0 30px 0;
  40. text-align: center;
  41. }
  42. input[type="email"],
  43. textarea,
  44. select {
  45. background: rgba(255,255,255,0.1);
  46. border: none;
  47. font-style: normal;
  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: #000000;
  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. </style>
  82. </head>
  83. <body>
  84. <form action="/repost" method="post">
  85. <h1>Zugangsdaten zum Intranet vergessen?</h1>
  86. <fieldset>
  87. <label for="mail">Bitte Dienstadresse angeben</label>
  88. <input type="email" id="mail" name="email" placeholder="Vorname.Name@fvbschulen.de">
  89. </fieldset>
  90. <button type="submit">Zugangsdaten zuschicken</button>
  91. </form>
  92. </body>
  93. </html>
  94. eos
  95. end
  96. post "/repost" do
  97. adresse = params["email"]
  98. domain = adresse.scan(/(?<=@)([^\s]+)(?=\s|$)/).join
  99. if ENV['MG_ZUL_DOMAIN']== domain
  100. repost(adresse)
  101. puts "Nachricht an #{adresse} verschickt"
  102. <<-eos
  103. <html>
  104. <head>
  105. <meta charset="utf-8">
  106. <title>Zugangsdaten verschickt</title>
  107. <style type="text/css">h1 {margin: 30px 30px 30px 30px; text-align: center;}</style>
  108. </head>
  109. <body><h1>Zugangsdaten verschickt, bis zum nächsten Mal.</h1></body>
  110. </html>
  111. eos
  112. else
  113. puts "Fehler: #{adresse} unzulässig"
  114. <<-eos
  115. <html>
  116. <head>
  117. <meta charset="utf-8">
  118. <title>Fehler!</title>
  119. <style type="text/css">h1 {margin: 30px 30px 30px 30px; text-align: center;}</style>
  120. </head>
  121. <body><h1>Nur Dienstadressen sind zulässig.</h1></body>
  122. </html>
  123. eos
  124. end
  125. end