You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
phd/README.md

170 lines
4.9 KiB
Markdown

4 years ago
<!--
4 years ago
/ |
___ (___ ___|
| )| )| )
4 years ago
|__/ | / |__/
|
--> <p align="center"> <img src="./img/logo.png"> <br>
<a href="https://github.com/dvkt/phd/releases">
<img src="https://img.shields.io/github/v/release/dvkt/phd?include_prereleases">
</a>
</p>
4 years ago
4 years ago
`phd` is an esoteric gopher server for small gopherholes.
4 years ago
4 years ago
point it at a directory and it'll serve up all its text files,
sub-directories, and binary files over gopher. any `.gph` files will
be served up as [gopermaps][map] and executable `.gph` files will be
run as a script with their output served to the client, like cgi!
4 years ago
4 years ago
### special files:
4 years ago
4 years ago
- **header.gph**: if it exists in a directory, its content will be
shown above the directory's content. put ascii art in it.
4 years ago
- **footer.gph**: same, but will be shown below a directory's content.
4 years ago
- **index.gph**: completely replaces a directory's content with what's
in this file.
- **??.gph**: visiting gopher://yoursite/1/dog/ will try to render
4 years ago
`dog.gph` from disk.
4 years ago
- **.reverse**: if this exists, the directory contents will be listed
in reverse alphanumeric order. useful for phloggin'.
any line in a `.gph` file that doesn't contain tabs (`\t`) and doesn't
start with an `i` will get an `i` automatically prefixed, turning it
into a gopher information item.
4 years ago
### dynamic content:
4 years ago
any `.gph` file that is marked **executable** with be run as if it
were a shell script and its output will be sent to the client. it will
be passed three arguments: the query string (if any, the host, and the
port. do with them what you will.
4 years ago
4 years ago
for example:
4 years ago
4 years ago
```sh
$ cat echo.gph
#!/bin/sh
echo "Hi, world! You said:" $1
echo "1Visit Gopherpedia / gopherpedia.com 70"
```
4 years ago
4 years ago
then:
4 years ago
4 years ago
$ gopher-client gopher://localhost/1/echo?something
4 years ago
[INFO] Hi, world! You said: something
[LINK] Visit Gopherpedia
or more seriously:
4 years ago
```sh
$ cat figlet.gph
#!/bin/sh
figlet $1
```
4 years ago
then:
$ gopher-client gopher://localhost/1/figlet?hi gopher
[INFO] _ _ _
[INFO] | |__ (_) __ _ ___ _ __ | |__ ___ _ __
4 years ago
[INFO] | '_ \| | / _` |/ _ \| '_ \| '_ \ / _ \ '__|
[INFO] | | | | | | (_| | (_) | |_) | | | | __/ |
[INFO] |_| |_|_| \__, |\___/| .__/|_| |_|\___|_|
[INFO] |___/ |_|
4 years ago
4 years ago
### ruby on rails:
`sh` is fun, but for serious work you need a serious scripting
language like Ruby or PHP or Node.JS:
4 years ago
```ruby
$ cat sizes.gph
#!/usr/bin/env ruby
def filesize(file)
(size=File.size file) > (k=1024) ? "#{size/k}K" : "#{size}B"
end
puts "~ file sizes ~"
spaces = 20
Dir[__dir__ + "/*"].each do |entry|
4 years ago
name = File.basename entry
puts "#{name}#{' ' * (spaces - name.length)}#{filesize entry}"
4 years ago
end
```
4 years ago
now you can finally share the file sizes of a directory with the world
of Gopher!
$ phetch -r 0.0.0.0:7070/1/sizes
i~ file sizes ~ (null) 127.0.0.1 7070
iCargo.toml 731B (null) 127.0.0.1 7070
iLICENSE 1K (null) 127.0.0.1 7070
iMakefile 724B (null) 127.0.0.1 7070
itarget 288B (null) 127.0.0.1 7070
iphd 248K (null) 127.0.0.1 7070
iCargo.lock 2K (null) 127.0.0.1 7070
iREADME.md 4K (null) 127.0.0.1 7070
img 96B (null) 127.0.0.1 7070
isizes.gph 276B (null) 127.0.0.1 7070
isrc 224B (null) 127.0.0.1 7070
4 years ago
4 years ago
## usage
4 years ago
Usage:
phd [options] <root directory>
Options:
-p, --port Port to bind to.
-h, --host Hostname to use when generating links.
Other flags:
-h, --help Print this screen.
-v, --version Print phd version.
Examples:
4 years ago
phd ./path/to/site # Serve directory over port 7070.
phd -p 70 docs # Serve 'docs' directory on port 70
phd -h gopher.com # Serve current directory over port 7070
# using hostname "gopher.com"
4 years ago
4 years ago
## installation
binaries for linux, mac, and raspberry pi are available at
gopher://phkt.io/1/releases/phd and https://github.com/dvkt/phd/releases:
4 years ago
- [phd-v0.1.6-linux-x86_64.tar.gz][0]
- [phd-v0.1.6-linux-armv7.tar.gz (RPi)][1]
- [phd-v0.1.6-macos.zip][2]
4 years ago
just unzip/untar the `phd` program into your $PATH and get going!
4 years ago
## development
cargo run -- ./path/to/gopher/site
## resources
- https://github.com/gophernicus/gophernicus/blob/master/README.Gophermap
- https://gopher.zone/posts/how-to-gophermap/
4 years ago
- [rfc 1436](https://tools.ietf.org/html/rfc1436)
4 years ago
4 years ago
## todo
4 years ago
- [ ] script/serverless mode
4 years ago
- [ ] systemd config, or something
4 years ago
- [ ] TLS support
- [ ] man page
4 years ago
- [ ] ipv6
4 years ago
- [ ] user input sanitization tests
[0]: https://github.com/dvkt/phd/releases/download/v0.1.6/phd-v0.1.6-linux-x86_64.tar.gz
[1]: https://github.com/dvkt/phd/releases/download/v0.1.6/phd-v0.1.6-linux-armv7.tar.gz
[2]: https://github.com/dvkt/phd/releases/download/v0.1.6/phd-v0.1.6-macos.zip
4 years ago
[map]: https://en.wikipedia.org/wiki/Gopher_(protocol)#Source_code_of_a_menu