Compare commits

..

No commits in common. 'master' and 'v0.1.10' have entirely different histories.

@ -49,17 +49,17 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Cache cargo registry
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

@ -13,17 +13,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Cache cargo registry
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
@ -57,17 +57,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Cache cargo registry
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
@ -90,17 +90,17 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Cache cargo registry
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

@ -1,44 +1,3 @@
## v0.1.15
- Update `alphanumeric-sort` dependency so `cargo install phd` works again.
- Recommend `cargo install phd --locked` in the README
## v0.1.14
- If the `NO_COLOR` env variable is set, colors won't be printed to
the log. Same as starting with `--no-color`.
See https://no-color.org/.
## v0.1.13
- Added `--no-color` command line option to not display color when
logging.
- Slight change to binding behavior: if `-p` is passed without `-b`,
we'll try to bind to that port. To this easier: `phd -p 7777`
- Accept `?` as query string indicator, not just `TAB`. See #3.
## v0.1.12
`phd` now uses `-b` and `--bind` to set the host and port to
bind to. `-p` and `-h` are now strictly for URL generation.
This should hopefully make it easier to run `phd` behind a
proxy and still generate proper links.
Thanks to @bradfier for the patch!
## v0.1.11
`phd` now ships with a basic manual!
It will be installed via homebrew and (eventually) AUR.
For now you can view it by cloning the repository and running:
man ./doc/phd.1
Enjoy!
## v0.1.10
`phd` can now render a single page to stdout, instead of starting

42
Cargo.lock generated

