utils

package
v0.0.0-...-0f698e2 Latest Latest
Warning

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

Go to latest
Published: May 22, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const API_KEY_apikey = "apikey"
View Source
const API_KEY_appname = "appname"
View Source
const API_KEY_clientid = "clientid"
View Source
const API_KEY_email = "email"
View Source
const API_KEY_file = "file"
View Source
const API_KEY_filename = "filename"
View Source
const API_KEY_image = "image"
View Source
const API_KEY_inviteid = "inviteid"
View Source
const API_KEY_message = "message"
View Source
const API_KEY_name = "name"
View Source
const API_KEY_pagenum = "pagenum"
View Source
const API_KEY_pagesize = "pagesize"
View Source
const API_KEY_password = "password"
View Source
const API_KEY_sequence = "sequence"
View Source
const API_KEY_startnum = "startnum"
View Source
const API_KEY_time = "time"
View Source
const API_KEY_token = "token"
View Source
const API_KEY_username = "username"
View Source
const API_URL = "http://localhost"
View Source
const API_URL_domain = "localhost"
View Source
const DB_NAME = "stunt.sqlite"
View Source
const DB_TYPE = "sqlite3"
View Source
const INVITE_VALIDITY_MS = 60 * 15 * 1000
View Source
const PATH_AddApiKey = "/apikeyadd"
View Source
const PATH_ApiKeyDelete = "/apikeydelete"
View Source
const PATH_ApiKeyDeleteConfirm = "/apikeydeleteconfirm"
View Source
const PATH_ApiKeys = "/apikeys"
View Source
const PATH_CLIENTINFO = "/sendclientinfo"
View Source
const PATH_ClientIds = "/clientids"
View Source
const PATH_ClientInfoUpdate = "/updateclientinfo"
View Source
const PATH_Login = "/login"
View Source
const PATH_MESSAGE = "/message"
View Source
const PATH_ROOT = "/"
View Source
const PATH_Register = "/register"
View Source
const PATH_Reports = "/reports"
View Source
const PATH_STATIC_TEMPLATES = "./templates"
View Source
const PATH_UPLOADFILE = "/uploadfile"
View Source
const PATH_UPLOADIMAGE = "/uploadimage"
View Source
const PATH_download = "/exports"
View Source
const PATH_filelog_delete = "/filelogdelete"
View Source
const PATH_invite = "/invite"
View Source
const PATH_logout = "/logout"
View Source
const PATH_reports_delete = "/reportsdelete"
View Source
const PATH_reports_delete_confirm = "/reportsdeleteconfirm"
View Source
const PORT_8080 = "8080"
View Source
const REPORTS_PAGE_SIZE = 100
View Source
const SALT_LENGTH = 32
View Source
const STMT_CREATE_TABLE_APIKEYS = "create table if not exists apikeys('id' integer primary key, 'userid' integer, 'apikey' text, 'appname' text)"
View Source
const STMT_CREATE_TABLE_CLIENTINFO = "" /* 128-byte string literal not displayed */
View Source
const STMT_CREATE_TABLE_INVITES = "" /* 131-byte string literal not displayed */
View Source
const STMT_CREATE_TABLE_REPORTS = "" /* 148-byte string literal not displayed */
View Source
const STMT_CREATE_TABLE_TOKENS = "" /* 128-byte string literal not displayed */
View Source
const STMT_CREATE_TABLE_USERS = "create table if not exists users('id' integer primary key, 'email' text unique, 'password' text, 'salt' text)"
View Source
const STMT_INSERT_INTO_APIKEYS = "insert or ignore into apikeys(userid, apikey, appname) values(?, ?, ?)"
View Source
const STMT_INSERT_INTO_CLIENTINFO = "insert or ignore into clientinfo%s(clientid, name, manufacturer, model, deviceid) values(?, ?, ?, ?, ?)"
View Source
const STMT_INSERT_INTO_INVITES = "insert or ignore into invites%s(inviteid, apikey, issued, expires) values(?, ?, ?, ?)"
View Source
const STMT_INSERT_INTO_REPORTS = "insert or ignore into reports%s(clientid, time, sequence, message, filepath) values(?, ?, ?, ?, ?)"
View Source
const STMT_INSERT_INTO_TOKENS = "insert or ignore into tokens(userid, token, issued, expires) values(?, ?, ?, ?)"
View Source
const STMT_INSERT_INTO_USERS = "insert or ignore into users(email, password, salt) values(?, ?, ?)"
View Source
const STR_All_clients = "All clients"
View Source
const STR_Authorization = "Authorization"
View Source
const STR_BLANK = " "
View Source
const STR_EMPTY = ""
View Source
const STR_GET = "GET"
View Source
const STR_MSG_404 = "404, Page not found"
View Source
const STR_MSG_NOTFOUND = "404 Not found"
View Source
const STR_MSG_invalidapikey = "Invalid api key"
View Source
const STR_MSG_invalidclientid = "Invalid client id"
View Source
const STR_MSG_login = "Please login"
View Source
const STR_MSG_register = "Please enter email and password"
View Source
const STR_MSG_server_error = "500 Server error"
View Source
const STR_PORT = "PORT"
View Source
const STR_POST = "POST"
View Source
const STR_error = "error"
View Source
const STR_export = "export"
View Source
const STR_filepath_download_template = "resources/exports/%s"
View Source
const STR_filepath_filelog = "resources/logs/logfile.txt"
View Source
const STR_filepath_upload_template = "resources/reportfiles/%s"
View Source
const STR_id = "id"
View Source
const STR_symbol_colon = ":"
View Source
const STR_symbol_dash = "-"
View Source
const STR_symbol_dot = "."
View Source
const STR_template_add_apikey_html = "templates/add_apikey.html"
View Source
const STR_template_apikey_deleteconfirm_html = "templates/apikey_deleteconfirm.html"
View Source
const STR_template_export_html = "templates/export.html"
View Source
const STR_template_invite_html = "templates/invite.html"
View Source
const STR_template_list_apikeys_html = "templates/list_apikeys.html"
View Source
const STR_template_list_clientids_for_apikey_html = "templates/list_clientids_for_apikey.html"
View Source
const STR_template_list_reports_for_apikey_html = "templates/list_reports_for_apikey.html"
View Source
const STR_template_page_error_html = "templates/page_error.html"
View Source
const STR_template_reports_deleteconfirm_html = "templates/reports_deleteconfirm.html"
View Source
const STR_template_result = "templates/result.json"
View Source
const STR_templates_Content_html = "templates/Page1.html"
View Source
const STR_templates_login_html = "templates/login.html"
View Source
const STR_templates_register_html = "templates/register.html"
View Source
const STR_txt = "txt"
View Source
const TABLE_APIKEYS_COLUMN_apikey = "apikey"
View Source
const TABLE_APIKEYS_COLUMN_appname = "appname"
View Source
const TABLE_APIKEYS_COLUMN_userid = "userid"
View Source
const TABLE_CLIENTINFO_clientid = "clientid"
View Source
const TABLE_CLIENTINFO_deviceid = "deviceid"
View Source
const TABLE_CLIENTINFO_manufacturer = "manufacturer"
View Source
const TABLE_CLIENTINFO_model = "model"
View Source
const TABLE_CLIENTINFO_name = "name"
View Source
const TABLE_INVITES_COLUMN_apikey = TABLE_APIKEYS_COLUMN_apikey
View Source
const TABLE_INVITES_COLUMN_expires = TABLE_TOKENS_COLUMN_expires
View Source
const TABLE_INVITES_COLUMN_inviteid = "inviteid"
View Source
const TABLE_INVITES_COLUMN_issued = TABLE_TOKENS_COLUMN_issued
View Source
const TABLE_REPORTS_COLUMN_clientid = "clientid"
View Source
const TABLE_REPORTS_COLUMN_filepath = "filepath"
View Source
const TABLE_REPORTS_COLUMN_id = STR_id
View Source
const TABLE_REPORTS_COLUMN_message = "message"
View Source
const TABLE_REPORTS_COLUMN_sequence = "sequence"
View Source
const TABLE_REPORTS_COLUMN_time = "time"
View Source
const TABLE_TOKENS_COLUMN_expires = "expires"
View Source
const TABLE_TOKENS_COLUMN_id = STR_id
View Source
const TABLE_TOKENS_COLUMN_issued = "issued"
View Source
const TABLE_TOKENS_COLUMN_token = "token"
View Source
const TABLE_TOKENS_COLUMN_userid = "userid"
View Source
const TABLE_USERS_COLUMN_email = "email"
View Source
const TABLE_USERS_COLUMN_id = STR_id
View Source
const TABLE_USERS_COLUMN_password = "password"
View Source
const TABLE_USERS_COLUMN_salt = "salt"
View Source
const TABLE_apikeys = "apikeys"
View Source
const TABLE_clientinfo = "clientinfo"
View Source
const TABLE_invites = "invites"
View Source
const TABLE_reports = "reports"
View Source
const TABLE_tokens = "tokens"
View Source
const TABLE_users = "users"
View Source
const TOKEN_VALIDITY_MS = TOKEN_VALIDITY_SECONDS * 1000
View Source
const TOKEN_VALIDITY_SECONDS = 60 * 60 * 24

