История изменений
Исправление lbvf50txt, (текущая версия) :
Я прочитал документацию 3 года назад и реализовал свой сервер
Теперь и я реализовал свой сервер.
- Запускать
./server.rb
. - Читать
bombadillo gemini://127.0.0.1:2165
. - Cервер отдает файлы из каталога
src
. - Классически отдается
src/index.gmi
для запроса наroot
.
Перед запуском надо сгенерировать ключи и сертификаты.
openssl genrsa -out server.key 2048
openssl req -new -x509 -key server.key -out server.crt -days 365 -subj "/CN=127.0.0.1"
server.rb:
#!/usr/bin/env ruby
require 'socket'
require 'openssl'
require 'uri'
# Create a TCP server
server = TCPServer.new('127.0.0.1',2165)
# Create an SSL context
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.cert = OpenSSL::X509::Certificate.new(File.read("server.crt"))
ssl_context.key = OpenSSL::PKey::RSA.new(File.read("server.key"))
# Wrap the TCP server in an SSL server
ssl_server = OpenSSL::SSL::SSLServer.new(server, ssl_context)
puts "TLS Server is listening on port 2165..."
loop do
# Accept a client connection
ssl_client = ssl_server.accept
puts "Client connected: #{ssl_client.peeraddr[2]}"
# Read data from the client
request = ssl_client.gets
puts "Received: #{request}"
uri = URI.parse(request.strip)
p uri.path
# Define path to the gmi file
if "/" == uri.path
file_path = "src/index.gmi"
else
file_path = "src" + uri.path
end
# Prepare a valid Gemini response
response = ""
if File.exists?(file_path)
# Get data from the gmi file
data = File.readlines(file_path).map{|x| x.strip}.join("\r\n")
response = "20 text/gemini\r\n"
response += data
else
response = "51 Not Found\r\n"
end
# Send a response back to the client
ssl_client.puts response
# Close the client connection
ssl_client.close
end
src/index.gmi
# Gemini content.
Links list.
=> gemini://127.0.0.1:2165 root
=> gemini://127.0.0.1:2165/first.gmi first level
=> gemini://127.0.0.1:2165/second/a.gmi second A
=> gemini://127.0.0.1:2165/second/b.gmi second B
And unexisted file.
=> gemini://127.0.0.1:2165/second/nofile.gmi unexisted file
Исправление lbvf50txt, :
Я прочитал документацию 3 года назад и реализовал свой сервер
Теперь и я реализовал свой сервер.
- Запускать
./server.rb
. - Читать
bombadillo gemini://127.0.0.1:2165
. - Cервер отдает файлы из каталога
src
. - Классически отдается
src/index.gmi
для запроса наroot
.
Перед запуском надо сгенерировать ключи и сертификаты.
openssl genrsa -out server.key 2048
openssl req -new -x509 -key server.key -out server.crt -days 365 -subj "/CN=127.0.0.1"
server.rb:
#!/usr/bin/env ruby
require 'socket'
require 'openssl'
require 'uri'
# Create a TCP server
server = TCPServer.new('127.0.0.1',2165)
# Create an SSL context
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.cert = OpenSSL::X509::Certificate.new(File.read("server.crt"))
ssl_context.key = OpenSSL::PKey::RSA.new(File.read("server.key"))
# Wrap the TCP server in an SSL server
ssl_server = OpenSSL::SSL::SSLServer.new(server, ssl_context)
puts "TLS Server is listening on port 2165..."
loop do
# Accept a client connection
ssl_client = ssl_server.accept
puts "Client connected: #{ssl_client.peeraddr[2]}"
# Read data from the client
request = ssl_client.gets
puts "Received: #{request}"
uri = URI.parse(request.strip)
p uri.path
# Define path to the gmi file
if "/" == uri.path
file_path = "src/index.gmi"
else
file_path = "src" + uri.path
end
# Prepare a valid Gemini response
response = ""
if File.exists?(file_path)
# Get data from the gmi file
data = File.readlines(file_path).map{|x| x.strip}.join("\r\n")
response = "20 text/gemini\r\n"
response += data
else
response = "51 Not Found"
end
# Send a response back to the client
ssl_client.puts response
# Close the client connection
ssl_client.close
end
src/index.gmi
# Gemini content.
Links list.
=> gemini://127.0.0.1:2165 root
=> gemini://127.0.0.1:2165/first.gmi first level
=> gemini://127.0.0.1:2165/second/a.gmi second A
=> gemini://127.0.0.1:2165/second/b.gmi second B
And unexisted file.
=> gemini://127.0.0.1:2165/second/nofile.gmi unexisted file
Исправление lbvf50txt, :
Я прочитал документацию 3 года назад и реализовал свой сервер
Теперь и я реализовал свой сервер.
- Запускать
./server.rb
. - Читать
bombadillo gemini://127.0.0.1:2165
. - Cервер отдает файлы из каталога
src
. - Классически отдается
src/index.gmi
для запроса наroot
.
Перед запуском надо сгенерировать ключи и сертификаты.
openssl genrsa -out server.key 2048
openssl req -new -x509 -key server.key -out server.crt -days 365 -subj "/CN=127.0.0.1"
server.rb:
#!/usr/bin/env ruby
require 'socket'
require 'openssl'
require 'uri'
# Create a TCP server
server = TCPServer.new('127.0.0.1',2165)
# Create an SSL context
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.cert = OpenSSL::X509::Certificate.new(File.read("server.crt"))
ssl_context.key = OpenSSL::PKey::RSA.new(File.read("server.key"))
# Wrap the TCP server in an SSL server
ssl_server = OpenSSL::SSL::SSLServer.new(server, ssl_context)
puts "TLS Server is listening on port 2165..."
loop do
# Accept a client connection
ssl_client = ssl_server.accept
puts "Client connected: #{ssl_client.peeraddr[2]}"
# Read data from the client
request = ssl_client.gets
puts "Received: #{request}"
uri = URI.parse(request.strip)
p uri.path
# Define path to file
if "/" == uri.path
file_path = "src/index.gmi"
else
file_path = "src" + uri.path
end
# Prepare a valid Gemini response
response = ""
if File.exists?(file_path)
# Get data from file
data = File.readlines(file_path).map{|x| x.strip}.join("\r\n")
response = "20 text/gemini\r\n"
response += data
else
response = "51 Not Found"
end
# Send a response back to the client
ssl_client.puts response
# Close the client connection
ssl_client.close
end
src/index.gmi
# Gemini content.
Links list.
=> gemini://127.0.0.1:2165 root
=> gemini://127.0.0.1:2165/first.gmi first level
=> gemini://127.0.0.1:2165/second/a.gmi second A
=> gemini://127.0.0.1:2165/second/b.gmi second B
And unexisted file.
=> gemini://127.0.0.1:2165/second/nofile.gmi unexisted file
Исправление lbvf50txt, :
Я прочитал документацию 3 года назад и реализовал свой сервер
Теперь и я реализовал свой сервер.
- Запускать
./server.rb
. - Читать
bombadillo gemini://127.0.0.1:2165
. - Cервер отдает файлы из каталога
src
. - Классически отдается
src/index.gmi
для запроса наroot
.
server.rb:
#!/usr/bin/env ruby
require 'socket'
require 'openssl'
require 'uri'
# Create a TCP server
server = TCPServer.new('127.0.0.1',2165)
# Create an SSL context
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.cert = OpenSSL::X509::Certificate.new(File.read("server.crt"))
ssl_context.key = OpenSSL::PKey::RSA.new(File.read("server.key"))
# Wrap the TCP server in an SSL server
ssl_server = OpenSSL::SSL::SSLServer.new(server, ssl_context)
puts "TLS Server is listening on port 2165..."
loop do
# Accept a client connection
ssl_client = ssl_server.accept
puts "Client connected: #{ssl_client.peeraddr[2]}"
# Read data from the client
request = ssl_client.gets
puts "Received: #{request}"
uri = URI.parse(request.strip)
p uri.path
# Define path to file
if "/" == uri.path
file_path = "src/index.gmi"
else
file_path = "src" + uri.path
end
# Prepare a valid Gemini response
response = ""
if File.exists?(file_path)
# Get data from file
data = File.readlines(file_path).map{|x| x.strip}.join("\r\n")
response = "20 text/gemini\r\n"
response += data
else
response = "51 Not Found"
end
# Send a response back to the client
ssl_client.puts response
# Close the client connection
ssl_client.close
end
src/index.gmi
# Gemini content.
Links list.
=> gemini://127.0.0.1:2165 root
=> gemini://127.0.0.1:2165/first.gmi first level
=> gemini://127.0.0.1:2165/second/a.gmi second A
=> gemini://127.0.0.1:2165/second/b.gmi second B
And unexisted file.
=> gemini://127.0.0.1:2165/second/nofile.gmi unexisted file
Исправление lbvf50txt, :
Я прочитал документацию 3 года назад и реализовал свой сервер
Теперь и я реализовал свой сервер.
- Запускать
./server.rb
. - Читать
bombadillo gemini://127.0.0.1:2165
. - Cервер отдает файлы из каталога
src
. - Классически отдается
src/index.gmi
для запроса наroot
.
server.rb:
#!/usr/bin/env ruby
require 'socket'
require 'openssl'
require 'uri'
# Create a TCP server
server = TCPServer.new('127.0.0.1',2165)
# Create an SSL context
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.cert = OpenSSL::X509::Certificate.new(File.read("server.crt"))
ssl_context.key = OpenSSL::PKey::RSA.new(File.read("server.key"))
# Wrap the TCP server in an SSL server
ssl_server = OpenSSL::SSL::SSLServer.new(server, ssl_context)
puts "TLS Server is listening on port 2165..."
loop do
# Accept a client connection
ssl_client = ssl_server.accept
puts "Client connected: #{ssl_client.peeraddr[2]}"
# Read data from the client
request = ssl_client.gets
puts "Received: #{request}"
uri = URI.parse(request.strip)
p uri.path
# Define path to file
if "/" == uri.path
file_path = "src/index.gmi"
else
file_path = "src" + uri.path
end
# Prepare a valid Gemini response
response = ""
if File.exists?(file_path)
# Get data from file
data = File.readlines(file_path).map{|x| x.strip}.join("\r\n")
response = "20 text/gemini\r\n"
response += data
else
response = "51 Not Found"
end
# Send a response back to the client
ssl_client.puts response
# Close the client connection
ssl_client.close
end
scr/index.gmi
# Gemini content.
Links list.
=> gemini://127.0.0.1:2165 root
=> gemini://127.0.0.1:2165/first.gmi first level
=> gemini://127.0.0.1:2165/second/a.gmi second A
=> gemini://127.0.0.1:2165/second/b.gmi second B
And unexisted file.
=> gemini://127.0.0.1:2165/second/nofile.gmi unexisted file
Исходная версия lbvf50txt, :
Я прочитал документацию 3 года назад и реализовал свой сервер
Теперь и я реализовал свой сервер.
Запускать ./server.rb
.
Читать bombadillo gemini://127.0.0.1:2165
.
server.rb:
#!/usr/bin/env ruby
require 'socket'
require 'openssl'
require 'uri'
# Create a TCP server
server = TCPServer.new('127.0.0.1',2165)
# Create an SSL context
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.cert = OpenSSL::X509::Certificate.new(File.read("server.crt"))
ssl_context.key = OpenSSL::PKey::RSA.new(File.read("server.key"))
# Wrap the TCP server in an SSL server
ssl_server = OpenSSL::SSL::SSLServer.new(server, ssl_context)
puts "TLS Server is listening on port 2165..."
loop do
# Accept a client connection
ssl_client = ssl_server.accept
puts "Client connected: #{ssl_client.peeraddr[2]}"
# Read data from the client
request = ssl_client.gets
puts "Received: #{request}"
uri = URI.parse(request.strip)
p uri.path
# Define path to file
if "/" == uri.path
file_path = "src/index.gmi"
else
file_path = "src" + uri.path
end
# Prepare a valid Gemini response
response = ""
if File.exists?(file_path)
# Get data from file
data = File.readlines(file_path).map{|x| x.strip}.join("\r\n")
response = "20 text/gemini\r\n"
response += data
else
response = "51 Not Found"
end
# Send a response back to the client
ssl_client.puts response
# Close the client connection
ssl_client.close
end