Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

57 lignes
1.9KB

  1. <%
  2. ' Reads KEY=VALUE secrets from the .env file in the project root (outside the
  3. ' public web root). Real environment variables take precedence over the file.
  4. Class EnvService_Class
  5. Private values
  6. Private Sub Class_Initialize()
  7. Set values = Server.CreateObject("Scripting.Dictionary")
  8. values.CompareMode = 1
  9. LoadFile
  10. End Sub
  11. Public Function Value(key, fallback)
  12. Dim shell : Set shell = Server.CreateObject("WScript.Shell")
  13. Value = shell.Environment("Process")(key)
  14. Set shell = Nothing
  15. If Len(Value) > 0 Then Exit Function
  16. If values.Exists(key) Then
  17. Value = values(key)
  18. Else
  19. Value = fallback
  20. End If
  21. End Function
  22. Private Sub LoadFile()
  23. Dim fso, path, stream, line, pos, key, val
  24. Set fso = Server.CreateObject("Scripting.FileSystemObject")
  25. path = Server.MapPath("..\.env")
  26. If Not fso.FileExists(path) Then Exit Sub
  27. Set stream = fso.OpenTextFile(path, 1, False)
  28. Do Until stream.AtEndOfStream
  29. line = Trim(stream.ReadLine())
  30. If Len(line) > 0 And Left(line, 1) <> "#" Then
  31. pos = InStr(line, "=")
  32. If pos > 1 Then
  33. key = Trim(Left(line, pos - 1))
  34. val = Trim(Mid(line, pos + 1))
  35. If Len(val) > 1 Then
  36. If (Left(val, 1) = """" And Right(val, 1) = """") Or (Left(val, 1) = "'" And Right(val, 1) = "'") Then val = Mid(val, 2, Len(val) - 2)
  37. End If
  38. values(key) = val
  39. End If
  40. End If
  41. Loop
  42. stream.Close
  43. End Sub
  44. End Class
  45. Dim EnvService_Class__Singleton
  46. Function EnvService()
  47. If IsEmpty(EnvService_Class__Singleton) Then
  48. Set EnvService_Class__Singleton = New EnvService_Class
  49. End If
  50. Set EnvService = EnvService_Class__Singleton
  51. End Function
  52. %>

Powered by TurnKey Linux.