Commit 014cc8a0 authored by eenge's avatar eenge
Browse files

*** empty log message ***

parents
# CVS default ignores begin
tags
TAGS
.make.state
.nse_depinfo
*~
#*
.#*
,*
_$*
*$
*.old
*.bak
*.BAK
*.orig
*.rej
.del-*
*.a
*.olb
*.o
*.obj
*.so
*.exe
*.Z
*.elc
*.ln
core
# CVS default ignores end
Brian Mastenbrook wrote lisppaste.
Erik Enge made asdf package and some other minor stuff.
\ No newline at end of file
Copyright (c) 2003 Brian Mastenbrook
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.
# $Id$
# $Source$
clean:
find -name "*.fasl" -o -name "*.faslmt" -o -name "*~" -o -name "*.err" -o -name "*.x86f" | xargs rm
commit:
make clean; cvs up; cvs ci
;;;; $Id$
;;;; $Source$
;;;; See the LICENSE file for licensing information.
;;; README for lisppaste:
;;;
;;; lisppaste is pretty easy to get running. First, edit the top few
;;; lines of variable.lisp and change *paste-site-name* and to what's
;;; appropriate for your host. If you want to run it behind a proxying
;;; Apache (recommended), edit apache.conf.include and include that
;;; from your httpd.conf. Then, run SBCL and invoke the magical
;;; invocation as follows, or simply (load "README").
(load "lisppaste.asd")
(asdf:oos 'asdf:load-op :lisppaste)
(lisppaste:start-lisppaste :channel "#lisppaste"
:nickname "toby"
:server "irc.freenode.net"
:port 6667)
#### $Id$
#### $Source$
# To include this file, simply add:
#
# Include path/to/this/file/apache.conf.include
#
# and you are set to go.
<VirtualHost localhost:80>
ServerName localhost
ProxyPass /paste/ http://localhost:8081/paste/
ProxyPassReverse /paste/ http://localhost:8081/paste/
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
</VirtualHost>
;;;; $Id$
;;;; $Source$
;;;; See the LICENSE file for licensing information.
(in-package :lisppaste)
(defun replace-in-string (str char repstr)
(declare (type string str repstr))
(let ((stri str)
(startpos 0))
(tagbody
start
(let ((pos (position char stri :test #'char= :start startpos)))
(when pos
(setf stri (concatenate 'string (subseq stri 0 pos) repstr (subseq stri (1+ pos) (length stri))))
(setf startpos (+ pos (length repstr)))
(go start))))
stri))
(defun encode-for-pre (str)
(replace-in-string
(replace-in-string
(replace-in-string str #\& "&amp;") #\< "&lt;") #\> "&gt;"))
\ No newline at end of file
;;;; $Id$
;;;; $Source$
;;;; See the LICENSE file for licensing information.
(in-package #:cl-user)
(defpackage #:lisppaste-system
(:use #:cl #:asdf))
(in-package #:lisppaste-system)
(defsystem lisppaste
:name "lisppaste"
:author "Brian Mastenbrook"
:version "0.1.0"
:licence "MIT"
:description "A pastebot written in Common Lisp"
:long-description "lisppaste sits on a webserver and users can
paste text into it. Once pasted, lisppaste will notify a
pre-configured IRC channel about the paste and where it can be
located."
:depends-on (:araneida :net-nittin-irc)
:components ((:file "package")
(:file "variable"
:depends-on ("package"))
(:file "encode-for-pre"
:depends-on ("variable"))
(:file "web-server"
:depends-on ("encode-for-pre"))
(:file "lisppaste"
:depends-on ("web-server"))))
;;;; $Id$
;;;; $Source$
;;;; See the LICENSE file for licensing information.
(in-package :lisppaste)
(defun start-lisppaste (&key (channel *default-channel*)
(nickname *default-nickname*)
(server *default-irc-server*)
(port *default-irc-server-port*))
"Connect to specified server, join specified channel and start
accepting requests through the web."
(let ((connection (irc:connect :nickname nickname
:server server
:port port)))
(setf *connection* connection)
(irc:join connection channel)
(araneida:install-serve-event-handlers)
(irc:read-message-loop connection)))
;;;; $Id$
;;;; $Source$
;;;; See the LICENSE file for licensing information.
(in-package :cl-user)
(eval-when (:execute :load-toplevel :compile-toplevel)
(defpackage :lisppaste
(:use :cl)
(:export :start-lisppaste)))
;;;; $Id$
;;;; $Source$
;;;; See the LICENSE file for licensing information.
(in-package :lisppaste)
(defparameter *internal-http-port* 8081
"Port lisppaste will listen on for WWW requests.")
(defparameter *paste-site-name* "common-lisp.net"
"Website we are running on (used for creating links).")
(defparameter *paste-url*
(araneida:merge-url
(make-instance 'araneida:http-url
:host *paste-site-name*
:port *internal-http-port*) "/paste/"))
(defparameter *paste-external-url*
(araneida:merge-url
(make-instance 'araneida:http-url
:host *paste-site-name*) "/paste/"))
(defparameter *say-url*
(araneida:merge-url *paste-external-url* "say/"))
(defparameter *display-paste-url*
(araneida:merge-url *paste-external-url* "display/"))
(defparameter *new-paste-url*
(araneida:merge-url *paste-external-url* "new"))
(defparameter *paste-server*
(make-instance 'araneida:server
:name *paste-site-name*
:base-url *paste-url*
:port *internal-http-port*))
(defvar *default-nickname* "devpaste")
(defvar *default-irc-server* "irc.freenode.net")
(defvar *default-irc-server-port* 6667)
(defvar *default-channel* "#lisppaste")
(defvar *pastes* nil)
(defvar *paste-counter* 0)
(defvar *connection* nil)
\ No newline at end of file
;;;; $Id$
;;;; $Source$
;;;; See the LICENSE file for licensing information.
(in-package :lisppaste)
(defstruct (paste (:conc-name paste-))
(number nil :type integer)
(user nil :type string)
(title nil :type string)
(contents nil :type string)
(universal-time nil :type integer))
(defun say-handler (request rest)
(araneida:request-send-headers request)
(irc:send-irc-message *connection* :privmsg rest (channel *connection*))
(princ
(html
`(html
(head
(title "Sent!"))
(body
,(format nil "Your text was sent to ~A!" (channel *connection*)))))))
(defun display-handler (request rest)
(araneida:request-send-headers request :expires 0)
(write-sequence
(let ((pnumber (parse-integer rest :junk-allowed t)))
(if (not pnumber)
(html
`(html (head (title "Invalid paste number!"))
(body (h1 ,(format nil "The supplied paste number is not an integer.")))))
(let ((thepaste (some #'(lambda (e) (and (eql pnumber (paste-number e)) e)) *pastes*)))
(if (not thepaste)
(html
`(html (head (title "Invalid paste number!"))
(body (h1 ,(format nil "No paste numbered ~A could be found." pnumber)))))
(html
`(html (head (title ,(format nil "Paste number ~A" pnumber)))
(body (h3 ,(format nil "Paste number ~A: ~A" pnumber (encode-for-pre (paste-title thepaste))))
,(format nil "Pasted by ~A" (encode-for-pre (paste-user thepaste)))
(hr)
((pre) ,(encode-for-pre (paste-contents thepaste))))))))))
(araneida:request-stream request)))
(defun new-paste-form ()
`((form :method post :action ,(araneida:urlstring *new-paste-url*))
"Enter a username, title, and paste contents into the fields below. If you choose a unique username for your pastes then other users will be able to search for your pastes (not now)."
(hr)
"Enter your username: " ((input :type text :name username)) (br)
"Enter a title: " ((input :type text :name title)) (br)
"Enter your paste: " (br) ((textarea :rows 24 :cols 80 :name text))
(br)
((input :type submit))
((input :type reset))))
#|(defun search-paste-handler (request rest)
(request-send-headers request :expires 0)
(write-sequence
(html
`(html
(head (title "Search Pastes"))
(body
,@(let ((username-param (body-param "USERNAME" (request-body request)))
(title-param (body-param "TITLE" (request-body request)))
(text-param (body-param "TEXT" (request-body request))))
(if (not (or username-param title-param text-param))
`((h1 "Search for pastes")
`((form :method post :action ,(urlstring *search-paste-url*))
"Enter one or more of a username, title, or paste contents to search for. The searches are exact substring searches."
(hr)
"Search for a username: " ((input :type text :name username)) (br)
"Search for a title: " ((input :type text :name title)) (br)
"Search for a paste: " ((input :type text :name text)) (br)
((input :type submit))
((input :type reset)))))))))))|#
(defun new-paste-handler (request rest)
(araneida:request-send-headers request :expires 0)
(write-sequence
(html
`(html
(head (title "Paste"))
(body
,@(let ((username-param (body-param "USERNAME" (araneida:request-body request)))
(title-param (body-param "TITLE" (araneida:request-body request)))
(text-param (body-param "TEXT" (araneida:request-body request))))
(print 'hi)
(if (not username-param) ;;; We weren't supplied a paste
`((h1 "Enter your paste")
,(new-paste-form))
(if (string= username-param "")
`(((font :color red) "Please enter a valid username!")
(br)
(h1 "Enter your paste")
,(new-paste-form))
(if (or (not title-param) (string= title-param ""))
`(((font :color red) "Please enter a valid title!")
(h1 "Enter your paste")
,(new-paste-form))
(if (or (not text-param) (string= text-param ""))
`(((font :color red) "Please enter some text for your paste!")
(h1 "Enter your paste")
,(new-paste-form))
(progn
(incf *paste-counter*)
(push (make-paste :number *paste-counter*
:user username-param
:title title-param
:contents text-param
:universal-time (get-universal-time)) *pastes*)
(let ((theurl (urlstring (merge-url *display-paste-url* (prin1-to-string *paste-counter*)))))
(irc:send-irc-message connection
:privmsg (format nil "~A pasted ~A at ~A" username-param title-param theurl)
(channel connection))
`((h1 "Pasted!")
"Your paste should be available at " ((a :href ,theurl) ,theurl))))))))))))
(araneida:request-stream request)))
(araneida:export-server *paste-server*)
(araneida:export-handler *new-paste-url*
#'new-paste-handler
:method t :stage :response)
(araneida:export-handler *say-url*
#'say-handler
:match :prefix :method t :stage :response)
(araneida:export-handler *display-paste-url*
#'display-handler
:match :prefix :method t :stage :response)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment