boxlet 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/boxlet +12 -0
- data/boxlet.gemspec +27 -0
- data/config.yml +8 -0
- data/lib/boxlet.rb +33 -0
- data/lib/boxlet/log.rb +16 -0
- data/lib/boxlet/tcp_server.rb +62 -0
- data/lib/boxlet/version.rb +3 -0
- metadata +90 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 arktisklada
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Boxlet
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'boxlet'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install boxlet
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/boxlet
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require "boxlet"
|
4
|
+
|
5
|
+
# Check to make sure we aren't running in Windows
|
6
|
+
if RUBY_PLATFORM =~ /(win|w)32$/ then
|
7
|
+
puts "Sorry, Boxlet is currently only available for Unix/Linux."
|
8
|
+
exit!
|
9
|
+
end
|
10
|
+
|
11
|
+
server = Boxlet::Server.new
|
12
|
+
server.run
|
data/boxlet.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "boxlet/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "boxlet"
|
8
|
+
spec.version = Boxlet::VERSION
|
9
|
+
spec.authors = ["Clayton Liggitt", "arktisklada"]
|
10
|
+
spec.email = ["mail@enorganik.com"]
|
11
|
+
spec.description = %q{A server for Boxlet, a DIY, self-hosted file storage system}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = "http://github.com/arktisklada/boxlet"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# spec.files = `git ls-files`.split($/)
|
17
|
+
spec.files = %w[config.yml LICENSE.txt README.md Rakefile boxlet.gemspec]
|
18
|
+
spec.files += Dir.glob('lib/**/*.rb')
|
19
|
+
|
20
|
+
# spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.executables = 'boxlet'
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
|
+
spec.require_paths = %w[lib]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
end
|
data/config.yml
ADDED
data/lib/boxlet.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "yaml"
|
3
|
+
|
4
|
+
require "boxlet/version"
|
5
|
+
require "boxlet/log"
|
6
|
+
require "boxlet/tcp_server"
|
7
|
+
|
8
|
+
|
9
|
+
module Boxlet
|
10
|
+
|
11
|
+
class Server
|
12
|
+
def initialize()
|
13
|
+
# Load the config
|
14
|
+
@@config = YAML.load_file("config.yml")
|
15
|
+
|
16
|
+
if @@config['git_debug'] then
|
17
|
+
Grit.debug = true
|
18
|
+
end
|
19
|
+
|
20
|
+
@server = TcpServer.new
|
21
|
+
end
|
22
|
+
|
23
|
+
public
|
24
|
+
|
25
|
+
def self.config
|
26
|
+
return @@config
|
27
|
+
end
|
28
|
+
|
29
|
+
def run
|
30
|
+
@server.start
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/boxlet/log.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "fileutils"
|
3
|
+
|
4
|
+
module Log
|
5
|
+
def get_logger(name, shift_age, shift_size, level)
|
6
|
+
# create the directory for the log if it doesn't exist
|
7
|
+
if !File.exist? File.dirname(name) then
|
8
|
+
FileUtils.mkdir_p File.dirname(name)
|
9
|
+
end
|
10
|
+
|
11
|
+
# create the logger and give it back
|
12
|
+
log = Logger.new(name, shift_age, shift_size)
|
13
|
+
log.level = level
|
14
|
+
log
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "socket"
|
2
|
+
|
3
|
+
class TcpServer
|
4
|
+
|
5
|
+
include Log
|
6
|
+
|
7
|
+
def initialize()
|
8
|
+
@listen_ip = Boxlet::Server.config['tcp_listen_ip'] || '127.0.0.1'
|
9
|
+
@listen_port = Boxlet::Server.config['tcp_listen_port'] || 11311
|
10
|
+
|
11
|
+
@log = get_logger('log/tcp.log', 10, 1024000, Boxlet::Server.config['tcp_debug'] ? Logger::DEBUG : Logger::WARN);
|
12
|
+
@log.info("Initializing TCP server on #{@listen_ip}:#{@listen_port}")
|
13
|
+
@server = TCPServer.open(@listen_ip, @listen_port)
|
14
|
+
|
15
|
+
@connections = Hash.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def start
|
19
|
+
@log.info("Starting TCP server")
|
20
|
+
|
21
|
+
# Start a new thread for the TCP server so that it does not block and
|
22
|
+
# hold up the rest of the program execution
|
23
|
+
# Thread.start() do
|
24
|
+
loop {
|
25
|
+
# When a new connection comes in, create a new thread and begin handling
|
26
|
+
# requests
|
27
|
+
Thread.start(@server.accept) do |client|
|
28
|
+
@log.info("Client connected!")
|
29
|
+
|
30
|
+
# Output welcome messages
|
31
|
+
client.puts Time.now.ctime
|
32
|
+
client.puts "Welcome to Boxlet!"
|
33
|
+
|
34
|
+
# Read input from TCP client
|
35
|
+
while line = client.gets
|
36
|
+
entry = line.split
|
37
|
+
cmd = entry.shift
|
38
|
+
|
39
|
+
case cmd
|
40
|
+
# Retrieve config value
|
41
|
+
when "config_get" then client.puts(Boxlet::Server.config[entry[0]] || "ERROR")
|
42
|
+
|
43
|
+
# Halt the server
|
44
|
+
when "stop" then
|
45
|
+
client.puts "Daemon halting!"
|
46
|
+
@log.info("Daemon halting!")
|
47
|
+
exit(0)
|
48
|
+
|
49
|
+
# Disconnect the client
|
50
|
+
when "quit" then
|
51
|
+
client.puts "Goodbye!"
|
52
|
+
client.close
|
53
|
+
else
|
54
|
+
client.puts "INVALID"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
}
|
59
|
+
# end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: boxlet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Clayton Liggitt
|
9
|
+
- arktisklada
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-06-02 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.3'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.3'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rake
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: A server for Boxlet, a DIY, self-hosted file storage system
|
48
|
+
email:
|
49
|
+
- mail@enorganik.com
|
50
|
+
executables:
|
51
|
+
- boxlet
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- config.yml
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- boxlet.gemspec
|
60
|
+
- lib/boxlet/log.rb
|
61
|
+
- lib/boxlet/tcp_server.rb
|
62
|
+
- lib/boxlet/version.rb
|
63
|
+
- lib/boxlet.rb
|
64
|
+
- bin/boxlet
|
65
|
+
homepage: http://github.com/arktisklada/boxlet
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.23
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: A server for Boxlet, a DIY, self-hosted file storage system
|
90
|
+
test_files: []
|