Skip to content

Commit

Permalink
web:reinitialize
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyMcMillan committed Nov 27, 2024
1 parent 0f00d83 commit 04ea0f4
Show file tree
Hide file tree
Showing 28 changed files with 2,612 additions and 62 deletions.
1,491 changes: 1,430 additions & 61 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["gnostr <admin@gnostr.org>", "Jordan Doyle <jordan@doyle.la>"]
license = "WTFPL"

[workspace]
members = ["tree-sitter-grammar-repository"]
members = ["tree-sitter-grammar-repository", "web"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
15 changes: 15 additions & 0 deletions server.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name = "gnostr.org"
port = 2222

hostname = "gnostr.org"

[users.gnostr]
is_admin = true
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDaBogLsfsOkKIpZEZYa3Ee+wFaaxeJuHps05sH2rZLf+KEE6pWX5MT2iWMgP7ihmm6OqbAPkWoBUGEO5m+m/K1S0MgQXUvaTsTI0II3MDqJT/RXA6Z9c+ZIDROEAkNIDrfeU2n8hQXfMHwG6aJjwv3Zky9jR/ey2rSgKLMcTOLrMeAyop6fYhjIHqp0dTagHo1j+XHAbVsrjw6oxC0ohTkp8rzH6cYJyjK4TOKApEgCALJUOA2rbHNxr68wAIe2RS36dRQobD3ops2+HoOGk7pkBQazBAlZp/H4monWRrq7tTEw8FkGMX5udZQX6BNEI0vJZqtdkSpG7jSS3aL7GXcuOYKpsTKxuGm5BWsrRPiphsc25U02oe/y3+qM0ceP/njJp3ZvXQ/a2QGPU4+P8WSD+J0oKS+TiRKrpiTR4ChJk8zWupg4PI5zflN3yyK7MrGXg1n0DsvHxPXcqpvVRz4i8ORt6IlKGkve1tC0Wd9pVy4044LDethMORRZFjWAdS/caN1EMgTrrGMxi0DLVw6ahedGUgZj2WYWfsrEg8Kzbfk3fn32sO/lMnNyz5hmavMBiNORGlIi2Qe2RjQEtcJHn89B7UtyEfnj87V+jZYcFf4nnNQigT2eQ3NlB1YzZS4Zk/OxQeYypclzYFaiYc7RZv2yxKVOy0KvEpldyUKeQ== randy.lee.mcmillan@gmail.com"

[users.gnostr-user]
can_create_repos = true
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDaBogLsfsOkKIpZEZYa3Ee+wFaaxeJuHps05sH2rZLf+KEE6pWX5MT2iWMgP7ihmm6OqbAPkWoBUGEO5m+m/K1S0MgQXUvaTsTI0II3MDqJT/RXA6Z9c+ZIDROEAkNIDrfeU2n8hQXfMHwG6aJjwv3Zky9jR/ey2rSgKLMcTOLrMeAyop6fYhjIHqp0dTagHo1j+XHAbVsrjw6oxC0ohTkp8rzH6cYJyjK4TOKApEgCALJUOA2rbHNxr68wAIe2RS36dRQobD3ops2+HoOGk7pkBQazBAlZp/H4monWRrq7tTEw8FkGMX5udZQX6BNEI0vJZqtdkSpG7jSS3aL7GXcuOYKpsTKxuGm5BWsrRPiphsc25U02oe/y3+qM0ceP/njJp3ZvXQ/a2QGPU4+P8WSD+J0oKS+TiRKrpiTR4ChJk8zWupg4PI5zflN3yyK7MrGXg1n0DsvHxPXcqpvVRz4i8ORt6IlKGkve1tC0Wd9pVy4044LDethMORRZFjWAdS/caN1EMgTrrGMxi0DLVw6ahedGUgZj2WYWfsrEg8Kzbfk3fn32sO/lMnNyz5hmavMBiNORGlIi2Qe2RjQEtcJHn89B7UtyEfnj87V+jZYcFf4nnNQigT2eQ3NlB1YzZS4Zk/OxQeYypclzYFaiYc7RZv2yxKVOy0KvEpldyUKeQ== randy.lee.mcmillan@gmail.com"

# Optional.
welcome_message = "welcome to gnostr.org!"
6 changes: 6 additions & 0 deletions server_key
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-----BEGIN PRIVATE KEY-----
MHMCAQEwBQYDK2VwBEIEQNRIVy4cg8dkufVFU6Qr1FIRDjb6KCn42NDo05HmbOBYuEUT6y3uzu7H
mLVQiH7S0et3vtIKS/SiLgd4zlFy0OmhIwMhALhFE+st7s7ux5i1UIh+0tHrd77SCkv0oi4HeM5R
ctDp

-----END PRIVATE KEY-----
1 change: 1 addition & 0 deletions web/.cargo-checksum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"files":{"CHANGELOG.md":"d8bc948c16137f50f651a28d93242d5715f356c475d150814e431ffd1ba169c6","Cargo.lock":"51568edac98957d7d81124cc2782c1a3ef31cfb420dce2840578922b60bba4dd","Cargo.toml":"5ae80ce7424bf49d93f50b66f655f79d1d6db40f5dfede76c6380cebeb570493","LICENSE":"77af13347f22e2b31e96fbc7221d3bab9fa1d907721c64a05e57471a5d1fcdbb","README.md":"05734056038ccb368d13f084257034f03e6b7f64ee1935dcf2c41b35b34d8e56","TODO.md":"833633498c436d054f187b9f5de8107419d47878c16a697659c2e698ee9e46a2","cog.toml":"ccf68b865813e1345781b46cc062a808aaf8440d7f584bce46adbfd0e40dd8e1","eejit.toml":"41f2769b100859bfbf15f9d6a534c54fe4c1d13249cb408f1891e43d0c4e3656","src/config/mod.rs":"b700aedb19168aac6041ca478e07494f256275790aa7f17ad77cdbb320cdf3a0","src/config/repo.rs":"b76752c9d267e9c3cee03d8fb4658351c2894550ff673385f97d2defee4bb96a","src/config/server.rs":"1eb1d6c2a495ad56ec5633967156a764953b02f2f6b0b85396d12cd9d80a2ffa","src/git/mod.rs":"92a294a12726981834bb97ea0f6d2301e899a3043f9b068daf1c498112772904","src/main.rs":"3b72797a79a400e968d6b69ed93c47314b2173d388800362cf2ff3e4f8480035","src/site/default.html":"eaa2a6ed0a842fc47074732abf82f9138fa4450306eaa515e768febfe64d6491","src/site/mod.rs":"a05983f47fc94980a8fcf57306fd60f410da5c48c046e7db5870ebed97e69145","src/ssh/commands.rs":"d10fa2352c08f03406788816a2a34c48323a9fe5cb9d38c916f949049f061771","src/ssh/keys.rs":"47072ad7fb5665be69cca54d4e89f350de9781ae895c4ed8edf65a2500dcbfab","src/ssh/messages.rs":"7b5e1d10ea1d8bb5487f6883851b9b77f32b08e52e7d08731b4aa18fabaaaa6c","src/ssh/mod.rs":"6d006b9793f6b120049b98a3e81b5fd0fa24a8f666bb0a6ed80770c5240a53a2","src/state.rs":"5e691985c13ce4f2507c208f82bd7222abf5a7d17485f743cc058592bd8cb03b","src/utils.rs":"407dc8c4977c0c62db3d909d83687faca24a4daf521a116adb94e609ff591636","src/vars.rs":"e76f22508610641393efb9601a777ae575b55a515b2c6f31b840360c0168ddaf"},"package":"6a7b509ba0e7c69753e7f5c92df37063506e70480956c0854dbcbb928c805f3b"}
45 changes: 45 additions & 0 deletions web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Changelog
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.