@ -1,74 +1,74 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "alphanumeric-sort"
version = "1.4.4"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77e9c9abb82613923ec78d7a461595d52491ba7240f3c64c0bbe0e6d98e0fce0"
[[package]]
name = "content_inspector"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7bda66e858c683005a53a9a60c69a4aca7eeaa45d124526e389f7aec8e62f38"
dependencies = [
"memchr",
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "hermit-abi"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f629dc602392d3ec14bfc8a09b5e644d7ffd725102b48b81e59f90f2633621d7"
dependencies = [
"libc",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
[[package]]
name = "memchr"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
[[package]]
name = "num_cpus"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72"
dependencies = [
"hermit-abi",
"libc",
"hermit-abi 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "phd"
version = "0.1.15"
version = "0.1.10"
dependencies = [
"alphanumeric-sort",
"content_inspector",
"shell-escape",
"threadpool",
"alphanumeric-sort 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"content_inspector 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"shell-escape 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "shell-escape"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "170a13e64f2a51b77a45702ba77287f5c6829375b04a69cf2222acd17d0cfab9"
[[package]]
name = "threadpool"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865"
dependencies = [
"num_cpus",
"num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum alphanumeric-sort 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f37ce94154d73f6961f87571a3ab7814e1608f373bd55a933e3e771b6dd59fc4"
"checksum content_inspector 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b7bda66e858c683005a53a9a60c69a4aca7eeaa45d124526e389f7aec8e62f38"
"checksum hermit-abi 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f629dc602392d3ec14bfc8a09b5e644d7ffd725102b48b81e59f90f2633621d7"
"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
"checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72"
"checksum shell-escape 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "170a13e64f2a51b77a45702ba77287f5c6829375b04a69cf2222acd17d0cfab9"
"checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865"

@ -1,6 +1,6 @@
[package]
name = "phd"
version = "0.1.15"
version = "0.1.10"
authors = ["chris west <c@xvxx.io>"]
license = "MIT"
edition = "2018"
@ -22,11 +22,11 @@ opt-level = 'z' # Optimize for size.
pre-release-replacements = [
{file="README.md", search="phd-v\\d+\\.\\d+\\.\\d+-", replace="{{crate_name}}-v{{version}}-"},
{file="README.md", search="/v\\d+\\.\\d+\\.\\d+/", replace="/v{{version}}/"},
{file="CHANGELOG.md", search="\\d+\\.\\d+\\.\\d+-dev", replace="{{version}}"},
]
dev-version-ext = "dev"
[dependencies]
content_inspector = "0.2.4"
threadpool = "1.7.1"
alphanumeric-sort = "1.4"
alphanumeric-sort = "1.0.11"
shell-escape = "0.1.4"

@ -34,15 +34,3 @@ $(RELEASE): $(SOURCES)
# Build the debug version
$(DEBUG): $(SOURCES)
cargo build
# Build manual
.PHONY: manual
manual: doc/phd.1
doc/phd.1: doc/phd.1.md scdoc
scdoc < doc/phd.1.md > doc/phd.1
# Must have scdoc installed to build manual.
scdoc:
@which scdoc || (echo "scdoc(1) not found."; \
echo "please install to build the manual: https://repology.org/project/scdoc"; exit 1)

@ -25,7 +25,7 @@
Point it at a directory and it'll serve up all the text files,
sub-directories, and binary files over Gopher. Any `.gph` files will
be served up as [gophermaps][map] and executable `.gph` files will be
be served up as [gopermaps][map] and executable `.gph` files will be
run as a program with their output served to the client, like the
glorious cgi-bin days of yore!
@ -139,10 +139,8 @@ of Gopher!
Options:
-r, --render SELECTOR Render and print SELECTOR to stdout only.
-h, --host HOST Hostname for links. [Default: {host}]
-p, --port PORT Port for links. [Default: {port}]
-b, --bind ADDRESS Socket address to bind to. [Default: {bind}]
--no-color Don't show colors in log messages.
-p, --port Port to bind to. [Default: {port}]
-h, --host Hostname for links. [Default: {host}]
Other flags:
@ -166,15 +164,15 @@ On macOS you can install with [Homebrew](https://brew.sh/):
Binaries for Linux, Mac, and Raspberry Pi are available at
gopher://phkt.io/1/releases/phd and https://github.com/xvxx/phd/releases:
- [phd-v0.1.15-linux-x86_64.tar.gz][0]
- [phd-v0.1.15-linux-armv7.tar.gz (Raspberry Pi)][1]
- [phd-v0.1.15-macos.zip][2]
- [phd-v0.1.10-linux-x86_64.tar.gz][0]
- [phd-v0.1.10-linux-armv7.tar.gz (Raspberry Pi)][1]
- [phd-v0.1.10-macos.zip][2]
Just unzip/untar the `phd` program into your `$PATH` and get going!
If you have **[cargo][rustup]**, you can install the crate directly:
cargo install phd --locked
cargo install phd
## ~ development ~
@ -191,15 +189,13 @@ If you have **[cargo][rustup]**, you can install the crate directly:
- [ ] systemd config, or something
- [ ] TLS support
- [ ] man page
- [ ] ipv6
- [ ] user input sanitization tests
## ~ status ~
phd is no longer under active development, but the latest version works great.
[0]: https://github.com/xvxx/phd/releases/download/v0.1.15/phd-v0.1.15-linux-x86_64.tar.gz
[1]: https://github.com/xvxx/phd/releases/download/v0.1.15/phd-v0.1.15-linux-armv7.tar.gz
[2]: https://github.com/xvxx/phd/releases/download/v0.1.15/phd-v0.1.15-macos.zip
[0]: https://github.com/xvxx/phd/releases/download/v0.1.10/phd-v0.1.10-linux-x86_64.tar.gz
[1]: https://github.com/xvxx/phd/releases/download/v0.1.10/phd-v0.1.10-linux-armv7.tar.gz
[2]: https://github.com/xvxx/phd/releases/download/v0.1.10/phd-v0.1.10-macos.zip
[map]: https://en.wikipedia.org/wiki/Gopher_(protocol)#Source_code_of_a_menu
[gmi]: http://r-36.net/scm/geomyidae/
[rustup]: https://rustup.rs

@ -1,206 +0,0 @@
.\" Generated by scdoc 1.11.0
.\" Complete documentation for this program is not available as a GNU info page
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.nh
.ad l
.\" Begin generated content:
.TH "PHD" "1" "2020-06-27"
.P
.SH NAME
.P
phd - an estoeric gopher server
.P
.SH SYNOPSIS
.P
\fBphd\fR [\fIOPTIONS\fR] [\fISITE ROOT\fR]
.P
.SH DESCRIPTION
.P
\fBphd\fR is a small, easy-to-use gopher server.
.P
Point it at a directory and it'll serve up all the text files,
sub-directories, and binary files over Gopher. Any \fB.gph\fR files will
be served up as Gophermaps and executable \fB.gph\fR files will be
run as a program with their output served to the client, like the
glorious cgi-bin days of yore!
.P
Usually \fBphd\fR is started with a path to your Gopher site:
.P
.RS 4
phd /srv/gopher
.P
.RE
If no path is given, \fBphd\fR will use the current directory as the root
of your Gopher site.
.P
.SH OPTIONS
.P
\fB-r\fR \fISELECTOR\fR, \fB--render\fR \fISELECTOR\fR
.P
.RS 4
Rather than start as a server, render the \fISELECTOR\fR of the site using the options provided and print the raw response to \fBSTDOUT\fR.
.P
.RE
\fB-b\fR \fIADDRESS\fR, \fB--bind\fR \fIADDRESS\fR
.RS 4
Set the socket address to bind to, e.g. \fB127.0.0.1:7070\fR
.P
.RE
\fB-p\fR \fIPORT\fR, \fB--port\fR \fIPORT\fR
.RS 4
Set the \fIPORT\fR to use when generating Gopher links.
.P
.RE
\fB-h\fR \fIHOST\fR, \fB--host\fR \fIHOST\fR
.RS 4
Set the \fIHOST\fR to use when generating Gopher links.
.P
.RE
\fB-h\fR, \fB--help\fR
.RS 4
Print a help summary and exit.
.P
.RE
\fB-v\fR, \fB--version\fR
.RS 4
Print version information and exit.
.P
.RE
.SH SPECIAL FILES
.P
The following files have special behavior when present in a directory
that \fBphd\fR is tasked with serving:
.P
\fBheader.gph\fR
.RS 4
If it exists in a directory, its content will be shown above the directory's content. Put ASCII art in it.
.P
.RE
\fBfooter.gph\fR
.RS 4
Same, but will be shown below a directory's content.
.P
.RE
\fBindex.gph\fR
.RS 4
Completely replaces a directory's content with what's in this file.
.P
.RE
\fB??.gph\fR
.RS 4
Visiting \fBgopher://yoursite/1/dog/\fR will try to render \fBdog.gph\fR from disk. Visiting \fB/1/dog.gph\fR will render the raw content of the .gph file.
.P
.RE
\fB.reverse\fR
.RS 4
If this exists, the directory contents will be listed in reverse alphanumeric order. Useful for phloggin', if you date your posts.
.P
.RE
.SH GOPHERMAP SYNTAX
.P
Any line in a \fB.gph\fR file that doesn't contain tabs (\fBt\fR) will get an
\fBi\fR automatically prefixed, turning it into a Gopher information item.
.P
For your convenience, phd supports \fBgeomyidae\fR syntax for
creating links:
.P
.nf
.RS 4
This is an info line\&.
[1|This is a link|/help|server|port]
[h|URL Link|URL:https://noogle\&.com]
.fi
.RE
.P
\fBserver\fR and \fBport\fR will get translated into the server and port of
the actively running server, eg \fBlocalhost\fR and \fB7070\fR.
.P
Any line containing a tab character (\fBt\fR) will be sent as-is to the
client, meaning you can write and serve up raw Gophermap files too.
.P
.SH DYNAMIC CONTENT
.P
Any \fB.gph\fR file that is marked \fBexecutable\fR with be run as if it
were a standalone program and its output will be sent to the client.
It will be passed three arguments: the query string (if any), the
server's hostname, and the current port. Do with them what you will.
.P
For example:
.P
.nf
.RS 4
$ cat echo\&.gph
#!/bin/sh
echo "Hi, world! You said:" $1
echo "1Visit Gopherpedia / gopherpedia\&.com 70"
.fi
.RE
.P
Then:
.P
.nf
.RS 4
$ gopher-client gopher://localhost/1/echo?something
[INFO] Hi, world! You said: something
[LINK] Visit Gopherpedia
.fi
.RE
.P
Or more seriously:
.P
.nf
.RS 4
$ cat figlet\&.gph
#!/bin/sh
figlet $1
.fi
.RE
.P
then:
.P
.nf
.RS 4
$ gopher-client gopher://localhost/1/figlet?hi gopher
[INFO] _ _ _
[INFO] | |__ (_) __ _ ___ _ __ | |__ ___ _ __
[INFO] | '_ | | / _` |/ _ | '_ | '_ / _ '__|
[INFO] | | | | | | (_| | (_) | |_) | | | | __/ |
[INFO] |_| |_|_| __, |___/| \&.__/|_| |_|___|_|
[INFO] |___/ |_|
.fi
.RE
.P
.SS RESOURCES
.P
geomyidae source code
.RS 4
gopher://bitreich.org/1/scm/geomyidae/files.gph
.P
.RE
Example Gophermap
.RS 4
https://github.com/gophernicus/gophernicus/blob/master/README.Gophermap
.P
.RE
Gophermaps
.RS 4
https://gopher.zone/posts/how-to-gophermap/
.P
.RE
RFC 1436:
.RS 4
https://tools.ietf.org/html/rfc1436
.P
.RE
.SH ABOUT
.P
\fBphd\fR is maintained by chris west and released under the MIT license.
.P
phd's Gopher hole:
.RS 4
\fIgopher://phkt.io/1/phd\fR
.RE
phd's webpage:
.RS 4
\fIhttps://github.com/xvxx/phd\fR

@ -1,154 +0,0 @@
PHD(1)
# NAME
phd - an estoeric gopher server
# SYNOPSIS
*phd* [_OPTIONS_] [_SITE ROOT_]
# DESCRIPTION
*phd* is a small, easy-to-use gopher server.
Point it at a directory and it'll serve up all the text files,
sub-directories, and binary files over Gopher. Any *.gph* files will
be served up as Gophermaps and executable *.gph* files will be
run as a program with their output served to the client, like the
glorious cgi-bin days of yore!
Usually *phd* is started with a path to your Gopher site:
phd /srv/gopher
If no path is given, *phd* will use the current directory as the root
of your Gopher site.
# OPTIONS
*-r* _SELECTOR_, *--render* _SELECTOR_
Rather than start as a server, render the _SELECTOR_ of the site using the options provided and print the raw response to *STDOUT*.
*-b* _ADDRESS_, *--bind* _ADDRESS_
Set the socket address to bind to, e.g. *127.0.0.1:7070*
*-p* _PORT_, *--port* _PORT_
Set the _PORT_ to use when generating Gopher links.
*-h* _HOST_, *--host* _HOST_
Set the _HOST_ to use when generating Gopher links.
*-h*, *--help*
Print a help summary and exit.
*-v*, *--version*
Print version information and exit.
# SPECIAL FILES
The following files have special behavior when present in a directory
that *phd* is tasked with serving:
*header.gph*
If it exists in a directory, its content will be shown above the directory's content. Put ASCII art in it.
*footer.gph*
Same, but will be shown below a directory's content.
*index.gph*
Completely replaces a directory's content with what's in this file.
*??.gph*
Visiting *gopher://yoursite/1/dog/* will try to render *dog.gph* from disk. Visiting */1/dog.gph* will render the raw content of the .gph file.
*.reverse*
If this exists, the directory contents will be listed in reverse alphanumeric order. Useful for phloggin', if you date your posts.
# GOPHERMAP SYNTAX
Any line in a *.gph* file that doesn't contain tabs (*\t*) will get an
*i* automatically prefixed, turning it into a Gopher information item.
For your convenience, phd supports *geomyidae* syntax for
creating links:
```
This is an info line.
[1|This is a link|/help|server|port]
[h|URL Link|URL:https://noogle.com]
```
*server* and *port* will get translated into the server and port of
the actively running server, eg *localhost* and *7070*.
Any line containing a tab character (*\t*) will be sent as-is to the
client, meaning you can write and serve up raw Gophermap files too.
# DYNAMIC CONTENT
Any *.gph* file that is marked *executable* with be run as if it
were a standalone program and its output will be sent to the client.
It will be passed three arguments: the query string (if any), the
server's hostname, and the current port. Do with them what you will.
For example:
```
$ cat echo.gph
#!/bin/sh
echo "Hi, world! You said:" $1
echo "1Visit Gopherpedia / gopherpedia.com 70"
```
Then:
```
$ gopher-client gopher://localhost/1/echo?something
[INFO] Hi, world! You said: something
[LINK] Visit Gopherpedia
```
Or more seriously:
```
$ cat figlet.gph
#!/bin/sh
figlet $1
```
then:
```
$ gopher-client gopher://localhost/1/figlet?hi gopher
[INFO] _ _ _
[INFO] | |__ (_) __ _ ___ _ __ | |__ ___ _ __
[INFO] | '_ \| | / _` |/ _ \| '_ \| '_ \ / _ \ '__|
[INFO] | | | | | | (_| | (_) | |_) | | | | __/ |
[INFO] |_| |_|_| \__, |\___/| .__/|_| |_|\___|_|
[INFO] |___/ |_|
```
## RESOURCES
geomyidae source code
gopher://bitreich.org/1/scm/geomyidae/files.gph
Example Gophermap
https://github.com/gophernicus/gophernicus/blob/master/README.Gophermap
Gophermaps
https://gopher.zone/posts/how-to-gophermap/
RFC 1436:
https://tools.ietf.org/html/rfc1436
# ABOUT
*phd* is maintained by chris west and released under the MIT license.
phd's Gopher hole:
_gopher://phkt.io/1/phd_
phd's webpage:
_https://github.com/xvxx/phd_

@ -5,24 +5,7 @@
//! println!("{}Error: {}{}", color::Red, "Something broke.", color::Reset);
//! ```
use std::{
fmt,
sync::atomic::{AtomicBool, Ordering as AtomicOrdering},
};
/// Whether to show colors or not.
/// Defaults to true.
static SHOW_COLORS: AtomicBool = AtomicBool::new(true);
/// Hide colors.
pub fn hide_colors() {
SHOW_COLORS.swap(false, AtomicOrdering::Relaxed);
}
/// Are we showing colors are not?
pub fn showing_colors() -> bool {
SHOW_COLORS.load(AtomicOrdering::Relaxed)
}
use std::fmt;
macro_rules! color {
($t:ident, $code:expr) => {
@ -30,11 +13,7 @@ macro_rules! color {
pub struct $t;
impl fmt::Display for $t {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if showing_colors() {
write!(f, "\x1b[{}m", $code)
} else {
write!(f, "")
}
write!(f, "\x1b[{}m", $code)
}
}
};

@ -1,7 +1,6 @@
use phd;
use std::process;
const DEFAULT_BIND: &str = "[::]:7070";
const DEFAULT_HOST: &str = "127.0.0.1";
const DEFAULT_PORT: u16 = 7070;
@ -9,16 +8,13 @@ fn main() {
let args = std::env::args().skip(1).collect::<Vec<_>>();
let mut args = args.iter();
let mut root = ".";
let mut addr = DEFAULT_BIND;
let mut host = DEFAULT_HOST;
let mut port = DEFAULT_PORT;
let mut render = "";
while let Some(arg) = args.next() {
match arg.as_ref() {
"--version" | "-v" | "-version" => return print_version(),
"--help" | "-help" => return print_help(),
"--no-color" | "-no-color" => phd::color::hide_colors(),
"--render" | "-render" | "-r" => {
if let Some(path) = args.next() {
render = path;
@ -26,11 +22,6 @@ fn main() {
render = "/";
}
}
"--bind" | "-b" | "-bind" => {
if let Some(a) = args.next() {
addr = a
}
}
"--port" | "-p" | "-port" => {
if let Some(p) = args.next() {
port = p
@ -65,18 +56,6 @@ fn main() {
}
}
// https://no-color.org/
if std::env::var("NO_COLOR").is_ok() {
phd::color::hide_colors()
}
// If port was given and socket wasn't, bind to that port.
let bind = if port != DEFAULT_PORT && addr == DEFAULT_BIND {
format!("[::]:{}", port).parse().unwrap()
} else {
addr.parse().unwrap()
};
if !render.is_empty() {
return match phd::server::render(host, port, root, &render) {
Ok(out) => print!("{}", out),
@ -84,7 +63,7 @@ fn main() {
};
}
if let Err(e) = phd::server::start(bind, host, port, root) {
if let Err(e) = phd::server::start(host, port, root) {
eprintln!("{}", e);
}
}
@ -98,10 +77,8 @@ fn print_help() {
Options:
-r, --render SELECTOR Render and print SELECTOR to stdout only.
-h, --host HOST Hostname for links. [Default: {host}]
-p, --port PORT Port for links. [Default: {port}]
-b, --bind ADDRESS Socket address to bind to. [Default: {bind}]
--no-color Don't show colors in log messages.
-p, --port Port to bind to. [Default: {port}]
-h, --host Hostname for links. [Default: {host}]
Other flags:
@ -118,7 +95,6 @@ Examples:
",
host = DEFAULT_HOST,
port = DEFAULT_PORT,
bind = DEFAULT_BIND,
);
}

@ -51,11 +51,7 @@ impl Request {
pub fn parse_request(&mut self, line: &str) {
self.query.clear();
self.selector.clear();
if let Some((i, _)) = line
.chars()
.enumerate()
.find(|&(_, c)| c == '\t' || c == '?')
{
if let Some(i) = line.find('\t') {
if line.len() > i {
self.query.push_str(&line[i + 1..]);
self.selector.push_str(&line[..i]);

@ -5,12 +5,11 @@ use std::{
cmp::Ordering,
fs::{self, DirEntry},
io::{self, prelude::*, BufReader, Read, Write},
net::{SocketAddr, TcpListener, TcpStream},
net::{TcpListener, TcpStream},
os::unix::fs::PermissionsExt,
path::Path,
process::Command,
str,
sync::atomic::{AtomicBool, Ordering as AtomicOrdering},
};
use threadpool::ThreadPool;
@ -24,6 +23,8 @@ const MAX_PEEK_SIZE: usize = 1024;
/// Files not displayed in directory listings.
const IGNORED_FILES: [&str; 3] = ["header.gph", "footer.gph", ".reverse"];
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
/// Whether to print info!() messages to stdout.
/// Defaults to true.
static SHOW_INFO: AtomicBool = AtomicBool::new(true);
@ -49,8 +50,9 @@ macro_rules! info {
}
/// Starts a Gopher server at the specified host, port, and root directory.
pub fn start(bind: SocketAddr, host: &str, port: u16, root: &str) -> Result<()> {
let listener = TcpListener::bind(&bind)?;
pub fn start(host: &str, port: u16, root: &str) -> Result<()> {
let addr = format!("{}:{}", "0.0.0.0", port);
let listener = TcpListener::bind(&addr)?;
let full_root_path = fs::canonicalize(&root)?.to_string_lossy().to_string();
let pool = ThreadPool::new(MAX_WORKERS);
@ -59,7 +61,7 @@ pub fn start(bind: SocketAddr, host: &str, port: u16, root: &str) -> Result<()>
color::Yellow,
color::Reset,
color::Yellow,
bind,
addr,
color::Reset,
color::Blue,
full_root_path,
@ -410,10 +412,7 @@ fn sort_paths(dir_path: &str, reverse: bool) -> Result<Vec<DirEntry>> {
let a_is_dir = is_dir(a);
let b_is_dir = is_dir(b);
if a_is_dir && b_is_dir || !a_is_dir && !b_is_dir {
let ord = alphanumeric_sort::compare_os_str::<&Path, &Path>(
a.path().as_ref(),
b.path().as_ref(),
);
let ord = alphanumeric_sort::compare_os_str(a.path().as_ref(), b.path().as_ref());
if reverse {
ord.reverse()
} else {

Loading…
Cancel
Save