rscore

package
v0.0.0-...-81c28c1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ALEV_ADMIN = 2 // BOFH
View Source
const ALEV_CONTRIB = 1 // Contributor
View Source
const ALEV_USER = 0 // Regular user

User level definitions

View Source
const BPMAX = 8 // Max number of bullet points for lists
View Source
const BPMIN = 3 // Min number of bullet points for lists
View Source
const BPOINTMAX = 20 // Max length for bullet point
View Source
const BTEXTMAX = 80 // Max length for body text
View Source
const CU_CPASS = 2 // Password change request
View Source
const CU_MKADM = 0 // Makes specified user admin

Operation codes for user handling

View Source
const CU_PWDRS = 4 // Requests password reset email
View Source
const CU_RMADM = 1 // Removes admin status from user
View Source
const CU_RMUSR = 3 // Removes user account
View Source
const C_ALEV = 7 // User does not have sufficient access level
View Source
const C_IEMA = 12 // Invalid email address
View Source
const C_NLOG = 6 // User not logged in
View Source
const C_NOBJ = 14 // No such database object
View Source
const C_NOSU = 5 // No such user
View Source
const C_NSOP = 9 // No such operation
View Source
const C_NTAG = 8 // No tags provided
View Source
const C_OK = 0 // OK

Status response codes sent to client

View Source
const C_UICH = 4 // Username includes illegal characters
View Source
const C_UIDB = 3 // User already exists in database
View Source
const C_UNKN = 10 // Unknown error
View Source
const C_UNTS = 15 // User name too short
View Source
const C_USPW = 11 // Unsafe password
View Source
const C_WEMA = 13 // Incorrect email address
View Source
const C_WRFF = 1 // Incorrect file format
View Source
const C_WRSZ = 2 // Not able to classify image size
View Source
const DBNAME = "./data/rs.db" // Database location (change at own peril)
View Source
const DEFAULTPORT = 6291 // Port can also be supplied with -p flag
View Source
const FBFILE = "./data/fb.txt" // Storage of feedback data
View Source
const IMGDIR = "./static/img/" // Image directory
View Source
const IMG_BO = 2 // Box-shaped
View Source
const IMG_LS = 1 // Landscape
View Source
const IMG_PO = 3 // Portrait
View Source
const IMG_XL = 0 // X Large

Image type classifications

View Source
const LOGPATH = "./static/log/" // Logs should be accessible from frontend
View Source
const L_REQ = 0 // Request log

Logging codes parsed by Addlog()

View Source
const L_RESP = 1 // Response log
View Source
const L_SHUTDOWN = 2 // Server shutdown request log
View Source
const PIDFILEPATH = "./data/" // Base directory for storage of PID file
View Source
const PWMINLEN = 6 // Minimum accepted lendth of password
View Source
const RFNLEN = 20 // Length of random file names (w/o .ext)
View Source
const RNUMBMAX = 30 // Random number base max
View Source
const RNUMEMAX = 3 // Random number exponent max
View Source
const RPWDLEN = 15 // Length of random generated passwords
View Source
const SKEYLEN = 40 // # of characters in a session key
View Source
const STYPES = 8 // Number of slide types available
View Source
const THDIR = "./static/css/themes/" // CSS theme file directory
View Source
const TTEXTMAX = 35 // Max length for title text
View Source
const UNMINLEN = 2 // Minimum accepted lendth of user names
View Source
const VERBDEF = false // Verbose mode defaults to false

Variables

View Source
var ALLSUF = []int{0, 1, 2, 3}

Data object including references to all IKEYs

View Source
var BBUC = []byte("bbuc") // Body text bucket
View Source
var DBUC = []byte("dbuc") // Deck bucket
View Source
var IBUC = []byte("ibuc") // Image bucket
View Source
var IMGMAX = [][]uint{
	{1920, 1080},
	{1920, 1080},
	{1080, 1080},
	{1080, 1920},
}

Max bounds for image sizes (w, h)

View Source
var IMGMIME = []string{
	"image/jpeg",
	"image/png",
	"image/gif",
}

