utils

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2015 License: AGPL-3.0, Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MODE_DEV        = "dev"
	MODE_BETA       = "beta"
	MODE_PROD       = "prod"
	LOG_ROTATE_SIZE = 10000
)
View Source
const (
	DIAGNOSTIC_URL = "https://d7zmvsa9e04kk.cloudfront.net"

	PROP_DIAGNOSTIC_ID                = "id"
	PROP_DIAGNOSTIC_CATEGORY          = "c"
	VAL_DIAGNOSTIC_CATEGORY_DEFAULT   = "d"
	PROP_DIAGNOSTIC_BUILD             = "b"
	PROP_DIAGNOSTIC_DATABASE          = "db"
	PROP_DIAGNOSTIC_OS                = "os"
	PROP_DIAGNOSTIC_USER_COUNT        = "uc"
	PROP_DIAGNOSTIC_ACTIVE_USER_COUNT = "auc"
)
View Source
const (
	ALPHANUMERIC = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
	LOWERCASE    = "abcdefghijklmnopqrstuvwxyz"
)
View Source
const GIBBERISH_TEXT = `` /* 9068-byte string literal not displayed */

Lovely giberish for all to use

Variables

View Source
var CfgFileName string = ""
View Source
var CfgLastModified int64 = 0
View Source
var ClientProperties map[string]string = map[string]string{}
View Source
var FUZZY_STRINGS_EMAILS = []string{
	"sue@thatmightbe",
	"sue@thatmightbe.c",
	"sue@thatmightbe.co",
	"su+san@thatmightbe.com",
	"1@2.am",
	"a@b.co.uk",
	"a@b.cancerresearch",
	"su+s+an@thatmightbe.com",
	"per.iod@thatmightbe.com",
}

Strings that should pass as acceptable emails

View Source
var FUZZY_STRINGS_NAMES = []string{
	"*",
	"?",
	".",
	"}{][)(><",
	"{}[]()<>",

	"qahwah ( قهوة)",
	"שָׁלוֹם עֲלֵיכֶם",
	"Ramen チャーシュー chāshū",
	"言而无信",
	"Ṫ͌ó̍ ̍͂̓̍̍̀i̊ͯ͒",
	"&amp; &lt; &qu",

	"' or '1'='1' -- ",
	"' or '1'='1' ({ ",
	"' or '1'='1' /* ",
	"1;DROP TABLE users",

	"<b><i><u><strong><em>",

	"sue@thatmightbe",
	"sue@thatmightbe.",
	"sue@thatmightbe.c",
	"sue@thatmightbe.co",
	"sue @ thatmightbe.com",
	"apos'trophe@thatmightbe.com",
	"apos''''trophe@thatmightbe.com",
	"su+san@thatmightbe.com",
	"su+s+an@thatmightbe.com",
	"per.iod@thatmightbe.com",
	"per..iods@thatmightbe.com",
	".period@thatmightbe.com",
	"tom(comment)@thatmightbe.com",
	"(comment)tom@thatmightbe.com",
	"\"quotes\"@thatmightbe.com",
	"\"\\\"(),:;<>@[\\]\"@thatmightbe.com",
	"a!#$%&'*+-/=?^_`{|}~b@thatmightbe.com",
	"local@[127.0.0.1]",
	"jill@(comment)example.com",
	"jill@example.com(comment)",
	"a@b.中国",
	"1@2.am",
	"a@b.co.uk",
	"a@b.cancerresearch",

	"<a href=\"//www.google.com\">Teh Googles</a>",
	"<img src=\"//upload.wikimedia.org/wikipelogo-v2_2x.png\" />",
	"<b><i><u><strong><em>",
	"&amp; &lt; &quot; &apos;",

	";alert('Well this is awkward.');",
	"<script type='text/javascript'>alert('yay puppies');</script>",

	"Ṫ͌ó̍ ̍͂̓̍̍̀i̊ͯ͒nͧ̍̓̃͋v",
	"H҉̵̞̟̠̖̗̘Ȅ̐̐̑̒̚OMI҉̵̞̟̠",
}

