diff --git a/package/secubox/luci-app-haproxy/Makefile b/package/secubox/luci-app-haproxy/Makefile index a3c416bb..7b401dd3 100644 --- a/package/secubox/luci-app-haproxy/Makefile +++ b/package/secubox/luci-app-haproxy/Makefile @@ -11,7 +11,7 @@ LUCI_PKGARCH:=all PKG_NAME:=luci-app-haproxy PKG_VERSION:=1.0.0 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_MAINTAINER:=CyberMind PKG_LICENSE:=MIT diff --git a/package/secubox/luci-app-haproxy/htdocs/luci-static/resources/haproxy/api.js b/package/secubox/luci-app-haproxy/htdocs/luci-static/resources/haproxy/api.js index 74e7df43..1916f410 100644 --- a/package/secubox/luci-app-haproxy/htdocs/luci-static/resources/haproxy/api.js +++ b/package/secubox/luci-app-haproxy/htdocs/luci-static/resources/haproxy/api.js @@ -1,276 +1,367 @@ 'use strict'; +'require baseclass'; 'require rpc'; -var api = { - // Status - status: rpc.declare({ - object: 'luci.haproxy', - method: 'status', - expect: { } - }), +// ============================================ +// Status +// ============================================ - getStats: rpc.declare({ - object: 'luci.haproxy', - method: 'get_stats', - expect: { } - }), +var callStatus = rpc.declare({ + object: 'luci.haproxy', + method: 'status', + expect: {} +}); + +var callGetStats = rpc.declare({ + object: 'luci.haproxy', + method: 'get_stats', + expect: {} +}); + +// ============================================ +// Vhosts +// ============================================ + +var callListVhosts = rpc.declare({ + object: 'luci.haproxy', + method: 'list_vhosts', + expect: { vhosts: [] } +}); + +var callGetVhost = rpc.declare({ + object: 'luci.haproxy', + method: 'get_vhost', + params: ['id'], + expect: {} +}); + +var callCreateVhost = rpc.declare({ + object: 'luci.haproxy', + method: 'create_vhost', + params: ['domain', 'backend', 'ssl', 'ssl_redirect', 'acme', 'enabled'], + expect: {} +}); + +var callUpdateVhost = rpc.declare({ + object: 'luci.haproxy', + method: 'update_vhost', + params: ['id', 'domain', 'backend', 'ssl', 'ssl_redirect', 'acme', 'enabled'], + expect: {} +}); + +var callDeleteVhost = rpc.declare({ + object: 'luci.haproxy', + method: 'delete_vhost', + params: ['id'], + expect: {} +}); + +// ============================================ +// Backends +// ============================================ + +var callListBackends = rpc.declare({ + object: 'luci.haproxy', + method: 'list_backends', + expect: { backends: [] } +}); + +var callGetBackend = rpc.declare({ + object: 'luci.haproxy', + method: 'get_backend', + params: ['id'], + expect: {} +}); + +var callCreateBackend = rpc.declare({ + object: 'luci.haproxy', + method: 'create_backend', + params: ['name', 'mode', 'balance', 'health_check', 'enabled'], + expect: {} +}); + +var callUpdateBackend = rpc.declare({ + object: 'luci.haproxy', + method: 'update_backend', + params: ['id', 'name', 'mode', 'balance', 'health_check', 'enabled'], + expect: {} +}); + +var callDeleteBackend = rpc.declare({ + object: 'luci.haproxy', + method: 'delete_backend', + params: ['id'], + expect: {} +}); + +// ============================================ +// Servers +// ============================================ + +var callListServers = rpc.declare({ + object: 'luci.haproxy', + method: 'list_servers', + params: ['backend'], + expect: { servers: [] } +}); + +var callCreateServer = rpc.declare({ + object: 'luci.haproxy', + method: 'create_server', + params: ['backend', 'name', 'address', 'port', 'weight', 'check', 'enabled'], + expect: {} +}); + +var callUpdateServer = rpc.declare({ + object: 'luci.haproxy', + method: 'update_server', + params: ['id', 'backend', 'name', 'address', 'port', 'weight', 'check', 'enabled'], + expect: {} +}); + +var callDeleteServer = rpc.declare({ + object: 'luci.haproxy', + method: 'delete_server', + params: ['id'], + expect: {} +}); + +// ============================================ +// Certificates +// ============================================ + +var callListCertificates = rpc.declare({ + object: 'luci.haproxy', + method: 'list_certificates', + expect: { certificates: [] } +}); + +var callRequestCertificate = rpc.declare({ + object: 'luci.haproxy', + method: 'request_certificate', + params: ['domain'], + expect: {} +}); + +var callImportCertificate = rpc.declare({ + object: 'luci.haproxy', + method: 'import_certificate', + params: ['domain', 'cert', 'key'], + expect: {} +}); + +var callDeleteCertificate = rpc.declare({ + object: 'luci.haproxy', + method: 'delete_certificate', + params: ['id'], + expect: {} +}); + +// ============================================ +// ACLs +// ============================================ + +var callListAcls = rpc.declare({ + object: 'luci.haproxy', + method: 'list_acls', + expect: { acls: [] } +}); + +var callCreateAcl = rpc.declare({ + object: 'luci.haproxy', + method: 'create_acl', + params: ['name', 'type', 'pattern', 'backend', 'enabled'], + expect: {} +}); + +var callUpdateAcl = rpc.declare({ + object: 'luci.haproxy', + method: 'update_acl', + params: ['id', 'name', 'type', 'pattern', 'backend', 'enabled'], + expect: {} +}); + +var callDeleteAcl = rpc.declare({ + object: 'luci.haproxy', + method: 'delete_acl', + params: ['id'], + expect: {} +}); + +// ============================================ +// Redirects +// ============================================ + +var callListRedirects = rpc.declare({ + object: 'luci.haproxy', + method: 'list_redirects', + expect: { redirects: [] } +}); + +var callCreateRedirect = rpc.declare({ + object: 'luci.haproxy', + method: 'create_redirect', + params: ['name', 'match_host', 'target_host', 'strip_www', 'code', 'enabled'], + expect: {} +}); + +var callDeleteRedirect = rpc.declare({ + object: 'luci.haproxy', + method: 'delete_redirect', + params: ['id'], + expect: {} +}); + +// ============================================ +// Settings +// ============================================ + +var callGetSettings = rpc.declare({ + object: 'luci.haproxy', + method: 'get_settings', + expect: {} +}); + +var callSaveSettings = rpc.declare({ + object: 'luci.haproxy', + method: 'save_settings', + params: ['main', 'defaults', 'acme'], + expect: {} +}); + +// ============================================ +// Service Control +// ============================================ + +var callInstall = rpc.declare({ + object: 'luci.haproxy', + method: 'install', + expect: {} +}); + +var callStart = rpc.declare({ + object: 'luci.haproxy', + method: 'start', + expect: {} +}); + +var callStop = rpc.declare({ + object: 'luci.haproxy', + method: 'stop', + expect: {} +}); + +var callRestart = rpc.declare({ + object: 'luci.haproxy', + method: 'restart', + expect: {} +}); + +var callReload = rpc.declare({ + object: 'luci.haproxy', + method: 'reload', + expect: {} +}); + +var callGenerate = rpc.declare({ + object: 'luci.haproxy', + method: 'generate', + expect: {} +}); + +var callValidate = rpc.declare({ + object: 'luci.haproxy', + method: 'validate', + expect: {} +}); + +var callGetLogs = rpc.declare({ + object: 'luci.haproxy', + method: 'get_logs', + params: ['lines'], + expect: { logs: '' } +}); + +// ============================================ +// Helper Functions +// ============================================ + +function getDashboardData() { + return Promise.all([ + callStatus(), + callListVhosts(), + callListBackends(), + callListCertificates() + ]).then(function(results) { + return { + status: results[0], + vhosts: results[1].vhosts || [], + backends: results[2].backends || [], + certificates: results[3].certificates || [] + }; + }); +} + +// ============================================ +// Module Export +// ============================================ + +return baseclass.extend({ + // Status + status: callStatus, + getStats: callGetStats, // Vhosts - listVhosts: rpc.declare({ - object: 'luci.haproxy', - method: 'list_vhosts', - expect: { vhosts: [] } - }), - - getVhost: rpc.declare({ - object: 'luci.haproxy', - method: 'get_vhost', - params: ['id'], - expect: { } - }), - - createVhost: rpc.declare({ - object: 'luci.haproxy', - method: 'create_vhost', - params: ['domain', 'backend', 'ssl', 'ssl_redirect', 'acme', 'enabled'], - expect: { } - }), - - updateVhost: rpc.declare({ - object: 'luci.haproxy', - method: 'update_vhost', - params: ['id', 'domain', 'backend', 'ssl', 'ssl_redirect', 'acme', 'enabled'], - expect: { } - }), - - deleteVhost: rpc.declare({ - object: 'luci.haproxy', - method: 'delete_vhost', - params: ['id'], - expect: { } - }), + listVhosts: callListVhosts, + getVhost: callGetVhost, + createVhost: callCreateVhost, + updateVhost: callUpdateVhost, + deleteVhost: callDeleteVhost, // Backends - listBackends: rpc.declare({ - object: 'luci.haproxy', - method: 'list_backends', - expect: { backends: [] } - }), - - getBackend: rpc.declare({ - object: 'luci.haproxy', - method: 'get_backend', - params: ['id'], - expect: { } - }), - - createBackend: rpc.declare({ - object: 'luci.haproxy', - method: 'create_backend', - params: ['name', 'mode', 'balance', 'health_check', 'enabled'], - expect: { } - }), - - updateBackend: rpc.declare({ - object: 'luci.haproxy', - method: 'update_backend', - params: ['id', 'name', 'mode', 'balance', 'health_check', 'enabled'], - expect: { } - }), - - deleteBackend: rpc.declare({ - object: 'luci.haproxy', - method: 'delete_backend', - params: ['id'], - expect: { } - }), + listBackends: callListBackends, + getBackend: callGetBackend, + createBackend: callCreateBackend, + updateBackend: callUpdateBackend, + deleteBackend: callDeleteBackend, // Servers - listServers: rpc.declare({ - object: 'luci.haproxy', - method: 'list_servers', - params: ['backend'], - expect: { servers: [] } - }), - - createServer: rpc.declare({ - object: 'luci.haproxy', - method: 'create_server', - params: ['backend', 'name', 'address', 'port', 'weight', 'check', 'enabled'], - expect: { } - }), - - updateServer: rpc.declare({ - object: 'luci.haproxy', - method: 'update_server', - params: ['id', 'backend', 'name', 'address', 'port', 'weight', 'check', 'enabled'], - expect: { } - }), - - deleteServer: rpc.declare({ - object: 'luci.haproxy', - method: 'delete_server', - params: ['id'], - expect: { } - }), + listServers: callListServers, + createServer: callCreateServer, + updateServer: callUpdateServer, + deleteServer: callDeleteServer, // Certificates - listCertificates: rpc.declare({ - object: 'luci.haproxy', - method: 'list_certificates', - expect: { certificates: [] } - }), - - requestCertificate: rpc.declare({ - object: 'luci.haproxy', - method: 'request_certificate', - params: ['domain'], - expect: { } - }), - - importCertificate: rpc.declare({ - object: 'luci.haproxy', - method: 'import_certificate', - params: ['domain', 'cert', 'key'], - expect: { } - }), - - deleteCertificate: rpc.declare({ - object: 'luci.haproxy', - method: 'delete_certificate', - params: ['id'], - expect: { } - }), + listCertificates: callListCertificates, + requestCertificate: callRequestCertificate, + importCertificate: callImportCertificate, + deleteCertificate: callDeleteCertificate, // ACLs - listAcls: rpc.declare({ - object: 'luci.haproxy', - method: 'list_acls', - expect: { acls: [] } - }), - - createAcl: rpc.declare({ - object: 'luci.haproxy', - method: 'create_acl', - params: ['name', 'type', 'pattern', 'backend', 'enabled'], - expect: { } - }), - - updateAcl: rpc.declare({ - object: 'luci.haproxy', - method: 'update_acl', - params: ['id', 'name', 'type', 'pattern', 'backend', 'enabled'], - expect: { } - }), - - deleteAcl: rpc.declare({ - object: 'luci.haproxy', - method: 'delete_acl', - params: ['id'], - expect: { } - }), + listAcls: callListAcls, + createAcl: callCreateAcl, + updateAcl: callUpdateAcl, + deleteAcl: callDeleteAcl, // Redirects - listRedirects: rpc.declare({ - object: 'luci.haproxy', - method: 'list_redirects', - expect: { redirects: [] } - }), - - createRedirect: rpc.declare({ - object: 'luci.haproxy', - method: 'create_redirect', - params: ['name', 'match_host', 'target_host', 'strip_www', 'code', 'enabled'], - expect: { } - }), - - deleteRedirect: rpc.declare({ - object: 'luci.haproxy', - method: 'delete_redirect', - params: ['id'], - expect: { } - }), + listRedirects: callListRedirects, + createRedirect: callCreateRedirect, + deleteRedirect: callDeleteRedirect, // Settings - getSettings: rpc.declare({ - object: 'luci.haproxy', - method: 'get_settings', - expect: { } - }), - - saveSettings: rpc.declare({ - object: 'luci.haproxy', - method: 'save_settings', - params: ['main', 'defaults', 'acme'], - expect: { } - }), + getSettings: callGetSettings, + saveSettings: callSaveSettings, // Service control - install: rpc.declare({ - object: 'luci.haproxy', - method: 'install', - expect: { } - }), + install: callInstall, + start: callStart, + stop: callStop, + restart: callRestart, + reload: callReload, + generate: callGenerate, + validate: callValidate, + getLogs: callGetLogs, - start: rpc.declare({ - object: 'luci.haproxy', - method: 'start', - expect: { } - }), - - stop: rpc.declare({ - object: 'luci.haproxy', - method: 'stop', - expect: { } - }), - - restart: rpc.declare({ - object: 'luci.haproxy', - method: 'restart', - expect: { } - }), - - reload: rpc.declare({ - object: 'luci.haproxy', - method: 'reload', - expect: { } - }), - - generate: rpc.declare({ - object: 'luci.haproxy', - method: 'generate', - expect: { } - }), - - validate: rpc.declare({ - object: 'luci.haproxy', - method: 'validate', - expect: { } - }), - - getLogs: rpc.declare({ - object: 'luci.haproxy', - method: 'get_logs', - params: ['lines'], - expect: { logs: '' } - }), - - // Fetch all data for dashboard - getDashboardData: function() { - return Promise.all([ - this.status(), - this.listVhosts(), - this.listBackends(), - this.listCertificates() - ]).then(function(results) { - return { - status: results[0], - vhosts: results[1], - backends: results[2], - certificates: results[3] - }; - }); - } -}; - -return api; + // Helpers + getDashboardData: getDashboardData +});