Variables

View Source
var FileLog *os.File
View Source
var Letters = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
View Source
var Port string

Functions

func AddCookie

func AddCookie(responseWriter http.ResponseWriter, token string)

AddCookie adds the passed in token to the Cookie header.

func DbAddApiKey

func DbAddApiKey(aUserId int, aAppName string, aDb *sql.DB) bool

DbAddApiKey adds additional API Keys for a user. Initial API Key is added in the DbAddUser.

func DbAddClientInfo

func DbAddClientInfo(aApiKey string, aClientId string, aName string, aManufacturer string, aModel string, aDeviceId string, aDb *sql.DB) error

DbAddClientInfo adds client info to the TABLE_clientinfo for API key table.

func DbAddReport

func DbAddReport(aApiKey string, aClientId string, aTime int64, aSequence int, aMessage string, aFilePath string, aDb *sql.DB)

DbAddReport adds report to TABLE_reports for API key table.

func DbAddToken

func DbAddToken(aUserId int, aDb *sql.DB) (token string)

DbAddToken adds a token for a user to the tokens table.

func DbAddUser

func DbAddUser(aEmail string, aPassword string, aDb *sql.DB) (isUserExists bool, isUserAdded bool, errorUser error)

DbAddUser adds a user in the users table if it does not exist. ApiKey is also generated for the user.