Strings that should pass as acceptable team names

View Source
var FUZZY_STRINGS_POSTS = []string{
	"*", "?", ".", "}{][)(><", "{}[]()<>",

	"qahwah ( قهوة)",
	"שָׁלוֹם עֲלֵיכֶם",
	"Ramen チャーシュー chāshū",
	"言而无信",
	"Ṫ͌ó̍ ̍͂̓̍̍̀i̊ͯ͒",
	"&amp; &lt; &qu",

	"' or '1'='1' -- ",
	"' or '1'='1' ({ ",
	"' or '1'='1' /* ",
	"1;DROP TABLE users",

	"<b><i><u><strong><em>",

	"sue@thatmightbe",
	"sue@thatmightbe.",
	"sue@thatmightbe.c",
	"sue@thatmightbe.co",
	"su+san@thatmightbe.com",
	"a@b.中国",
	"1@2.am",
	"a@b.co.uk",
	"a@b.cancerresearch",
	"local@[127.0.0.1]",

	"!@$%^&:*.,/|;'\"+=?`~#",
	"'\"/\\\"\"''\\/",
	"gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg",
	"gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg",
	"ą ć ę ł ń ó ś ź ż č ď ě ň ř š ť ž ă î ø å æ á é í ó ú Ç Ğ İ Ö Ş Ü",
	"abcdefghijklmnopqrstuvwrxyz0123456789 -_",
	"Ṫ͌ó̍ ̍͂̓̍̍̀i̊ͯ͒nͧ̍̓̃͋vok̂̓ͤ̓̂ěͬ ͆tͬ̐́̐͆h̒̏͌̓e͂ ̎̊h̽͆ͯ̄ͮi͊̂ͧͫ̇̃vͥͦ́ẻͤ-͒m̈́̀i̓ͮ͗̑͌̆̅n̓̓ͨd̊̑͛̔̚ ͨͮ̊̾rͪeͭͭ͑ͧ́͋p̈́̅̚rͧe̒̈̌s̍̽ͩ̓̇e͗n̏͊ͬͭtͨ͆ͤ̚iͪ͗̍n͐͒g̾ͦ̎ ͥ͌̽̊ͩͥ͗c̀ͬͣha̍̏̉ͪ̈̚o̊̏s̊̋̀̏̽̚.͒ͫ͛͛̎ͥ",
	"H҉̵̞̟̠̖̗̘Ȅ̐̑̒̚̕̚ IS C̒̓̔̿̿̿̕̚̚̕̚̕̚̕̚̕̚̕̚OMI҉̵̞̟̠̖̗̘NG > ͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿̿̚ ҉ ҉҉̡̢̡̢̛̛̖̗̘̙̜̝̞̟̠̖̗̘̙̜̝̞̟̠̊̋̌̍̎̏̐̑̒̓̔̊̋̌̍̎̏̐̑ ͡҉҉",

	"<a href=\"//www.google.com\">Teh Googles</a>",
	"<img src=\"//upload.wikimedia.org/wikipedia/meta/b/be/Wikipedia-logo-v2_2x.png\" />",
	"&amp; &lt; &quot; &apos;",
	" %21 %23 %24 %26 %27 %28 %29 %2A	%2B	%2C	%2F	%3A	%3B	%3D	%3F	%40	%5B	%5D %0D %0A %0D%0A %20 %22 %25 %2D %2E %3C %3E %5C %5E %5F %60 %7B %7C %7D %7E",

	";alert('Well this is awkward.');",
	"<script type='text/javascript'>alert('yay puppies');</script>",

	"http?q=foobar%0d%0aContent-\nLength:%200%0d%0a%0d%0aHTTP/1.1%20200%20OK%0d%0aContent-\nType:%20text/html%0d%0aContent-Length:%2019%0d%0a%0d%0a<html>Shazam</html>",

	"apos'trophe@thatmightbe.com",
	"apos''''trophe@thatmightbe.com",
	"su+s+an@thatmightbe.com",
	"per.iod@thatmightbe.com",
	"per..iods@thatmightbe.com",
	".period@thatmightbe.com",
	"tom(comment)@thatmightbe.com",
	"(comment)tom@thatmightbe.com",
	"\"quotes\"@thatmightbe.com",
	"\"\\\"(),:;<>@[\\]\"@thatmightbe.com",
	"a!#$%&'*+-/=?^_`{|}~b@thatmightbe.com",
	"jill@(comment)example.com",
	"jill@example.com(comment)",
	"ben@ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg.com",
	"judy@gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg.com",
	"ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg@AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.com",
}

