mirror of
https://github.com/bytedream/docker4ssh.git
synced 2025-06-27 18:00:31 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
86e403be19 | |||
c73bdd5b51 | |||
90da7b4999 | |||
73c24e457a | |||
f3e032cf54 | |||
9f29b1b8dd |
12
Makefile
12
Makefile
@ -1,4 +1,4 @@
|
|||||||
VERSION=0.1.0
|
VERSION=0.1.2
|
||||||
|
|
||||||
BUILDDIR = .
|
BUILDDIR = .
|
||||||
_BUILDDIR = $(shell realpath $(BUILDDIR))/
|
_BUILDDIR = $(shell realpath $(BUILDDIR))/
|
||||||
@ -6,7 +6,7 @@ _BUILDDIR = $(shell realpath $(BUILDDIR))/
|
|||||||
build: build-server build-container build-extra
|
build: build-server build-container build-extra
|
||||||
|
|
||||||
build-server:
|
build-server:
|
||||||
cd server/ && go build -o $(_BUILDDIR)/docker4ssh
|
cd server/ && CGO_ENABLED=0 go build -o $(_BUILDDIR)/docker4ssh
|
||||||
|
|
||||||
build-container: DEBUG=false
|
build-container: DEBUG=false
|
||||||
build-container:
|
build-container:
|
||||||
@ -17,15 +17,15 @@ build-container:
|
|||||||
fi
|
fi
|
||||||
cp -rf $(_BUILDDIR)/x86_64-unknown-linux-musl/$(shell if $(DEBUG); then echo debug; else echo release; fi)/configure $(_BUILDDIR)
|
cp -rf $(_BUILDDIR)/x86_64-unknown-linux-musl/$(shell if $(DEBUG); then echo debug; else echo release; fi)/configure $(_BUILDDIR)
|
||||||
|
|
||||||
build-extra: SSHPASS:=$(shell LC_ALL=C tr -dc 'A-Za-z0-9!#$%&()*,-./:<=>?@[\]^_{}~' < /dev/urandom | head -c 18 ; echo)
|
build-extra: SSHPASS:=$(shell LC_ALL=C tr -dc 'A-Za-z0-9!#$%&()*,-.:<=>?@[]^_{}~' < /dev/urandom | head -c 18 ; echo)
|
||||||
build-extra:
|
build-extra:
|
||||||
if [ "$(_BUILDDIR)" != "$(shell realpath .)/" ]; then\
|
@if [ "$(_BUILDDIR)" != "$(shell realpath .)/" ]; then\
|
||||||
cp -rf LICENSE $(_BUILDDIR)/LICENSE;\
|
cp -rf LICENSE $(_BUILDDIR)/LICENSE;\
|
||||||
cp -rf man/ $(_BUILDDIR);\
|
cp -rf man/ $(_BUILDDIR);\
|
||||||
fi
|
fi
|
||||||
yes | ssh-keygen -t ed25519 -f $(_BUILDDIR)/docker4ssh.key -N "$(SSHPASS)" -b 4096 > /dev/null
|
yes | ssh-keygen -t ed25519 -f $(_BUILDDIR)/docker4ssh.key -N "$(SSHPASS)" -b 4096 > /dev/null
|
||||||
cp -rf extra/docker4ssh.conf $(_BUILDDIR)
|
cp -rf extra/docker4ssh.conf $(_BUILDDIR)
|
||||||
sed -i 's|Passphrase = ""|Passphrase = "$(SSHPASS)"|' $(_BUILDDIR)/docker4ssh.conf
|
sed -i "s|Passphrase = \"\"|Passphrase = \"$(SSHPASS)\"|" $(_BUILDDIR)/docker4ssh.conf
|
||||||
cat extra/database.sql | sqlite3 $(_BUILDDIR)/docker4ssh.sqlite3
|
cat extra/database.sql | sqlite3 $(_BUILDDIR)/docker4ssh.sqlite3
|
||||||
mkdir -p $(_BUILDDIR)/profile/ && cp -f extra/profile.conf $(_BUILDDIR)/profile/
|
mkdir -p $(_BUILDDIR)/profile/ && cp -f extra/profile.conf $(_BUILDDIR)/profile/
|
||||||
|
|
||||||
@ -67,6 +67,8 @@ install:
|
|||||||
install -Dm644 $(_BUILDDIR)profile/* -t $(DESTDIR)/etc/docker4ssh/profile/
|
install -Dm644 $(_BUILDDIR)profile/* -t $(DESTDIR)/etc/docker4ssh/profile/
|
||||||
install -Dm644 $(_BUILDDIR)LICENSE $(DESTDIR)/etc/docker4ssh/LICENSE
|
install -Dm644 $(_BUILDDIR)LICENSE $(DESTDIR)/etc/docker4ssh/LICENSE
|
||||||
|
|
||||||
|
touch $(DESTDIR)/etc/docker4ssh/docker4ssh.log && chmod 777 $(DESTDIR)/etc/docker4ssh/docker4ssh.log
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -rf $(DESTDIR)/etc/docker4ssh/
|
rm -rf $(DESTDIR)/etc/docker4ssh/
|
||||||
rm -f $(DESTDIR)$(PREFIX)/bin/docker4ssh
|
rm -f $(DESTDIR)$(PREFIX)/bin/docker4ssh
|
||||||
|
19
README.md
19
README.md
@ -47,17 +47,11 @@
|
|||||||
|
|
||||||
For every install method your OS **must** be linux and docker has to be installed.
|
For every install method your OS **must** be linux and docker has to be installed.
|
||||||
|
|
||||||
- Download from the latest release (currently only x64 architecture supported)
|
- From the latest release (currently only x64 architecture supported)
|
||||||
- Download `docker4ssh-<version>.tar.gz` from the [latest release](https://github.com/ByteDream/docker4ssh/releases/latest)
|
|
||||||
- Install it
|
Replace the `RELEASE` value in the following oneliner with the latest release [version](https://github.com/ByteDream/docker4ssh/releases/latest).
|
||||||
- Into your root directory (recommended)
|
```shell
|
||||||
```shell
|
$ export RELEASE=<latest version> && curl -L https://github.com/ByteDream/docker4ssh/releases/download/v$RELEASE/docker4ssh-$RELEASE.tar.gz | tar -xvzf - -C /
|
||||||
$ sudo tar -xvzf docker4ssh-<version>.tar.gz -C /
|
|
||||||
```
|
|
||||||
- To the same directory
|
|
||||||
```shell
|
|
||||||
$ sudo tar -xvzf docker4ssh-<version>.tar.gz
|
|
||||||
```
|
|
||||||
- Building from source
|
- Building from source
|
||||||
|
|
||||||
Before start installing, make sure you have to following things ready:
|
Before start installing, make sure you have to following things ready:
|
||||||
@ -69,6 +63,7 @@ For every install method your OS **must** be linux and docker has to be installe
|
|||||||
```shell
|
```shell
|
||||||
$ git clone https://github.com/ByteDream/docker4ssh
|
$ git clone https://github.com/ByteDream/docker4ssh
|
||||||
$ cd docker4ssh
|
$ cd docker4ssh
|
||||||
|
$ make build
|
||||||
$ make install
|
$ make install
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -109,4 +104,4 @@ For further information, visit the [wiki](https://github.com/ByteDream/docker4ss
|
|||||||
|
|
||||||
## ⚖ License
|
## ⚖ License
|
||||||
|
|
||||||
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) - see the [LICENSE](LICENSE) file for more details.
|
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) - see the [LICENSE](LICENSE) file for more details.
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
use std::fmt::{Debug, format};
|
use std::process::Command;
|
||||||
use std::net::TcpStream;
|
|
||||||
use std::os::unix::process::ExitStatusExt;
|
|
||||||
use std::process::{Command, ExitStatus};
|
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
@ -9,7 +6,7 @@ use structopt::clap::AppSettings;
|
|||||||
use crate::configure::cli::parser;
|
use crate::configure::cli::parser;
|
||||||
use crate::shared::api::api::API;
|
use crate::shared::api::api::API;
|
||||||
use crate::shared::api::request;
|
use crate::shared::api::request;
|
||||||
use crate::shared::api::request::{ConfigGetResponse, ConfigNetworkMode, ConfigPostRequest, ConfigRunLevel};
|
use crate::shared::api::request::{ConfigGetResponse, ConfigNetworkMode, ConfigRunLevel};
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, failure::Error>;
|
type Result<T> = std::result::Result<T, failure::Error>;
|
||||||
|
|
||||||
@ -24,9 +21,6 @@ trait Execute {
|
|||||||
settings = &[AppSettings::ArgRequiredElseHelp]
|
settings = &[AppSettings::ArgRequiredElseHelp]
|
||||||
)]
|
)]
|
||||||
struct Opts {
|
struct Opts {
|
||||||
#[structopt(short, long, global = true, help = "Verbose output")]
|
|
||||||
verbose: bool,
|
|
||||||
|
|
||||||
#[structopt(subcommand)]
|
#[structopt(subcommand)]
|
||||||
commands: Option<Root>
|
commands: Option<Root>
|
||||||
}
|
}
|
||||||
@ -259,7 +253,7 @@ enum Root {
|
|||||||
pub fn cli(route: String) {
|
pub fn cli(route: String) {
|
||||||
if let Some(subcommand) = Opts::from_args().commands {
|
if let Some(subcommand) = Opts::from_args().commands {
|
||||||
let mut result: Result<()> = Ok(());
|
let mut result: Result<()> = Ok(());
|
||||||
let mut api = API::new(route, String::new());
|
let mut api = API::new(route);
|
||||||
match subcommand {
|
match subcommand {
|
||||||
Root::Auth(auth) => {
|
Root::Auth(auth) => {
|
||||||
if let Some(subsubcommand) = auth.commands {
|
if let Some(subsubcommand) = auth.commands {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
use std::f32::consts::E;
|
|
||||||
use std::fmt::format;
|
|
||||||
use crate::shared::api::request::{ConfigNetworkMode, ConfigRunLevel};
|
use crate::shared::api::request::{ConfigNetworkMode, ConfigRunLevel};
|
||||||
|
|
||||||
pub fn parse_network_mode(src: &str) -> Result<ConfigNetworkMode, String> {
|
pub fn parse_network_mode(src: &str) -> Result<ConfigNetworkMode, String> {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::net::TcpStream;
|
|
||||||
use std::os::unix::net::UnixStream;
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use log::{LevelFilter, trace, warn, info, error};
|
use log::{LevelFilter, error};
|
||||||
use docker4ssh::configure::cli;
|
use docker4ssh::configure::cli;
|
||||||
use docker4ssh::shared::logging::init_logger;
|
use docker4ssh::shared::logging::init_logger;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
init_logger(LevelFilter::Debug);
|
if init_logger(LevelFilter::Debug).is_err() {
|
||||||
|
println!("Failed to initialize logger");
|
||||||
|
}
|
||||||
|
|
||||||
match fs::read_to_string("/etc/docker4ssh") {
|
match fs::read_to_string("/etc/docker4ssh") {
|
||||||
Ok(route) => cli(route),
|
Ok(route) => cli(route),
|
||||||
|
@ -1,21 +1,18 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use log::Level::Error;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, failure::Error>;
|
pub type Result<T> = std::result::Result<T, failure::Error>;
|
||||||
|
|
||||||
pub struct API {
|
pub struct API {
|
||||||
route: String,
|
route: String,
|
||||||
host: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl API {
|
impl API {
|
||||||
pub const fn new(route: String, host: String) -> Self {
|
pub const fn new(route: String) -> Self {
|
||||||
API {
|
API {
|
||||||
route,
|
route,
|
||||||
host,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +83,7 @@ impl APIResult {
|
|||||||
let result: T = serde_json::from_str(&self.result_body).map_err(|e| {
|
let result: T = serde_json::from_str(&self.result_body).map_err(|e| {
|
||||||
// checks if the error has a body and if so, return it
|
// checks if the error has a body and if so, return it
|
||||||
if self.has_body() {
|
if self.has_body() {
|
||||||
let error: APIError = serde_json::from_str(&self.result_body).unwrap_or_else(|ee| {
|
let error: APIError = serde_json::from_str(&self.result_body).unwrap_or_else(|_| {
|
||||||
APIError{message: format!("could not deserialize response: {}", e.to_string())}
|
APIError{message: format!("could not deserialize response: {}", e.to_string())}
|
||||||
});
|
});
|
||||||
failure::format_err!("Failed to call '{}': {}", self.request_path, error.message)
|
failure::format_err!("Failed to call '{}': {}", self.request_path, error.message)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde::de::Unexpected::Str;
|
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
|
|
||||||
use crate::shared::api::api::{API, Method, Request, Result};
|
use crate::shared::api::api::{API, Method, Request, Result};
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use log::{info, Metadata, Record};
|
use log::{Metadata, Record};
|
||||||
|
|
||||||
pub struct Logger;
|
pub struct Logger;
|
||||||
|
|
||||||
impl log::Log for Logger {
|
impl log::Log for Logger {
|
||||||
fn enabled(&self, metadata: &Metadata) -> bool {
|
fn enabled(&self, _metadata: &Metadata) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13,7 +13,5 @@ impl log::Log for Logger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush(&self) {
|
fn flush(&self) {}
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,6 @@ pub mod logger;
|
|||||||
|
|
||||||
pub use logger::Logger;
|
pub use logger::Logger;
|
||||||
|
|
||||||
static LOGGER: Logger = Logger;
|
|
||||||
|
|
||||||
pub fn init_logger(level: LevelFilter) -> Result<(), SetLoggerError> {
|
pub fn init_logger(level: LevelFilter) -> Result<(), SetLoggerError> {
|
||||||
log::set_logger(&Logger).map(|()| log::set_max_level(level))
|
log::set_logger(&Logger).map(|()| log::set_max_level(level))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user