func DbCleanTokens

func DbCleanTokens(aUserId int, aDb *sql.DB)

DbCleanTokens deletes expired token records from the TABLE_tokens table.

func DbClearClientInfo

func DbClearClientInfo(aApiKey string, aDb *sql.DB) error

DbClearClientInfo deletes all client info records from TABLE_clientinfo for API key table.

func DbClearReports

func DbClearReports(aApiKey string, aDb *sql.DB) error

DbClearReports deletes all records in the TABLE_reports for API key table.

func DbDeleteApiKey

func DbDeleteApiKey(aApiKey string, aDb *sql.DB) (isDeleted bool)

DbDeleteApiKey deletes API key from api keys table.

func DbDeleteClientInfo

func DbDeleteClientInfo(aApiKey string, aClientId string, aDb *sql.DB) (isDeleted bool)

DbDeleteClientInfo deletes client info from the TABLE_clientinfo for API Key table.

func DbDeleteReport

func DbDeleteReport(aApiKey string, aId int, aDb *sql.DB)

DbDeleteReport deletes report from TABLE_reports for API key table.

func DbDeleteUser

func DbDeleteUser(aUserId int, aDb *sql.DB) bool

Deletes a user and his apiKeys and the reports<apiKey> tables of that user.

func DbGetApiKey

func DbGetApiKey(aUserId int, aDb *sql.DB) []*objects.ApiKey

DbGetApiKey gets all apiKeys of a user.

func DbGetClientInfo

func DbGetClientInfo(aApiKey string, aClientId string, aDb *sql.DB) *objects.ClientInfo

DbGetClientInfo gets client info from the TABLE_clientinfo for an API Key.

func DbGetClientInfos

func DbGetClientInfos(aApiKey string, aDb *sql.DB) []*objects.ClientInfo

DbGetClientInfos gets all client info records from TABLE_clientinfo for API key table.

func DbGetReports

func DbGetReports(aApiKey string, aId int, aPageSize int, aDb *sql.DB) (sliceReports []*objects.Report)

DbGetReports gets all reports from TABLE_reports for API key table.

func DbGetReportsByApiKey