For verification of image mime types

View Source
var IMGMIN = [][]uint{
	{1920, 1080},
	{640, 360},
	{360, 360},
	{360, 480},
}

Min bounds for image sizes (w, h)

View Source
var INDEX = []byte(".index") // Untouchable database index position
View Source
var ISZINDEX = [][]int{
	{0, 1},
	{0},
	{0},
	{3},
	{1, 2, 3},
	{},
	{1, 2, 3},
	{},
}

Image size per slide type reference chart TODO map with TT & BT bools

View Source
var NUMPREF = []byte("$+-") // Potential number prefixes for slide type 2
View Source
var NUMSUFF = []byte("%!?") // Potential number suffixes for slide type 2
View Source
var RXTAGS = "[^a-zåäöüæø]+" // Regex for allowed tags
View Source
var RXUSER = "[^a-z0-9]+" // Regex for allowed user names
View Source
var SBUC = []byte("sbuc") // Settings bucket
View Source
var SPROB = []int{2, 6, 3, 4, 9, 6, 5, 4}

Probability chart for slide occurance. Higher number = higher probability.

View Source
var SUFINDEX = []string{
	".s0",
	".s1",
	".s2",
	".s3",
}

Index keys to be used for image size indexes

View Source
var Smut sync.Mutex // Settings mutex
View Source
var TBUC = []byte("tbuc") // Title text bucket
View Source
var TINDEX = []byte(".tindex") // Untouchable database tag index position
View Source
var UBUC = []byte("ubuc") // User bucket

Functions

func Addlog

func Addlog(ltype int, msg []byte, llev int, u User, r *http.Request)

Log file wrapper

func Addtagsuf

func Addtagsuf(tags []string, suf []string) []string

Adds tag suffixes and returns new tag list

func Appendfile

func Appendfile(fname string, str string)

Appends str to file at fname

func Cherr

func Cherr(e error) error

Log all errors to file

func Cleanstring

func Cleanstring(src string, pat string) string

Removes whitespace and special characters from string

func Cp

func Cp(s string, d string) (int64, error)

Makes a hard copy of a file on the file system

func Findstrinslice

func Findstrinslice(v string, list []string) bool

Returns true if string is present in list

func Formattags

func Formattags(s string) []string

Transforms whitespace separated string to tag slice

func Identicalbs

func Identicalbs(s1 []byte, s2 []byte) bool

Compares two byte slices, returs true if identical

func Initlog

func Initlog(prgname string)

Initialize logger

func Prettyfsize

func Prettyfsize(b int64) string

Convert file size to human readable format

func Randstr

func Randstr(ln int) string

Returns random sting with length ln

func Rmall

func Rmall(dir string)

Removes all files residing in dir (except .gitkeep)

func Rmdupstrfslice

func Rmdupstrfslice(list []string) []string

Removes duplicate strings from slice

func Rmifrslice

func Rmifrslice(n int, s []int) ([]int, bool)

Removes int from slice if present returns 1 if action taken

func Sendstatus

func Sendstatus(code int, text string, w http.ResponseWriter)

Sends a status code response as JSON object

func Sendtagstatus

func Sendtagstatus(r int, w http.ResponseWriter)

Wrapper for tag status responses

func Shutdown

func Shutdown(settings Settings)

Enables clean shutdown. Needs delay for caller to send response

func Sighandler

func Sighandler(settings Settings)

Setting up signal handler

func Striptagsuf

func Striptagsuf(stags []string) []string

Removes all tag suffixes and returns 'clean' list

func Valuser

func Valuser(u User, pass []byte) bool

Returns true if user password validates

func Wrdatafile

func Wrdatafile(fnp string, sf io.Reader) error

Writes raw data to file

Types

type Apicall

