Documentation ¶
Index ¶
- Constants
- Variables
- func AddCookie(responseWriter http.ResponseWriter, token string)
- func DbAddApiKey(aUserId int, aAppName string, aDb *sql.DB) bool
- func DbAddClientInfo(aApiKey string, aClientId string, aName string, aManufacturer string, ...) error
- func DbAddReport(aApiKey string, aClientId string, aTime int64, aSequence int, aMessage string, ...)
- func DbAddToken(aUserId int, aDb *sql.DB) (token string)
- func DbAddUser(aEmail string, aPassword string, aDb *sql.DB) (isUserExists bool, isUserAdded bool, errorUser error)
- func DbCleanTokens(aUserId int, aDb *sql.DB)
- func DbClearClientInfo(aApiKey string, aDb *sql.DB) error
- func DbClearReports(aApiKey string, aDb *sql.DB) error
- func DbDeleteApiKey(aApiKey string, aDb *sql.DB) (isDeleted bool)
- func DbDeleteClientInfo(aApiKey string, aClientId string, aDb *sql.DB) (isDeleted bool)
- func DbDeleteReport(aApiKey string, aId int, aDb *sql.DB)
- func DbDeleteUser(aUserId int, aDb *sql.DB) bool
- func DbGetApiKey(aUserId int, aDb *sql.DB) []*objects.ApiKey
- func DbGetClientInfo(aApiKey string, aClientId string, aDb *sql.DB) *objects.ClientInfo
- func DbGetClientInfos(aApiKey string, aDb *sql.DB) []*objects.ClientInfo
- func DbGetReports(aApiKey string, aId int, aPageSize int, aDb *sql.DB) (sliceReports []*objects.Report)
- func DbGetReportsByApiKey(aApiKey string, aClientId string, aStartNum int, aPageSize int, aDb *sql.DB) (sliceReports []*objects.Report, endNum int)
- func DbGetReportsLastPage(aApiKey string, aClientId string, aPageSize int, aDb *sql.DB) (sliceReports []*objects.Report, count int64)
- func DbGetUser(aEmail string, aPassword string, aDb *sql.DB) (id int, err error)
- func DbGetUserLoad(aUserId int, aDb *sql.DB) (user *objects.User, err error)
- func DbInit() error
- func DbInviteAdd(aApiKey string, aDb *sql.DB) (inviteId string)
- func DbInviteAddApiKey(aUserId int, aInviteId string, aApiKey string, aAppName string, aDb *sql.DB)
- func DbInviteClean(aApiKey string, aDb *sql.DB)
- func DbInviteCreateTable(aApiKey string, aDb *sql.DB)
- func DbIsApiKeyValid(aApiKey string, aDb *sql.DB) (isValid bool, userId int)
- func DbIsTokenValid(aToken string, aDb *sql.DB) (isValid bool, userId int)
- func DbUpdateClientInfo(aApiKey string, aClientId string, aName string, aDb *sql.DB) error
- func FileLogCreate()
- func GenerateRandomString(aLength int) string
- func GenerateToken() (string, error)
- func GenerateUUID() (string, error)
- func GetApiUrlInvite() string
- func GetApiUrlListApiKeys() string
- func GetApiUrlListClientIds() string
- func GetCookieToken(aRequest *http.Request) string
- func HandlerAddApiKey(responseWriter http.ResponseWriter, request *http.Request)
- func HandlerApiKeyDelete(responseWriter http.ResponseWriter, request *http.Request)
- func HandlerApiKeyDeleteConfirm(responseWriter http.ResponseWriter, request *http.Request)
- func HandlerApiKeys(responseWriter http.ResponseWriter, request *http.Request)
- func HandlerClientIds(responseWriter http.ResponseWriter, request *http.Request)
- func HandlerClientInfoSend(responseWriter http.ResponseWriter, request *http.Request)
- func HandlerClientInfoUpdate(responseWriter http.ResponseWriter, request *http.Request)
- func HandlerDownload(aResponseWriter http.ResponseWriter, aRequest *http.Request)
- func HandlerFileLogDelete(aResponseWriter http.ResponseWriter, aRequest *http.Request)
- func HandlerInviteCreate(responseWriter http.ResponseWriter, request *http.Request)
- func HandlerLogin(responseWriter http.ResponseWriter, request *http.Request)
- func HandlerLogout(responseWriter http.ResponseWriter, request *http.Request)
- func HandlerMessage(aResponseWriter http.ResponseWriter, aRequest *http.Request)
- func HandlerRegister(responseWriter http.ResponseWriter, request *http.Request)
- func HandlerReports(responseWriter http.ResponseWriter, request *http.Request)
- func HandlerReportsClear(aResponseWriter http.ResponseWriter, aRequest *http.Request)
- func HandlerReportsClearConfirm(aResponseWriter http.ResponseWriter, aRequest *http.Request)
- func HandlerRoot(aResponseWriter http.ResponseWriter, aRequest *http.Request)
- func HandlerUploadFile(aResponseWriter http.ResponseWriter, aRequest *http.Request)
- func HandlerUploadImage(aResponseWriter http.ResponseWriter, aRequest *http.Request)
- func HashSha1(aValue string) (string, error)
- func IsApiKeyValid(aApiKey string) (isValid bool, userId int)
- func IsTokenValid(responseWriter http.ResponseWriter, request *http.Request) bool
- func ServeAddApiKey(responseWriter http.ResponseWriter)
- func ServeError(aResponseWriter http.ResponseWriter, aMessage string, aTemplateFilePath string)
- func ServeLogin(responseWriter http.ResponseWriter, message string)
- func ServeRegister(responseWriter http.ResponseWriter, message string)
- func ServeResult(aResponseWriter http.ResponseWriter, aResult *objects.Result, ...)
Constants ¶
const API_KEY_apikey = "apikey"
const API_KEY_appname = "appname"
const API_KEY_clientid = "clientid"
const API_KEY_email = "email"
const API_KEY_file = "file"
const API_KEY_filename = "filename"
const API_KEY_image = "image"
const API_KEY_inviteid = "inviteid"
const API_KEY_message = "message"
const API_KEY_name = "name"
const API_KEY_pagenum = "pagenum"
const API_KEY_pagesize = "pagesize"
const API_KEY_password = "password"
const API_KEY_sequence = "sequence"
const API_KEY_startnum = "startnum"
const API_KEY_time = "time"
const API_KEY_token = "token"
const API_KEY_username = "username"
const API_URL = "http://localhost"
const API_URL_domain = "localhost"
const DB_NAME = "stunt.sqlite"
const DB_TYPE = "sqlite3"
const INVITE_VALIDITY_MS = 60 * 15 * 1000
const PATH_AddApiKey = "/apikeyadd"
const PATH_ApiKeyDelete = "/apikeydelete"
const PATH_ApiKeyDeleteConfirm = "/apikeydeleteconfirm"
const PATH_ApiKeys = "/apikeys"
const PATH_CLIENTINFO = "/sendclientinfo"
const PATH_ClientIds = "/clientids"
const PATH_ClientInfoUpdate = "/updateclientinfo"
const PATH_Login = "/login"
const PATH_MESSAGE = "/message"
const PATH_ROOT = "/"
const PATH_Register = "/register"
const PATH_Reports = "/reports"
const PATH_STATIC_TEMPLATES = "./templates"
const PATH_UPLOADFILE = "/uploadfile"
const PATH_UPLOADIMAGE = "/uploadimage"
const PATH_download = "/exports"
const PATH_filelog_delete = "/filelogdelete"
const PATH_invite = "/invite"
const PATH_logout = "/logout"
const PATH_reports_delete = "/reportsdelete"
const PATH_reports_delete_confirm = "/reportsdeleteconfirm"
const PORT_8080 = "8080"
const REPORTS_PAGE_SIZE = 100
const SALT_LENGTH = 32
const STMT_CREATE_TABLE_APIKEYS = "create table if not exists apikeys('id' integer primary key, 'userid' integer, 'apikey' text, 'appname' text)"
const STMT_CREATE_TABLE_CLIENTINFO = "" /* 128-byte string literal not displayed */
const STMT_CREATE_TABLE_INVITES = "" /* 131-byte string literal not displayed */
const STMT_CREATE_TABLE_REPORTS = "" /* 148-byte string literal not displayed */
const STMT_CREATE_TABLE_TOKENS = "" /* 128-byte string literal not displayed */
const STMT_CREATE_TABLE_USERS = "create table if not exists users('id' integer primary key, 'email' text unique, 'password' text, 'salt' text)"
const STMT_INSERT_INTO_APIKEYS = "insert or ignore into apikeys(userid, apikey, appname) values(?, ?, ?)"
const STMT_INSERT_INTO_CLIENTINFO = "insert or ignore into clientinfo%s(clientid, name, manufacturer, model, deviceid) values(?, ?, ?, ?, ?)"
const STMT_INSERT_INTO_INVITES = "insert or ignore into invites%s(inviteid, apikey, issued, expires) values(?, ?, ?, ?)"
const STMT_INSERT_INTO_REPORTS = "insert or ignore into reports%s(clientid, time, sequence, message, filepath) values(?, ?, ?, ?, ?)"
const STMT_INSERT_INTO_TOKENS = "insert or ignore into tokens(userid, token, issued, expires) values(?, ?, ?, ?)"
const STMT_INSERT_INTO_USERS = "insert or ignore into users(email, password, salt) values(?, ?, ?)"
const STR_All_clients = "All clients"
const STR_Authorization = "Authorization"
const STR_BLANK = " "
const STR_EMPTY = ""
const STR_GET = "GET"
const STR_MSG_404 = "404, Page not found"
const STR_MSG_NOTFOUND = "404 Not found"
const STR_MSG_invalidapikey = "Invalid api key"
const STR_MSG_invalidclientid = "Invalid client id"
const STR_MSG_login = "Please login"
const STR_MSG_register = "Please enter email and password"
const STR_MSG_server_error = "500 Server error"
const STR_PORT = "PORT"
const STR_POST = "POST"
const STR_error = "error"
const STR_export = "export"
const STR_filepath_download_template = "resources/exports/%s"
const STR_filepath_filelog = "resources/logs/logfile.txt"
const STR_filepath_upload_template = "resources/reportfiles/%s"
const STR_id = "id"
const STR_symbol_colon = ":"
const STR_symbol_dash = "-"
const STR_symbol_dot = "."
const STR_template_add_apikey_html = "templates/add_apikey.html"
const STR_template_apikey_deleteconfirm_html = "templates/apikey_deleteconfirm.html"
const STR_template_export_html = "templates/export.html"
const STR_template_invite_html = "templates/invite.html"
const STR_template_list_apikeys_html = "templates/list_apikeys.html"
const STR_template_list_clientids_for_apikey_html = "templates/list_clientids_for_apikey.html"
const STR_template_list_reports_for_apikey_html = "templates/list_reports_for_apikey.html"
const STR_template_page_error_html = "templates/page_error.html"
const STR_template_reports_deleteconfirm_html = "templates/reports_deleteconfirm.html"
const STR_template_result = "templates/result.json"
const STR_templates_Content_html = "templates/Page1.html"
const STR_templates_login_html = "templates/login.html"
const STR_templates_register_html = "templates/register.html"
const STR_txt = "txt"
const TABLE_APIKEYS_COLUMN_apikey = "apikey"
const TABLE_APIKEYS_COLUMN_appname = "appname"
const TABLE_APIKEYS_COLUMN_userid = "userid"
const TABLE_CLIENTINFO_clientid = "clientid"
const TABLE_CLIENTINFO_deviceid = "deviceid"
const TABLE_CLIENTINFO_manufacturer = "manufacturer"
const TABLE_CLIENTINFO_model = "model"
const TABLE_CLIENTINFO_name = "name"
const TABLE_INVITES_COLUMN_apikey = TABLE_APIKEYS_COLUMN_apikey
const TABLE_INVITES_COLUMN_expires = TABLE_TOKENS_COLUMN_expires
const TABLE_INVITES_COLUMN_inviteid = "inviteid"
const TABLE_INVITES_COLUMN_issued = TABLE_TOKENS_COLUMN_issued
const TABLE_REPORTS_COLUMN_clientid = "clientid"
const TABLE_REPORTS_COLUMN_filepath = "filepath"
const TABLE_REPORTS_COLUMN_id = STR_id
const TABLE_REPORTS_COLUMN_message = "message"
const TABLE_REPORTS_COLUMN_sequence = "sequence"
const TABLE_REPORTS_COLUMN_time = "time"
const TABLE_TOKENS_COLUMN_expires = "expires"
const TABLE_TOKENS_COLUMN_id = STR_id
const TABLE_TOKENS_COLUMN_issued = "issued"
const TABLE_TOKENS_COLUMN_token = "token"
const TABLE_TOKENS_COLUMN_userid = "userid"
const TABLE_USERS_COLUMN_email = "email"
const TABLE_USERS_COLUMN_id = STR_id
const TABLE_USERS_COLUMN_password = "password"
const TABLE_USERS_COLUMN_salt = "salt"
const TABLE_apikeys = "apikeys"
const TABLE_clientinfo = "clientinfo"
const TABLE_invites = "invites"
const TABLE_reports = "reports"
const TABLE_tokens = "tokens"
const TABLE_users = "users"
const TOKEN_VALIDITY_MS = TOKEN_VALIDITY_SECONDS * 1000
const TOKEN_VALIDITY_SECONDS = 60 * 60 * 24
Variables ¶
var FileLog *os.File
var Letters = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
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 ¶
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 ¶
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 ¶
DbCleanTokens deletes expired token records from the TABLE_tokens table.
func DbClearClientInfo ¶
DbClearClientInfo deletes all client info records from TABLE_clientinfo for API key table.
func DbClearReports ¶
DbClearReports deletes all records in the TABLE_reports for API key table.
func DbDeleteApiKey ¶
DbDeleteApiKey deletes API key from api keys table.
func DbDeleteClientInfo ¶
DbDeleteClientInfo deletes client info from the TABLE_clientinfo for API Key table.
func DbDeleteReport ¶
DbDeleteReport deletes report from TABLE_reports for API key table.
func DbDeleteUser ¶
Deletes a user and his apiKeys and the reports<apiKey> tables of that user.
func DbGetApiKey ¶
DbGetApiKey gets all apiKeys of a user.
func DbGetClientInfo ¶
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 DbGetUserLoad ¶
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 ¶
DbInviteAdd adds an invitation to TABLE_invites for API key.
func DbInviteAddApiKey ¶
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 ¶
DbInviteClean deletes expired invitation records from TABLE_invites for API key table.
func DbInviteCreateTable ¶
DbInviteCreateTable creates TABLE_invites for API key table.
func DbIsApiKeyValid ¶
DbIsApiKeyValid checks if an API Key is valid. The check is against the TABLE_apikeys table.
func DbIsTokenValid ¶
DbIsTokenValid checks if a token is valid. The check is against the TABLE_tokens table.
func DbUpdateClientInfo ¶
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 ¶
GenerateRandomString creates a random string with the passed in length.
func GenerateToken ¶
GenerateToken creates an Authentication token to be used by the web application client.
func GetApiUrlListApiKeys ¶
func GetApiUrlListApiKeys() string
GetApiUrlListApiKeys gets URL to PATH_ApiKeys.
func GetApiUrlListClientIds ¶
func GetApiUrlListClientIds() string
GetApiUrlListClientIds gets URL to PATH_ClientIds.
func GetCookieToken ¶
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 IsApiKeyValid ¶
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.