func DbGetReportsByApiKey(aApiKey string, aClientId string, aStartNum int, aPageSize int, aDb *sql.DB) (sliceReports []*objects.Report, endNum int)

DbGetReportsByApiKey deletes reports from TABLE_reports for API key. All records will be deleted if no clientId is supplied, otherwise only the records for the supplied clientId will be deleted.

func DbGetReportsLastPage

func DbGetReportsLastPage(aApiKey string, aClientId string, aPageSize int, aDb *sql.DB) (sliceReports []*objects.Report, count int64)

DbGetReportsLastPage gets the last records from the TABLE_reports for API key, that are in the last page according to the pagination.

func DbGetUser

func DbGetUser(aEmail string, aPassword string, aDb *sql.DB) (id int, err error)

DbGetUser gets a user record from the users table.

func DbGetUserLoad

func DbGetUserLoad(aUserId int, aDb *sql.DB) (user *objects.User, err error)

DbGetUserLoad gets a user record from the users table.

func DbInit

func DbInit() error

DbInit initalizes the database - creates tables used by the application.

func DbInviteAdd

func DbInviteAdd(aApiKey string, aDb *sql.DB) (inviteId string)

DbInviteAdd adds an invitation to TABLE_invites for API key.

func DbInviteAddApiKey

func DbInviteAddApiKey(aUserId int, aInviteId string, aApiKey string, aAppName string, aDb *sql.DB)

DbInviteAddApiKey adds an API key to a user that has been invited. The TABLE_invites for API key is queried to check if the invitation has expired and if the it exists.

func DbInviteClean

func DbInviteClean(aApiKey string, aDb *sql.DB)

DbInviteClean deletes expired invitation records from TABLE_invites for API key table.

func DbInviteCreateTable

func DbInviteCreateTable(aApiKey string, aDb *sql.DB)

DbInviteCreateTable creates TABLE_invites for API key table.

func DbIsApiKeyValid

func DbIsApiKeyValid(aApiKey string, aDb *sql.DB) (isValid bool, userId int)

DbIsApiKeyValid checks if an API Key is valid. The check is against the TABLE_apikeys table.

func DbIsTokenValid

func DbIsTokenValid(aToken string, aDb *sql.DB) (isValid bool, userId int)

DbIsTokenValid checks if a token is valid. The check is against the TABLE_tokens table.

func DbUpdateClientInfo

func DbUpdateClientInfo(aApiKey string, aClientId string, aName string, aDb *sql.DB) error

DbUpdateClientInfo updates client info in TABLE_clientinfo for API key table.

func FileLogCreate

func FileLogCreate()

FileLogCreate creates a log file to which logs can be written instead to standart output.

func GenerateRandomString

func GenerateRandomString(aLength int) string

GenerateRandomString creates a random string with the passed in length.

func GenerateToken

func GenerateToken() (string, error)

GenerateToken creates an Authentication token to be used by the web application client.

func GenerateUUID

func GenerateUUID() (string, error)

GenerateUUID creates a UUID.

func GetApiUrlInvite

func GetApiUrlInvite() string

GetApiUrlInvite gets URL to PATH_ApiKeys.

func GetApiUrlListApiKeys

func GetApiUrlListApiKeys() string

GetApiUrlListApiKeys gets URL to PATH_ApiKeys.

func GetApiUrlListClientIds

func GetApiUrlListClientIds() string

GetApiUrlListClientIds gets URL to PATH_ClientIds.

func GetCookieToken

func GetCookieToken(aRequest *http.Request) string

GetCookieToken gets the authentication token from the Cookie header.

func HandlerAddApiKey

func HandlerAddApiKey(responseWriter http.ResponseWriter, request *http.Request)

HandlerAddApiKey handles access to PATH_AddApiKey.

func HandlerApiKeyDelete

func HandlerApiKeyDelete(responseWriter http.ResponseWriter, request *http.Request)

HandlerApiKeyDelete handles access to PATH_ApiKeyDelete.

func HandlerApiKeyDeleteConfirm

func HandlerApiKeyDeleteConfirm(responseWriter http.ResponseWriter, request *http.Request)

HandlerApiKeyDeleteConfirm handles access to PATH_ApiKeyDeleteConfirm.

func HandlerApiKeys

