Skip to content

Commit

Permalink
working proof of concept
Browse files Browse the repository at this point in the history
  • Loading branch information
someodd committed Mar 5, 2024
0 parents commit fe11500
Show file tree
Hide file tree
Showing 16 changed files with 1,332 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dist-newstyle/
*.swp
dashboard
querytest.log
result/
result
gopherdashboard-deb/
*.deb
gopherdashboard-*.zip
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

...

### Fixed

...

### Changed

...

## [0.1.0.0] - 2024-03-04

First release, a proof of concept.

[unreleased]: https://github.com/someodd/gopherden/compare/v0.1.0.0...HEAD
[0.1.0.0]: https://github.com/someodd/gopherden/release/v0.1.0.0
209 changes: 209 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# gopherden: Gopher Protocol BBS

An anonymous, ephemeral text bulletin board system for the Gopher Protocol written in Haskell.

## Try it out

Run the server:

```
cabal run . -- launch
```

Visit the gopherhole:

```
gopher -p "/" localhost 7000
```

Here are some commands related to banning:

* `cabal run . -- ban --post 1 --delete --reason "rule violation"`: ban user for post #1 and delete said post for the `--reason` supplied.
* `cabal run . -- unban --ip someipv6addr`: remove the ipv6 address from the ban table

## Features

* View threads as an ASCII-art text file
* Navigate the board as a menu
* Post threads and replies
* Ban system

## Features probably coming soon

* Currently has a `Config.hs` with many configurable parameters. Coming soon is a config
file to set these parameters. This also allows for internationalization. This config
file will also allow you to set some server parameters.
* Text wrapping
* Captcha-like system
* Build with nix
* Debian package + systemd daemon
4 changes: 4 additions & 0 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import CLI

main :: IO ()
main = entryPoint
65 changes: 65 additions & 0 deletions gopherden.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.36.0.
--
-- see: https://github.com/sol/hpack

name: gopherden
version: 0.5.0.0
description: Please see the README on GitHub at <https://github.com/someodd/gopherden#readme>
homepage: https://github.com/someodd/gopherden#readme
bug-reports: https://github.com/someodd/gopherden/issues
author: Someodd
maintainer: someodd@pm.me
copyright: 2024 Someodd
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
CHANGELOG.md

source-repository head
type: git
location: https://github.com/someodd/gopherden

executable gopherden-exe
main-is: Main.hs
other-modules:
Paths_gopherden
hs-source-dirs:
app
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
base,
gopherden,
spacecookie
default-language: GHC2021

library
exposed-modules:
Config,
Database,
Handle,
Server,
MenuViews,
MenuBuild,
TextViews,
TextBuild,
ViewHelpers,
CLI
other-modules:
Paths_gopherden
hs-source-dirs:
src
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints
build-depends:
base,
spacecookie,
optparse-applicative,
bytestring,
postgresql-simple,
regex-posix,
time
default-language: GHC2021
--default-language: Haskell2010
77 changes: 77 additions & 0 deletions src/CLI.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{- | Command line interface.
-}
{-# LANGUAGE OverloadedStrings #-}

module CLI (entryPoint) where

import Server (runServer)
import Database (banIP, unbanIP, listBannedIPs)

import Options.Applicative

-- Some say partials are bad, but I'm lazy and I frankly just generate a lot of the CLI stuff.
data Command
= LaunchServer
| BanIP { postId :: Integer, reason :: String, deletePost :: Bool }
| UnbanIP { ipAddr :: String }
| ListBans

parseListBans :: Parser Command
parseListBans = pure ListBans

parseLaunchServer :: Parser Command
parseLaunchServer = pure LaunchServer

parseUnbanIP :: Parser Command
parseUnbanIP = UnbanIP
<$> strOption
( long "ip"
<> metavar "IPADDRESS"
<> help "IP address to unban" )

parseBanIP :: Parser Command
parseBanIP = BanIP
<$> option auto
( long "post"
<> metavar "POSTID"
<> help "ID of the post associated with the IP to ban" )
<*> strOption
( long "reason"
<> metavar "REASON"
<> help "Reason for banning the IP" )
<*> switch
( long "delete"
<> help "Delete the post as well as banning the IP" )

entryPoint :: IO ()
entryPoint = runCLI =<< execParser opts
where
opts = info (commands <**> helper)
( fullDesc
<> progDesc "Run server or ban an IP"
<> header "server-cli - a simple CLI for managing your server" )

commands :: Parser Command
commands = subparser
( command "launch" (info parseLaunchServer (progDesc "Launch the server"))
<> command "ban" (info parseBanIP (progDesc "Ban an IP by post ID"))
<> command "unban" (info parseUnbanIP (progDesc "Unban an IP address"))
<> command "list_bans" (info parseListBans (progDesc "List all banned IPs"))
)

runCLI :: Command -> IO ()
runCLI LaunchServer = runServer
runCLI (BanIP postId reason delete) = do
putStrLn $ "Banning IP for post: " ++ show postId ++ " for reason: " ++ reason
banIP postId reason delete
putStrLn "Done."
runCLI (UnbanIP ipAddr) = do
putStrLn $ "Unbanning IP: " ++ ipAddr
unbanIP ipAddr
putStrLn "IP unbanned successfully."
runCLI ListBans = do
putStrLn "Listing all banned IPs:"
bannedIPs <- listBannedIPs
mapM_ (\(ip, reason) -> putStrLn $ ip ++ " - " ++ reason) bannedIPs

Loading

0 comments on commit fe11500

Please sign in to comment.