2016-12-06 20:58:28 +01:00
|
|
|
//
|
|
|
|
// telme10
|
|
|
|
//
|
|
|
|
// Copyright (c) 2016 Christian Pointner <equinox@realraum.at>
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer in the
|
|
|
|
// documentation and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of telgo nor the names of its contributors may be
|
|
|
|
// used to endorse or promote products derived from this software without
|
|
|
|
// specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-12-06 23:05:47 +01:00
|
|
|
"os"
|
2016-12-06 22:13:56 +01:00
|
|
|
"time"
|
2016-12-07 00:24:51 +01:00
|
|
|
|
|
|
|
"github.com/coreos/go-systemd/activation"
|
|
|
|
"github.com/spreadspace/telgo"
|
2016-12-06 20:58:28 +01:00
|
|
|
)
|
|
|
|
|
2016-12-10 23:15:21 +01:00
|
|
|
func wait(length time.Duration, cancel <-chan bool) bool {
|
|
|
|
t := time.NewTimer(length)
|
|
|
|
defer t.Stop()
|
|
|
|
select {
|
|
|
|
case <-t.C:
|
|
|
|
return false
|
|
|
|
case <-cancel:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-10 23:39:45 +01:00
|
|
|
func printLogo(c *telgo.Client) {
|
2017-12-01 22:27:10 +01:00
|
|
|
for _, line := range logoBW80 {
|
2016-12-10 23:39:45 +01:00
|
|
|
c.Sayln(" " + line)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-10 23:15:21 +01:00
|
|
|
type Greeter struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g Greeter) Exec(c *telgo.Client, args []string) bool {
|
2016-12-29 19:19:07 +01:00
|
|
|
fmt.Printf("client(%s): connected\n", c.Conn.RemoteAddr())
|
2016-12-29 19:07:57 +01:00
|
|
|
|
2016-12-06 22:13:56 +01:00
|
|
|
c.Sayln("")
|
2016-12-10 23:39:45 +01:00
|
|
|
c.Sayln("")
|
|
|
|
printLogo(c)
|
|
|
|
c.Sayln("")
|
2017-12-01 22:27:10 +01:00
|
|
|
c.Sayln(" Hello there")
|
2016-12-06 22:13:56 +01:00
|
|
|
c.Sayln("")
|
|
|
|
|
2017-12-01 22:52:09 +01:00
|
|
|
if wait(5*time.Second, c.Cancel) {
|
2016-12-10 23:15:21 +01:00
|
|
|
return true
|
|
|
|
}
|
2017-12-01 22:27:10 +01:00
|
|
|
c.Sayln(" welcome to <<</>>")
|
|
|
|
c.Sayln(" your friendly tech neighborhood")
|
|
|
|
c.Sayln(" from the valley of the clueless")
|
|
|
|
c.Sayln("")
|
|
|
|
|
2017-12-01 22:52:09 +01:00
|
|
|
if wait(5*time.Second, c.Cancel) {
|
2017-12-01 22:27:10 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
c.Sayln(" we run a comfy hackspace")
|
2017-12-01 22:52:09 +01:00
|
|
|
c.Sayln(" with a peaceful community")
|
2017-12-01 22:27:10 +01:00
|
|
|
c.Sayln("")
|
|
|
|
|
2017-12-01 22:52:09 +01:00
|
|
|
if wait(3*time.Second, c.Cancel) {
|
2017-12-01 22:27:10 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
c.Sayln(" we are part of")
|
|
|
|
c.Sayln(" Chaos Computer Club")
|
|
|
|
c.Sayln(" over 10 years")
|
2016-12-06 22:13:56 +01:00
|
|
|
c.Sayln("")
|
|
|
|
|
2017-12-01 22:52:09 +01:00
|
|
|
if wait(3*time.Second, c.Cancel) {
|
2016-12-10 23:15:21 +01:00
|
|
|
return true
|
|
|
|
}
|
2016-12-10 23:39:45 +01:00
|
|
|
c.Sayln(" you should come by!")
|
2016-12-06 22:13:56 +01:00
|
|
|
c.Sayln("")
|
|
|
|
|
2016-12-10 23:15:21 +01:00
|
|
|
if wait(3*time.Second, c.Cancel) {
|
|
|
|
return true
|
|
|
|
}
|
2017-12-01 22:27:10 +01:00
|
|
|
c.Sayln(" fun on the device")
|
|
|
|
c.Sayln(" mate for days")
|
|
|
|
c.Sayln(" like minded people")
|
2016-12-06 22:13:56 +01:00
|
|
|
c.Sayln("")
|
|
|
|
|
2016-12-10 23:15:21 +01:00
|
|
|
if wait(3*time.Second, c.Cancel) {
|
|
|
|
return true
|
|
|
|
}
|
2017-12-01 22:27:10 +01:00
|
|
|
c.Sayln(" come and visit us ... we mean it!")
|
2016-12-06 22:13:56 +01:00
|
|
|
c.Sayln("")
|
2016-12-10 23:39:45 +01:00
|
|
|
c.Sayln(" you have now 10s to decide:")
|
2016-12-06 22:13:56 +01:00
|
|
|
|
2016-12-10 23:39:45 +01:00
|
|
|
c.Say(" deciding ... 0.0%%\r")
|
2016-12-10 23:15:21 +01:00
|
|
|
DECISION:
|
2016-12-06 22:13:56 +01:00
|
|
|
for i := uint(0); i < 100; i++ {
|
|
|
|
select {
|
|
|
|
case <-c.Cancel:
|
2016-12-10 23:15:21 +01:00
|
|
|
break DECISION
|
2016-12-06 22:13:56 +01:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
2016-12-10 23:39:45 +01:00
|
|
|
c.Say(" deciding ... %5.1f%%\r", (float64(i)/float64(100))*100.0)
|
2016-12-06 22:13:56 +01:00
|
|
|
}
|
2016-12-10 23:39:45 +01:00
|
|
|
c.Sayln(" deciding ... 100.0%% ... done.")
|
2016-12-06 22:13:56 +01:00
|
|
|
c.Sayln("")
|
2016-12-10 23:15:21 +01:00
|
|
|
|
2016-12-10 23:39:45 +01:00
|
|
|
c.Prompt = " are you coming? "
|
2016-12-10 23:15:21 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func answer(c *telgo.Client, args []string) bool {
|
|
|
|
if len(args) > 1 {
|
2016-12-10 23:39:45 +01:00
|
|
|
c.Sayln(" yes or no?")
|
2016-12-29 19:19:07 +01:00
|
|
|
fmt.Printf("client(%s) said: %q\n", c.Conn.RemoteAddr(), args)
|
2016-12-10 23:15:21 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
switch args[0] {
|
|
|
|
case "y":
|
|
|
|
fallthrough
|
|
|
|
case "yes":
|
|
|
|
c.Sayln("")
|
2017-12-01 22:27:10 +01:00
|
|
|
c.Sayln(" Great! We'll see you at our hackspace then.")
|
2017-02-23 15:27:14 +01:00
|
|
|
c.Sayln("")
|
2017-12-01 22:27:10 +01:00
|
|
|
c.Sayln(" expect Music, sometimes Food, Mate,")
|
2022-12-11 01:32:27 +01:00
|
|
|
c.Sayln(" Hacksessions and more")
|
2017-02-23 15:27:14 +01:00
|
|
|
c.Sayln("")
|
|
|
|
c.Sayln(" Find the place:")
|
2017-12-01 22:27:10 +01:00
|
|
|
c.Sayln(" HQ im Zentralwerk, Riesaer Straße 32, 01127 Dresden")
|
|
|
|
c.Sayln(" https://www.openstreetmap.org/way/372193022")
|
2017-02-23 15:27:14 +01:00
|
|
|
c.Sayln("")
|
|
|
|
c.Sayln(" Save the date:")
|
2017-12-01 22:27:10 +01:00
|
|
|
c.Sayln(" Chaostuesday is on Thurdays")
|
|
|
|
c.Sayln(" Chaosthursday is on Tuesdays")
|
|
|
|
c.Sayln(" https://c3d2.de/ical.ics")
|
2017-02-23 15:27:14 +01:00
|
|
|
c.Sayln("")
|
|
|
|
c.Sayln(" Get more Info:")
|
2017-12-01 22:27:10 +01:00
|
|
|
c.Sayln(" https://c3d2.de")
|
|
|
|
c.Sayln(" idle at xmpp://chat.c3d2.de/c3d2")
|
|
|
|
c.Sayln(" or irc://irc.hackint.net/#c3d2")
|
|
|
|
fmt.Printf("client(%s) wants to come to the hq!\n", c.Conn.RemoteAddr())
|
2016-12-10 23:15:21 +01:00
|
|
|
case "n":
|
|
|
|
fallthrough
|
|
|
|
case "no":
|
|
|
|
c.Sayln("")
|
2016-12-11 02:13:51 +01:00
|
|
|
c.Sayln(" Sorry to hear! You're missing out on a great experience.")
|
2017-02-23 15:27:14 +01:00
|
|
|
c.Sayln(" We trust in your ability to listen to great music and have lot's")
|
2017-12-01 22:27:10 +01:00
|
|
|
c.Sayln(" of fun with great hacks and mate at home though.")
|
2016-12-29 19:19:07 +01:00
|
|
|
fmt.Printf("client(%s) won't show up :(\n", c.Conn.RemoteAddr())
|
2016-12-10 23:15:21 +01:00
|
|
|
default:
|
2016-12-11 02:13:51 +01:00
|
|
|
c.Sayln(" yes or no?")
|
2016-12-29 19:19:07 +01:00
|
|
|
fmt.Printf("client(%s) said: %q\n", c.Conn.RemoteAddr(), args)
|
2016-12-10 23:15:21 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-12-06 22:13:56 +01:00
|
|
|
c.Sayln("")
|
2017-12-01 22:27:10 +01:00
|
|
|
c.Sayln(" https://github.com/c3d2/telme10")
|
2016-12-06 22:24:47 +01:00
|
|
|
c.Sayln("")
|
2016-12-06 22:13:56 +01:00
|
|
|
time.Sleep(1 * time.Second)
|
2016-12-06 21:56:34 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-12-06 20:58:28 +01:00
|
|
|
func main() {
|
|
|
|
cmdlist := make(telgo.CmdList)
|
|
|
|
|
2022-12-11 01:32:27 +01:00
|
|
|
listeners, err := activation.Listeners()
|
2016-12-06 23:05:47 +01:00
|
|
|
if err != nil {
|
2022-12-11 01:32:27 +01:00
|
|
|
fmt.Printf("error while getting socket form systemd: %s", err)
|
2016-12-29 19:07:57 +01:00
|
|
|
os.Exit(1)
|
2016-12-07 00:24:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var s *telgo.Server
|
|
|
|
if len(listeners) == 0 {
|
|
|
|
if len(os.Args) < 2 {
|
|
|
|
fmt.Println("please specify a address to listen on")
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
if s, err = telgo.NewServer(os.Args[1], "", cmdlist, nil); err != nil {
|
|
|
|
fmt.Println("failed to initialize the server:", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2016-12-29 19:07:57 +01:00
|
|
|
fmt.Println("running telnet server on", os.Args[1])
|
2016-12-07 00:24:51 +01:00
|
|
|
} else {
|
2016-12-29 19:07:57 +01:00
|
|
|
fmt.Printf("got %d sockets from systemd\n", len(listeners))
|
2016-12-07 00:24:51 +01:00
|
|
|
if len(listeners) > 1 {
|
|
|
|
fmt.Println("warning got more than one socket from systemd, only using the first", err)
|
|
|
|
}
|
|
|
|
if s, err = telgo.NewServerFromListener(listeners[0], "", cmdlist, nil); err != nil {
|
|
|
|
fmt.Println("failed to initialize the server:", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2016-12-29 19:07:57 +01:00
|
|
|
fmt.Println("running telnet server on", listeners[0].Addr())
|
2016-12-06 23:05:47 +01:00
|
|
|
}
|
2016-12-10 23:15:21 +01:00
|
|
|
if err = s.Run(Greeter{}, answer); err != nil {
|
2016-12-06 22:13:56 +01:00
|
|
|
fmt.Println("telnet server returned:", err)
|
2016-12-06 20:58:28 +01:00
|
|
|
}
|
|
|
|
}
|