-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
688 lines (596 loc) · 19.2 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
package main
/*
_
___ ___ ___ __ _ ___ | |
/ __/ _ \/ __|/ _` |/ _ \| |
| (_| (_) \__ \ (_| | (_) |_|
\___\___/|___/\__, |\___/(_)
|___/
https://github.com/aerth/cosgo
Contact form server. Saves to local mailbox or uses Mandrill or Sendgrid SMTP API.
*/
// The MIT License (MIT)
//
// Copyright (c) 2016 aerth
//
// 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.
import (
"errors"
"flag"
"fmt"
"log"
"math/rand"
"net"
"net/http"
"net/http/fcgi"
"net/url"
"os"
"os/signal"
"runtime"
"strconv"
"strings"
"syscall"
"time"
"github.com/aerth/cosgo/mbox"
"github.com/dchest/captcha"
"github.com/gorilla/csrf"
"github.com/gorilla/mux"
sl "github.com/hydrogen18/stoppableListener"
"github.com/microcosm-cc/bluemonday"
)
var (
mandrillKey string
sendgridKey string
cosgoDestination string
antiCSRFkey []byte
cosgoRefresh = 42 * time.Minute
err error
hitcounter int
boottime time.Time
Version = "0.7-go-get"
)
// Cosgo - This changes every [cosgoRefresh] minutes
type Cosgo struct {
PostKey string
Boottime time.Time
Static string
Templates string // Directory where templates are located. Defaults to ./templates and falls back to /usr/local/share/cosgo/templates
Dir string // Directory where we are currently located (./)
}
var cosgo = new(Cosgo)
type C struct {
CaptchaID string
}
const (
/* With these settings, the captcha string will be from 3 to 5 characters. */
// CaptchaLength is the minimum captcha string length.
CaptchaLength = 3
// Captcha will add *up to* CaptchaVariation to the CaptchaLength
CaptchaVariation = 2
CollectNum = 100
Expiration = 10 * time.Minute
StdWidth = 240
StdHeight = 90
)
//usage shows how and available flags.
func usage() {
fmt.Println("\nusage: cosgo [flags]")
fmt.Println("\nflags:")
//time.Sleep(1000 * time.Millisecond)
flag.PrintDefaults()
//time.Sleep(1000 * time.Millisecond)
fmt.Println("\nExample: cosgo -secure -port 8080 -fastcgi -debug")
}
var (
mandrillAPIUrl = "https://mandrillapp.com/api/1.0/"
)
var (
// ErrNoReferer is returned when a HTTPS request provides an empty Referer
// header.
ErrNoReferer = errors.New("referer not supplied")
// ErrBadReferer is returned when the scheme & host in the URL do not match
// the supplied Referer header.
ErrBadReferer = errors.New("referer invalid")
// ErrNoToken is returned if no CSRF token is supplied in the request.
ErrNoToken = errors.New("CSRF token not found in request")
// ErrBadToken is returned if the CSRF token in the request does not match
// the token in the session, or is otherwise malformed.
ErrBadToken = errors.New("CSRF token invalid, yo")
)
const (
localmail = "mailbox"
smtpmandrill = "mandrill"
smtpsendgrid = "sendgrid"
)
var (
// TODO: dont use flags. Will be using env/seconf only. seconf is an environmental variable based configuration system. Try cosgo -config
help = flag.Bool("help", false, "Show this and quit")
port = flag.String("port", "8080", "Port to listen on")
bind = flag.String("bind", "0.0.0.0", "Default: 0.0.0.0 (all interfaces)...\nTry -bind=127.0.0.1")
debug = flag.Bool("debug", false, "Send logs to stdout. \nDont switch to cosgo.log")
secure = flag.Bool("secure", false, "Accept only https secure cookie transfer.")
mailmode = flag.String("mailmode", localmail, "Choose one: mailbox, mandrill, sendgrid \nExample: -mailmode=mailbox")
fastcgi = flag.Bool("fastcgi", false, "Use fastcgi (for with nginx etc)")
static = flag.Bool("static", true, "Serve /static/ files. Use -static=false to disable")
files = flag.Bool("files", true, "Serve /files/ files. Use -files=false to disable")
noredirect = flag.Bool("noredirect", false, "Default is to redirect all 404s back to /. \nSet true to enable error.html template")
love = flag.Bool("love", false, "Fun. Show I love ___ instead of redirect")
config = flag.Bool("config", false, "Use config file at ~/.cosgo")
custom = flag.String("custom", "default", "Example: cosgo2 ...creates $HOME/.cosgo2")
logpath = flag.String("log", "cosgo.log", "Example: /dev/null or /var/log/cosgo/log")
quiet = flag.Bool("quiet", false, "No output to stdout. \nFor use with cron and -log flag such as: cosgo -quiet -log=/dev/null or cosgo -quiet -log=/var/log/cosgo/log")
nolog = flag.Bool("nolog", false, "No Output Whatsoever")
form = flag.Bool("form", false, "Use /page/index.html and /templates/form.html, \nsets -pages flag automatically.")
pages = flag.Bool("pages", false, "Serve /page/")
sendgridflag = flag.Bool("sendgrid", false, "Set -sendgrid to not use local mailbox. This automatically sets \"-mailmode sendgrid\"")
resolvemail = flag.Bool("resolvemail", false, "Set true to check email addresses")
custompages = flag.String("custompages", "page", "Serve pages from X dir")
mailbox = true
)
/*
*/
func main() {
// Hopefully a clean exit
interrupt := make(chan os.Signal, 1)
stop := make(chan os.Signal, 1)
reload := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
signal.Notify(stop, syscall.SIGINT)
signal.Notify(reload, syscall.SIGHUP)
go func() {
select {
case signal := <-interrupt:
fmt.Println("Got signal:", signal)
fmt.Println("Dying")
os.Exit(0)
case signal := <-reload:
fmt.Println("Got signal:", signal)
fmt.Println("Dying")
os.Exit(0)
case signal := <-stop:
fmt.Printf("Got signal:%v\n", signal)
fmt.Println("Dying")
os.Exit(0)
}
}()
// Future: dont use flags pkg
flag.Parse()
cwd, err := os.Getwd()
if err != nil {
log.Fatalln(err)
}
cosgo.Dir = cwd + "/"
// Custom refresh time
// Example: COSGOREFRESH=10m cosgo -debug
if os.Getenv("COSGOREFRESH") != "" {
cosgoRefresh, err = time.ParseDuration(os.Getenv("COSGOREFRESH"))
if err != nil {
log.Println(err.Error() + "... Using default (42m).")
cosgoRefresh = 42 * time.Minute
}
}
if runtime.GOOS == "windows" && flag.NFlag() == 0 && flag.NArg() == 0 {
fmt.Println("cosgo is running on Windows with no flags. \nThis may work, but *please* run from cmd.exe!\nClick Start -> Run, Type: cmd.exe\n\nIf this is your first run, you will see a Windows Firewall request in a moment.\nCheck all the boxes and click \"Allow access\" for typical usage. \nSince no flags were set, the default port is 8080. \nSo open up firefox and visit http:https://localhost:8080 !!!\n\n\tThank you for using cosgo!\n\t-aerth")
time.Sleep(5 * time.Second)
}
// nolog flag = no output whatsoever. Equivilent of -quiet -logpath=/dev/null
if *nolog {
*quiet = true
if runtime.GOOS == "windows" { // fix for windows soon
fmt.Println("You chose -nolog on Windows. Experimental results!")
}
*logpath = os.DevNull
}
if *custompages != "page" {
*pages = true
}
if *custom != "default" {
*config = true
}
if *custom == "default" {
*custom = "cosgorc"
}
if *sendgridflag {
*mailmode = "sendgrid"
}
if *mailmode != localmail {
mailbox = false
}
if *resolvemail {
mbox.ValidationLevel = 2
}
// -custom="anything" sets -config=true
if *custom != "cosgorc" && *config == false {
*config = true
}
// Load Configuration from seconf/secenv
if *config == true {
if *custom == "default" {
*custom = "cosgorc"
}
//fmt.Printf("Loading cosgo config: %s.\n", *custom)
if !loadConfig() {
fmt.Println("Fatal: Can't load configuration file.")
os.Exit(1)
}
// else {
// //fmt.Printf("done.")
// }
}
if !*quiet {
fmt.Println(logo)
fmt.Printf("\n\tcosgo v" + Version + "\n\tCopyright 2016 aerth\n\tSource code at https://github.com/aerth/cosgo\n")
}
if !*quiet {
func() {
opts := ""
opts = opts + "[" + *bind + ":" + *port + "]"
if *files == true {
opts = opts + "[files]"
}
if *static == true {
opts = opts + "[static]"
}
if *fastcgi == true {
opts = opts + "[fastcgi]"
}
opts = opts + "[" + *mailmode + "]"
if *pages == true {
opts = opts + "[pages]"
}
if *secure == true {
opts = opts + "[https]"
} else {
opts = opts + "[no https]"
}
if *custompages != "page" && *pages == true {
opts = opts + "[" + *custompages + "]"
}
opts = opts + "[refresh: " + cosgoRefresh.String() + "]"
fmt.Println("\t" + opts)
}()
if !*nolog {
fmt.Println("\t[logs: " + *logpath + "]")
}
if *config {
fmt.Println("\t[config: " + *custom + "]")
}
if *debug == true {
fmt.Println("\t[debug: on]")
}
fmt.Printf("\n\n")
}
args := flag.Args() // arguments that arent -flags
if len(args) > 1 {
usage()
os.Exit(1)
}
if len(os.Args) > 1 {
if os.Args[1] == "config" {
if detectConfig() {
fmt.Println("Config file already exists, use -config to read it.")
os.Exit(1)
}
loadConfig()
os.Exit(1)
}
if os.Args[1] == "help" {
usage()
os.Exit(1)
}
}
if os.Getenv("COSGOPAGEDIR") != "" {
*custompages = os.Getenv("COSGOPAGEDIR")
}
// // If user is still using CASGO_DESTINATION or CASGO_API_KEY (instead of COSGO)
// backwardsComp()
// Define antiCSRFkey with env var, or set default.
if !*config {
if os.Getenv("COSGO_CSRF_KEY") == "" && string(antiCSRFkey) == "" {
// log.Println("You can now set COSGO_CSRF_KEY environmental variable. Using default.")
antiCSRFkey = []byte("LI80PNK1xcT01jmQBsEyxyrNCrbyyFPjPU8CKnxwmCruxNijgnyb3hXXD3p1RBc0+LIRQUUbTtis6hc6LD4I/A==")
} else {
log.Println("CSRF key OK", os.Getenv("COSGO_CSRF_KEY"))
antiCSRFkey = []byte(os.Getenv("COSGO_CSRF_KEY"))
}
}
// Check templates and variables
if err = quickSelfTest(); err != nil {
log.Fatal(err.Error())
}
if os.Getenv("COSGO_API_KEY") == "" {
// The length of the POST key can be modified here.
go func() {
for {
if *debug && !*quiet {
log.Println("Info: Generating Random POST Key...")
}
cosgo.PostKey = generateAPIKey(40)
if *debug && !*quiet {
log.Printf("Info: POST Key is " + cosgo.PostKey + "\n")
}
time.Sleep(cosgoRefresh) // Internal cron!!!
}
}()
} else {
cosgo.PostKey = os.Getenv("COSGO_API_KEY")
// Print selected COSGO_API_KEY
log.Println("COSGO_API_KEY:", getKey())
}
//Begin Routing
r := mux.NewRouter()
//Redirect or show custom error?
if *noredirect == false {
r.NotFoundHandler = http.HandlerFunc(redirecthomeHandler)
} else {
r.NotFoundHandler = http.HandlerFunc(customErrorHandler)
}
r.HandleFunc("/", homeHandler)
// POST endpoint (emailHandler checks the key)
r.HandleFunc("/{{whatever}}/send", emailHandler)
// TODO: maybe allow changing static and files directory names
// TODO: mime types
//s := http.StripPrefix("/static/", http.FileServer(http.Dir("./static/")))
s := http.StripPrefix("/static/", http.FileServer(http.Dir(cosgo.Static)))
ss := http.FileServer(http.Dir(cosgo.Static))
sf := http.FileServer(http.Dir("./files/"))
sp := http.StripPrefix("/"+*custompages+"/", http.FileServer(http.Dir("./"+*custompages+"/")))
// *static defaults to true. We are serving out of /static/ for now
if *static == true {
// Serve /static folder and favicon etc
r.Methods("GET").Path("/favicon.ico").Handler(ss)
r.Methods("GET").Path("/robots.txt").Handler(ss)
r.Methods("GET").Path("/sitemap.xml").Handler(ss)
r.Methods("GET").Path("/static/{dir}/{whatever}.css").Handler(s)
r.Methods("GET").Path("/static/{dir}/{whatever}.js").Handler(s)
r.Methods("GET").Path("/static/{dir}/{whatever}.png").Handler(s)
r.Methods("GET").Path("/static/{dir}/{whatever}.jpg").Handler(s)
r.Methods("GET").Path("/static/{dir}/{whatever}.jpeg").Handler(s)
r.Methods("GET").Path("/static/{dir}/{whatever}.woff").Handler(s)
r.Methods("GET").Path("/static/{dir}/{whatever}.ttf").Handler(s)
r.Methods("GET").Path("/static/{dir}/{whatever}.txt").Handler(s)
r.Methods("GET").Path("/static/{dir}/{whatever}.mp3").Handler(s)
r.Methods("GET").Path("/static/{dir}/{whatever}.m3u").Handler(s)
r.Methods("GET").Path("/static/{dir}/{whatever}.md").Handler(s)
}
if *static == true && *files == true {
r.Methods("GET").Path("/files/{whatever}.tgz").Handler(sf)
r.Methods("GET").Path("/files/{whatever}.tar").Handler(sf)
r.Methods("GET").Path("/files/{whatever}.zip").Handler(sf)
r.Methods("GET").Path("/files/{whatever}.tar.gz").Handler(sf)
}
if *static == true && *pages == true { // No /page/index.html
r.Methods("GET").Path("/" + *custompages + "/{whatever}.html").Handler(sp)
r.Methods("GET").Path("/" + *custompages + "/{dir}/{whatever}.html").Handler(sp)
}
if *love == true {
r.HandleFunc("/{whatever}", loveHandler)
}
if *pages == true {
r.HandleFunc("/"+*custompages+"{whatever}", pageHandler)
}
// Retrieve Captcha IMG and WAV
r.Methods("GET").Path("/captcha/{captchacode}.png").Handler(captcha.Server(StdWidth, StdHeight))
r.Methods("GET").Path("/captcha/download/{captchacode}.wav").Handler(captcha.Server(StdWidth, StdHeight))
r.Methods("GET").Path("/captcha/{captchacode}.wav").Handler(captcha.Server(StdWidth, StdHeight))
http.Handle("/", r)
//End Routing
// Start Runtime Info
if *secure == false && !*quiet && *debug {
log.Println("Warning: Running in *insecure* mode.")
}
if mailbox == true {
f, err := os.OpenFile("./cosgo.mbox", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
log.Printf("error opening file: %v", err)
log.Fatal("Hint: touch ./cosgo.mbox, or chown/chmod it so that the cosgo process can access it.")
os.Exit(1)
}
mbox.Destination = cosgoDestination
mbox.Mail = log.New(f, "", 0)
}
// Right-clickable link
if *debug && !*quiet {
log.Printf("Link: " + getLink(*fastcgi, *bind, *port))
}
// Switch to cosgo.log if not debug
if *debug == false {
if !*quiet && *debug {
log.Println("[logs at " + *logpath + "]")
}
openLogFile()
}
oglistener, binderr := net.Listen("tcp", *bind+":"+*port)
if binderr != nil {
log.Println(binderr)
os.Exit(1)
}
listener, stoperr := sl.New(oglistener)
if stoperr != nil {
log.Println(stoperr)
os.Exit(1)
}
if *debug && !*quiet {
log.Printf("Info: Got listener %s %s", listener.Addr().String(), listener.Addr().Network())
}
go func() {
boottime := time.Now()
cosgo.Boottime = boottime
}()
// Start Serving Loop
for {
listener, err = sl.New(oglistener)
if err != nil {
log.Fatalln(err)
}
// Start listening in a goroutine switch case on *fastcgi and *secure
go func() {
switch *fastcgi {
case true:
switch *secure {
case false: // Fastcgi + http:https://
if listener != nil {
go fcgi.Serve(listener,
csrf.Protect(antiCSRFkey,
csrf.HttpOnly(true),
csrf.FieldName("cosgo"),
csrf.CookieName("cosgo"),
csrf.Secure(false))(r))
} else {
log.Fatalln("nil listener")
}
case true: //
if listener != nil {
go fcgi.Serve(listener,
csrf.Protect(antiCSRFkey,
csrf.HttpOnly(true),
csrf.FieldName("cosgo"),
csrf.CookieName("cosgo"),
csrf.Secure(true))(r))
} else {
log.Fatalln("nil listener")
}
}
case false:
switch *secure {
case true: // https://, no fastcgi
if listener != nil {
go http.Serve(listener,
csrf.Protect(antiCSRFkey,
csrf.HttpOnly(true),
csrf.FieldName("cosgo"),
csrf.CookieName("cosgo"), csrf.Secure(true))(r))
} else {
log.Fatalln("nil listener")
}
case false: // This is using http:https://, no fastcgi.
if listener != nil {
go http.Serve(listener,
csrf.Protect(antiCSRFkey,
csrf.HttpOnly(true),
csrf.FieldName("cosgo"),
csrf.CookieName("cosgo"),
csrf.Secure(false))(r))
} else {
log.Fatalln("nil listener")
}
}
}
}()
// End the for loop with a select loop with cosgoRefresh sleep timer.
select {
default:
if !*quiet {
log.Printf("Uptime: %s", time.Since(boottime))
log.Printf("Hits: %s", strconv.Itoa(hitcounter))
}
time.Sleep(cosgoRefresh)
}
}
}
var logo = `
_
___ ___ ___ __ _ ___ | |
/ __/ _ \/ __|/ _ |/ _ \| |
| (_| (_) \__ \ (_| | (_) |_|
\___\___/|___/\__, |\___/(_)
|___/
`
// Hello functions
func getKey() string {
return cosgo.PostKey
}
func getDestination() string {
return cosgoDestination
}
func getMandrillKey() string {
return mandrillKey
}
func parseQuery(query url.Values) *Form {
p := bluemonday.UGCPolicy()
form := new(Form)
additionalFields := ""
for k, v := range query {
k = strings.ToLower(k)
if k == "email" {
form.Email = v[0]
//} else if (k == "name") {
// form.Name = v[0]
} else if k == "subject" {
form.Subject = v[0]
form.Subject = p.Sanitize(form.Subject)
} else if k == "message" {
form.Message = k + ": " + v[0] + "<br>\n"
form.Message = p.Sanitize(form.Message)
} else if k != "cosgo" && k != "captchaid" && k != "captchasolution" {
additionalFields = additionalFields + k + ": " + v[0] + "<br>\n"
}
}
if form.Subject == "" {
form.Subject = "[New Message]"
}
if additionalFields != "" {
if form.Message == "" {
form.Message = form.Message + "Message:\n<br>" + p.Sanitize(additionalFields)
} else {
form.Message = form.Message + "\n<br>Additional:\n<br>" + p.Sanitize(additionalFields)
}
}
return form
}
func getDomain(r *http.Request) string {
type Domains map[string]http.Handler
hostparts := strings.Split(r.Host, ":")
requesthost := hostparts[0]
return requesthost
}
func getSubdomain(r *http.Request) string {
type Subdomains map[string]http.Handler
hostparts := strings.Split(r.Host, ":")
requesthost := hostparts[0]
if net.ParseIP(requesthost) == nil {
//log.Println("Info: " + requesthost)
domainParts := strings.Split(requesthost, ".")
if len(domainParts) > 2 {
if domainParts[0] != "127" {
return domainParts[0]
}
}
}
return ""
}
// Key Generator
func init() {
rand.Seed(time.Now().UnixNano())
}
var runes = []rune("____ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890123456789012345678901234567890")
//generateAPIKey does API Key Generation with the given runes.
func generateAPIKey(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = runes[rand.Intn(len(runes))]
}
return strings.TrimSpace(string(b))
}
func pgpEncode(plain string) (ciphertext string) {
ciphertext = plain
return ciphertext
}
// Copyright 2016 aerth and contributors. Source code at https://github.com/aerth/cosgo
// There should be a copy of the MIT license bundled with this software.