This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| tutorials:gopher [2012/01/28 19:41] – memnon | tutorials:gopher [2012/01/28 19:57] (current) – memnon | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Gopher ====== | ||
| + | |||
| + | Contents | ||
| + | |||
| + | - [[#What is Gopher]] | ||
| + | - [[#Creating your gopherspace]] | ||
| + | - [[#Gopher log]] | ||
| + | - [[#Dynamic content (moles)]] | ||
| + | |||
| + | ===== What is Gopher? ===== | ||
| + | |||
| + | //From:// [[http:// | ||
| + | |||
| + | > The Gopher protocol is a TCP/IP Application layer protocol designed for distributing, | ||
| + | |||
| + | You can find more info here: | ||
| + | |||
| + | * [[http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | |||
| + | ===== Creating your Gopherspace ===== | ||
| + | |||
| + | You can use the command " | ||
| + | |||
| + | You can use mkgopher to publish documents, create directories, | ||
| + | |||
| + | ==== Gophermap ==== | ||
| + | |||
| + | Say that you have " | ||
| + | |||
| + | < | ||
| + | $ ls -lF | ||
| + | drwxr-x--- | ||
| + | -rw-r----- | ||
| + | -rw-r----- | ||
| + | -rw-r----- | ||
| + | </ | ||
| + | |||
| + | When you visit it, if there is no file named gophermap (yes, this file has no extension) you'll see a list of the files and the directory, like this: | ||
| + | |||
| + | < | ||
| + | ,,, | ||
| + | Gopher Menu | ||
| + | |||
| + | (DIR) dir | ||
| + | (FILE) file1.txt | ||
| + | (FILE) file2.pdf | ||
| + | (FILE) file3.rtf | ||
| + | </ | ||
| + | |||
| + | If there is a gophermap file, the server will parse it and will present the content as you specified in gophermap. | ||
| + | |||
| + | The gophermap syntax is: | ||
| + | |||
| + | XSome text here< | ||
| + | |||
| + | where the first character (X in the example) is an itemtype (more below), "Some text here" is the text that you want to be displayed, <TAB> is a tab character, "/ | ||
| + | |||
| + | The itemtype is one of these characters: | ||
| + | |||
| + | ^ Itemtype ^ Content ^ | ||
| + | | 0 | Text file | | ||
| + | | 1 | Directory | | ||
| + | | 2 | CSO name server | | ||
| + | | 3 | Error | | ||
| + | | 4 | Mac HQX filer | | ||
| + | | 5 | PC binary | | ||
| + | | 6 | UNIX uuencoded file | | ||
| + | | 7 | Search server | | ||
| + | | 8 | Telnet Session | | ||
| + | | 9 | Binary File | | ||
| + | | c | Calendar (not in 2.06) | | ||
| + | | e | Event (not in 2.06) | | ||
| + | | g | GIF image | | ||
| + | | h | HTML, Hypertext Markup Language | | ||
| + | | i | " | ||
| + | | s | Sound | | ||
| + | | I | Image (other than GIF) | | ||
| + | | M | MIME multipart/ | ||
| + | | T | TN3270 Session/ | | ||
| + | |||
| + | === Gophermap example === | ||
| + | |||
| + | OK, let's say that you want to display a welcome message, a description for " | ||
| + | |||
| + | < | ||
| + | Welcome to my Gopherspace! | ||
| + | |||
| + | 0My text file file1.txt | ||
| + | 9My pdf file file2.pdf | ||
| + | 1My dir dir | ||
| + | </ | ||
| + | |||
| + | 0Why is Gopher Still Relevant? | ||
| + | hAn http link URL: | ||
| + | |||
| + | Remember the gophermap syntax? Then be careful about tab characters. In the example above, there are some < | ||
| + | |||
| + | 0My text file< | ||
| + | |||
| + | while the seventh is | ||
| + | |||
| + | 0Why is Gopher Still Relevant?< | ||
| + | |||
| + | How come the pdf file has an itemtype 9? Well, not every kind of file has its own itemtype, so you can use one that makes more sense. | ||
| + | |||
| + | Even if you don't need a blank line as the second line of your document, you can find this useful as there is a known Lynx bug that makes it display the second line together with the first (you can find a patch for this here: gopher:// | ||
| + | |||
| + | This is (more or less) the output you'll see if you use a gophermap like the one in the example above: | ||
| + | |||
| + | < | ||
| + | ,,, | ||
| + | Gopher Menu | ||
| + | |||
| + | | ||
| + | |||
| + | (FILE) My text file | ||
| + | (BIN) My pdf file | ||
| + | (DIR) My dir | ||
| + | |||
| + | (FILE) Why is Gopher Still Relevant? | ||
| + | (HTML) An http link | ||
| + | </ | ||
| + | |||
| + | ===== Gopher log ===== | ||
| + | |||
| + | A gopher log (" | ||
| + | |||
| + | Maintaining a glog consists basically (but not necessarily) in creating an entry (in your log directory) and modifying your phlog gophermap so that the new entry is displayed with its creation date. Here is a script that you can run on SDF-EU called mkgopherentry that will allow you to do exactly that. It will also extract the first paragraph from the entry and will add it on the gophermap with a " | ||
| + | |||
| + | <code bash> | ||
| + | #!/bin/ksh | ||
| + | |||
| + | # TODO: | ||
| + | # - make the script runable from any directory (GOPHERBLOG variable?) | ||
| + | # - if no text file, fetch it from stdin | ||
| + | # - check for 1st, 2nd and 3rd of the month and adjust the date prefix | ||
| + | # - add a full interactive mode? | ||
| + | |||
| + | if [[ -z $1 ]] || [[ -z $2 ]]; then | ||
| + | echo " | ||
| + | exit 1 | ||
| + | fi | ||
| + | |||
| + | intro=`cat $2 | awk 'BEGIN { N = 0} /^$/ {N = 1} {if (N == 0) print; | ||
| + | |||
| + | # Create an entry. | ||
| + | cat >> | ||
| + | --$1-- | ||
| + | `date "+%A, %B %dth, %Y"` | ||
| + | $intro | ||
| + | 0Continued... | ||
| + | |||
| + | EOF | ||
| + | |||
| + | # Add the old ones to its tail. | ||
| + | if [[ -f gophermap ]]; then | ||
| + | cat gophermap >> gophermap.tmp | ||
| + | fi | ||
| + | mv gophermap.tmp gophermap | ||
| + | chmod 640 gophermap $2 | ||
| + | </ | ||
| + | |||
| + | Creating an entry is as simple as typing (without the quotes): | ||
| + | |||
| + | " | ||
| + | |||
| + | where the 2 arguments are self-explaining. | ||
| + | |||
| + | Say that you have two entries in your diary. If you use " | ||
| + | |||
| + | < | ||
| + | --This is my second post!-- | ||
| + | Tuesday, December 01th, 2009 | ||
| + | Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
| + | Cras eros turpis, tristique semper aliquet sit amet, | ||
| + | hendrerit vel enim. Integer pulvinar leo in dolor posuere | ||
| + | blandit. | ||
| + | Continued... | ||
| + | |||
| + | --First post-- | ||
| + | Monday, November 30th, 2009 | ||
| + | First entry in my gopher log at SDF. | ||
| + | Continued... | ||
| + | </ | ||
| + | |||
| + | ==== Other glog/phlog software ==== | ||
| + | |||
| + | There is some software authored by SDF/SDF-EU members that you could find useful if you want to maintain a gopher log. | ||
| + | |||
| + | You can find more information in the Glogging/ | ||
| + | |||
| + | ===== Dynamic content (moles) ===== | ||
| + | |||
| + | The server used by SDF-EU (bucktooth) is able to serve moles. A mole is an executable (by the server) file with extension cgi that are //similar// to CGIs. This means that you can write a script, that the server will execute and it will present the data that your mole dumps to standard output. With moles you don't have to declare a content type header. Moles get arguments from the address used to access the document and can be accessed with whatever itemtype makes sense for the kind of output the mole generates. | ||
| + | |||
| + | You can code moles with the language(s) you are comfortable and can use on SDF-EU. Below we will see some examples using shell scripts. | ||
| + | |||
| + | ==== Mole examples ==== | ||
| + | |||
| + | Remember that your moles need to be executable (and readable) by the server. So, you will have to do: "chmod 750 YOURSCRIPT.cgi" | ||
| + | |||
| + | === cal.cgi === | ||
| + | |||
| + | The following example will generate a calendar starting weeks on Monday: | ||
| + | |||
| + | #!/bin/sh | ||
| + | cal -d 1 | ||
| + | |||
| + | Easy enough, isn't it? As it is raw text, you can access it using an itemtype = 0, | ||
| + | |||
| + | Notice that other similar commands need to be called with a full path. That's because the server' | ||
| + | |||
| + | === ls.cgi === | ||
| + | |||
| + | The following example will generate a list of files on a specified directory. It will be possible to sort the content alphabetically or by modification time, based on how you access the script. | ||
| + | |||
| + | <code bash> | ||
| + | #!/bin/sh | ||
| + | |||
| + | directory=/ | ||
| + | rel_dir=/ | ||
| + | server=sdfeu.org | ||
| + | port=70 | ||
| + | |||
| + | # The internal field separator is set to be a newline | ||
| + | IFS=' | ||
| + | ' | ||
| + | |||
| + | if [ -n " | ||
| + | ls_arg=t | ||
| + | fi | ||
| + | |||
| + | for i in $(ls -l${ls_arg} $directory) ; do | ||
| + | |||
| + | content=$(echo " | ||
| + | date=$(echo " | ||
| + | |||
| + | if [ -z " | ||
| + | continue | ||
| + | fi | ||
| + | |||
| + | if [ -d $directory/ | ||
| + | itemtype=1 | ||
| + | else | ||
| + | itemtype=0 | ||
| + | fi | ||
| + | |||
| + | echo " | ||
| + | done | ||
| + | </ | ||
| + | |||
| + | Note that the echo... line is\\ " echo " | ||
| + | |||
| + | If you go to gopher:// | ||
| + | |||
| + | === figlet.cgi === | ||
| + | |||
| + | You can add some interactivity by using the itemtype 7. This itemtype is intended to make it possible to type some characters in a search field in your browser. However, you can use it to make it possible to pass arguments to your scripts. The following example will use the text you type in the search field and will pass it through the program figlet. | ||
| + | |||
| + | <code bash> | ||
| + | #!/bin/sh | ||
| + | |||
| + | IFS=' | ||
| + | ' | ||
| + | |||
| + | for line in $(/ | ||
| + | echo " | ||
| + | done | ||
| + | </ | ||
| + | |||
| + | When you access the script via gopher:// | ||
| + | |||
| + | The i in the echo... line is important here. Indeed, the document is being accessed with an itemtype 7 (but the same applies for itemtype 1), so the document should be structured similarly to gophermaps. It's not a gophermap, though. That's why you need to explicitily state the line should be displayed as simple (or inline) text. | ||
| + | |||
| + | ==== Caveat ==== | ||
| + | |||
| + | Besides what was said in the last paragraph of the figlet.cgi example, there' | ||
| + | echo " | ||
| + | where <TAB> is a tab character (you should already know this!) and error.host and 1 are, respectively, | ||