2018-01-22 13:01:38 -08:00
'use strict' ;
2020-06-03 23:17:06 +02:00
/* global $ */
/* global angular */
/* global EventSource */
/* global async */
2018-01-22 13:01:38 -08:00
2019-09-27 18:11:48 +02:00
// keep in sync with box/src/apps.js
var ISTATES = {
PENDING _INSTALL : 'pending_install' ,
PENDING _CLONE : 'pending_clone' ,
PENDING _CONFIGURE : 'pending_configure' ,
PENDING _UNINSTALL : 'pending_uninstall' ,
PENDING _RESTORE : 'pending_restore' ,
2021-05-26 09:32:17 -07:00
PENDING _IMPORT : 'pending_import' ,
2019-09-27 18:11:48 +02:00
PENDING _UPDATE : 'pending_update' ,
PENDING _BACKUP : 'pending_backup' ,
PENDING _RECREATE _CONTAINER : 'pending_recreate_container' , // env change or addon change
PENDING _LOCATION _CHANGE : 'pending_location_change' ,
PENDING _DATA _DIR _MIGRATION : 'pending_data_dir_migration' ,
2023-07-14 18:09:07 +05:30
PENDING _SERVICES _CHANGE : 'pending_services_change' ,
2019-09-27 18:11:48 +02:00
PENDING _RESIZE : 'pending_resize' ,
PENDING _DEBUG : 'pending_debug' ,
PENDING _START : 'pending_start' ,
PENDING _STOP : 'pending_stop' ,
2019-12-20 11:18:48 -08:00
PENDING _RESTART : 'pending_restart' ,
2019-09-27 18:11:48 +02:00
ERROR : 'error' ,
INSTALLED : 'installed'
} ;
var HSTATES = {
HEALTHY : 'healthy' ,
UNHEALTHY : 'unhealthy' ,
ERROR : 'error' ,
DEAD : 'dead'
} ;
var RSTATES = {
RUNNING : 'running' ,
STOPPED : 'stopped'
} ;
var ERROR = {
ACCESS _DENIED : 'Access Denied' ,
ALREADY _EXISTS : 'Already Exists' ,
BAD _FIELD : 'Bad Field' ,
COLLECTD _ERROR : 'Collectd Error' ,
CONFLICT : 'Conflict' ,
DATABASE _ERROR : 'Database Error' ,
DNS _ERROR : 'DNS Error' ,
DOCKER _ERROR : 'Docker Error' ,
EXTERNAL _ERROR : 'External Error' ,
FS _ERROR : 'FileSystem Error' ,
INTERNAL _ERROR : 'Internal Error' ,
LOGROTATE _ERROR : 'Logrotate Error' ,
NETWORK _ERROR : 'Network Error' ,
NOT _FOUND : 'Not found' ,
REVERSEPROXY _ERROR : 'ReverseProxy Error' ,
TASK _ERROR : 'Task Error' ,
UNKNOWN _ERROR : 'Unknown Error' // only used for portin,
} ;
2020-02-21 16:52:37 -08:00
var ROLES = {
OWNER : 'owner' ,
ADMIN : 'admin' ,
2021-12-02 09:29:33 -08:00
MAIL _MANAGER : 'mailmanager' ,
2020-02-21 16:52:37 -08:00
USER _MANAGER : 'usermanager' ,
USER : 'user'
} ;
2020-09-01 16:31:09 +02:00
// sync up with tasks.js
var TASK _TYPES = {
TASK _APP : 'app' ,
TASK _BACKUP : 'backup' ,
TASK _UPDATE : 'update' ,
2023-01-25 10:06:35 +01:00
TASK _CHECK _CERTS : 'checkCerts' ,
2020-09-01 16:31:09 +02:00
TASK _SETUP _DNS _AND _CERT : 'setupDnsAndCert' ,
TASK _CLEAN _BACKUPS : 'cleanBackups' ,
TASK _SYNC _EXTERNAL _LDAP : 'syncExternalLdap' ,
TASK _CHANGE _MAIL _LOCATION : 'changeMailLocation' ,
2021-02-24 22:18:39 -08:00
TASK _SYNC _DNS _RECORDS : 'syncDnsRecords' ,
2023-01-25 10:06:35 +01:00
TASK _UPDATE _DISK _USAGE : 'updateDiskUsage' ,
2023-07-08 19:48:12 +05:30
TASK _SYNC _DYNDNS : 'syncDyndns' ,
2020-09-01 16:31:09 +02:00
} ;
2022-07-11 16:58:10 +02:00
const APP _TYPES = {
APP : 'app' , //default
LINK : 'link' ,
PROXIED : 'proxied'
} ;
2020-05-14 23:04:19 +02:00
var SECRET _PLACEHOLDER = String . fromCharCode ( 0x25CF ) . repeat ( 8 ) ;
2022-09-27 13:31:13 +02:00
// List is from http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
const REGIONS _S3 = [
2023-02-06 22:06:39 +01:00
{ name : 'Africa (Cape Town)' , value : 'af-south-1' } ,
{ name : 'Asia Pacific (Hong Kong)' , value : 'ap-east-1' } ,
{ name : 'Asia Pacific (Hyderabad)' , value : 'ap-south-2' } ,
{ name : 'Asia Pacific (Jakarta)' , value : 'ap-southeast-3' } ,
2023-02-03 11:27:57 +01:00
{ name : 'Asia Pacific (Melbourne)' , value : 'ap-southeast-4' } ,
2022-09-27 13:31:13 +02:00
{ name : 'Asia Pacific (Mumbai)' , value : 'ap-south-1' } ,
2023-02-06 22:06:39 +01:00
{ name : 'Asia Pacific (Osaka)' , value : 'ap-northeast-3' } ,
2022-09-27 13:31:13 +02:00
{ name : 'Asia Pacific (Seoul)' , value : 'ap-northeast-2' } ,
{ name : 'Asia Pacific (Singapore)' , value : 'ap-southeast-1' } ,
{ name : 'Asia Pacific (Sydney)' , value : 'ap-southeast-2' } ,
{ name : 'Asia Pacific (Tokyo)' , value : 'ap-northeast-1' } ,
{ name : 'Canada (Central)' , value : 'ca-central-1' } ,
{ name : 'China (Beijing)' , value : 'cn-north-1' } ,
{ name : 'China (Ningxia)' , value : 'cn-northwest-1' } ,
2023-02-06 22:06:39 +01:00
{ name : 'Middle East (Bahrain)' , value : 'me-south-1' } ,
{ name : 'Middle East (UAE)' , value : 'me-central-1' } ,
2022-09-27 13:31:13 +02:00
{ name : 'EU (Frankfurt)' , value : 'eu-central-1' } ,
{ name : 'EU (Ireland)' , value : 'eu-west-1' } ,
{ name : 'EU (London)' , value : 'eu-west-2' } ,
2023-02-06 22:06:39 +01:00
{ name : 'EU (Milan)' , value : 'eu-south-1' } ,
2022-09-27 13:31:13 +02:00
{ name : 'EU (Paris)' , value : 'eu-west-3' } ,
2023-02-06 22:06:39 +01:00
{ name : 'EU (Spain)' , value : 'eu-south-2' } ,
2022-09-27 13:31:13 +02:00
{ name : 'EU (Stockholm)' , value : 'eu-north-1' } ,
2023-02-06 22:06:39 +01:00
{ name : 'EU (Zurich)' , value : 'eu-central-2' } ,
2022-09-27 13:31:13 +02:00
{ name : 'South America (São Paulo)' , value : 'sa-east-1' } ,
{ name : 'US East (N. Virginia)' , value : 'us-east-1' } ,
{ name : 'US East (Ohio)' , value : 'us-east-2' } ,
{ name : 'US West (N. California)' , value : 'us-west-1' } ,
{ name : 'US West (Oregon)' , value : 'us-west-2' } ,
] ;
2023-02-06 22:15:25 +01:00
// https://wasabi.com/locations/
2022-09-27 13:31:13 +02:00
const REGIONS _WASABI = [
{ name : 'Amsterdam (EU Central 1)' , value : 'https://s3.eu-central-1.wasabisys.com' } ,
{ name : 'Frankfurt (EU Central 2)' , value : 'https://s3.eu-central-2.wasabisys.com' } ,
{ name : 'London (EU West 1)' , value : 'https://s3.eu-west-1.wasabisys.com' } ,
{ name : 'Oregon (US West 1)' , value : 'https://s3.us-west-1.wasabisys.com' } ,
{ name : 'Osaka (AP Northeast 2)' , value : 'https://s3.ap-northeast-2.wasabisys.com' } ,
{ name : 'Paris (EU West 2)' , value : 'https://s3.eu-west-2.wasabisys.com' } ,
{ name : 'Plano (US Central 1)' , value : 'https://s3.us-central-1.wasabisys.com' } ,
{ name : 'Singapore (AP Southeast 1)' , value : 'https://s3.ap-southeast-1.wasabisys.com' } ,
{ name : 'Sydney (AP Southeast 2)' , value : 'https://s3.ap-southeast-2.wasabisys.com' } ,
{ name : 'Tokyo (AP Northeast 1)' , value : 'https://s3.ap-northeast-1.wasabisys.com' } ,
{ name : 'Toronto (CA Central 1)' , value : 'https://s3.ca-central-1.wasabisys.com' } ,
{ name : 'Virginia (US East 1)' , value : 'https://s3.us-east-1.wasabisys.com' } ,
{ name : 'Virginia (US East 2)' , value : 'https://s3.us-east-2.wasabisys.com' }
] ;
2023-02-06 22:12:25 +01:00
// https://docs.digitalocean.com/products/platform/availability-matrix/
2022-09-27 13:31:13 +02:00
const REGIONS _DIGITALOCEAN = [
{ name : 'AMS3' , value : 'https://ams3.digitaloceanspaces.com' } ,
{ name : 'FRA1' , value : 'https://fra1.digitaloceanspaces.com' } ,
{ name : 'NYC3' , value : 'https://nyc3.digitaloceanspaces.com' } ,
{ name : 'SFO2' , value : 'https://sfo2.digitaloceanspaces.com' } ,
{ name : 'SFO3' , value : 'https://sfo3.digitaloceanspaces.com' } ,
2023-02-06 22:12:25 +01:00
{ name : 'SGP1' , value : 'https://sgp1.digitaloceanspaces.com' } ,
{ name : 'SYD1' , value : 'https://syd1.digitaloceanspaces.com' }
2022-09-27 13:31:13 +02:00
] ;
2023-02-06 22:17:52 +01:00
// https://www.exoscale.com/datacenters/
2022-09-27 13:31:13 +02:00
const REGIONS _EXOSCALE = [
2023-02-06 22:17:52 +01:00
{ name : 'Vienna (AT-VIE-1)' , value : 'https://sos-at-vie-1.exo.io' } ,
{ name : 'Sofia (BG-SOF-1)' , value : 'https://sos-bg-sof-1.exo.io' } ,
{ name : 'Zurich (CH-DK-2)' , value : 'https://sos-ch-dk-2.exo.io' } ,
{ name : 'Geneva (CH-GVA-2)' , value : 'https://sos-ch-gva-2.exo.io' } ,
{ name : 'Frankfurt (DE-FRA-1)' , value : 'https://sos-de-fra-1.exo.io' } ,
{ name : 'Munich (DE-MUC-1)' , value : 'https://sos-de-muc-1.exo.io' } ,
2022-09-27 13:31:13 +02:00
] ;
// https://www.scaleway.com/docs/object-storage-feature/
const REGIONS _SCALEWAY = [
2023-02-06 22:15:25 +01:00
{ name : 'Paris (FR-PAR)' , value : 'https://s3.fr-par.scw.cloud' , region : 'fr-par' } , // default
{ name : 'Amsterdam (NL-AMS)' , value : 'https://s3.nl-ams.scw.cloud' , region : 'nl-ams' } ,
{ name : 'Warsaw (PL-WAW)' , value : 'https://s3.pl-waw.scw.cloud' , region : 'nl-ams' }
2022-09-27 13:31:13 +02:00
] ;
const REGIONS _LINODE = [
2023-04-04 10:12:29 +02:00
{ name : 'Atlanta' , value : 'us-southeast-1.linodeobjects.com' , region : 'us-east-1' } , // default
{ name : 'Newark' , value : 'us-east-1.linodeobjects.com' , region : 'us-east-1' } ,
2022-09-27 13:31:13 +02:00
{ name : 'Frankfurt' , value : 'eu-central-1.linodeobjects.com' , region : 'us-east-1' } ,
{ name : 'Singapore' , value : 'ap-south-1.linodeobjects.com' , region : 'us-east-1' }
] ;
2023-02-06 22:27:04 +01:00
// note: ovh also has a storage endpoint but that only supports path style access (https://docs.ovh.com/au/en/storage/object-storage/s3/location/)
2022-09-27 13:31:13 +02:00
const REGIONS _OVH = [
{ name : 'Beauharnois (BHS)' , value : 'https://s3.bhs.cloud.ovh.net' , region : 'bhs' } , // default
{ name : 'Frankfurt (DE)' , value : 'https://s3.de.cloud.ovh.net' , region : 'de' } ,
{ name : 'Gravelines (GRA)' , value : 'https://s3.gra.cloud.ovh.net' , region : 'gra' } ,
{ name : 'Strasbourg (SBG)' , value : 'https://s3.sbg.cloud.ovh.net' , region : 'sbg' } ,
{ name : 'London (UK)' , value : 'https://s3.uk.cloud.ovh.net' , region : 'uk' } ,
{ name : 'Sydney (SYD)' , value : 'https://s3.syd.cloud.ovh.net' , region : 'syd' } ,
{ name : 'Warsaw (WAW)' , value : 'https://s3.waw.cloud.ovh.net' , region : 'waw' } ,
] ;
2023-05-08 14:04:23 +02:00
// https://docs.ionos.com/cloud/managed-services/s3-object-storage/endpoints
2022-09-27 13:31:13 +02:00
const REGIONS _IONOS = [
2023-05-08 14:04:23 +02:00
{ name : 'Frankfurt (DE)' , value : 'https://s3-de-central.profitbricks.com' , region : 's3-de-central' } , // default
{ name : 'Berlin (eu-central-2)' , value : 'https://s3-eu-central-2.ionoscloud.com' , region : 'eu-central-2' } , // default
{ name : 'Logrono (eu-south-2)' , value : 'https://s3-eu-south-2.ionoscloud.com' , region : 'eu-south-2' } , // default
2022-09-27 13:31:13 +02:00
] ;
2023-02-06 22:27:04 +01:00
// this is not used anywhere because upcloud needs endpoint URL. we detect region from the URL (https://upcloud.com/data-centres)
2022-09-27 13:31:13 +02:00
const REGIONS _UPCLOUD = [
{ name : 'AU-SYD1 (Australia)' , value : 'https://au-syd1.upcloudobjects.com' , region : 'au-syd1' } , // default
{ name : 'DE-FRA1 (Germany)' , value : 'https://de-fra1.upcloudobjects.com' , region : 'de-fra1' } ,
{ name : 'ES-MAD1 (Spain)' , value : 'https://es-mad1.upcloudobjects.com' , region : 'es-mad1' } ,
{ name : 'FI-HEL2 (Finland)' , value : 'https://fi-hel2.upcloudobjects.com' , region : 'fi-hel2' } ,
{ name : 'NL-AMS1 (Netherlands)' , value : 'https://nl-ams1.upcloudobjects.com' , region : 'nl-ams1' } ,
{ name : 'PL-WAW1 (Poland)' , value : 'https://pl-waw1.upcloudobjects.com' , region : 'pl-waw1' } ,
{ name : 'SG-SIN1 (Singapore)' , value : 'https://sg-sin1.upcloudobjects.com' , region : 'sg-sin1' } ,
{ name : 'UK-LON1 (United Kingdom)' , value : 'https://uk-lon1.upcloudobjects.com' , region : 'uk-lon1' } ,
{ name : 'US-CHI1 (USA)' , value : 'https://us-chi1.upcloudobjects.com' , region : 'us-chi1' } ,
{ name : 'US-NYC1 (USA)' , value : 'https://us-nyc1.upcloudobjects.com' , region : 'us-nyc1' } ,
{ name : 'US-SJO1 (USA)' , value : 'https://us-sjo1.upcloudobjects.com' , region : 'us-sjo1' } ,
] ;
2023-02-06 22:27:04 +01:00
// region is ignored in vultr (https://www.vultr.com/docs/vultr-object-storage/)
2022-09-27 13:31:13 +02:00
const REGIONS _VULTR = [
2022-10-13 10:40:38 +02:00
{ name : 'Amsterdam' , value : 'https://ams1.vultrobjects.com' , region : 'eu-central-1' } ,
2023-02-06 22:27:04 +01:00
{ name : 'Bangalore' , value : 'https://blr1.vultrobjects.com' , region : 'ap-south-1' } ,
2022-10-13 10:40:38 +02:00
{ name : 'New Jersey' , value : 'https://ewr1.vultrobjects.com' , region : 'us-east-1' } ,
2023-02-06 22:27:04 +01:00
{ name : 'Silicon Valley' , value : 'https://sjc1.vultrobjects.com' , region : 'us-west-1' } ,
2022-10-13 10:40:38 +02:00
{ name : 'Singapore' , value : 'https://sgp1.vultrobjects.com' , region : 'ap-southeast-1' } ,
2022-09-27 13:31:13 +02:00
] ;
2022-12-24 11:10:04 +01:00
const STORAGE _PROVIDERS = [
2022-09-27 13:31:13 +02:00
{ name : 'Amazon S3' , value : 's3' } ,
{ name : 'Backblaze B2 (S3 API)' , value : 'backblaze-b2' } ,
{ name : 'CIFS Mount' , value : 'cifs' } ,
2022-09-27 19:40:58 +02:00
{ name : 'Cloudflare R2' , value : 'cloudflare-r2' } ,
2022-09-27 13:31:13 +02:00
{ name : 'DigitalOcean Spaces' , value : 'digitalocean-spaces' } ,
{ name : 'EXT4 Disk' , value : 'ext4' } ,
{ name : 'Exoscale SOS' , value : 'exoscale-sos' } ,
{ name : 'Filesystem' , value : 'filesystem' } ,
{ name : 'Filesystem (Mountpoint)' , value : 'mountpoint' } , // legacy
{ name : 'Google Cloud Storage' , value : 'gcs' } ,
2023-01-10 11:16:09 +01:00
{ name : 'IDrive e2' , value : 'idrive-e2' } ,
2022-09-27 13:31:13 +02:00
{ name : 'IONOS (Profitbricks)' , value : 'ionos-objectstorage' } ,
{ name : 'Linode Object Storage' , value : 'linode-objectstorage' } ,
{ name : 'Minio' , value : 'minio' } ,
{ name : 'NFS Mount' , value : 'nfs' } ,
{ name : 'OVH Object Storage' , value : 'ovh-objectstorage' } ,
{ name : 'S3 API Compatible (v4)' , value : 's3-v4-compat' } ,
{ name : 'Scaleway Object Storage' , value : 'scaleway-objectstorage' } ,
{ name : 'SSHFS Mount' , value : 'sshfs' } ,
{ name : 'UpCloud Object Storage' , value : 'upcloud-objectstorage' } ,
{ name : 'Vultr Object Storage' , value : 'vultr-objectstorage' } ,
{ name : 'Wasabi' , value : 'wasabi' } ,
{ name : 'XFS Disk' , value : 'xfs' } ,
] ;
const BACKUP _FORMATS = [
{ name : 'Tarball (zipped)' , value : 'tgz' } ,
{ name : 'rsync' , value : 'rsync' }
] ;
2021-04-07 10:47:29 +02:00
// ----------------------------------------------
// Helper to ensure loading a fallback app icon on first load failure
// ----------------------------------------------
function imageErrorHandler ( elem ) {
elem . src = elem . getAttribute ( 'fallback-icon' ) ;
}
2020-06-02 14:34:38 +02:00
// ----------------------------------------------
// Shared Angular Filters
// ----------------------------------------------
2022-10-13 21:48:03 +02:00
// https://en.wikipedia.org/wiki/Binary_prefix
// binary units (IEC) 1024 based
function prettyBinarySize ( size , fallback ) {
2020-06-02 14:34:38 +02:00
if ( ! size ) return fallback || 0 ;
2022-12-02 19:06:06 +01:00
if ( size === - 1 ) return 'Unlimited' ;
2020-06-02 14:34:38 +02:00
2022-10-13 21:48:03 +02:00
// we can also use KB here (JEDEC)
2020-06-02 14:34:38 +02:00
var i = Math . floor ( Math . log ( size ) / Math . log ( 1024 ) ) ;
2022-10-13 21:48:03 +02:00
return ( size / Math . pow ( 1024 , i ) ) . toFixed ( 2 ) * 1 + ' ' + [ 'B' , 'KiB' , 'MiB' , 'GiB' , 'TiB' ] [ i ] ;
2021-01-29 11:15:33 +01:00
}
2020-06-02 14:34:38 +02:00
2022-10-13 21:48:03 +02:00
// decimal units (SI) 1000 based
function prettyDecimalSize ( size , fallback ) {
if ( ! size ) return fallback || 0 ;
var i = Math . floor ( Math . log ( size ) / Math . log ( 1000 ) ) ;
return ( size / Math . pow ( 1000 , i ) ) . toFixed ( 2 ) * 1 + ' ' + [ 'B' , 'kB' , 'MB' , 'GB' , 'TB' ] [ i ] ;
}
angular . module ( 'Application' ) . filter ( 'prettyDecimalSize' , function ( ) {
return function ( size , fallback ) { return prettyDecimalSize ( size , fallback ) || '0 kb' ; } ;
} ) ;
angular . module ( 'Application' ) . filter ( 'prettyBinarySize' , function ( ) {
2022-10-13 21:57:12 +02:00
return function ( size , fallback ) { return prettyBinarySize ( size , fallback ) || '0 KiB' ; } ;
2020-06-02 14:34:38 +02:00
} ) ;
angular . module ( 'Application' ) . filter ( 'prettyDiskSize' , function ( ) {
2022-10-13 21:48:03 +02:00
return function ( size , fallback ) { return prettyDecimalSize ( size , fallback ) || 'Not available yet' ; } ;
2020-06-02 14:34:38 +02:00
} ) ;
2021-04-01 16:05:13 +02:00
angular . module ( 'Application' ) . filter ( 'trKeyFromPeriod' , function ( ) {
return function ( period ) {
if ( period === 6 ) return 'app.graphs.period.6h' ;
if ( period === 12 ) return 'app.graphs.period.12h' ;
if ( period === 24 ) return 'app.graphs.period.24h' ;
if ( period === 24 * 7 ) return 'app.graphs.period.7d' ;
if ( period === 24 * 30 ) return 'app.graphs.period.30d' ;
return '' ;
} ;
} ) ;
2021-04-01 17:04:46 +02:00
angular . module ( 'Application' ) . filter ( 'prettyDate' , function ( $translate ) {
2021-01-29 11:52:47 +01:00
// http://ejohn.org/files/pretty.js
return function prettyDate ( utc ) {
var date = new Date ( utc ) , // this converts utc into browser timezone and not cloudron timezone!
diff = ( ( ( new Date ( ) ) . getTime ( ) - date . getTime ( ) ) / 1000 ) + 30 , // add 30seconds for clock skew
day _diff = Math . floor ( diff / 86400 ) ;
2021-04-01 17:04:46 +02:00
if ( isNaN ( day _diff ) || day _diff < 0 ) return $translate . instant ( 'main.prettyDate.justNow' , { } ) ;
2021-01-29 11:52:47 +01:00
2023-03-24 10:54:14 +01:00
return day _diff === 0 && ( diff < 60 && $translate . instant ( 'main.prettyDate.justNow' , { } ) ||
2023-04-15 19:00:01 +02:00
moment ( utc ) . locale ( navigator . language ) . format ( 'LT' ) ) ||
2021-04-01 17:04:46 +02:00
day _diff === 1 && $translate . instant ( 'main.prettyDate.yeserday' , { } ) ||
2023-04-15 19:00:01 +02:00
moment ( utc ) . locale ( navigator . language ) . format ( 'L' ) ;
2021-01-29 11:52:47 +01:00
} ;
} ) ;
2022-09-22 19:46:36 +02:00
angular . module ( 'Application' ) . filter ( 'prettyFutureDate' , function ( ) {
return function prettyFutureDate ( utc ) {
return moment ( utc ) . fromNow ( ) ; // this converts utc into browser timezone and not cloudron timezone!
} ;
} ) ;
2021-01-29 11:52:47 +01:00
angular . module ( 'Application' ) . filter ( 'prettyLongDate' , function ( ) {
return function prettyLongDate ( utc ) {
2023-04-15 19:00:01 +02:00
return moment ( utc ) . locale ( navigator . language ) . format ( 'LLL' ) ; // this converts utc into browser timezone and not cloudron timezone!
2021-01-29 11:52:47 +01:00
} ;
} ) ;
angular . module ( 'Application' ) . filter ( 'prettyShortDate' , function ( ) {
return function prettyShortDate ( utc ) {
2023-04-15 19:00:01 +02:00
return moment ( utc ) . locale ( navigator . language ) . format ( 'L' ) ; // this converts utc into browser timezone and not cloudron timezone!
2021-01-29 11:52:47 +01:00
} ;
} ) ;
2020-07-10 15:20:53 +02:00
angular . module ( 'Application' ) . filter ( 'markdown2html' , function ( ) {
var converter = new showdown . Converter ( {
simplifiedAutoLink : true ,
strikethrough : true ,
2020-08-08 21:58:12 -07:00
tables : true ,
openLinksInNewWindow : true
2020-07-10 15:20:53 +02:00
} ) ;
// without this cache, the code runs into some infinite loop (https://github.com/angular/angular.js/issues/3980)
var cache = { } ;
return function ( text ) {
if ( cache [ text ] ) return cache [ text ] ;
cache [ text ] = converter . makeHtml ( text ) ;
return cache [ text ] ;
} ;
} ) ;
2020-11-08 10:41:42 +01:00
angular . module ( 'Application' ) . config ( [ '$translateProvider' , function ( $translateProvider ) {
$translateProvider . useStaticFilesLoader ( {
prefix : 'translation/' ,
2021-01-30 11:55:21 +01:00
suffix : '.json?' + '<%= revision %>'
2020-11-08 10:41:42 +01:00
} ) ;
$translateProvider . useLocalStorage ( ) ;
$translateProvider . preferredLanguage ( 'en' ) ;
$translateProvider . fallbackLanguage ( 'en' ) ;
} ] ) ;
// Add shorthand "tr" filter to avoid having ot use "translate"
// This is a copy of the code at https://github.com/angular-translate/angular-translate/blob/master/src/filter/translate.js
// If we find out how to get that function handle somehow dynamically we can use that, otherwise the copy is required
function translateFilterFactory ( $parse , $translate ) {
var translateFilter = function ( translationId , interpolateParams , interpolation , forceLanguage ) {
if ( ! angular . isObject ( interpolateParams ) ) {
var ctx = this || {
'__SCOPE_IS_NOT_AVAILABLE' : 'More info at https://github.com/angular/angular.js/commit/8863b9d04c722b278fa93c5d66ad1e578ad6eb1f'
} ;
interpolateParams = $parse ( interpolateParams ) ( ctx ) ;
}
return $translate . instant ( translationId , interpolateParams , interpolation , forceLanguage ) ;
} ;
if ( $translate . statefulFilter ( ) ) {
translateFilter . $stateful = true ;
}
return translateFilter ;
}
translateFilterFactory . displayName = 'translateFilterFactory' ;
angular . module ( 'Application' ) . filter ( 'tr' , translateFilterFactory ) ;
2020-06-02 14:34:38 +02:00
// ----------------------------------------------
// Cloudron REST API wrapper
// ----------------------------------------------
2019-09-05 22:22:42 +02:00
angular . module ( 'Application' ) . service ( 'Client' , [ '$http' , '$interval' , '$timeout' , 'md5' , 'Notification' , function ( $http , $interval , $timeout , md5 , Notification ) {
2018-01-22 13:01:38 -08:00
var client = null ;
// variable available only here to avoid this._property pattern
var token = null ;
function ClientError ( statusCode , messageOrObject ) {
Error . call ( this ) ;
this . name = this . constructor . name ;
this . statusCode = statusCode ;
if ( messageOrObject === null || typeof messageOrObject === 'undefined' ) {
this . message = 'Empty message or object' ;
} else if ( typeof messageOrObject === 'string' ) {
this . message = messageOrObject ;
2019-09-01 21:38:30 -07:00
} else if ( messageOrObject ) {
angular . extend ( this , messageOrObject ) ; // status, message, reason and other properties
2018-01-22 13:01:38 -08:00
}
}
function defaultErrorHandler ( callback ) {
2020-03-06 02:38:17 -08:00
function handleServerOffline ( ) {
if ( client . offline ) return ;
( function onlineCheck ( ) {
$http . get ( client . apiOrigin + '/api/v1/cloudron/status' , { } ) . success ( function ( data , status ) {
client . offline = false ;
client . _reconnectListener . forEach ( function ( handler ) { handler ( ) ; } ) ;
} ) . error ( function ( data , status ) {
2022-02-26 14:01:05 +01:00
client . offline = true ;
2020-03-06 02:38:17 -08:00
$timeout ( onlineCheck , 5000 ) ;
} ) ;
} ) ( ) ;
}
2018-01-22 13:01:38 -08:00
return function ( data , status ) {
2018-12-11 18:17:53 +01:00
// handle request killed by browser (eg. cors issue)
if ( data === null && status === - 1 ) {
2020-03-06 02:38:17 -08:00
handleServerOffline ( ) ;
2019-01-10 14:37:43 +01:00
return callback ( new ClientError ( 'Request cancelled by browser' ) ) ;
2018-12-11 18:17:53 +01:00
}
2019-05-10 09:45:37 -07:00
// re-login will make the code get a new token
2020-03-06 12:23:50 -08:00
if ( status === 401 ) return client . login ( ) ;
2019-09-07 09:18:35 +02:00
if ( status === 500 || status === 501 ) {
2021-03-29 10:37:11 +02:00
// actual internal server error, most likely a bug or timeout log to console only to not alert the user
if ( ! client . offline ) {
console . error ( status , data ) ;
console . log ( '------\nCloudron Internal Error\n\nIf you see this, please send a mail with above log to support@cloudron.io\n------\n' ) ;
}
2019-09-07 09:18:35 +02:00
} else if ( status === 502 || status === 503 || status === 504 ) {
// This means the box service is not reachable. We just show offline banner for now
}
2018-12-11 18:17:53 +01:00
2021-06-22 16:25:11 +02:00
if ( status >= 502 ) {
2020-03-06 02:38:17 -08:00
handleServerOffline ( ) ;
2018-01-22 13:01:38 -08:00
return callback ( new ClientError ( status , data ) ) ;
}
var obj = data ;
try {
obj = JSON . parse ( data ) ;
} catch ( e ) { }
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( new ClientError ( status , obj ) ) ;
} ;
}
2018-12-11 18:17:53 +01:00
function defaultSuccessHandler ( callback ) {
return function ( data , status ) {
return callback ( null , data , status ) ;
2019-05-05 09:05:06 -07:00
} ;
2018-12-11 18:17:53 +01:00
}
2018-01-22 13:01:38 -08:00
// XHR wrapper to set the auth header
2018-12-11 18:17:53 +01:00
function get ( url , config , callback ) {
2018-12-11 18:55:25 +01:00
if ( arguments . length !== 3 ) {
console . error ( 'GET' , arguments ) ;
throw ( 'Wrong number of arguments' ) ;
}
2018-01-22 13:01:38 -08:00
config = config || { } ;
config . headers = config . headers || { } ;
config . headers . Authorization = 'Bearer ' + token ;
2021-03-02 16:24:15 +01:00
return $http . get ( client . apiOrigin + url , config )
2018-12-11 18:17:53 +01:00
. success ( defaultSuccessHandler ( callback ) )
. error ( defaultErrorHandler ( callback ) ) ;
2018-01-22 13:01:38 -08:00
}
2018-12-11 18:17:53 +01:00
function head ( url , config , callback ) {
2018-12-11 18:55:25 +01:00
if ( arguments . length !== 3 ) {
console . error ( 'HEAD' , arguments ) ;
throw ( 'Wrong number of arguments' ) ;
}
2018-01-22 13:01:38 -08:00
config = config || { } ;
config . headers = config . headers || { } ;
config . headers . Authorization = 'Bearer ' + token ;
2021-03-02 16:24:15 +01:00
return $http . head ( client . apiOrigin + url , config )
2018-12-11 18:17:53 +01:00
. success ( defaultSuccessHandler ( callback ) )
. error ( defaultErrorHandler ( callback ) ) ;
2018-01-22 13:01:38 -08:00
}
2018-12-11 18:17:53 +01:00
function post ( url , data , config , callback ) {
2018-12-11 18:55:25 +01:00
if ( arguments . length !== 4 ) {
console . error ( 'POST' , arguments ) ;
throw ( 'Wrong number of arguments' ) ;
}
2018-01-22 13:01:38 -08:00
data = data || { } ;
config = config || { } ;
config . headers = config . headers || { } ;
config . headers . Authorization = 'Bearer ' + token ;
2021-03-02 16:24:15 +01:00
return $http . post ( client . apiOrigin + url , data , config )
2018-12-11 18:17:53 +01:00
. success ( defaultSuccessHandler ( callback ) )
. error ( defaultErrorHandler ( callback ) ) ;
2018-01-22 13:01:38 -08:00
}
2018-12-11 18:17:53 +01:00
function put ( url , data , config , callback ) {
2018-12-11 18:55:25 +01:00
if ( arguments . length !== 4 ) {
console . error ( 'PUT' , arguments ) ;
throw ( 'Wrong number of arguments' ) ;
}
2018-01-22 13:01:38 -08:00
data = data || { } ;
config = config || { } ;
config . headers = config . headers || { } ;
config . headers . Authorization = 'Bearer ' + token ;
2021-03-02 16:24:15 +01:00
return $http . put ( client . apiOrigin + url , data , config )
2018-12-11 18:17:53 +01:00
. success ( defaultSuccessHandler ( callback ) )
. error ( defaultErrorHandler ( callback ) ) ;
2018-01-22 13:01:38 -08:00
}
2018-12-11 18:17:53 +01:00
function del ( url , config , callback ) {
2018-12-11 18:55:25 +01:00
if ( arguments . length !== 3 ) {
console . error ( 'DEL' , arguments ) ;
throw ( 'Wrong number of arguments' ) ;
}
2018-01-22 13:01:38 -08:00
config = config || { } ;
config . headers = config . headers || { } ;
config . headers . Authorization = 'Bearer ' + token ;
2021-03-02 16:24:15 +01:00
return $http . delete ( client . apiOrigin + url , config )
2018-12-11 18:17:53 +01:00
. success ( defaultSuccessHandler ( callback ) )
. error ( defaultErrorHandler ( callback ) ) ;
2018-01-22 13:01:38 -08:00
}
function Client ( ) {
2018-12-11 18:17:53 +01:00
this . offline = false ;
2018-01-22 13:01:38 -08:00
this . _ready = false ;
this . _configListener = [ ] ;
this . _readyListener = [ ] ;
2020-03-06 02:38:17 -08:00
this . _reconnectListener = [ ] ;
2018-01-22 13:01:38 -08:00
this . _userInfo = {
id : null ,
username : null ,
email : null ,
2019-08-30 13:36:52 +02:00
twoFactorAuthenticationEnabled : false ,
2019-11-25 16:12:43 +01:00
source : null ,
2022-05-17 15:25:19 +02:00
avatarUrl : null ,
hasBackgroundImage : false
2018-01-22 13:01:38 -08:00
} ;
this . _config = {
2022-05-05 16:34:45 +02:00
consoleServerOrigin : null ,
2018-01-22 13:01:38 -08:00
fqdn : null ,
ip : null ,
revision : null ,
update : { box : null , apps : null } ,
progress : { } ,
region : null ,
2019-12-20 10:02:01 -08:00
size : null
2018-01-22 13:01:38 -08:00
} ;
this . _installedApps = [ ] ;
2018-06-26 19:07:34 -07:00
this . _installedAppsById = { } ;
2019-04-12 11:06:56 +02:00
this . _appTags = [ ] ;
2018-01-22 13:01:38 -08:00
// window.location fallback for websocket connections which do not have relative uris
2020-02-07 13:41:10 +01:00
this . apiOrigin = '<%= apiOrigin %>' || window . location . origin ;
2018-01-22 13:01:38 -08:00
this . avatar = '' ;
2020-11-18 00:28:10 +01:00
this . _availableLanguages = [ 'en' ] ;
2019-05-04 18:15:33 -07:00
this . _appstoreAppCache = [ ] ;
2018-01-22 13:01:38 -08:00
this . resetAvatar ( ) ;
this . setToken ( localStorage . token ) ;
}
2019-09-05 23:59:38 +02:00
Client . prototype . error = function ( error , action ) {
2018-01-22 13:01:38 -08:00
var message = '' ;
2019-09-05 23:59:38 +02:00
console . error ( error ) ;
2018-01-22 13:01:38 -08:00
if ( typeof error === 'object' ) {
message = error . message || error ;
} else {
message = error ;
}
2019-09-06 00:00:22 +02:00
// give more info in case the error was a request which failed with empty response body,
// this happens mostly if the box crashes
if ( message === 'Empty message or object' ) {
2021-01-29 11:15:33 +01:00
message = 'Got empty response. Click to check the server logs.' ;
2023-07-12 14:33:57 +02:00
action = action || '/frontend/logs.html?id=box' ;
2019-09-06 00:00:22 +02:00
}
2019-09-05 23:59:38 +02:00
this . notify ( 'Cloudron Error' , message , true , 'error' , action ) ;
2018-01-22 13:01:38 -08:00
} ;
2019-09-05 22:22:42 +02:00
// handles application startup errors, mostly only when dashboard is loaded and api endpoint is down
Client . prototype . initError = function ( error , initFunction ) {
console . error ( 'Application startup error' , error ) ;
$timeout ( initFunction , 5000 ) ; // we will try to re-init the app
} ;
2018-06-07 11:19:43 -07:00
Client . prototype . clearNotifications = function ( ) {
Notification . clearAll ( ) ;
} ;
2018-01-22 13:01:38 -08:00
/*
2019-01-07 17:30:01 +01:00
If `action` is a non-empty string, it will be treated as a url, if it is a function, that function will be exectued on click
2018-01-22 13:01:38 -08:00
*/
2019-01-07 17:23:26 +01:00
Client . prototype . notify = function ( title , message , persistent , type , action ) {
2018-01-22 13:01:38 -08:00
var options = { title : title , message : message } ;
2018-06-07 11:19:43 -07:00
if ( persistent ) options . delay = 'never' ; // any non Number means never timeout
2018-01-22 13:01:38 -08:00
2019-01-07 17:23:26 +01:00
if ( action ) {
options . onClick = function ( /* params */ ) {
// if action is a string, we assume it is a link
if ( typeof action === 'string' && action !== '' ) window . location = action ;
else if ( typeof action === 'function' ) action ( ) ;
else console . warn ( 'Notification action is not supported.' , action ) ;
} ;
2018-01-22 13:01:38 -08:00
}
if ( type === 'error' ) Notification . error ( options ) ;
else if ( type === 'success' ) Notification . success ( options ) ;
else if ( type === 'info' ) Notification . info ( options ) ;
else if ( type === 'warning' ) Notification . warning ( options ) ;
else throw ( 'Invalid notification type "' + type + '"' ) ;
} ;
Client . prototype . setReady = function ( ) {
if ( this . _ready ) return ;
this . _ready = true ;
this . _readyListener . forEach ( function ( callback ) {
callback ( ) ;
} ) ;
// clear the listeners, we only callback once!
this . _readyListener = [ ] ;
} ;
Client . prototype . onReady = function ( callback ) {
if ( this . _ready ) callback ( ) ;
else this . _readyListener . push ( callback ) ;
} ;
Client . prototype . onConfig = function ( callback ) {
this . _configListener . push ( callback ) ;
2022-05-05 16:53:10 +02:00
if ( this . _config ) callback ( this . _config ) ;
2018-01-22 13:01:38 -08:00
} ;
2020-03-06 02:38:17 -08:00
Client . prototype . onReconnect = function ( callback ) {
if ( this . _ready ) callback ( ) ;
else this . _reconnectListener . push ( callback ) ;
} ;
2018-01-22 13:01:38 -08:00
Client . prototype . resetAvatar = function ( ) {
this . avatar = this . apiOrigin + '/api/v1/cloudron/avatar?' + String ( Math . random ( ) ) . slice ( 2 ) ;
var favicon = $ ( '#favicon' ) ;
if ( favicon ) favicon . attr ( 'href' , this . avatar ) ;
} ;
Client . prototype . setUserInfo = function ( userInfo ) {
// In order to keep the angular bindings alive, set each property individually
this . _userInfo . id = userInfo . id ;
this . _userInfo . username = userInfo . username ;
this . _userInfo . email = userInfo . email ;
this . _userInfo . fallbackEmail = userInfo . fallbackEmail ;
this . _userInfo . displayName = userInfo . displayName ;
2018-04-26 15:12:29 +02:00
this . _userInfo . twoFactorAuthenticationEnabled = userInfo . twoFactorAuthenticationEnabled ;
2020-02-24 12:56:13 +01:00
this . _userInfo . role = userInfo . role ;
2019-08-30 13:36:52 +02:00
this . _userInfo . source = userInfo . source ;
2019-12-13 13:50:48 -08:00
this . _userInfo . avatarUrl = userInfo . avatarUrl + '?s=128&default=mp&ts=' + Date . now ( ) ; // we add the timestamp to avoid caching
2022-05-17 15:25:19 +02:00
this . _userInfo . hasBackgroundImage = userInfo . hasBackgroundImage ;
2020-02-24 12:56:13 +01:00
this . _userInfo . isAtLeastOwner = [ ROLES . OWNER ] . indexOf ( userInfo . role ) !== - 1 ;
this . _userInfo . isAtLeastAdmin = [ ROLES . OWNER , ROLES . ADMIN ] . indexOf ( userInfo . role ) !== - 1 ;
2021-12-02 09:29:33 -08:00
this . _userInfo . isAtLeastMailManager = [ ROLES . OWNER , ROLES . ADMIN , ROLES . MAIL _MANAGER ] . indexOf ( userInfo . role ) !== - 1 ;
this . _userInfo . isAtLeastUserManager = [ ROLES . OWNER , ROLES . ADMIN , ROLES . MAIL _MANAGER , ROLES . USER _MANAGER ] . indexOf ( userInfo . role ) !== - 1 ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . setConfig = function ( config ) {
var that = this ;
angular . copy ( config , this . _config ) ;
2022-05-05 16:34:45 +02:00
< % if ( appstore . consoleOrigin ) { - % >
this . _config . consoleServerOrigin = '<%= appstore.consoleOrigin %>' ;
< % } - % >
2020-02-14 20:44:27 +01:00
// => This is just for easier testing
// this._config.features.externalLdap = false;
2018-01-22 13:01:38 -08:00
this . _configListener . forEach ( function ( callback ) {
callback ( that . _config ) ;
} ) ;
} ;
Client . prototype . getInstalledApps = function ( ) {
return this . _installedApps ;
} ;
2022-09-15 12:12:32 +02:00
Client . prototype . getInstalledAppsByAppId = function ( ) {
return this . _installedAppsById ;
} ;
2019-04-12 11:06:56 +02:00
Client . prototype . getAppTags = function ( ) {
return this . _appTags ;
} ;
2018-01-22 13:01:38 -08:00
Client . prototype . getUserInfo = function ( ) {
return this . _userInfo ;
} ;
Client . prototype . getConfig = function ( ) {
return this . _config ;
} ;
2020-11-18 00:28:10 +01:00
Client . prototype . getAvailableLanguages = function ( ) {
return this . _availableLanguages ;
} ;
2018-01-22 13:01:38 -08:00
Client . prototype . setToken = function ( accessToken ) {
if ( ! accessToken ) localStorage . removeItem ( 'token' ) ;
else localStorage . token = accessToken ;
// set the token closure
token = accessToken ;
} ;
Client . prototype . getToken = function ( ) {
return token ;
} ;
/*
* Rest API wrappers
*/
Client . prototype . config = function ( callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/config' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 200 || typeof data !== 'object' ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . userInfo = function ( callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/profile' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 200 || typeof data !== 'object' ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . changeCloudronAvatar = function ( avatarFile , callback ) {
var fd = new FormData ( ) ;
fd . append ( 'avatar' , avatarFile ) ;
2018-12-11 18:17:53 +01:00
var config = {
2018-01-22 13:01:38 -08:00
headers : { 'Content-Type' : undefined } ,
transformRequest : angular . identity
2018-12-11 18:17:53 +01:00
} ;
2020-03-18 21:31:51 -07:00
post ( '/api/v1/branding/cloudron_avatar' , fd , config , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2022-02-16 10:10:40 -08:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-22 13:01:38 -08:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . changeCloudronName = function ( name , callback ) {
var data = {
name : name
} ;
2020-03-18 21:31:51 -07:00
post ( '/api/v1/branding/cloudron_name' , data , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2022-02-16 10:10:40 -08:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-22 13:01:38 -08:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . installApp = function ( id , manifest , title , config , callback ) {
var data = {
appStoreId : id + '@' + manifest . version ,
2022-01-16 18:29:32 -08:00
subdomain : config . subdomain ,
2018-01-22 13:01:38 -08:00
domain : config . domain ,
2022-01-20 16:58:00 -08:00
secondaryDomains : config . secondaryDomains ,
2018-01-22 13:01:38 -08:00
portBindings : config . portBindings ,
accessRestriction : config . accessRestriction ,
cert : config . cert ,
key : config . key ,
2019-09-24 00:21:01 +02:00
sso : config . sso ,
2022-06-09 14:21:50 +02:00
overwriteDns : config . overwriteDns ,
upstreamUri : config . upstreamUri
2018-01-22 13:01:38 -08:00
} ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/apps/install' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-22 13:01:38 -08:00
callback ( null , data . id ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2018-05-28 00:47:53 -07:00
Client . prototype . cloneApp = function ( appId , config , callback ) {
var data = {
2022-01-16 18:29:32 -08:00
subdomain : config . subdomain ,
2018-05-28 00:47:53 -07:00
domain : config . domain ,
2022-02-07 22:56:34 -08:00
secondaryDomains : config . secondaryDomains ,
2018-05-28 00:47:53 -07:00
portBindings : config . portBindings ,
2022-02-08 22:16:49 +01:00
backupId : config . backupId ,
overwriteDns : ! ! config . overwriteDns
2018-05-28 00:47:53 -07:00
} ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/apps/' + appId + '/clone' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
2018-05-28 00:47:53 -07:00
2018-06-26 08:33:04 -07:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-05-28 00:47:53 -07:00
} ;
2019-05-13 23:31:45 +02:00
Client . prototype . restoreApp = function ( appId , backupId , callback ) {
var data = { backupId : backupId } ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/apps/' + appId + '/restore' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2018-05-23 20:36:54 -07:00
Client . prototype . backupApp = function ( appId , callback ) {
2018-12-11 18:17:53 +01:00
var data = { } ;
post ( '/api/v1/apps/' + appId + '/backup' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-05-23 20:36:54 -07:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-05-23 20:36:54 -07:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-05-23 20:36:54 -07:00
} ;
2019-05-13 23:31:45 +02:00
Client . prototype . uninstallApp = function ( appId , callback ) {
var data = { } ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/apps/' + appId + '/uninstall' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2019-09-10 19:21:30 +02:00
Client . prototype . configureApp = function ( id , setting , data , callback ) {
post ( '/api/v1/apps/' + id + '/configure/' + setting , data , null , function ( error , data , status ) {
2019-09-21 22:45:26 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 200 && status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
Client . prototype . repairApp = function ( id , data , callback ) {
2019-12-06 11:44:33 -08:00
post ( '/api/v1/apps/' + id + '/repair' , data , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2019-09-10 19:21:30 +02:00
if ( status !== 200 && status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2019-09-10 19:21:30 +02:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2022-04-08 10:57:45 -07:00
Client . prototype . editAppBackup = function ( id , backupId , label , preserveSecs , callback ) {
post ( '/api/v1/apps/' + id + '/backups/' + backupId , { label : label , preserveSecs : preserveSecs } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2019-09-26 20:10:25 -07:00
Client . prototype . updateApp = function ( id , manifest , options , callback ) {
2018-01-22 13:01:38 -08:00
var data = {
2019-09-26 20:10:25 -07:00
appStoreId : manifest . id + '@' + manifest . version ,
skipBackup : ! ! options . skipBackup
2018-01-22 13:01:38 -08:00
} ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/apps/' + id + '/update' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2019-09-23 15:50:41 -07:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . startApp = function ( id , callback ) {
2018-12-14 16:01:10 -08:00
post ( '/api/v1/apps/' + id + '/start' , { } , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2019-09-23 15:50:41 -07:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . stopApp = function ( id , callback ) {
2018-12-14 16:01:10 -08:00
post ( '/api/v1/apps/' + id + '/stop' , { } , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2019-09-23 15:50:41 -07:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2019-09-12 17:42:33 +02:00
Client . prototype . restartApp = function ( id , callback ) {
2020-01-06 16:38:48 +01:00
post ( '/api/v1/apps/' + id + '/restart' , { } , null , function ( error , data , status ) {
2019-09-12 17:42:33 +02:00
if ( error ) return callback ( error ) ;
2019-12-20 11:18:48 -08:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2019-09-12 17:42:33 +02:00
2019-12-20 11:18:48 -08:00
callback ( null , data ) ;
2019-09-12 17:42:33 +02:00
} ) ;
} ;
2018-01-22 13:01:38 -08:00
Client . prototype . debugApp = function ( id , state , callback ) {
var data = {
debugMode : state ? {
2021-03-26 13:20:38 -07:00
readonlyRootfs : false ,
2018-01-22 13:01:38 -08:00
cmd : [ '/bin/bash' , '-c' , 'echo "Repair mode. Use the webterminal or cloudron exec to repair. Sleeping" && sleep infinity' ]
} : null
} ;
2019-09-19 17:30:24 -07:00
post ( '/api/v1/apps/' + id + '/configure/debug_mode' , data , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . version = function ( callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/cloudron/status' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-22 13:01:38 -08:00
callback ( null , data ) ;
2019-09-05 21:52:26 +02:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . getStatus = function ( callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/cloudron/status' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 200 || typeof data !== 'object' ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
2022-11-30 20:54:58 +01:00
} ) ;
} ;
Client . prototype . getPlatformStatus = function ( callback ) {
get ( '/api/v1/platform_status' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 || typeof data !== 'object' ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
2019-09-05 21:52:26 +02:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . setBackupConfig = function ( backupConfig , callback ) {
2023-08-04 11:24:28 +05:30
post ( '/api/v1/backups/config' , backupConfig , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . getBackupConfig = function ( callback ) {
2023-08-04 11:24:28 +05:30
get ( '/api/v1/backups/config' , null , function ( error , data , status ) {
2020-07-28 18:08:57 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
2023-07-12 10:01:53 +05:30
Client . prototype . setBackupPolicy = function ( backupPolicy , callback ) {
2023-08-04 11:24:28 +05:30
post ( '/api/v1/backups/policy' , backupPolicy , null , function ( error , data , status ) {
2023-07-12 10:01:53 +05:30
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
Client . prototype . getBackupPolicy = function ( callback ) {
2023-08-04 11:24:28 +05:30
get ( '/api/v1/backups/policy' , null , function ( error , data , status ) {
2023-07-12 10:01:53 +05:30
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . policy ) ;
} ) ;
} ;
2023-04-30 17:21:18 +02:00
Client . prototype . getBackupMountStatus = function ( callback ) {
get ( '/api/v1/backups/mount_status' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
2021-10-11 17:45:55 +02:00
Client . prototype . remountBackupStorage = function ( callback ) {
post ( '/api/v1/backups/remount' , { } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2020-02-05 14:15:46 -08:00
Client . prototype . getSupportConfig = function ( callback ) {
2023-08-02 22:21:30 +05:30
get ( '/api/v1/support/config' , null , function ( error , data , status ) {
2020-02-05 14:15:46 -08:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
2019-08-29 09:59:57 +02:00
Client . prototype . setExternalLdapConfig = function ( config , callback ) {
2023-08-03 02:06:07 +05:30
post ( '/api/v1/external_ldap/config' , config , null , function ( error , data , status ) {
2019-08-29 09:59:57 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
Client . prototype . getExternalLdapConfig = function ( callback ) {
2023-08-03 02:06:07 +05:30
get ( '/api/v1/external_ldap/config' , null , function ( error , data , status ) {
2019-08-29 09:59:57 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2020-07-09 21:51:51 -07:00
callback ( null , data ) ;
} ) ;
} ;
2022-01-13 14:40:07 -08:00
Client . prototype . setProfileConfig = function ( config , callback ) {
2023-08-03 08:11:42 +05:30
post ( '/api/v1/user_directory/profile_config' , config , null , function ( error , data , status ) {
2020-07-09 21:51:51 -07:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2022-01-13 14:40:07 -08:00
Client . prototype . getProfileConfig = function ( callback ) {
2023-08-03 08:11:42 +05:30
get ( '/api/v1/user_directory/profile_config' , null , function ( error , data , status ) {
2020-07-09 21:51:51 -07:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2019-08-29 09:59:57 +02:00
callback ( null , data ) ;
} ) ;
} ;
2022-01-07 14:22:07 +01:00
Client . prototype . setUserDirectoryConfig = function ( config , callback ) {
2023-08-03 02:26:11 +05:30
post ( '/api/v1/settings/directory_server/config' , config , null , function ( error , data , status ) {
2021-11-24 17:05:19 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2022-01-07 14:22:07 +01:00
Client . prototype . getUserDirectoryConfig = function ( callback ) {
2023-08-03 02:26:11 +05:30
get ( '/api/v1/settings/directory_server/config' , null , function ( error , data , status ) {
2021-11-24 17:05:19 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
2020-08-31 21:45:56 -07:00
// network
2023-08-03 06:05:29 +05:30
Client . prototype . setIPv4Config = function ( config , callback ) {
post ( '/api/v1/network/ipv4_config' , config , null , function ( error , data , status ) {
2019-10-31 19:33:05 -07:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2023-08-03 06:05:29 +05:30
Client . prototype . getIPv4Config = function ( callback ) {
get ( '/api/v1/network/ipv4_config' , null , function ( error , data , status ) {
2019-11-07 10:41:24 -08:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2022-01-06 12:51:08 -08:00
callback ( null , data ) ;
2019-11-07 10:41:24 -08:00
} ) ;
} ;
2022-02-15 12:51:06 -08:00
Client . prototype . getServerIpv4 = function ( callback ) {
2023-08-03 13:38:42 +05:30
get ( '/api/v1/network/ipv4' , null , function ( error , data , status ) {
2022-02-15 12:51:06 -08:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
Client . prototype . getServerIpv6 = function ( callback ) {
2023-08-03 13:38:42 +05:30
get ( '/api/v1/network/ipv6' , null , function ( error , data , status ) {
2019-10-31 19:33:05 -07:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
2020-08-31 21:45:56 -07:00
Client . prototype . getBlocklist = function ( callback ) {
2023-05-13 14:59:57 +02:00
get ( '/api/v1/network/blocklist' , null , function ( error , data , status ) {
2020-08-31 21:45:56 -07:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . blocklist ) ;
} ) ;
} ;
Client . prototype . setBlocklist = function ( blocklist , callback ) {
post ( '/api/v1/network/blocklist' , { blocklist : blocklist } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2023-05-13 14:59:57 +02:00
Client . prototype . getTrustedIps = function ( callback ) {
2023-08-04 13:19:48 +05:30
get ( '/api/v1/reverseproxy/trusted_ips' , null , function ( error , data , status ) {
2023-05-13 14:59:57 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . trustedIps ) ;
} ) ;
} ;
Client . prototype . setTrustedIps = function ( trustedIps , callback ) {
2023-08-04 13:19:48 +05:30
post ( '/api/v1/reverseproxy/trusted_ips' , { trustedIps : trustedIps } , null , function ( error , data , status ) {
2023-05-13 14:59:57 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2018-10-31 16:03:09 +01:00
Client . prototype . setDynamicDnsConfig = function ( enabled , callback ) {
2023-08-02 22:53:29 +05:30
post ( '/api/v1/network/dynamic_dns' , { enabled : enabled } , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-10-31 16:03:09 +01:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-10-31 16:03:09 +01:00
} ;
Client . prototype . getDynamicDnsConfig = function ( callback ) {
2023-08-02 22:53:29 +05:30
get ( '/api/v1/network/dynamic_dns' , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-10-31 16:03:09 +01:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-10-31 16:03:09 +01:00
callback ( null , data . enabled ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-10-31 16:03:09 +01:00
} ;
2022-02-15 12:51:06 -08:00
Client . prototype . setIPv6Config = function ( config , callback ) {
2023-08-03 06:05:29 +05:30
post ( '/api/v1/network/ipv6_config' , config , null , function ( error , data , status ) {
2022-01-06 21:50:23 -08:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
Client . prototype . getIPv6Config = function ( callback ) {
2023-08-03 06:05:29 +05:30
get ( '/api/v1/network/ipv6_config' , null , function ( error , data , status ) {
2022-01-06 21:50:23 -08:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2022-02-15 12:51:06 -08:00
callback ( null , data ) ;
2022-01-06 21:50:23 -08:00
} ) ;
} ;
2020-08-31 21:45:56 -07:00
// branding
2020-02-14 15:34:44 +01:00
Client . prototype . setFooter = function ( footer , callback ) {
2020-03-18 17:53:50 -07:00
post ( '/api/v1/branding/footer' , { footer : footer } , null , function ( error , data , status ) {
2020-02-14 15:34:44 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
Client . prototype . getFooter = function ( callback ) {
2020-03-18 17:53:50 -07:00
get ( '/api/v1/branding/footer' , null , function ( error , data , status ) {
2020-02-14 15:34:44 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . footer ) ;
} ) ;
} ;
2019-10-22 22:31:38 -07:00
Client . prototype . setRegistryConfig = function ( rc , callback ) {
post ( '/api/v1/settings/registry_config' , rc , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
Client . prototype . getRegistryConfig = function ( callback ) {
get ( '/api/v1/settings/registry_config' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
2018-06-28 17:44:11 -07:00
Client . prototype . getUpdateInfo = function ( callback ) {
2020-02-24 17:15:50 +01:00
if ( ! this . _userInfo . isAtLeastAdmin ) return callback ( new Error ( 'Not allowed' ) ) ;
2019-05-14 16:41:08 +02:00
2023-08-03 14:26:41 +05:30
get ( '/api/v1/updater/updates' , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-06-28 17:44:11 -07:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-06-28 17:44:11 -07:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-06-28 17:44:11 -07:00
} ;
2018-01-22 13:01:38 -08:00
Client . prototype . checkForUpdates = function ( callback ) {
2023-08-03 14:26:41 +05:30
post ( '/api/v1/updater/check_for_updates' , { } , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
client . refreshConfig ( callback ) ;
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2021-09-21 19:55:48 -07:00
Client . prototype . checkForAppUpdates = function ( appId , callback ) {
post ( '/api/v1/apps/' + appId + '/check_for_updates' , { } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
client . refreshConfig ( callback ) ;
} ) ;
} ;
2020-08-19 22:30:48 -07:00
Client . prototype . setAutoupdatePattern = function ( pattern , callback ) {
2023-08-03 14:26:41 +05:30
post ( '/api/v1/updater/autoupdate_pattern' , { pattern : pattern } , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-02-06 19:23:52 +01:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-02-06 19:23:52 +01:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-02-06 19:23:52 +01:00
} ;
2020-08-19 22:30:48 -07:00
Client . prototype . getAutoupdatePattern = function ( callback ) {
2023-08-03 14:26:41 +05:30
get ( '/api/v1/updater/autoupdate_pattern' , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2020-01-07 21:41:45 +01:00
Client . prototype . setTimeZone = function ( timeZone , callback ) {
2023-08-04 10:10:08 +05:30
post ( '/api/v1/cloudron/time_zone' , { timeZone : timeZone } , null , function ( error , data , status ) {
2020-01-07 21:41:45 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
Client . prototype . getTimeZone = function ( callback ) {
2023-08-04 10:10:08 +05:30
get ( '/api/v1/cloudron/time_zone' , null , function ( error , data , status ) {
2020-01-07 21:41:45 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . timeZone ) ;
} ) ;
} ;
2020-11-18 00:10:29 +01:00
Client . prototype . setLanguage = function ( language , callback ) {
2023-08-04 10:10:08 +05:30
post ( '/api/v1/cloudron/language' , { language : language } , null , function ( error , data , status ) {
2020-11-18 00:10:29 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
Client . prototype . getLanguage = function ( callback ) {
2023-08-04 10:10:08 +05:30
get ( '/api/v1/cloudron/language' , null , function ( error , data , status ) {
2020-11-18 00:10:29 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . language ) ;
} ) ;
} ;
2018-12-19 13:22:27 -08:00
Client . prototype . getRemoteSupport = function ( callback ) {
get ( '/api/v1/support/remote_support' , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-12-19 13:22:27 -08:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-12-19 13:22:27 -08:00
callback ( null , data . enabled ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2018-12-19 13:22:27 -08:00
Client . prototype . enableRemoteSupport = function ( enable , callback ) {
post ( '/api/v1/support/remote_support' , { enable : enable } , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . getBackups = function ( callback ) {
2023-01-26 12:42:05 +01:00
var page = 1 ;
var perPage = 100 ;
var backups = [ ] ;
function fetchMore ( ) {
var config = {
params : {
page : page ,
per _page : perPage
}
} ;
2018-12-11 18:17:53 +01:00
2023-01-26 12:42:05 +01:00
get ( '/api/v1/backups' , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
backups = backups . concat ( data . backups ) ;
if ( data . backups . length < perPage ) return callback ( null , backups ) ;
page ++ ;
fetchMore ( ) ;
} ) ;
}
fetchMore ( ) ;
2018-01-22 13:01:38 -08:00
} ;
2018-12-08 20:21:11 -08:00
Client . prototype . getLatestTaskByType = function ( type , callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/tasks?page=1&per_page=1&type=' + type , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2019-01-06 14:52:36 -08:00
callback ( null , data . tasks . length ? data . tasks [ 0 ] : null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-12-08 20:21:11 -08:00
} ;
2023-05-02 16:55:57 +02:00
Client . prototype . getTasksByType = function ( type , callback ) {
get ( '/api/v1/tasks?type=' + type , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . tasks ) ;
} ) ;
} ;
2018-12-08 20:21:11 -08:00
Client . prototype . getTask = function ( taskId , callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/tasks/' + taskId , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-11-19 17:34:14 -08:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-11-19 17:34:14 -08:00
} ;
2022-04-05 14:41:41 +02:00
Client . prototype . editBackup = function ( backupId , label , preserveSecs , callback ) {
post ( '/api/v1/backups/' + backupId , { label : label , preserveSecs : preserveSecs } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2018-11-17 19:55:37 -08:00
Client . prototype . startBackup = function ( callback ) {
2019-04-13 18:09:51 -07:00
post ( '/api/v1/backups/create' , { } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . taskId ) ;
} ) ;
} ;
Client . prototype . cleanupBackups = function ( callback ) {
post ( '/api/v1/backups/cleanup' , { } , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-08 20:21:11 -08:00
callback ( null , data . taskId ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-11-17 19:55:37 -08:00
} ;
2018-11-19 17:34:14 -08:00
Client . prototype . stopTask = function ( taskId , callback ) {
2018-12-14 16:01:10 -08:00
post ( '/api/v1/tasks/' + taskId + '/stop' , { } , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2019-01-06 14:52:36 -08:00
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2023-08-03 06:05:29 +05:30
Client . prototype . restore = function ( backupConfig , remotePath , version , ipv4Config , skipDnsSetup , setupToken , callback ) {
2018-01-22 13:01:38 -08:00
var data = {
backupConfig : backupConfig ,
2022-05-03 14:28:55 -07:00
remotePath : remotePath ,
2019-11-11 11:07:52 -08:00
version : version ,
2023-08-03 06:05:29 +05:30
ipv4Config : ipv4Config ,
2022-01-26 10:28:36 -08:00
skipDnsSetup : skipDnsSetup ,
setupToken : setupToken
2018-01-22 13:01:38 -08:00
} ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/cloudron/restore' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 200 ) return callback ( new ClientError ( status ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2022-04-05 09:41:09 -07:00
Client . prototype . importBackup = function ( appId , remotePath , backupFormat , backupConfig , callback ) {
2020-02-06 16:08:22 -08:00
var data = {
2022-04-05 09:41:09 -07:00
remotePath : remotePath ,
2020-02-06 16:08:22 -08:00
backupFormat : backupFormat ,
backupConfig : backupConfig ,
} ;
post ( '/api/v1/apps/' + appId + '/import' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status ) ) ;
callback ( null ) ;
} ) ;
} ;
2021-05-29 12:11:17 -07:00
Client . prototype . getNotifications = function ( options , page , perPage , callback ) {
2019-01-07 17:23:26 +01:00
var config = {
params : {
page : page ,
per _page : perPage
}
} ;
2021-05-29 12:11:17 -07:00
if ( typeof options . acknowledged === 'boolean' ) config . params . acknowledged = options . acknowledged ;
2019-01-07 17:23:26 +01:00
get ( '/api/v1/notifications' , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . notifications ) ;
} ) ;
} ;
2021-05-29 12:11:17 -07:00
Client . prototype . ackNotification = function ( notificationId , acknowledged , callback ) {
post ( '/api/v1/notifications/' + notificationId , { acknowledged : acknowledged } , null , function ( error , data , status ) {
2019-01-07 18:04:52 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 204 ) return callback ( new ClientError ( status ) ) ;
callback ( null ) ;
} ) ;
} ;
2019-01-23 16:44:57 +01:00
Client . prototype . getEvent = function ( eventId , callback ) {
2023-08-04 12:46:54 +05:30
get ( '/api/v1/eventlog/' + eventId , { } , function ( error , data , status ) {
2019-01-23 16:44:57 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . event ) ;
} ) ;
} ;
2018-03-05 11:15:25 +01:00
Client . prototype . getEventLogs = function ( actions , search , page , perPage , callback ) {
2018-01-22 13:01:38 -08:00
var config = {
params : {
2018-03-05 11:15:25 +01:00
actions : actions ,
2018-01-22 13:01:38 -08:00
search : search ,
page : page ,
per _page : perPage
}
} ;
2023-08-04 12:46:54 +05:30
get ( '/api/v1/eventlog' , config , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-22 13:01:38 -08:00
callback ( null , data . eventlogs ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . getApps = function ( callback ) {
2020-06-08 17:20:18 -07:00
var that = this ;
2018-12-11 18:17:53 +01:00
get ( '/api/v1/apps' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2020-06-08 17:20:18 -07:00
var apps = data . apps ;
for ( var i = 0 ; i < apps . length ; i ++ ) {
that . _appPostProcess ( apps [ i ] ) ; // this will also set the correct iconUrl
}
callback ( null , apps ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . getAppBackups = function ( appId , callback ) {
2022-12-19 17:10:43 +01:00
var page = 1 ;
var perPage = 100 ;
var backups = [ ] ;
function fetchMore ( ) {
var config = {
params : {
page : page ,
per _page : perPage
}
} ;
2018-12-11 18:17:53 +01:00
2022-12-19 17:10:43 +01:00
get ( '/api/v1/apps/' + appId + '/backups' , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
backups = backups . concat ( data . backups ) ;
if ( data . backups . length < perPage ) return callback ( null , backups ) ;
page ++ ;
fetchMore ( ) ;
} ) ;
}
fetchMore ( ) ;
2018-01-22 13:01:38 -08:00
} ;
2022-11-04 10:18:12 +01:00
Client . prototype . getAppBackupDownloadLink = function ( appId , backupId ) {
return client . apiOrigin + '/api/v1/apps/' + appId + '/backups/' + backupId + '/download?access_token=' + token ;
} ;
2018-12-02 18:07:11 -08:00
Client . prototype . getServices = function ( callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/services' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-02 18:07:11 -08:00
callback ( null , data . services ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-11-15 19:59:24 +01:00
} ;
2018-12-02 18:07:11 -08:00
Client . prototype . getService = function ( serviceName , callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/services/' + serviceName , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-02 18:07:11 -08:00
callback ( null , data . service ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-11-15 19:59:24 +01:00
} ;
2020-01-28 13:34:08 -08:00
Client . prototype . configureService = function ( serviceName , data , callback ) {
post ( '/api/v1/services/' + serviceName , data , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-11-21 15:57:26 +01:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-11-21 15:57:26 +01:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-11-20 16:53:42 +01:00
} ;
2018-12-02 18:07:11 -08:00
Client . prototype . restartService = function ( serviceName , callback ) {
2018-12-14 16:01:10 -08:00
post ( '/api/v1/services/' + serviceName + '/restart' , { } , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-11-16 17:21:57 +01:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-11-16 17:21:57 +01:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-11-16 17:21:57 +01:00
} ;
2021-01-21 17:41:16 -08:00
Client . prototype . rebuildService = function ( serviceName , callback ) {
post ( '/api/v1/services/' + serviceName + '/rebuild' , { } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2022-02-14 14:55:04 +01:00
Client . prototype . getAllUsers = function ( callback ) {
var page = 1 ;
2022-02-14 17:34:36 +01:00
var perPage = 5000 ;
2022-02-14 14:55:04 +01:00
var users = [ ] ;
function fetchMore ( ) {
var config = {
params : {
page : page ,
per _page : perPage
}
} ;
get ( '/api/v1/users' , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
users = users . concat ( data . users ) ;
2022-02-16 20:56:12 -08:00
if ( data . users . length < perPage ) return callback ( null , users ) ;
2022-02-14 14:55:04 +01:00
page ++ ;
fetchMore ( ) ;
} ) ;
2019-01-15 13:30:37 +01:00
}
2022-02-14 14:55:04 +01:00
fetchMore ( ) ;
} ;
Client . prototype . getUsers = function ( search , active , page , perPage , callback ) {
2019-01-14 16:57:41 +01:00
var config = {
params : {
2019-01-15 13:30:37 +01:00
page : page ,
per _page : perPage
2019-01-14 16:57:41 +01:00
}
} ;
2019-01-16 14:02:08 +01:00
if ( search ) config . params . search = search ;
2022-02-14 14:55:04 +01:00
if ( active !== null ) config . params . active = active ? 'true' : 'false' ;
2019-01-16 14:02:08 +01:00
2019-01-14 16:57:41 +01:00
get ( '/api/v1/users' , config , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-22 13:01:38 -08:00
callback ( null , data . users ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2018-06-25 16:14:14 -07:00
Client . prototype . getUser = function ( userId , callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/users/' + userId , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-06-25 16:14:14 -07:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-06-25 16:14:14 -07:00
} ;
2018-01-22 13:01:38 -08:00
Client . prototype . getGroups = function ( callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/groups' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-22 13:01:38 -08:00
callback ( null , data . groups ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . setGroups = function ( userId , groupIds , callback ) {
2018-12-11 18:17:53 +01:00
put ( '/api/v1/users/' + userId + '/groups' , { groupIds : groupIds } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . getGroup = function ( groupId , callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/groups/' + groupId , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-22 13:01:38 -08:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2018-07-26 11:38:20 -07:00
Client . prototype . createGroup = function ( name , callback ) {
2018-01-22 13:01:38 -08:00
var data = {
2018-07-26 11:38:20 -07:00
name : name
2018-01-22 13:01:38 -08:00
} ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/groups' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-22 13:01:38 -08:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2018-07-26 11:38:20 -07:00
Client . prototype . updateGroup = function ( id , name , callback ) {
2018-06-18 17:45:09 -07:00
var data = {
2018-07-26 11:38:20 -07:00
name : name
2018-06-18 17:45:09 -07:00
} ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/groups/' + id , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-07-24 22:20:00 -07:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-07-24 22:20:00 -07:00
} ;
Client . prototype . setGroupMembers = function ( id , userIds , callback ) {
var data = {
userIds : userIds
} ;
2018-12-11 18:17:53 +01:00
put ( '/api/v1/groups/' + id + '/members' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-06-18 17:45:09 -07:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-06-18 17:45:09 -07:00
} ;
2019-05-13 23:55:54 +02:00
Client . prototype . removeGroup = function ( groupId , callback ) {
2018-01-22 13:01:38 -08:00
var config = {
2019-05-13 23:55:54 +02:00
data : { } ,
2018-01-22 13:01:38 -08:00
headers : {
'Content-Type' : 'application/json'
}
} ;
2018-12-11 18:17:53 +01:00
del ( '/api/v1/groups/' + groupId , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . getApp = function ( appId , callback ) {
2019-09-10 19:21:30 +02:00
var that = this ;
2018-12-11 18:17:53 +01:00
get ( '/api/v1/apps/' + appId , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2019-09-10 19:21:30 +02:00
that . _appPostProcess ( data ) ;
2019-03-20 09:22:54 -07:00
2018-06-25 18:55:07 -07:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-06-25 18:55:07 -07:00
} ;
2021-09-21 22:19:34 -07:00
Client . prototype . getAppTask = function ( appId , callback ) {
get ( '/api/v1/apps/' + appId + '/task' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
2021-09-21 22:29:05 -07:00
Client . prototype . getAppLimits = function ( appId , callback ) {
get ( '/api/v1/apps/' + appId + '/limits' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . limits ) ;
} ) ;
} ;
2020-06-14 13:35:28 +02:00
Client . prototype . getAppWithTask = function ( appId , callback ) {
var that = this ;
this . getApp ( appId , function ( error , app ) {
if ( error ) return callback ( error ) ;
if ( ! app . taskId ) return callback ( null , app ) ;
2021-09-21 22:19:34 -07:00
that . getAppTask ( appId , function ( error , task ) {
2020-06-14 13:35:28 +02:00
if ( error ) return callback ( error ) ;
if ( task ) {
app . progress = task . percent ;
app . message = task . message ;
app . taskMinutesActive = moment . duration ( moment . utc ( ) . diff ( moment . utc ( task . creationTime ) ) ) . asMinutes ( ) ;
} else {
app . progress = 0 ;
app . message = '' ;
app . taskMinutesActive = 0 ;
}
callback ( null , app ) ;
} ) ;
} ) ;
} ;
2019-02-05 16:40:46 +01:00
Client . prototype . getCachedAppSync = function ( appId ) {
var appFound = null ;
this . _installedApps . some ( function ( app ) {
if ( app . id === appId ) {
appFound = app ;
return true ;
} else {
return false ;
}
} ) ;
return appFound ;
} ;
2021-04-14 20:58:43 -07:00
Client . prototype . disableTwoFactorAuthenticationByUserId = function ( userId , callback ) {
post ( '/api/v1/users/' + userId + '/twofactorauthentication_disable' , { } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
2019-12-11 13:58:29 -08:00
Client . prototype . setup = function ( data , callback ) {
2018-12-11 18:17:53 +01:00
post ( '/api/v1/cloudron/setup' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2020-12-21 22:36:43 -08:00
Client . prototype . createAdmin = function ( data , callback ) {
2018-01-22 13:01:38 -08:00
var that = this ;
2020-12-21 22:36:43 -08:00
post ( '/api/v1/cloudron/activate' , data , null , function ( error , result , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2020-12-21 22:36:43 -08:00
if ( status !== 201 ) return callback ( new ClientError ( status , result ) ) ;
2018-01-22 13:01:38 -08:00
2020-12-21 22:36:43 -08:00
that . setToken ( result . token ) ;
that . setUserInfo ( { username : data . username , email : data . email , admin : true , twoFactorAuthenticationEnabled : false , source : '' , avatarUrl : null } ) ;
2018-01-22 13:01:38 -08:00
2020-12-21 22:36:43 -08:00
callback ( null , result . activated ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2020-02-07 16:42:35 +01:00
Client . prototype . getTokens = function ( callback ) {
get ( '/api/v1/tokens/' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . tokens ) ;
} ) ;
} ;
2022-09-22 21:59:10 +02:00
Client . prototype . createToken = function ( name , scope , callback ) {
2020-02-07 16:42:35 +01:00
var data = {
2022-09-22 21:59:10 +02:00
name : name ,
scope : scope
2020-02-07 16:42:35 +01:00
} ;
post ( '/api/v1/tokens' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
2021-06-04 13:11:06 -07:00
callback ( null , data ) ;
2020-02-07 16:42:35 +01:00
} ) ;
} ;
// FIXME clashes with existing getToken()
// Client.prototype.getToken = function (id, callback) {
// get('/api/v1/tokens/' + id, null, function (error, data, status) {
// if (error) return callback(error);
// if (status !== 200) return callback(new ClientError(status, data));
// callback(null, data.token);
// });
// };
Client . prototype . delToken = function ( tokenId , callback ) {
del ( '/api/v1/tokens/' + tokenId , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2023-03-24 20:08:17 +01:00
Client . prototype . destroyOidcSession = function ( callback ) {
del ( '/api/v1/oidc/sessions' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2023-03-21 17:40:32 +01:00
Client . prototype . getOidcClients = function ( callback ) {
get ( '/api/v1/oidc/clients' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . clients ) ;
} ) ;
} ;
2023-07-20 13:26:07 +02:00
Client . prototype . addOidcClient = function ( id , name , secret , loginRedirectUri , tokenSignatureAlgorithm , callback ) {
2023-03-21 17:40:32 +01:00
var data = {
id : id ,
2023-03-23 09:27:40 +01:00
name : name ,
2023-03-21 17:40:32 +01:00
secret : secret ,
2023-04-04 15:38:45 +02:00
loginRedirectUri : loginRedirectUri ,
tokenSignatureAlgorithm : tokenSignatureAlgorithm
2023-03-21 17:40:32 +01:00
} ;
post ( '/api/v1/oidc/clients' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2023-07-20 13:26:07 +02:00
Client . prototype . updateOidcClient = function ( id , name , secret , loginRedirectUri , tokenSignatureAlgorithm , callback ) {
2023-03-21 17:40:32 +01:00
var data = {
secret : secret ,
2023-03-23 09:27:40 +01:00
name : name ,
2023-04-04 15:38:45 +02:00
loginRedirectUri : loginRedirectUri ,
tokenSignatureAlgorithm , tokenSignatureAlgorithm
2023-03-21 17:40:32 +01:00
} ;
post ( '/api/v1/oidc/clients/' + id , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
Client . prototype . delOidcClient = function ( id , callback ) {
del ( '/api/v1/oidc/clients/' + id , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2020-02-01 10:04:09 -08:00
Client . prototype . addAppPassword = function ( identifier , name , callback ) {
var data = {
identifier : identifier ,
name : name
} ;
post ( '/api/v1/app_passwords' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
Client . prototype . getAppPasswords = function ( callback ) {
get ( '/api/v1/app_passwords' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
Client . prototype . delAppPassword = function ( id , callback ) {
del ( '/api/v1/app_passwords/' + id , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2019-05-12 13:08:40 -07:00
Client . prototype . update = function ( options , callback ) {
var data = {
skipBackup : ! ! options . skipBackup
} ;
2018-01-22 13:01:38 -08:00
2023-08-03 14:26:41 +05:30
post ( '/api/v1/updater/update' , data , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-08 20:21:11 -08:00
callback ( null , data . taskId ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2018-11-26 08:48:58 +01:00
Client . prototype . isRebootRequired = function ( callback ) {
2023-08-04 13:41:13 +05:30
get ( '/api/v1/system/reboot' , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-11-26 08:48:58 +01:00
callback ( null , data . rebootRequired ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-11-26 08:48:58 +01:00
} ;
2018-01-22 13:01:38 -08:00
Client . prototype . reboot = function ( callback ) {
2023-08-04 13:41:13 +05:30
post ( '/api/v1/system/reboot' , { } , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-22 13:01:38 -08:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . setCertificate = function ( certificateFile , keyFile , callback ) {
var data = {
cert : certificateFile ,
key : keyFile
} ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/settings/certificate' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2023-01-23 18:43:54 +01:00
Client . prototype . getBlockDevices = function ( callback ) {
2023-08-04 13:41:13 +05:30
get ( '/api/v1/system/block_devices' , null , function ( error , data , status ) {
2023-01-23 18:43:54 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . devices ) ;
} ) ;
} ;
2018-01-22 13:01:38 -08:00
Client . prototype . disks = function ( callback ) {
2023-08-04 13:41:13 +05:30
get ( '/api/v1/system/disks' , null , function ( error , data , status ) {
2019-11-21 13:22:24 -08:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
2022-10-12 16:26:09 +02:00
Client . prototype . diskUsage = function ( callback ) {
2023-08-04 13:41:13 +05:30
get ( '/api/v1/system/disk_usage' , null , function ( error , data , status ) {
2022-10-12 16:26:09 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
Client . prototype . refreshDiskUsage = function ( callback ) {
2023-08-04 13:41:13 +05:30
post ( '/api/v1/system/disk_usage' , { } , null , function ( error , data , status ) {
2022-10-12 16:26:09 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
2022-11-09 15:04:21 +01:00
callback ( null , data . taskId ) ;
2022-10-12 16:26:09 +02:00
} ) ;
} ;
2019-11-21 13:22:24 -08:00
Client . prototype . memory = function ( callback ) {
2023-08-04 13:41:13 +05:30
get ( '/api/v1/system/memory' , null , function ( error , data , status ) {
2022-09-14 13:03:24 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
Client . prototype . getAppGraphs = function ( appId , fromMinutes , callback ) {
get ( '/api/v1/apps/' + appId + '/graphs' , { params : { fromMinutes : fromMinutes } } , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-22 13:01:38 -08:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2022-09-15 12:12:32 +02:00
Client . prototype . getSystemGraphs = function ( fromMinutes , callback ) {
2023-08-04 13:41:13 +05:30
get ( '/api/v1/system/graphs' , { params : { fromMinutes : fromMinutes } } , function ( error , data , status ) {
2022-09-15 12:12:32 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
Client . prototype . systemGraphs = function ( targets , from , options , callback ) {
2020-04-18 21:25:10 -07:00
// if we have a lot of apps, targets can be very large. node will just disconnect since it exceeds header size
var size = 10 , chunks = [ ] ;
for ( var i = 0 ; i < targets . length ; i += size ) {
chunks . push ( targets . slice ( i , i + size ) ) ;
}
2018-01-22 13:01:38 -08:00
2020-04-18 21:25:10 -07:00
var result = [ ] ;
2020-06-03 23:17:06 +02:00
async . eachSeries ( chunks , function ( chunk , iteratorCallback ) {
2020-04-18 21:25:10 -07:00
var config = {
params : {
target : chunk ,
format : 'json' ,
2020-05-22 17:16:37 +02:00
from : from ,
until : 'now'
2020-04-18 21:25:10 -07:00
}
} ;
2019-08-20 19:38:32 -07:00
2020-04-18 21:25:10 -07:00
if ( options . noNullPoints ) config . params . noNullPoints = true ;
2018-12-11 18:17:53 +01:00
2021-09-21 21:50:44 -07:00
get ( options . appId ? '/api/v1/apps/' + options . appId + '/graphs' : '/api/v1/cloudron/graphs' , config , function ( error , data , status ) {
2020-04-18 21:25:10 -07:00
if ( error ) return iteratorCallback ( error ) ;
if ( status !== 200 ) return iteratorCallback ( new ClientError ( status , data ) ) ;
// the datapoint returned here is an [value, timestamp]
result = result . concat ( data ) ;
iteratorCallback ( null ) ;
} ) ;
} , function iteratorDone ( error ) {
callback ( error , result ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2020-10-05 15:20:07 +02:00
Client . prototype . createTicket = function ( ticket , callback ) {
// just to be eplicit here
2018-01-22 13:01:38 -08:00
var data = {
2020-10-05 15:20:07 +02:00
enableSshSupport : ! ! ticket . enableSshSupport ,
type : ticket . type ,
subject : ticket . subject ,
description : ticket . description ,
appId : ticket . appId || undefined ,
altEmail : ticket . altEmail || undefined
2018-01-22 13:01:38 -08:00
} ;
2019-05-07 11:36:12 -07:00
post ( '/api/v1/support/ticket' , data , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2019-05-28 10:04:18 -07:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2022-07-07 13:32:20 +02:00
Client . prototype . getApplinks = function ( callback ) {
2022-07-07 15:22:10 +02:00
var that = this ;
2022-07-07 13:32:20 +02:00
get ( '/api/v1/applinks' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
// amend properties to mimick full app
data . applinks . forEach ( function ( applink ) {
2022-07-11 16:58:10 +02:00
applink . type = APP _TYPES . LINK ;
2022-07-07 13:32:20 +02:00
applink . fqdn = applink . upstreamUri ; // this fqdn may contain the protocol!
applink . manifest = { addons : { } } ;
applink . installationState = ISTATES . INSTALLED ;
applink . runState = RSTATES . RUNNING ;
applink . health = HSTATES . HEALTHY ;
2022-07-07 15:22:10 +02:00
applink . iconUrl = that . apiOrigin + '/api/v1/applinks/' + applink . id + '/icon?access_token=' + token + '&ts=' + applink . ts ;
2022-07-08 15:09:02 +02:00
applink . accessLevel = that . _userInfo . isAtLeastAdmin ? 'admin' : 'user' ;
2022-07-07 13:32:20 +02:00
} ) ;
callback ( null , data . applinks ) ;
} ) ;
} ;
Client . prototype . addApplink = function ( applink , callback ) {
2022-07-07 18:53:14 +02:00
post ( '/api/v1/applinks' , applink , null , function ( error , data , status ) {
2022-07-07 13:32:20 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2022-07-07 16:41:12 +02:00
Client . prototype . updateApplink = function ( id , data , callback ) {
post ( '/api/v1/applinks/' + id , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2022-07-07 16:25:04 +02:00
Client . prototype . removeApplink = function ( id , callback ) {
del ( '/api/v1/applinks/' + id , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2021-08-10 13:53:28 -07:00
Client . prototype . addUser = function ( user , callback ) {
2018-01-22 13:01:38 -08:00
var data = {
2018-07-26 15:52:06 -07:00
email : user . email ,
2021-10-26 23:39:15 +02:00
fallbackEmail : user . fallbackEmail ,
2018-07-26 15:52:06 -07:00
displayName : user . displayName ,
2020-02-21 21:12:25 +01:00
role : user . role
2018-01-22 13:01:38 -08:00
} ;
2022-02-17 14:42:24 -08:00
if ( user . username ) data . username = user . username ;
if ( user . password ) data . password = user . password ;
2018-01-22 13:01:38 -08:00
2018-12-11 18:17:53 +01:00
post ( '/api/v1/users' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
2021-08-10 13:53:28 -07:00
callback ( null , data . id ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . updateUser = function ( user , callback ) {
var data = {
email : user . email ,
2018-01-24 16:21:14 +01:00
displayName : user . displayName ,
2018-07-26 15:45:52 -07:00
fallbackEmail : user . fallbackEmail ,
2020-02-17 14:05:26 +01:00
active : user . active ,
2020-02-21 21:12:25 +01:00
role : user . role
2018-01-22 13:01:38 -08:00
} ;
2022-01-12 16:20:50 -08:00
if ( user . username ) data . username = user . username ;
2018-01-22 13:01:38 -08:00
2018-12-11 18:17:53 +01:00
post ( '/api/v1/users/' + user . id , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2021-01-15 14:28:52 +01:00
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2019-05-13 23:55:54 +02:00
Client . prototype . removeUser = function ( userId , callback ) {
2018-01-22 13:01:38 -08:00
var config = {
2019-05-13 23:55:54 +02:00
data : { } ,
2018-01-22 13:01:38 -08:00
headers : {
'Content-Type' : 'application/json'
}
} ;
2018-12-11 18:17:53 +01:00
del ( '/api/v1/users/' + userId , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . updateProfile = function ( data , callback ) {
2018-12-11 18:17:53 +01:00
post ( '/api/v1/profile' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2021-07-07 14:39:17 +02:00
Client . prototype . changeAvatar = function ( avatarFileOrType , callback ) {
// Blob type if object
if ( typeof avatarFileOrType === 'object' ) {
var fd = new FormData ( ) ;
fd . append ( 'avatar' , avatarFileOrType ) ;
2019-11-25 16:12:43 +01:00
2021-07-07 14:39:17 +02:00
var config = {
headers : { 'Content-Type' : undefined } ,
transformRequest : angular . identity
} ;
2019-11-25 16:12:43 +01:00
2021-07-07 14:39:17 +02:00
post ( '/api/v1/profile/avatar' , fd , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} else {
post ( '/api/v1/profile/avatar' , { avatar : avatarFileOrType === 'gravatar' ? 'gravatar' : '' } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
}
2019-11-25 16:12:43 +01:00
} ;
2022-04-24 22:11:35 +02:00
2022-05-14 19:41:47 +02:00
Client . prototype . getBackgroundImageUrl = function ( ) {
return client . apiOrigin + '/api/v1/profile/backgroundImage?access_token=' + token + '&bustcache=' + Date . now ( ) ;
} ;
Client . prototype . setBackgroundImage = function ( backgroundImage , callback ) {
// Blob type if object
var fd = new FormData ( ) ;
2022-05-15 12:14:32 +02:00
if ( backgroundImage ) fd . append ( 'backgroundImage' , backgroundImage ) ;
2022-05-14 19:41:47 +02:00
var config = {
headers : { 'Content-Type' : undefined } ,
transformRequest : angular . identity
} ;
post ( '/api/v1/profile/backgroundImage' , fd , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2022-04-24 22:11:35 +02:00
Client . prototype . makeUserLocal = function ( userId , callback ) {
post ( '/api/v1/users/' + userId + '/make_local' , { } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2019-11-25 16:12:43 +01:00
2018-01-22 13:01:38 -08:00
Client . prototype . changePassword = function ( currentPassword , newPassword , callback ) {
var data = {
password : currentPassword ,
newPassword : newPassword
} ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/profile/password' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2021-10-27 18:36:41 +02:00
Client . prototype . getPasswordResetLink = function ( userId , callback ) {
get ( '/api/v1/users/' + userId + '/password_reset_link' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
Client . prototype . sendPasswordResetEmail = function ( userId , email , callback ) {
post ( '/api/v1/users/' + userId + '/send_password_reset_email' , { email } , null , function ( error , data , status ) {
2021-09-09 22:24:35 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2021-09-16 14:35:17 +02:00
callback ( null , data ) ;
2021-09-09 22:24:35 +02:00
} ) ;
} ;
2021-10-28 18:45:54 +02:00
Client . prototype . sendSelfPasswordReset = function ( identifier , callback ) {
post ( '/api/v1/cloudron/password_reset_request' , { identifier } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
2021-10-27 19:57:57 +02:00
Client . prototype . getInviteLink = function ( userId , callback ) {
get ( '/api/v1/users/' + userId + '/invite_link' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
Client . prototype . sendInviteEmail = function ( userId , email , callback ) {
post ( '/api/v1/users/' + userId + '/send_invite_email' , { email } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
2018-04-26 15:12:29 +02:00
Client . prototype . setTwoFactorAuthenticationSecret = function ( callback ) {
var data = { } ;
2021-04-14 20:00:31 -07:00
post ( '/api/v1/profile/twofactorauthentication_secret' , data , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-04-26 15:12:29 +02:00
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-04-26 15:12:29 +02:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-04-26 15:12:29 +02:00
} ;
Client . prototype . enableTwoFactorAuthentication = function ( totpToken , callback ) {
var data = {
totpToken : totpToken
} ;
2021-04-14 20:00:31 -07:00
post ( '/api/v1/profile/twofactorauthentication_enable' , data , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-04-26 15:12:29 +02:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-04-26 15:12:29 +02:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-04-26 15:12:29 +02:00
} ;
Client . prototype . disableTwoFactorAuthentication = function ( password , callback ) {
var data = {
password : password
} ;
2021-04-14 20:00:31 -07:00
post ( '/api/v1/profile/twofactorauthentication_disable' , data , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-04-26 15:12:29 +02:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-04-26 15:12:29 +02:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-04-26 15:12:29 +02:00
} ;
2021-09-17 15:53:11 +02:00
Client . prototype . setGhost = function ( userId , password , expiresAt , callback ) {
var data = { password } ;
if ( expiresAt ) data . expiresAt = expiresAt ;
post ( '/api/v1/users/' + userId + '/ghost' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2019-08-29 17:22:39 +02:00
Client . prototype . startExternalLdapSync = function ( callback ) {
2023-08-03 02:06:07 +05:30
post ( '/api/v1/external_ldap/sync' , { } , null , function ( error , data , status ) {
2019-08-29 17:22:39 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2019-08-29 23:19:34 +02:00
callback ( null , data . taskId ) ;
2019-08-29 17:22:39 +02:00
} ) ;
} ;
2019-08-08 07:39:43 -07:00
Client . prototype . setUserActive = function ( userId , active , callback ) {
var data = {
active : active
} ;
post ( '/api/v1/users/' + userId + '/active' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2018-01-22 13:01:38 -08:00
Client . prototype . refreshUserInfo = function ( callback ) {
var that = this ;
callback = typeof callback === 'function' ? callback : function ( ) { } ;
this . userInfo ( function ( error , result ) {
if ( error ) return callback ( error ) ;
that . setUserInfo ( result ) ;
callback ( null ) ;
} ) ;
} ;
Client . prototype . refreshConfig = function ( callback ) {
var that = this ;
callback = typeof callback === 'function' ? callback : function ( ) { } ;
this . config ( function ( error , result ) {
if ( error ) return callback ( error ) ;
2018-06-28 17:44:11 -07:00
that . getUpdateInfo ( function ( error , info ) { // note: non-admin users may get access denied for this
if ( ! error ) result . update = info . update ; // attach update information to config object
2018-01-22 13:01:38 -08:00
2018-06-28 17:44:11 -07:00
that . setConfig ( result ) ;
callback ( null ) ;
} ) ;
2018-01-22 13:01:38 -08:00
} ) ;
} ;
2020-11-18 00:28:10 +01:00
Client . prototype . refreshAvailableLanguages = function ( callback ) {
var that = this ;
get ( '/api/v1/cloudron/languages' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
angular . copy ( data . languages , that . _availableLanguages ) ;
callback ( null , data . languages ) ;
} ) ;
} ;
2019-09-12 12:18:10 +02:00
Client . prototype . _appPostProcess = function ( app ) {
// calculate the icon paths
2021-04-30 16:05:04 -07:00
app . iconUrl = app . iconUrl ? ( this . apiOrigin + app . iconUrl + '?access_token=' + token + '&ts=' + app . ts ) : null ;
2018-01-22 13:01:38 -08:00
2018-06-14 15:46:55 +02:00
// amend the post install confirm state
app . pendingPostInstallConfirmation = ! ! localStorage [ 'confirmPostInstall_' + app . id ] ;
2021-12-21 11:25:23 -08:00
if ( app . manifest . upstreamVersion ) {
app . upstreamVersion = app . manifest . upstreamVersion ;
} else if ( app . manifest . description ) { // can be empty for dev apps
2019-11-12 17:09:18 -08:00
var tmp = app . manifest . description . match ( /\<upstream\>(.*)\<\/upstream\>/i ) ;
app . upstreamVersion = ( tmp && tmp [ 1 ] ) ? tmp [ 1 ] : '' ;
} else {
app . upstreamVersion = '' ;
}
if ( ! app . manifest . title ) app . manifest . title = 'Untitled' ;
2019-09-10 19:21:30 +02:00
2020-08-08 18:07:06 -07:00
if ( app . manifest . postInstallMessage ) {
var text = app . manifest . postInstallMessage ;
// we chose - because underscore has special meaning in markdown
2022-01-16 18:29:32 -08:00
text = text . replace ( /\$CLOUDRON-APP-LOCATION/g , app . subdomain ) ;
2021-05-25 11:32:53 -07:00
text = text . replace ( /\$CLOUDRON-APP-DOMAIN/g , app . domain ) ;
text = text . replace ( /\$CLOUDRON-APP-FQDN/g , app . fqdn ) ;
2020-08-08 22:02:31 -07:00
text = text . replace ( /\$CLOUDRON-APP-ORIGIN/g , 'https://' + app . fqdn ) ;
text = text . replace ( /\$CLOUDRON-API-DOMAIN/g , this . _config . adminFqdn ) ;
text = text . replace ( /\$CLOUDRON-API-ORIGIN/g , 'https://' + this . _config . adminFqdn ) ;
text = text . replace ( /\$CLOUDRON-USERNAME/g , this . _userInfo . username ) ;
text = text . replace ( /\$CLOUDRON-APP-ID/g , app . id ) ;
2020-08-08 18:07:06 -07:00
// [^] matches even newlines. '?' makes it non-greedy
if ( app . sso ) text = text . replace ( /<nosso>[^]*?<\/nosso>/g , '' ) ;
else text = text . replace ( /<sso>[^]*?<\/sso>/g , '' ) ;
app . manifest . postInstallMessage = text ;
}
2022-09-08 23:37:20 +02:00
app . type = app . manifest . id === 'io.cloudron.builtin.appproxy' ? APP _TYPES . PROXIED : APP _TYPES . APP ;
2018-01-22 13:01:38 -08:00
return app ;
} ;
2018-06-26 17:12:55 -07:00
function binarySearch ( array , pred ) {
var lo = - 1 , hi = array . length ;
while ( 1 + lo !== hi ) {
var mi = lo + ( ( hi - lo ) >> 1 ) ;
if ( pred ( array [ mi ] ) ) {
hi = mi ;
} else {
lo = mi ;
}
}
return hi ;
}
2018-06-26 08:41:25 -07:00
Client . prototype . _updateAppCache = function ( app ) {
var tmp = { } ;
angular . copy ( app , tmp ) ;
2020-06-14 16:31:06 +02:00
var foundIndex = this . _installedApps . findIndex ( function ( a ) { return a . id === app . id ; } ) ;
// we replace new data into the existing reference to keep angular bindings
if ( foundIndex !== - 1 ) {
angular . copy ( tmp , this . _installedApps [ foundIndex ] ) ;
2018-06-26 08:41:25 -07:00
} else {
2020-06-14 16:31:06 +02:00
this . _installedApps . push ( tmp ) ;
2022-09-15 14:43:00 +02:00
foundIndex = this . _installedApps . length - 1 ;
2018-06-26 08:41:25 -07:00
}
2018-06-26 19:07:34 -07:00
2020-06-14 16:31:06 +02:00
// add reference to object map with appId keys
this . _installedAppsById [ app . id ] = this . _installedApps [ foundIndex ] ;
2019-04-12 11:06:56 +02:00
// TODO this not very elegant
// update app tags
tmp = this . _installedApps
. map ( function ( app ) { return app . tags || [ ] ; } ) // return array of arrays
. reduce ( function ( a , i ) { return a . concat ( i ) ; } , [ ] ) // merge all arrays into one
2019-05-16 09:42:34 -07:00
. filter ( function ( v , i , self ) { return self . indexOf ( v ) === i ; } ) // filter duplicates
. sort ( function ( a , b ) { return a . localeCompare ( b ) ; } ) ; // sort
2019-04-12 11:06:56 +02:00
// keep tag array references
angular . copy ( tmp , this . _appTags ) ;
2018-06-26 08:41:25 -07:00
} ;
2018-01-22 13:01:38 -08:00
Client . prototype . refreshInstalledApps = function ( callback ) {
2021-02-18 17:01:35 +01:00
callback = callback || function ( error ) { if ( error ) console . error ( error ) ; } ;
2018-01-22 13:01:38 -08:00
var that = this ;
2018-06-26 17:56:23 -07:00
this . getApps ( function ( error , apps ) {
2018-01-22 13:01:38 -08:00
if ( error ) return callback ( error ) ;
2022-07-07 13:32:20 +02:00
that . getApplinks ( function ( error , applinks ) {
if ( error ) return callback ( error ) ;
2021-02-24 17:12:18 +01:00
2022-07-07 13:32:20 +02:00
apps = apps . concat ( applinks ) ;
2021-02-24 17:12:18 +01:00
2022-07-07 13:32:20 +02:00
async . eachLimit ( apps , 20 , function ( app , iteratorCallback ) {
2023-05-30 11:06:33 +02:00
app . ssoAuth = app . sso && ( app . manifest . addons [ 'ldap' ] || app . manifest . addons [ 'oidc' ] || app . manifest . addons [ 'proxyAuth' ] ) ; // checking app.sso first ensures app.manifest.addons is not null
2020-06-14 13:35:28 +02:00
2022-07-07 13:32:20 +02:00
if ( app . accessLevel !== 'operator' && app . accessLevel !== 'admin' ) { // only fetch if we have permissions
2020-06-14 13:35:28 +02:00
app . progress = 0 ;
app . message = '' ;
app . taskMinutesActive = 0 ;
2018-01-22 13:01:38 -08:00
2022-07-07 13:32:20 +02:00
that . _updateAppCache ( app ) ;
2018-01-22 13:01:38 -08:00
2022-07-07 13:32:20 +02:00
return iteratorCallback ( ) ;
}
2018-06-26 19:07:34 -07:00
2022-07-07 13:32:20 +02:00
var getTaskFunc = app . taskId ? that . getAppTask . bind ( null , app . id ) : function ( next ) { return next ( ) ; } ;
getTaskFunc ( function ( error , task ) {
if ( error ) return iteratorCallback ( error ) ;
if ( task ) {
app . progress = task . percent ;
app . message = task . message ;
app . taskMinutesActive = moment . duration ( moment . utc ( ) . diff ( moment . utc ( task . creationTime ) ) ) . asMinutes ( ) ;
} else {
app . progress = 0 ;
app . message = '' ;
app . taskMinutesActive = 0 ;
}
that . _updateAppCache ( app ) ;
iteratorCallback ( ) ;
} ) ;
} , function iteratorDone ( error ) {
if ( error ) return callback ( error ) ;
// filter out old apps, going backwards to allow splicing
for ( var i = that . _installedApps . length - 1 ; i >= 0 ; -- i ) {
if ( ! apps . some ( function ( elem ) { return ( elem . id === that . _installedApps [ i ] . id ) ; } ) ) {
var removed = that . _installedApps . splice ( i , 1 ) ;
delete that . _installedAppsById [ removed [ 0 ] . id ] ;
}
2018-06-26 17:56:23 -07:00
}
2022-07-07 13:32:20 +02:00
callback ( null ) ;
} ) ;
2018-06-26 17:56:23 -07:00
} ) ;
2018-01-22 13:01:38 -08:00
} ) ;
} ;
Client . prototype . login = function ( ) {
this . setToken ( null ) ;
2023-06-02 20:47:36 +02:00
// start oidc flow
2023-06-15 16:41:14 +02:00
window . location . href = this . apiOrigin + '/openid/auth?client_id=' + ( '<%= apiOrigin %>' ? 'development' : 'dashboard' ) + '&scope=openid email profile&response_type=code token&redirect_uri=' + window . location . origin + '/authcallback.html' ;
2018-01-22 13:01:38 -08:00
} ;
2020-02-04 14:35:59 +01:00
Client . prototype . logout = function ( ) {
2023-06-02 20:47:36 +02:00
var that = this ;
// destroy oidc session in the spirit of true SSO
del ( '/api/v1/oidc/sessions' , null , function ( error , data , status ) {
if ( error ) console . error ( 'Failed to logout from oidc session' ) ;
that . setToken ( null ) ;
2018-01-22 13:01:38 -08:00
2023-06-02 20:47:36 +02:00
window . location . href = '/' ;
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2021-09-21 19:46:18 -07:00
Client . prototype . getAppEventLog = function ( appId , page , perPage , callback ) {
var config = {
params : {
page : page ,
per _page : perPage
}
} ;
get ( '/api/v1/apps/' + appId + '/eventlog' , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . eventlogs ) ;
} ) ;
} ;
2018-01-23 16:10:09 -08:00
Client . prototype . sendTestMail = function ( domain , to , callback ) {
2018-01-22 13:01:38 -08:00
var data = {
2018-01-23 16:10:09 -08:00
to : to
2018-01-22 13:01:38 -08:00
} ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/mail/' + domain + '/send_test_mail' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-22 13:01:38 -08:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
// Domains
Client . prototype . getDomains = function ( callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/domains' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-22 13:01:38 -08:00
callback ( null , data . domains ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
Client . prototype . getDomain = function ( domain , callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/domains/' + domain , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-22 13:01:38 -08:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2019-09-24 00:04:31 -07:00
Client . prototype . checkDNSRecords = function ( domain , subdomain , callback ) {
2019-09-23 23:47:33 +02:00
get ( '/api/v1/domains/' + domain + '/dns_check?subdomain=' + subdomain , null , function ( error , data , status ) {
2019-09-20 01:55:45 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2019-09-23 23:46:55 +02:00
callback ( null , data ) ;
2019-09-20 01:55:45 +02:00
} ) ;
} ;
2021-12-24 15:15:07 -08:00
Client . prototype . addDomain = function ( domain , zoneName , provider , config , fallbackCertificate , tlsConfig , callback ) {
2018-01-22 13:01:38 -08:00
var data = {
domain : domain ,
provider : provider ,
2018-01-31 20:51:25 -08:00
config : config ,
2021-01-07 19:19:53 -08:00
tlsConfig : tlsConfig ,
2018-01-22 13:01:38 -08:00
} ;
2018-05-15 12:37:16 -07:00
if ( zoneName ) data . zoneName = zoneName ;
2018-01-25 10:46:41 -08:00
var that = this ;
2018-01-22 13:01:38 -08:00
if ( fallbackCertificate ) data . fallbackCertificate = fallbackCertificate ;
2018-01-25 10:46:41 -08:00
// hack until we fix the domains.js
2018-12-11 18:17:53 +01:00
post ( '/api/v1/domains' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-25 10:46:41 -08:00
2020-03-31 10:56:02 -07:00
callback ( ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2021-12-03 13:46:42 -08:00
Client . prototype . updateDomainConfig = function ( domain , zoneName , provider , config , fallbackCertificate , tlsConfig , callback ) {
2018-01-22 13:01:38 -08:00
var data = {
provider : provider ,
2018-01-31 20:51:25 -08:00
config : config ,
2021-12-03 13:46:42 -08:00
tlsConfig : tlsConfig
2018-01-22 13:01:38 -08:00
} ;
2018-05-15 12:37:16 -07:00
if ( zoneName ) data . zoneName = zoneName ;
2018-03-08 17:23:39 -08:00
var that = this ;
2018-01-22 13:01:38 -08:00
if ( fallbackCertificate ) data . fallbackCertificate = fallbackCertificate ;
2021-12-03 13:46:42 -08:00
post ( '/api/v1/domains/' + domain + '/config' , data , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-01-22 13:01:38 -08:00
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
2018-03-08 17:23:39 -08:00
2021-02-24 22:00:05 -08:00
that . setDnsRecords ( { domain : domain , type : 'mail' } , callback ) ; // this is done so that an out-of-sync dkim key can be synced
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2021-12-03 13:46:42 -08:00
Client . prototype . updateDomainWellKnown = function ( domain , wellKnown , callback ) {
var data = {
wellKnown : wellKnown
} ;
var that = this ;
post ( '/api/v1/domains/' + domain + '/wellknown' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2022-11-29 18:12:51 +01:00
Client . prototype . renewCerts = function ( options , callback ) {
2023-08-04 13:19:48 +05:30
post ( '/api/v1/reverseproxy/renew_certs' , options , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-10-24 15:24:23 -07:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-12-11 10:17:27 -08:00
callback ( null , data . taskId ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-10-24 15:24:23 -07:00
} ;
2019-05-20 18:41:08 -07:00
Client . prototype . removeDomain = function ( domain , callback ) {
2018-01-25 10:46:41 -08:00
var config = {
data : {
} ,
headers : {
'Content-Type' : 'application/json'
}
} ;
2020-03-31 10:56:02 -07:00
del ( '/api/v1/domains/' + domain , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2020-03-31 10:56:02 -07:00
callback ( null ) ;
2018-01-25 10:46:41 -08:00
} ) ;
2018-01-22 13:01:38 -08:00
} ;
2018-12-18 15:05:11 -08:00
Client . prototype . prepareDashboardDomain = function ( domain , callback ) {
var data = {
domain : domain
} ;
post ( '/api/v1/cloudron/prepare_dashboard_domain' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . taskId ) ;
} ) ;
} ;
Client . prototype . setDashboardDomain = function ( domain , callback ) {
var data = {
domain : domain
} ;
post ( '/api/v1/cloudron/set_dashboard_domain' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2018-01-23 12:29:57 +01:00
// Email
2020-03-25 20:13:45 -07:00
Client . prototype . getMailEventLogs = function ( search , types , page , perPage , callback ) {
2020-02-11 22:07:58 -08:00
var config = {
params : {
page : page ,
2020-03-25 20:13:45 -07:00
types : types ,
2020-02-14 09:09:32 -08:00
per _page : perPage ,
search : search
2020-02-11 22:07:58 -08:00
}
} ;
get ( '/api/v1/mailserver/eventlog' , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . eventlogs ) ;
} ) ;
} ;
2020-02-20 12:08:56 -08:00
Client . prototype . getMailUsage = function ( domain , callback ) {
var config = {
params : {
domain : domain
}
} ;
get ( '/api/v1/mailserver/usage' , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2023-01-24 18:31:40 +01:00
callback ( null , data . usage ) ; // { quotaValue (IEC/1024), quotaLimit (IEC/1024), quotaPercent }
2020-08-20 22:07:20 -07:00
} ) ;
} ;
2020-08-20 23:06:22 -07:00
Client . prototype . getMailLocation = function ( callback ) {
var config = { } ;
get ( '/api/v1/mailserver/location' , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ; // { subdomain, domain }
} ) ;
} ;
Client . prototype . setMailLocation = function ( subdomain , domain , callback ) {
post ( '/api/v1/mailserver/location' , { subdomain : subdomain , domain : domain } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , { taskId : data . taskId } ) ;
} ) ;
} ;
2020-08-20 22:07:20 -07:00
Client . prototype . getMaxEmailSize = function ( callback ) {
var config = { } ;
get ( '/api/v1/mailserver/max_email_size' , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . size ) ;
} ) ;
} ;
Client . prototype . setMaxEmailSize = function ( size , callback ) {
post ( '/api/v1/mailserver/max_email_size' , { size : size } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
2020-02-20 12:08:56 -08:00
} ) ;
} ;
2021-12-08 11:33:36 -08:00
Client . prototype . getMailboxSharing = function ( callback ) {
get ( '/api/v1/mailserver/mailbox_sharing' , { } , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . enabled ) ;
} ) ;
} ;
Client . prototype . setMailboxSharing = function ( enable , callback ) {
post ( '/api/v1/mailserver/mailbox_sharing' , { enable : enable } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2021-10-13 14:22:37 -07:00
Client . prototype . getDnsblConfig = function ( callback ) {
var config = { } ;
get ( '/api/v1/mailserver/dnsbl_config' , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
Client . prototype . setDnsblConfig = function ( zones , callback ) {
post ( '/api/v1/mailserver/dnsbl_config' , { zones : zones } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2020-11-19 17:45:16 -08:00
Client . prototype . getSolrConfig = function ( callback ) {
var config = { } ;
get ( '/api/v1/mailserver/solr_config' , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
Client . prototype . setSolrConfig = function ( enabled , callback ) {
post ( '/api/v1/mailserver/solr_config' , { enabled : enabled } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2020-08-22 13:01:25 -07:00
Client . prototype . getSpamAcl = function ( callback ) {
var config = { } ;
get ( '/api/v1/mailserver/spam_acl' , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
Client . prototype . setSpamAcl = function ( acl , callback ) {
post ( '/api/v1/mailserver/spam_acl' , { whitelist : acl . whitelist , blacklist : acl . blacklist } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
Client . prototype . getSpamCustomConfig = function ( callback ) {
var config = { } ;
get ( '/api/v1/mailserver/spam_custom_config' , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . config ) ;
} ) ;
} ;
Client . prototype . setSpamCustomConfig = function ( config , callback ) {
post ( '/api/v1/mailserver/spam_custom_config' , { config : config } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
2022-08-31 08:45:28 +02:00
} ;
Client . prototype . listMailQueue = function ( search , page , perPage , callback ) {
var config = {
params : {
search : search ,
page : page ,
per _page : perPage
}
} ;
2022-09-22 19:46:36 +02:00
get ( '/api/v1/mailserver/queue' , config , function ( error , data , status ) {
2022-08-31 08:45:28 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2022-09-20 11:16:33 +02:00
callback ( null , data . queue ) ;
2022-08-31 08:45:28 +02:00
} ) ;
} ;
Client . prototype . delMailQueueItem = function ( file , callback ) {
2022-09-22 19:46:36 +02:00
del ( '/api/v1/mailserver/queue/' + file , null , function ( error , data , status ) {
2022-08-31 08:45:28 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . usage ) ;
} ) ;
} ;
Client . prototype . resendMailQueueItem = function ( file , callback ) {
2022-09-22 19:46:36 +02:00
post ( '/api/v1/mailserver/queue/' + file + '/resend' , { } , null , function ( error , data , status ) {
2022-08-31 08:45:28 +02:00
if ( error ) return callback ( error ) ;
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . usage ) ;
} ) ;
2020-08-22 13:01:25 -07:00
} ;
2018-01-23 12:29:57 +01:00
Client . prototype . getMailConfigForDomain = function ( domain , callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/mail/' + domain , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-23 12:29:57 +01:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-23 12:29:57 +01:00
} ;
Client . prototype . enableMailForDomain = function ( domain , enabled , callback ) {
2018-12-11 18:17:53 +01:00
post ( '/api/v1/mail/' + domain + '/enable' , { enabled : enabled } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-23 15:35:02 +01:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-23 15:35:02 +01:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-23 12:29:57 +01:00
} ;
2021-02-24 22:00:05 -08:00
Client . prototype . setDnsRecords = function ( options , callback ) {
2023-08-04 12:53:11 +05:30
post ( '/api/v1/domains/sync_dns' , options , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-07-25 10:51:58 -07:00
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2021-02-24 22:00:05 -08:00
callback ( null , data . taskId ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-07-25 10:51:58 -07:00
} ;
2018-01-23 12:29:57 +01:00
Client . prototype . getMailStatusForDomain = function ( domain , callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/mail/' + domain + '/status' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-01-23 12:29:57 +01:00
callback ( null , data ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-23 12:29:57 +01:00
} ;
2018-12-11 18:17:53 +01:00
Client . prototype . setMailRelay = function ( domain , data , callback ) {
post ( '/api/v1/mail/' + domain + '/relay' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-23 12:29:57 +01:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2020-08-24 10:16:11 -07:00
callback ( null ) ;
} ) ;
} ;
Client . prototype . setMailBanner = function ( domain , data , callback ) {
post ( '/api/v1/mail/' + domain + '/banner' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-23 12:29:57 +01:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-23 12:29:57 +01:00
} ;
Client . prototype . setCatchallAddresses = function ( domain , addresses , callback ) {
2018-12-11 18:17:53 +01:00
post ( '/api/v1/mail/' + domain + '/catch_all' , { addresses : addresses } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-05-23 23:34:09 -07:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-05-23 23:34:09 -07:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-05-23 23:34:09 -07:00
} ;
Client . prototype . setMailFromValidation = function ( domain , enabled , callback ) {
2018-12-11 18:17:53 +01:00
post ( '/api/v1/mail/' + domain + '/mail_from_validation' , { enabled : enabled } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-23 12:29:57 +01:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-23 12:29:57 +01:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-23 12:29:57 +01:00
} ;
2018-01-24 16:20:21 +01:00
// Mailboxes
2021-12-03 11:23:25 +01:00
Client . prototype . getAllMailboxes = function ( callback ) {
var that = this ;
this . getDomains ( function ( error , domains ) {
if ( error ) return callback ( error ) ;
var mailboxes = [ ] ;
async . eachLimit ( domains , 5 , function ( domain , callback ) {
that . listMailboxes ( domain . domain , '' , 1 , 1000 , function ( error , result ) {
if ( error ) return callback ( error ) ;
mailboxes = mailboxes . concat ( result ) ;
callback ( ) ;
} ) ;
} , function ( error ) {
if ( error ) return callback ( error ) ;
callback ( null , mailboxes ) ;
} ) ;
} ) ;
} ;
2020-07-15 15:35:32 -07:00
Client . prototype . getMailboxCount = function ( domain , callback ) {
get ( '/api/v1/mail/' + domain + '/mailbox_count' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . count ) ;
} ) ;
} ;
2021-01-07 21:40:51 -08:00
Client . prototype . listMailboxes = function ( domain , search , page , perPage , callback ) {
2020-03-28 17:35:51 -07:00
var config = {
params : {
2020-07-05 12:18:34 -07:00
search : search ,
page : page ,
per _page : perPage
2020-03-28 17:35:51 -07:00
}
} ;
get ( '/api/v1/mail/' + domain + '/mailboxes' , config , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-01-24 16:20:21 +01:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-04-09 15:45:54 +02:00
2018-03-30 18:06:40 +02:00
callback ( null , data . mailboxes ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-24 16:20:21 +01:00
} ;
2018-04-05 14:02:56 +02:00
Client . prototype . getMailbox = function ( domain , name , callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/mail/' + domain + '/mailboxes/' + name , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-24 16:20:21 +01:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-24 16:20:21 +01:00
callback ( null , data . mailbox ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-24 16:20:21 +01:00
} ;
2020-11-12 23:53:02 -08:00
Client . prototype . addMailbox = function ( domain , name , ownerId , ownerType , callback ) {
2018-04-05 14:02:56 +02:00
var data = {
name : name ,
2020-11-12 23:53:02 -08:00
ownerId : ownerId ,
2021-04-14 22:37:59 -07:00
ownerType : ownerType ,
2022-08-18 09:11:15 +02:00
active : true ,
storageQuota : 0 ,
messagesQuota : 0
2018-04-05 14:02:56 +02:00
} ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/mail/' + domain + '/mailboxes' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-24 16:20:21 +01:00
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-24 16:20:21 +01:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-24 16:20:21 +01:00
} ;
2021-10-08 10:20:17 -07:00
Client . prototype . updateMailbox = function ( domain , name , data , callback ) {
2018-12-11 18:17:53 +01:00
post ( '/api/v1/mail/' + domain + '/mailboxes/' + name , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-04-05 14:02:56 +02:00
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-04-05 14:02:56 +02:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-04-05 14:02:56 +02:00
} ;
2020-07-27 22:36:38 -07:00
Client . prototype . removeMailbox = function ( domain , name , deleteMails , callback ) {
var config = {
data : {
deleteMails : deleteMails
} ,
headers : {
'Content-Type' : 'application/json'
}
} ;
del ( '/api/v1/mail/' + domain + '/mailboxes/' + name , config , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-01-24 16:20:21 +01:00
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-24 16:20:21 +01:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-24 16:20:21 +01:00
} ;
2020-04-20 19:09:25 -07:00
Client . prototype . getAliases = function ( name , domain , callback ) {
2020-03-28 17:35:51 -07:00
var config = {
params : {
page : 1 ,
per _page : 1000
}
} ;
2020-04-20 19:09:25 -07:00
get ( '/api/v1/mail/' + domain + '/mailboxes/' + name + '/aliases' , config , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-01-25 18:16:47 +01:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-25 18:16:47 +01:00
callback ( null , data . aliases ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-25 18:16:47 +01:00
} ;
2020-04-20 19:09:25 -07:00
Client . prototype . setAliases = function ( name , domain , aliases , callback ) {
2018-01-25 18:16:47 +01:00
var data = {
aliases : aliases
} ;
2020-04-20 19:09:25 -07:00
put ( '/api/v1/mail/' + domain + '/mailboxes/' + name + '/aliases' , data , null , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-01-26 15:39:02 +01:00
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-25 18:16:47 +01:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-25 18:16:47 +01:00
} ;
2020-07-05 11:55:17 -07:00
Client . prototype . listMailingLists = function ( domain , search , page , perPage , callback ) {
2020-07-05 10:49:30 -07:00
var config = {
params : {
2020-07-05 11:55:17 -07:00
search : search ,
page : page ,
per _page : perPage
2020-07-05 10:49:30 -07:00
}
} ;
get ( '/api/v1/mail/' + domain + '/lists' , config , function ( error , data , status ) {
2018-12-11 18:17:53 +01:00
if ( error ) return callback ( error ) ;
2018-04-01 21:58:12 +02:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-04-01 21:58:12 +02:00
callback ( null , data . lists ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-04-01 21:58:12 +02:00
} ;
2018-04-05 14:02:56 +02:00
Client . prototype . getMailingList = function ( domain , name , callback ) {
2018-12-11 18:17:53 +01:00
get ( '/api/v1/mail/' + domain + '/lists/' + name , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-26 11:31:19 +01:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-26 11:31:19 +01:00
callback ( null , data . list ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-26 11:31:19 +01:00
} ;
2020-04-17 17:37:19 -07:00
Client . prototype . addMailingList = function ( domain , name , members , membersOnly , callback ) {
2018-01-26 11:31:19 +01:00
var data = {
2018-04-05 14:02:56 +02:00
name : name ,
2020-04-17 17:37:19 -07:00
members : members ,
2021-04-14 22:37:59 -07:00
membersOnly : membersOnly ,
active : true
2018-01-26 11:31:19 +01:00
} ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/mail/' + domain + '/lists' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-26 11:31:19 +01:00
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-26 11:31:19 +01:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-26 11:31:19 +01:00
} ;
2021-04-14 22:37:59 -07:00
Client . prototype . updateMailingList = function ( domain , name , members , membersOnly , active , callback ) {
2018-04-05 14:02:56 +02:00
var data = {
2020-04-17 17:37:19 -07:00
members : members ,
2021-04-14 22:37:59 -07:00
membersOnly : membersOnly ,
active : active
2018-04-05 14:02:56 +02:00
} ;
2018-12-11 18:17:53 +01:00
post ( '/api/v1/mail/' + domain + '/lists/' + name , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-04-05 14:02:56 +02:00
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-04-05 14:02:56 +02:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-04-05 14:02:56 +02:00
} ;
Client . prototype . removeMailingList = function ( domain , name , callback ) {
2018-12-11 18:17:53 +01:00
del ( '/api/v1/mail/' + domain + '/lists/' + name , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
2018-01-30 13:38:06 +01:00
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
2018-12-11 18:17:53 +01:00
2018-01-26 11:31:19 +01:00
callback ( null ) ;
2018-12-11 18:17:53 +01:00
} ) ;
2018-01-26 11:31:19 +01:00
} ;
2020-10-28 16:14:32 -07:00
// Volumes
Client . prototype . getVolumes = function ( callback ) {
get ( '/api/v1/volumes' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data . volumes ) ;
} ) ;
} ;
Client . prototype . getVolume = function ( volume , callback ) {
get ( '/api/v1/volumes/' + volume , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2021-05-13 15:33:07 -07:00
callback ( null , data ) ;
} ) ;
} ;
Client . prototype . getVolumeStatus = function ( volume , callback ) {
get ( '/api/v1/volumes/' + volume + '/status' , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2020-10-28 16:14:32 -07:00
callback ( null , data ) ;
} ) ;
} ;
2023-02-25 23:14:54 +01:00
Client . prototype . addVolume = function ( name , mountType , mountOptions , callback ) {
2020-10-28 16:14:32 -07:00
var data = {
name : name ,
2021-05-12 21:40:30 -07:00
mountType : mountType ,
mountOptions : mountOptions
2020-10-28 16:14:32 -07:00
} ;
2021-06-24 16:59:13 -07:00
2020-10-28 16:14:32 -07:00
post ( '/api/v1/volumes' , data , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
2021-05-12 21:40:30 -07:00
callback ( null , data . id ) ;
} ) ;
} ;
2021-05-13 09:14:34 -07:00
Client . prototype . updateVolume = function ( volumeId , mountType , mountOptions , callback ) {
var data = {
mountType : mountType ,
mountOptions : mountOptions
} ;
post ( '/api/v1/volumes/' + volumeId , data , null , function ( error , data , status ) {
2021-05-12 21:40:30 -07:00
if ( error ) return callback ( error ) ;
2021-05-13 09:14:34 -07:00
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
2020-10-28 16:14:32 -07:00
callback ( ) ;
} ) ;
} ;
2021-10-11 15:51:26 +02:00
Client . prototype . remountVolume = function ( volumeId , callback ) {
post ( '/api/v1/volumes/' + volumeId + '/remount' , { } , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 202 ) return callback ( new ClientError ( status , data ) ) ;
callback ( ) ;
} ) ;
} ;
2020-10-28 16:14:32 -07:00
Client . prototype . removeVolume = function ( volume , callback ) {
var config = {
data : {
} ,
headers : {
'Content-Type' : 'application/json'
}
} ;
del ( '/api/v1/volumes/' + volume , config , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 204 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2020-02-21 12:34:40 +01:00
// This will change the location
Client . prototype . openSubscriptionSetup = function ( subscription ) {
2020-04-14 18:38:59 +02:00
// we only allow the owner to do so
if ( ! this . _userInfo . isAtLeastOwner ) return ;
2020-06-18 12:16:16 +02:00
// basically the user has not setup appstore account yet
if ( ! subscription . plan ) return window . location . href = '/#/appstore' ;
2022-06-04 05:44:18 +02:00
if ( subscription . plan . id === 'free' ) window . open ( this . getConfig ( ) . consoleServerOrigin + '/#/subscription_setup/' + subscription . cloudronId + '?email=' + subscription . emailEncoded , '_blank' ) ;
else window . open ( this . getConfig ( ) . consoleServerOrigin + '/#/cloudron/' + subscription . cloudronId + '?email=' + subscription . emailEncoded , '_blank' ) ;
2020-02-21 12:34:40 +01:00
} ;
2019-05-04 18:15:33 -07:00
Client . prototype . getAppstoreAppByIdAndVersion = function ( appId , version , callback ) {
var url = '/api/v1/appstore/apps/' + appId ;
if ( version && version !== 'latest' ) url += '/versions/' + version ;
get ( url , null , function ( error , data , status ) {
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null , data ) ;
} ) ;
} ;
2021-09-23 00:33:40 +02:00
Client . prototype . _onAppstoreApps = function ( callback ) {
if ( ! this . _fetchingAppstoreApps ) { console . log ( 'not fetching' ) ; callback ( ) ; }
else this . _fetchingAppstoreAppsListener . push ( callback ) ;
} ;
2023-04-02 18:03:41 +02:00
Client . prototype . getAppstoreApps = function ( callback ) {
2019-05-04 18:15:33 -07:00
var that = this ;
2022-11-09 14:18:04 +01:00
callback = callback || function ( ) { } ;
2023-04-02 18:03:41 +02:00
get ( '/api/v1/appstore/apps' , null , function ( error , data , status ) {
2019-05-04 18:15:33 -07:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
angular . copy ( data . apps , that . _appstoreAppCache ) ;
return callback ( null , that . _appstoreAppCache ) ;
} ) ;
} ;
2023-04-02 18:03:41 +02:00
Client . prototype . getAppstoreAppsFast = function ( callback ) {
if ( this . _appstoreAppCache . length !== 0 ) return callback ( null , this . _appstoreAppCache ) ;
2022-11-09 14:18:04 +01:00
2023-04-02 18:03:41 +02:00
this . getAppstoreApps ( callback ) ;
2019-05-04 18:15:33 -07:00
} ;
2019-05-04 19:22:24 -07:00
Client . prototype . getSubscription = function ( callback ) {
2019-05-05 13:02:23 -07:00
get ( '/api/v1/appstore/subscription' , null , function ( error , data , status ) {
2019-05-04 19:22:24 -07:00
if ( error ) return callback ( error ) ;
if ( status !== 200 ) return callback ( new ClientError ( status , data ) ) ;
// just some helper property, since angular bindings cannot dot his easily
data . emailEncoded = encodeURIComponent ( data . email ) ;
callback ( null , data ) ; // { email, plan: { id, name }, cancel_at, status }
} ) ;
} ;
2021-08-10 13:29:06 -07:00
Client . prototype . registerCloudron = function ( email , password , totpToken , signup , callback ) {
2019-05-04 19:22:24 -07:00
var data = {
email : email ,
password : password ,
2020-01-30 15:36:05 +01:00
signup : signup ,
2019-05-04 19:22:24 -07:00
} ;
if ( totpToken ) data . totpToken = totpToken ;
2019-05-05 13:02:23 -07:00
post ( '/api/v1/appstore/register_cloudron' , data , null , function ( error , data , status ) {
2019-05-04 19:22:24 -07:00
if ( error ) return callback ( error ) ;
if ( status !== 201 ) return callback ( new ClientError ( status , data ) ) ;
callback ( null ) ;
} ) ;
} ;
2021-09-14 12:17:17 +02:00
// ----------------------------------------------
// Eventlog helpers
// ----------------------------------------------
2021-10-19 09:49:53 -07:00
Client . prototype . eventLogDetails = function ( eventLog , appIdContext ) {
2021-09-14 12:17:17 +02:00
var ACTION _ACTIVATE = 'cloudron.activate' ;
var ACTION _PROVISION = 'cloudron.provision' ;
var ACTION _RESTORE = 'cloudron.restore' ;
var ACTION _APP _CLONE = 'app.clone' ;
var ACTION _APP _REPAIR = 'app.repair' ;
var ACTION _APP _CONFIGURE = 'app.configure' ;
var ACTION _APP _INSTALL = 'app.install' ;
var ACTION _APP _RESTORE = 'app.restore' ;
var ACTION _APP _IMPORT = 'app.import' ;
var ACTION _APP _UNINSTALL = 'app.uninstall' ;
var ACTION _APP _UPDATE = 'app.update' ;
var ACTION _APP _UPDATE _FINISH = 'app.update.finish' ;
2021-09-30 11:06:27 -07:00
var ACTION _APP _BACKUP = 'app.backup' ;
var ACTION _APP _BACKUP _FINISH = 'app.backup.finish' ;
2021-09-14 12:17:17 +02:00
var ACTION _APP _LOGIN = 'app.login' ;
var ACTION _APP _OOM = 'app.oom' ;
var ACTION _APP _UP = 'app.up' ;
var ACTION _APP _DOWN = 'app.down' ;
var ACTION _APP _START = 'app.start' ;
var ACTION _APP _STOP = 'app.stop' ;
var ACTION _APP _RESTART = 'app.restart' ;
var ACTION _BACKUP _FINISH = 'backup.finish' ;
var ACTION _BACKUP _START = 'backup.start' ;
var ACTION _BACKUP _CLEANUP _START = 'backup.cleanup.start' ;
var ACTION _BACKUP _CLEANUP _FINISH = 'backup.cleanup.finish' ;
var ACTION _CERTIFICATE _NEW = 'certificate.new' ;
var ACTION _CERTIFICATE _RENEWAL = 'certificate.renew' ;
2022-02-24 19:55:26 -08:00
var ACTION _CERTIFICATE _CLEANUP = 'certificate.cleanup' ;
2021-09-14 12:17:17 +02:00
var ACTION _DASHBOARD _DOMAIN _UPDATE = 'dashboard.domain.update' ;
var ACTION _DOMAIN _ADD = 'domain.add' ;
var ACTION _DOMAIN _UPDATE = 'domain.update' ;
var ACTION _DOMAIN _REMOVE = 'domain.remove' ;
2022-04-01 13:44:04 -07:00
var ACTION _INSTALL _FINISH = 'cloudron.install.finish' ;
2021-09-14 12:17:17 +02:00
var ACTION _START = 'cloudron.start' ;
2021-09-24 10:27:14 -07:00
var ACTION _SERVICE _CONFIGURE = 'service.configure' ;
var ACTION _SERVICE _REBUILD = 'service.rebuild' ;
var ACTION _SERVICE _RESTART = 'service.restart' ;
2021-09-14 12:17:17 +02:00
var ACTION _UPDATE = 'cloudron.update' ;
var ACTION _UPDATE _FINISH = 'cloudron.update.finish' ;
var ACTION _USER _ADD = 'user.add' ;
var ACTION _USER _LOGIN = 'user.login' ;
2022-07-29 21:35:52 +02:00
var ACTION _USER _LOGIN _GHOST = 'user.login.ghost' ;
2021-09-14 12:17:17 +02:00
var ACTION _USER _LOGOUT = 'user.logout' ;
var ACTION _USER _REMOVE = 'user.remove' ;
var ACTION _USER _UPDATE = 'user.update' ;
var ACTION _USER _TRANSFER = 'user.transfer' ;
var ACTION _MAIL _LOCATION = 'mail.location' ;
var ACTION _MAIL _ENABLED = 'mail.enabled' ;
var ACTION _MAIL _DISABLED = 'mail.disabled' ;
var ACTION _MAIL _MAILBOX _ADD = 'mail.box.add' ;
var ACTION _MAIL _MAILBOX _UPDATE = 'mail.box.update' ;
var ACTION _MAIL _MAILBOX _REMOVE = 'mail.box.remove' ;
var ACTION _MAIL _LIST _ADD = 'mail.list.add' ;
var ACTION _MAIL _LIST _UPDATE = 'mail.list.update' ;
var ACTION _MAIL _LIST _REMOVE = 'mail.list.remove' ;
var ACTION _SUPPORT _TICKET = 'support.ticket' ;
var ACTION _SUPPORT _SSH = 'support.ssh' ;
var ACTION _VOLUME _ADD = 'volume.add' ;
var ACTION _VOLUME _UPDATE = 'volume.update' ;
var ACTION _VOLUME _REMOVE = 'volume.remove' ;
var ACTION _DYNDNS _UPDATE = 'dyndns.update' ;
var data = eventLog . data ;
var errorMessage = data . errorMessage ;
var details , app ;
2021-10-19 09:49:53 -07:00
function appName ( pre , app , defaultValue ) {
if ( appIdContext ) return defaultValue || '' ;
2021-10-19 16:23:44 +02:00
pre = pre ? ( pre + ' ' ) : '' ;
2022-01-16 18:29:32 -08:00
return pre + ( app . label || app . fqdn || app . subdomain ) + ' (' + app . manifest . title + ') ' ;
2021-09-14 12:17:17 +02:00
}
switch ( eventLog . action ) {
case ACTION _ACTIVATE :
return 'Cloudron was activated' ;
case ACTION _PROVISION :
return 'Cloudron was setup' ;
case ACTION _RESTORE :
2022-04-05 10:28:30 -07:00
return 'Cloudron was restored using backup at ' + data . remotePath ;
2021-09-14 12:17:17 +02:00
case ACTION _APP _CONFIGURE : {
if ( ! data . app ) return '' ;
app = data . app ;
var q = function ( x ) {
return '"' + x + '"' ;
} ;
if ( 'accessRestriction' in data ) { // since it can be null
2021-10-19 16:23:44 +02:00
return 'Access restriction ' + appName ( 'of' , app ) + ' was changed' ;
2021-09-23 09:29:29 -07:00
} else if ( 'operators' in data ) {
2021-10-19 16:23:44 +02:00
return 'Operators ' + appName ( 'of' , app ) + ' was changed' ;
2021-09-14 12:17:17 +02:00
} else if ( data . label ) {
2021-10-19 16:23:44 +02:00
return 'Label ' + appName ( 'of' , app ) + ' was set to ' + q ( data . label ) ;
2021-09-14 12:17:17 +02:00
} else if ( data . tags ) {
2021-10-19 16:23:44 +02:00
return 'Tags ' + appName ( 'of' , app ) + ' was set to ' + q ( data . tags . join ( ',' ) ) ;
2021-09-14 12:17:17 +02:00
} else if ( data . icon ) {
2021-10-19 16:23:44 +02:00
return 'Icon ' + appName ( 'of' , app ) + ' was changed' ;
2021-09-14 12:17:17 +02:00
} else if ( data . memoryLimit ) {
2021-10-19 16:23:44 +02:00
return 'Memory limit ' + appName ( 'of' , app ) + ' was set to ' + data . memoryLimit ;
2021-09-14 12:17:17 +02:00
} else if ( data . cpuShares ) {
2021-10-19 16:23:44 +02:00
return 'CPU shares ' + appName ( 'of' , app ) + ' was set to ' + Math . round ( ( data . cpuShares * 100 ) / 1024 ) + '%' ;
2021-09-14 12:17:17 +02:00
} else if ( data . env ) {
2021-10-19 16:23:44 +02:00
return 'Env vars ' + appName ( 'of' , app ) + ' was changed' ;
2021-09-14 12:17:17 +02:00
} else if ( 'debugMode' in data ) { // since it can be null
if ( data . debugMode ) {
2021-10-19 09:49:53 -07:00
return appName ( '' , app , 'App' ) + ' was placed in repair mode' ;
2021-09-14 12:17:17 +02:00
} else {
2021-10-19 09:49:53 -07:00
return appName ( '' , app , 'App' ) + ' was taken out of repair mode' ;
2021-09-14 12:17:17 +02:00
}
} else if ( 'enableBackup' in data ) {
2021-10-19 16:23:44 +02:00
return 'Automatic backups ' + appName ( 'of' , app ) + ' were ' + ( data . enableBackup ? 'enabled' : 'disabled' ) ;
2021-09-14 12:17:17 +02:00
} else if ( 'enableAutomaticUpdate' in data ) {
2021-10-19 16:23:44 +02:00
return 'Automatic updates ' + appName ( 'of' , app ) + ' were ' + ( data . enableAutomaticUpdate ? 'enabled' : 'disabled' ) ;
2021-09-14 12:17:17 +02:00
} else if ( 'reverseProxyConfig' in data ) {
2021-10-19 16:23:44 +02:00
return 'Reverse proxy configuration ' + appName ( 'of' , app ) + ' was updated' ;
2022-09-29 19:26:22 +02:00
} else if ( 'upstreamUri' in data ) {
return 'Upstream URI ' + appName ( 'of' , app ) + ' was updated' ;
2021-09-14 12:17:17 +02:00
} else if ( 'cert' in data ) {
if ( data . cert ) {
2021-10-19 16:23:44 +02:00
return 'Custom certificate was set ' + appName ( 'for' , app ) ;
2021-09-14 12:17:17 +02:00
} else {
2021-10-19 16:23:44 +02:00
return 'Certificate ' + appName ( 'of' , app ) + ' was reset' ;
2021-09-14 12:17:17 +02:00
}
2022-01-16 18:29:32 -08:00
} else if ( data . subdomain ) {
2021-09-14 12:17:17 +02:00
if ( data . fqdn !== data . app . fqdn ) {
2021-10-19 16:23:44 +02:00
return 'Location ' + appName ( 'of' , app ) + ' was changed to ' + data . fqdn ;
2022-01-14 22:32:41 -08:00
} else if ( ! angular . equals ( data . redirectDomains , data . app . redirectDomains ) ) {
var altFqdns = data . redirectDomains . map ( function ( a ) { return a . fqdn ; } ) ;
2021-10-19 16:23:44 +02:00
return 'Alternate domains ' + appName ( 'of' , app ) + ' was ' + ( altFqdns . length ? 'set to ' + altFqdns . join ( ', ' ) : 'reset' ) ;
2021-09-14 12:17:17 +02:00
} else if ( ! angular . equals ( data . aliasDomains , data . app . aliasDomains ) ) {
var aliasDomains = data . aliasDomains . map ( function ( a ) { return a . fqdn ; } ) ;
2021-10-19 16:23:44 +02:00
return 'Alias domains ' + appName ( 'of' , app ) + ' was ' + ( aliasDomains . length ? 'set to ' + aliasDomains . join ( ', ' ) : 'reset' ) ;
2021-09-14 12:17:17 +02:00
} else if ( ! angular . equals ( data . portBindings , data . app . portBindings ) ) {
2021-10-19 16:23:44 +02:00
return 'Port bindings ' + appName ( 'of' , app ) + ' was changed' ;
2021-09-14 12:17:17 +02:00
}
} else if ( 'dataDir' in data ) {
if ( data . dataDir ) {
2021-10-19 16:23:44 +02:00
return 'Data directory ' + appName ( 'of' , app ) + ' was set ' + data . dataDir ;
2021-09-14 12:17:17 +02:00
} else {
2021-10-19 16:23:44 +02:00
return 'Data directory ' + appName ( 'of' , app ) + ' was reset' ;
2021-09-14 12:17:17 +02:00
}
} else if ( 'icon' in data ) {
if ( data . icon ) {
2021-10-19 16:23:44 +02:00
return 'Icon ' + appName ( 'of' , app ) + ' was set' ;
2021-09-14 12:17:17 +02:00
} else {
2021-10-19 16:23:44 +02:00
return 'Icon ' + appName ( 'of' , app ) + ' was reset' ;
2021-09-14 12:17:17 +02:00
}
} else if ( ( 'mailboxName' in data ) && data . mailboxName !== data . app . mailboxName ) {
if ( data . mailboxName ) {
2021-10-19 16:23:44 +02:00
return 'Mailbox ' + appName ( 'of' , app ) + ' was set to ' + q ( data . mailboxName ) ;
2021-09-14 12:17:17 +02:00
} else {
2021-10-19 16:23:44 +02:00
return 'Mailbox ' + appName ( 'of' , app ) + ' was reset' ;
2021-09-14 12:17:17 +02:00
}
}
2022-09-29 19:26:22 +02:00
return appName ( '' , app , 'App ' ) + 'was re-configured' ;
2021-09-14 12:17:17 +02:00
}
case ACTION _APP _INSTALL :
if ( ! data . app ) return '' ;
2021-10-19 16:23:44 +02:00
return data . app . manifest . title + ' (package v' + data . app . manifest . version + ') was installed ' + appName ( 'at' , data . app ) ;
2021-09-14 12:17:17 +02:00
case ACTION _APP _RESTORE :
if ( ! data . app ) return '' ;
2021-10-19 09:49:53 -07:00
details = appName ( '' , data . app , 'App' ) + ' was restored' ;
2021-09-14 12:17:17 +02:00
// older versions (<3.5) did not have these fields
if ( data . fromManifest ) details += ' from version ' + data . fromManifest . version ;
if ( data . toManifest ) details += ' to version ' + data . toManifest . version ;
2022-04-05 10:28:30 -07:00
if ( data . remotePath ) details += ' using backup at ' + data . remotePath ;
2021-09-14 12:17:17 +02:00
return details ;
case ACTION _APP _IMPORT :
if ( ! data . app ) return '' ;
2022-11-11 14:14:24 +01:00
details = appName ( '' , data . app , 'App' ) + ' was imported' ;
2021-09-14 12:17:17 +02:00
if ( data . toManifest ) details += ' to version ' + data . toManifest . version ;
2022-04-05 10:28:30 -07:00
if ( data . remotePath ) details += ' using backup at ' + data . remotePath ;
2021-09-14 12:17:17 +02:00
return details ;
case ACTION _APP _UNINSTALL :
if ( ! data . app ) return '' ;
2021-10-19 09:49:53 -07:00
return appName ( '' , data . app , 'App' ) + ' (package v' + data . app . manifest . version + ') was uninstalled' ;
2021-09-14 12:17:17 +02:00
case ACTION _APP _UPDATE :
if ( ! data . app ) return '' ;
2021-10-19 16:23:44 +02:00
return 'Update ' + appName ( 'of' , data . app ) + ' started from v' + data . fromManifest . version + ' to v' + data . toManifest . version ;
2021-09-14 12:17:17 +02:00
case ACTION _APP _UPDATE _FINISH :
if ( ! data . app ) return '' ;
2021-10-19 09:49:53 -07:00
return appName ( '' , data . app , 'App' ) + ' was updated to v' + data . app . manifest . version ;
2021-09-14 12:17:17 +02:00
2021-09-30 11:06:27 -07:00
case ACTION _APP _BACKUP :
if ( ! data . app ) return '' ;
2021-10-19 16:23:44 +02:00
return 'Backup ' + appName ( 'of' , data . app ) + ' started' ;
2021-09-30 11:06:27 -07:00
case ACTION _APP _BACKUP _FINISH :
if ( ! data . app ) return '' ;
if ( data . errorMessage ) {
2021-10-19 16:23:44 +02:00
return 'Backup ' + appName ( 'of' , data . app ) + ' failed: ' + data . errorMessage ;
2021-09-30 11:06:27 -07:00
} else {
2022-04-05 09:41:09 -07:00
return 'Backup ' + appName ( 'of' , data . app ) + ' succeeded with backup id ' + data . backupId + ' at ' + data . remotePath ;
2021-09-30 11:06:27 -07:00
}
2021-09-14 12:17:17 +02:00
case ACTION _APP _CLONE :
2021-10-19 09:49:53 -07:00
if ( appIdContext === data . oldAppId ) {
2022-04-05 10:28:30 -07:00
return 'App was cloned to ' + data . newApp . fqdn + ' using backup at ' + data . remotePath ;
2021-10-19 09:49:53 -07:00
} else if ( appIdContext === data . appId ) {
2022-04-05 10:28:30 -07:00
return 'App was cloned from ' + data . oldApp . fqdn + ' using backup at ' + data . remotePath ;
2021-10-19 09:49:53 -07:00
} else {
2022-04-05 10:28:30 -07:00
return appName ( '' , data . newApp , 'App' ) + ' was cloned ' + appName ( 'from' , data . oldApp ) + ' using backup at ' + data . remotePath ;
2021-10-19 09:49:53 -07:00
}
2021-09-14 12:17:17 +02:00
case ACTION _APP _REPAIR :
2021-10-19 09:49:53 -07:00
return appName ( '' , data . app , 'App' ) + ' was re-configured' ; // re-configure of email apps is more common?
2021-09-14 12:17:17 +02:00
case ACTION _APP _LOGIN : {
app = this . getCachedAppSync ( data . appId ) ;
if ( ! app ) return '' ;
return 'App ' + app . fqdn + ' logged in' ;
}
case ACTION _APP _OOM :
if ( ! data . app ) return '' ;
2021-10-19 09:49:53 -07:00
return appName ( '' , data . app , 'App' ) + ' ran out of memory' ;
2021-09-14 12:17:17 +02:00
case ACTION _APP _DOWN :
if ( ! data . app ) return '' ;
2021-10-19 09:49:53 -07:00
return appName ( '' , data . app , 'App' ) + ' is down' ;
2021-09-14 12:17:17 +02:00
case ACTION _APP _UP :
if ( ! data . app ) return '' ;
2021-10-19 09:49:53 -07:00
return appName ( '' , data . app , 'App' ) + ' is back online' ;
2021-09-14 12:17:17 +02:00
case ACTION _APP _START :
if ( ! data . app ) return '' ;
2021-10-19 09:49:53 -07:00
return appName ( '' , data . app , 'App' ) + ' was started' ;
2021-09-14 12:17:17 +02:00
case ACTION _APP _STOP :
if ( ! data . app ) return '' ;
2021-10-19 09:49:53 -07:00
return appName ( '' , data . app , 'App' ) + ' was stopped' ;
2021-09-14 12:17:17 +02:00
case ACTION _APP _RESTART :
if ( ! data . app ) return '' ;
2021-10-19 09:49:53 -07:00
return appName ( '' , data . app , 'App' ) + ' was restarted' ;
2021-09-14 12:17:17 +02:00
case ACTION _BACKUP _START :
return 'Backup started' ;
case ACTION _BACKUP _FINISH :
if ( ! errorMessage ) {
2022-04-05 09:41:09 -07:00
return 'Cloudron backup created at ' + data . remotePath ;
2021-09-14 12:17:17 +02:00
} else {
return 'Cloudron backup errored with error: ' + errorMessage ;
}
case ACTION _BACKUP _CLEANUP _START :
return 'Backup cleaner started' ;
case ACTION _BACKUP _CLEANUP _FINISH :
2022-06-22 09:30:12 -07:00
return data . errorMessage ? 'Backup cleaner errored: ' + data . errorMessage : 'Backup cleaner removed ' + ( data . removedBoxBackupPaths ? data . removedBoxBackupPaths . length : '0' ) + ' backups' ;
2021-09-14 12:17:17 +02:00
case ACTION _CERTIFICATE _NEW :
return 'Certificate install for ' + data . domain + ( errorMessage ? ' failed' : ' succeeded' ) ;
case ACTION _CERTIFICATE _RENEWAL :
return 'Certificate renewal for ' + data . domain + ( errorMessage ? ' failed' : ' succeeded' ) ;
2022-02-24 19:55:26 -08:00
case ACTION _CERTIFICATE _CLEANUP :
return 'Certificate(s) of ' + data . domains . join ( ',' ) + ' was cleaned up since they expired 6 months ago' ;
2021-09-14 12:17:17 +02:00
case ACTION _DASHBOARD _DOMAIN _UPDATE :
return 'Dashboard domain set to ' + data . fqdn ;
case ACTION _DOMAIN _ADD :
return 'Domain ' + data . domain + ' with ' + data . provider + ' provider was added' ;
case ACTION _DOMAIN _UPDATE :
return 'Domain ' + data . domain + ' with ' + data . provider + ' provider was updated' ;
case ACTION _DOMAIN _REMOVE :
return 'Domain ' + data . domain + ' was removed' ;
2022-04-01 13:44:04 -07:00
case ACTION _INSTALL _FINISH :
return 'Cloudron version ' + data . version + ' installed' ;
2021-09-14 12:17:17 +02:00
case ACTION _MAIL _LOCATION :
return 'Mail server location was changed to ' + data . subdomain + ( data . subdomain ? '.' : '' ) + data . domain ;
case ACTION _MAIL _ENABLED :
return 'Mail was enabled for domain ' + data . domain ;
case ACTION _MAIL _DISABLED :
return 'Mail was disabled for domain ' + data . domain ;
case ACTION _MAIL _MAILBOX _ADD :
2022-02-24 20:39:11 -08:00
return 'Mailbox ' + data . name + '@' + data . domain + ' was added' ;
2021-09-14 12:17:17 +02:00
case ACTION _MAIL _MAILBOX _UPDATE :
2022-02-24 20:39:11 -08:00
if ( data . aliases ) {
return 'Mailbox aliases of ' + data . name + '@' + data . domain + ' was updated' ;
} else {
return 'Mailbox ' + data . name + '@' + data . domain + ' was updated' ;
}
2021-09-14 12:17:17 +02:00
case ACTION _MAIL _MAILBOX _REMOVE :
2022-02-24 20:39:11 -08:00
return 'Mailbox ' + data . name + '@' + data . domain + ' was removed' ;
2021-09-14 12:17:17 +02:00
case ACTION _MAIL _LIST _ADD :
2022-02-24 20:39:11 -08:00
return 'Mail list ' + data . name + '@' + data . domain + 'was added' ;
2021-09-14 12:17:17 +02:00
case ACTION _MAIL _LIST _UPDATE :
2022-02-24 20:39:11 -08:00
return 'Mail list ' + data . name + '@' + data . domain + ' was updated' ;
2021-09-14 12:17:17 +02:00
case ACTION _MAIL _LIST _REMOVE :
2022-02-24 20:39:11 -08:00
return 'Mail list ' + data . name + '@' + data . domain + ' was removed' ;
2021-09-14 12:17:17 +02:00
case ACTION _START :
return 'Cloudron started with version ' + data . version ;
2021-09-24 10:27:14 -07:00
case ACTION _SERVICE _CONFIGURE :
return 'Service ' + data . id + ' was configured' ;
case ACTION _SERVICE _REBUILD :
return 'Service ' + data . id + ' was rebuilt' ;
case ACTION _SERVICE _RESTART :
return 'Service ' + data . id + ' was restarted' ;
2021-09-14 12:17:17 +02:00
case ACTION _UPDATE :
return 'Cloudron update to version ' + data . boxUpdateInfo . version + ' was started' ;
case ACTION _UPDATE _FINISH :
if ( data . errorMessage ) {
return 'Cloudron update errored. Error: ' + data . errorMessage ;
} else {
return 'Cloudron updated to version ' + data . newVersion ;
}
case ACTION _USER _ADD :
2022-09-27 21:30:13 +02:00
return 'User ' + data . email + ( data . user . username ? ' (' + data . user . username + ')' : '' ) + ' was added' ;
2021-09-14 12:17:17 +02:00
case ACTION _USER _UPDATE :
2022-09-27 21:30:13 +02:00
return 'User ' + ( data . user ? ( data . user . email + ( data . user . username ? ' (' + data . user . username + ')' : '' ) ) : data . userId ) + ' was updated' ;
2021-09-14 12:17:17 +02:00
case ACTION _USER _REMOVE :
2022-09-27 21:30:13 +02:00
return 'User ' + ( data . user ? ( data . user . email + ( data . user . username ? ' (' + data . user . username + ')' : '' ) ) : data . userId ) + ' was removed' ;
2021-09-14 12:17:17 +02:00
case ACTION _USER _TRANSFER :
return 'Apps of ' + data . oldOwnerId + ' was transferred to ' + data . newOwnerId ;
case ACTION _USER _LOGIN :
2023-07-25 18:02:39 +05:30
app = this . getCachedAppSync ( data . appId ) ;
return 'User ' + ( data . user ? data . user . username : data . userId ) + ' logged in to ' + ( app ? app . fqdn : data . appId ) ;
2021-09-14 12:17:17 +02:00
2022-07-29 21:35:52 +02:00
case ACTION _USER _LOGIN _GHOST :
2022-09-27 21:30:13 +02:00
return 'User ' + ( data . user ? data . user . username : data . userId ) + ' was impersonated' ;
2022-07-29 21:35:52 +02:00
2021-09-14 12:17:17 +02:00
case ACTION _USER _LOGOUT :
2022-09-27 21:30:13 +02:00
return 'User ' + ( data . user ? data . user . username : data . userId ) + ' logged out' ;
2021-09-14 12:17:17 +02:00
2022-03-15 10:00:48 -07:00
case ACTION _DYNDNS _UPDATE : {
2023-07-08 19:48:12 +05:30
details = data . errorMessage ? 'Error updating DNS. ' : 'Updated DNS. ' ;
if ( data . fromIpv4 !== data . toIpv4 ) details += 'From IPv4 ' + data . fromIpv4 + ' to ' + data . toIpv4 + '. ' ;
if ( data . fromIpv6 !== data . toIpv6 ) details += 'From IPv6 ' + data . fromIpv6 + ' to ' + data . toIpv6 + '.' ;
if ( data . errorMessage ) details += ' ' + data . errorMessage ;
2022-03-15 10:00:48 -07:00
return details ;
}
2021-09-14 12:17:17 +02:00
case ACTION _SUPPORT _SSH :
return 'Remote Support was ' + ( data . enable ? 'enabled' : 'disabled' ) ;
case ACTION _SUPPORT _TICKET :
return 'Support ticket was created' ;
case ACTION _VOLUME _ADD :
return 'Volume "' + data . volume . name + '" was added' ;
case ACTION _VOLUME _UPDATE :
return 'Volme "' + data . volume . name + '" was updated' ;
case ACTION _VOLUME _REMOVE :
return 'Volume "' + data . volume . name + '" was removed' ;
default : return eventLog . action ;
}
2022-07-29 21:35:52 +02:00
} ;
2021-09-14 12:17:17 +02:00
Client . prototype . eventLogSource = function ( eventLog ) {
var source = eventLog . source ;
var line = '' ;
line = source . username || source . userId || source . mailboxId || source . authType || 'system' ;
if ( source . appId ) {
var app = this . getCachedAppSync ( source . appId ) ;
line += ' - ' + ( app ? app . fqdn : source . appId ) ;
} else if ( source . ip ) {
line += ' - ' + source . ip ;
}
return line ;
2022-07-29 21:35:52 +02:00
} ;
2021-09-14 12:17:17 +02:00
2018-01-22 13:01:38 -08:00
client = new Client ( ) ;
return client ;
} ] ) ;