func HandlerApiKeys(responseWriter http.ResponseWriter, request *http.Request)

HandlerApiKeys handles access to PATH_ApiKeys.

func HandlerClientIds

func HandlerClientIds(responseWriter http.ResponseWriter, request *http.Request)

HandlerClientIds handles access to PATH_ClientIds.

func HandlerClientInfoSend

func HandlerClientInfoSend(responseWriter http.ResponseWriter, request *http.Request)

HandlerClientInfoSend handles access to PATH_CLIENTINFO.

func HandlerClientInfoUpdate

func HandlerClientInfoUpdate(responseWriter http.ResponseWriter, request *http.Request)

HandlerClientInfoUpdate handles access to PATH_ClientInfoUpdate.

func HandlerDownload

func HandlerDownload(aResponseWriter http.ResponseWriter, aRequest *http.Request)

HandlerDownload handles access to PATH_download.

func HandlerFileLogDelete

func HandlerFileLogDelete(aResponseWriter http.ResponseWriter, aRequest *http.Request)

HandlerFileLogDelete handles access to PATH_filelog_delete.

func HandlerInviteCreate

func HandlerInviteCreate(responseWriter http.ResponseWriter, request *http.Request)

HandlerInviteCreate handles access to PATH_invite.

func HandlerLogin

func HandlerLogin(responseWriter http.ResponseWriter, request *http.Request)

HandlerLogin handles access to PATH_Login.

func HandlerLogout

func HandlerLogout(responseWriter http.ResponseWriter, request *http.Request)

HandlerLogout handles access to PATH_logout.

func HandlerMessage

func HandlerMessage(aResponseWriter http.ResponseWriter, aRequest *http.Request)

HandlerMessage handles access to PATH_MESSAGE.

func HandlerRegister

func HandlerRegister(responseWriter http.ResponseWriter, request *http.Request)

HandlerRegister handles access to PATH_Register.

func HandlerReports

func HandlerReports(responseWriter http.ResponseWriter, request *http.Request)

HandlerReports handles access to PATH_Reports.

func HandlerReportsClear

func HandlerReportsClear(aResponseWriter http.ResponseWriter, aRequest *http.Request)

HandlerReportsClear handles access to PATH_reports_delete.

func HandlerReportsClearConfirm

func HandlerReportsClearConfirm(aResponseWriter http.ResponseWriter, aRequest *http.Request)

HandlerReportsClearConfirm handles access to PATH_reports_delete_confirm.

func HandlerRoot

func HandlerRoot(aResponseWriter http.ResponseWriter, aRequest *http.Request)

HandlerRoot handles access to "/" (root) path.

func HandlerUploadFile

func HandlerUploadFile(aResponseWriter http.ResponseWriter, aRequest *http.Request)

HandlerUploadFile handles access to PATH_UPLOADFILE.

func HandlerUploadImage

func HandlerUploadImage(aResponseWriter http.ResponseWriter, aRequest *http.Request)

HandlerUploadImage handles access to PATH_UPLOADIMAGE.

func HashSha1

func HashSha1(aValue string) (string, error)

HashSha1 hashes the passed in string value using sha1 hash.

func IsApiKeyValid

func IsApiKeyValid(aApiKey string) (isValid bool, userId int)

IsApiKeyValid validates the passed in API key against the database.

func IsTokenValid

func IsTokenValid(responseWriter http.ResponseWriter, request *http.Request) bool

IsTokenValid validates the token obtained from the Cookie header, against the database.

func ServeAddApiKey

func ServeAddApiKey(responseWriter http.ResponseWriter)

ServeAddApiKey serves add API key page to web portal clients.

func ServeError

func ServeError(aResponseWriter http.ResponseWriter, aMessage string, aTemplateFilePath string)

ServeError serves error HTML page to web portal clients.

func ServeLogin

func ServeLogin(responseWriter http.ResponseWriter, message string)

ServeLogin serves login page to web portal clients.

func ServeRegister

func ServeRegister(responseWriter http.ResponseWriter, message string)

ServeRegister serves register page to web portal clients.

func ServeResult

func ServeResult(aResponseWriter http.ResponseWriter, aResult *objects.Result, aTemplateFilePath string)

ServeResult serves result response to report clients.

Types

This section is empty.

Jump to

Keyboard shortcuts

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