type Apicall struct {
	User   string // User name
	Pass   string // Password
	Email  string // Email address
	Skey   string // Session key
	Tuser  string // Target user
	Tags   string // Tags
	Lang   string // Languge code, 'en', 'de', 'se', etc
	Id     string // Deck ID request
	Slide  string // Slide number for reference
	Amount string // Amount of slides requested
	Ttext  string // Title test
	Btext  string // Body test
	Msg    string // Feedback text
	Bpoint string // Bullet point
	Rop    string // Raw (unprocessed) operation
	Wipe   string // Request to wipe database
	Type   string // Object type reference
}

type Deck

type Deck struct {
	Id     int     // Deck ID for db
	N      int     // Total number of slides in deck
	Lang   string  // Languge code, 'en', 'de', 'se', etc
	Slides []Slide // Slice of Slide objects
}

type Deckreq

type Deckreq struct {
	Id      int      // Deck ID for db
	N       int      // Number of slides to generate
	Lang    string   // Languge code, 'en', 'de', 'se', etc
	Tags    []string // Slice of tags on which to base search
	Isidreq bool     // true if request has specified ID
}

type Hfn

type Hfn func(http.ResponseWriter, *http.Request, *bolt.DB)

Launcher of handle functions

type Iindex

type Iindex struct {
	Ids []int // All IDs associated with tag
}

type Imgobj

type Imgobj struct {
	Id    int      // Index number
	Fname string   // File name
	Tags  []string // All tags where object exists (for associative decks)
	Size  int      // S (0), M (1), L (2) or XL (3)
	Contr string   // Image object contributor
	H     int      // Image height
	W     int      // Image width
}

type Login

type Login struct {
	Name string // User name
	Skey string // Session key
	Alev int    // Access level
}

type Rtag

type Rtag struct {
	Name string // Tag name
	TN   int    // Number of title objects in db
	BN   int    // Number of body objects in db
	IN   int    // Number of image objects in db
}

type Settings

type Settings struct {
	Llev    int      // Log level
	Dmax    int      // Max id of decks
	Tmax    int      // Max id of title objects
	Bmax    int      // Max id of body objects
	Imax    int      // Max id of image objects
	Umax    int      // Max user ID in database
	Pidfile string   // Location of pidfile
	Taglist []string // List of all existing tags
	Smtp    Smtp     // Settings for sending email
}
var Set Settings // Global rsserver settings

func Mkpidfile

func Mkpidfile(settings Settings, prgname string, pid int) Settings

Creating PID file

func Rsinit

func Rsinit(settings Settings) Settings

Creates pid file, signal handler and starts logging

type Slide

type Slide struct {
	Type  int      // See CONTRIBUTING.md for type chart
	Title string   // Slide title
	Btext string   // Body text
	Bpts  []string // Bullet points
	Dpts  []int    // Graph data points
	Ctype int      // Chart type
	Img   Imgobj   // Image object
}

type Slidetype

type Slidetype struct {
	Type int   // The type ID number
	TT   bool  // Includes title text
	BT   bool  // Includes body text
	IMG  []int // Image size preferences
}

type Smtp

type Smtp struct {
	Admin  string // Admin email address
	Server string // Which server to connect to
	User   string // User account for logging in
	Pass   string // Password for user auth
	Port   int    // Server port
}

type Statusresp

type Statusresp struct {
	Code int    // Error code to be parsed in frontend
	Text string // Additional related data
}

type Tagresp

type Tagresp struct {
	Tags []Rtag // Array of tags for indexing
}

type Textobj

type Textobj struct {
	Id    int      // Index number
	Text  string   // The text itself
	Tags  []string // All tags where object exists (for associative decks)
	Contr string   // Text object contributor
}

type Textreq

type Textreq struct {
	Ttext  string   // Title text object to add to db
	Btext  string   // Body text object to add to db
	Bpoint string   // Bullet points for making lists
	Tags   []string // Tags for indexing
}

type Thindex

type Thindex struct {
	Themes []string // Theme filenames
}

type Uindex

type Uindex struct {
	Names []string // All user names in database
}

type User

type User struct {
	Name  string // Username
	Pass  []byte // Password hash
	Email string // Email address
	Skey  string // Session key
	Alev  int    // Access level
}

Jump to

Keyboard shortcuts

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