- - -
## 0.2.1 - 2023-04-20
#### Bug Fixes
- default template padding - (6c74013) - moh
- reloading information for new repos - (7f570d0) - moh

- - -

## 0.2.0 - 2023-04-15
#### Features
- static site generator - (bb38e80) - moh

- - -

## 0.1.6 - 2023-04-15
#### Bug Fixes
- notify systemd when ready - (15b889b) - moh

- - -

## 0.1.5 - 2023-04-15
#### Bug Fixes
- reject repos outside the server dir - (5c74ac5) - moh
#### Miscellaneous Chores
- update TODO - (7d2ad2d) - moh
- update eejit.toml - (2759c04) - moh
- cargo.lock - (193614a) - moh

- - -

## 0.1.4 - 2023-04-14
#### Documentation
- fix port in readme - (25bc81c) - moh
#### Miscellaneous Chores
- update cargo.toml - (9ff18aa) - moh
- update cargo.toml - (41d1b06) - moh
- update eejit.toml - (d2a97b0) - moh
- create repo config - (18eccef) - Eejit Server

- - -

Changelog generated by [cocogitto](https://github.com/cocogitto/cocogitto).
81 changes: 81 additions & 0 deletions web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.

[package]
edition = "2021"
name = "eejit"
version = "0.2.1"
description = "A self-hosted Git server that's easy to set up, use, and maintain."
homepage = "https://eejit.moh.ink"
readme = "README.md"
keywords = [
"cli",
"git",
]
categories = ["command-line-utilities"]
license = "MIT"

[dependencies.anyhow]
version = "1.0.70"

[dependencies.async-trait]
version = "0.1.68"

[dependencies.clean-path]
version = "0.2.1"

[dependencies.colored]
version = "2.0.0"

[dependencies.comrak]
version = "0.18.0"

[dependencies.env_logger]
version = "0.10.0"

[dependencies.futures]
version = "0.3.28"

[dependencies.log]
version = "0.4.17"

[dependencies.russh]
version = "0.37.1"
features = ["openssl"]

[dependencies.russh-keys]
version = "0.37.1"

[dependencies.sd-notify]
version = "0.4.1"

[dependencies.serde]
version = "1.0.159"
features = ["derive"]

[dependencies.shellwords]
version = "1.1.0"

[dependencies.tempfile]
version = "3.5.0"

[dependencies.tera]
version = "1.18.1"

[dependencies.textwrap]
version = "0.16.0"

[dependencies.tokio]
version = "1.27.0"
features = ["full"]

[dependencies.toml]
version = "0.7.3"
7 changes: 7 additions & 0 deletions web/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright © 2023 moh

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
62 changes: 62 additions & 0 deletions web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Eejit

Eejit is self-hosted Git server that's easy to set up, use, and maintain.

## Getting Started

- Install via cargo || source.
- Create an empty directory, and create a starting `server.toml` file (minimal example below).
- Run Eejit.
- Done!

## Server Config

Eejit is configured via the `server.toml` file inside the `/config.git` repo, which is only accessible to admin users.
When starting Eejit for the first time, it will copy an adjacent config file into the newly created config repo.
Here's a minimal example:

```toml
name = "Eejit Server"
port = 2222

hostname = "example.com"

[users.claudia]
is_admin = true
public_key = "ssh-rsa AAAAj74s..."

[users.alex]
can_create_repos = true
public_key = "ssh-rsa AAAAm8fd..."

# Optional.
welcome_message = "Welcome, %!"
```

## Repositories

You can create a new repository on an Eejit server by simply pushing an existing one. Non-admin users can only create
repos under their personal subdirectory (so for example, the user Alex above could push to `ssh://127.0.0.1:2222/alex/repo.git`
to create it).

When a new repository is created, Eejit will insert an `eejit.toml` config file into it. There, the user can specify if the repo
is public, and which other members can write to it. Here's a minimal example:

```toml
name = "Example Repo"

# Anyone can read...
public = true

# But only Alex can write...
members = ["alex"]

# Anyone else will see this message (OPTIONAL)
failed_push_message = "Patches can be emailed to alex@alex.alex"
```

## Static Site Generator

Eejit comes with a simple static site generator, which generates a webpage out of any public repository with a `README.md` file.
The generated pages are saved to the `static` directory, and reflect the repo path/name. There's a default Tera template, or
you can define your own with the `web_template` option in the repo config.
10 changes: 10 additions & 0 deletions web/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# TODO

- [x] Simple SSH Git server
- [x] Git commands only
- [x] Push to create repo
- [x] Config (global)
- [x] Config (repo)
- [x] Authentication
- [ ] Static site
- [ ] Fix fragility
1 change: 1 addition & 0 deletions web/cog.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pre_bump_hooks = ["cargo bump {{version}}"]
4 changes: 4 additions & 0 deletions web/eejit.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "Eejit"
public = true
members = ["moh"]
failed_push_message = "Issues and patches can be emailed to moh@moh.ink"
1 change: 1 addition & 0 deletions web/server.toml
6 changes: 6 additions & 0 deletions web/server_key
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-----BEGIN PRIVATE KEY-----
MHMCAQEwBQYDK2VwBEIEQHFTS6i84zsoiPP3yCVlFAPKeRT9NviOMT2w7vqTF+pM6gqHaiDbfEqt
E+7tb6fu1tHQy8fhAnbq2YbgM2J0EVahIwMhAOoKh2og23xKrRPu7W+n7tbR0MvH4QJ26tmG4DNi
dBFW

-----END PRIVATE KEY-----
2 changes: 2 additions & 0 deletions web/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod repo;
pub mod server;
54 changes: 54 additions & 0 deletions web/src/config/repo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::{
fs::{read_to_string, write},
path::{Path, PathBuf},
};

use anyhow::Context;
use serde::{Deserialize, Serialize};
use tempfile::tempdir;
use toml::Table;

use crate::{git::Repo, vars::*};

#[derive(Serialize, Deserialize)]
pub struct RepoConfig {
pub name: String,
pub public: bool,
pub members: Vec<String>,
pub failed_push_message: Option<String>,
pub web_template: Option<String>,
pub extra: Option<Table>,
}

pub async fn load_repo_config(repo_path: &Path) -> anyhow::Result<RepoConfig> {
let config_name = PathBuf::from(REPO_CONFIG_FILE);

let temp_dir = tempdir()?;
let clone_dir = temp_dir.path().join(repo_path);
Repo::clone(repo_path, &clone_dir).await?;

let text = read_to_string(clone_dir.join(&config_name)).context("Couldn't read eejit.toml")?;
Ok(toml::from_str(&text)?)
}

pub async fn new_repo_config(repo_path: &Path, username: &str) -> anyhow::Result<()> {
let config_name = PathBuf::from(REPO_CONFIG_FILE);

let temp_dir = tempdir()?;
let clone_dir = temp_dir.path().join(repo_path);
let repo = Repo::clone(repo_path, &clone_dir).await?;

let config = RepoConfig {
name: repo_path.to_str().unwrap().to_string(),
public: false,
members: vec![username.to_string()],
failed_push_message: None,
extra: None,
web_template: None,
};

let text = toml::to_string(&config)?;
write(clone_dir.join(config_name), text).context("Could not write default repo config")?;
repo.push_changes("chore: create repo config").await?;
Ok(())
}
Loading

0 comments on commit 04ea0f4

Please sign in to comment.