Strings that should pass as acceptable posts

View Source
var SanitizeOptions map[string]bool = map[string]bool{}

Functions

func ConfigureCmdLineLog

func ConfigureCmdLineLog()

func FindConfigFile

func FindConfigFile(fileName string) string

func FindDir

func FindDir(dir string) string

func FireAndForgetSendAppleNotify

func FireAndForgetSendAppleNotify(deviceId string, message string, badge int)

func FuzzEmail

func FuzzEmail() string

func FuzzName

func FuzzName() string

func FuzzPost

func FuzzPost() string

func GetLogFileLocation

func GetLogFileLocation(fileLocation string) string

func LoadConfig

func LoadConfig(fileName string)

LoadConfig will try to search around for the corresponding config file. It will search /tmp/fileName then attempt ./config/fileName, then ../config/fileName and last it will look at fileName

func RandIntFromRange

func RandIntFromRange(r Range) int

func RandString

func RandString(l int, charset string) string

func RandomEmail

func RandomEmail(length Range, charset string) string

func RandomName

func RandomName(length Range, charset string) string

func RandomText

func RandomText(length Range, hashtags Range, mentions Range, users []string) string

Random selection of text for post

func SaveConfig

func SaveConfig(fileName string, config *model.Config) *model.AppError

func SendAppleNotify

func SendAppleNotify(deviceId string, message string, badge int) *model.AppError

func SendDiagnostic added in v1.1.0

func SendDiagnostic(values url.Values)

func SendMail

func SendMail(to, subject, body string) *model.AppError

func SendMailUsingConfig

func SendMailUsingConfig(to, subject, body string, config *model.Config) *model.AppError

func TestConnection added in v1.1.0

func TestConnection(config *model.Config)

func UrlEncode

func UrlEncode(str string) string

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a thread-safe fixed size LRU cache.

func NewLru

func NewLru(size int) *Cache

New creates an LRU of the given size

func NewLruWithEvict

func NewLruWithEvict(size int, onEvicted func(key interface{}, value interface{})) (*Cache, error)

func (*Cache) Add

func (c *Cache) Add(key, value interface{}) bool

func (*Cache) AddWithExpiresInSecs

func (c *Cache) AddWithExpiresInSecs(key, value interface{}, expireAtSecs int64) bool

Add adds a value to the cache. Returns true if an eviction occured.

func (*Cache) Get

func (c *Cache) Get(key interface{}) (value interface{}, ok bool)

Get looks up a key's value from the cache.

func (*Cache) Keys

func (c *Cache) Keys() []interface{}

Keys returns a slice of the keys in the cache, from oldest to newest.

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of items in the cache.

func (*Cache) Purge

func (c *Cache) Purge()

Purge is used to completely clear the cache

func (*Cache) Remove

func (c *Cache) Remove(key interface{})

Remove removes the provided key from the cache.

func (*Cache) RemoveOldest

func (c *Cache) RemoveOldest()

RemoveOldest removes the oldest item from the cache.

type Range

type Range struct {
	Begin int
	End   int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL