@ -33,7 +33,8 @@ moment.locale( window.navigator.languages );
let localized _invalid _date = moment ( 'today' , '!@#' ) ,
let localized _invalid _date = moment ( 'today' , '!@#' ) ,
time _language = null ,
time _language = null ,
time _format = null ;
time _format = null ,
allowed _dirs = null ;
@ -44,7 +45,7 @@ let localized_invalid_date = moment('today', '!@#'),
*
*
* @ memberOf LightDM
* @ memberOf LightDM
* /
* /
const ThemeUtils = {
class ThemeUtils {
/ * *
/ * *
* Binds ` this ` to class , ` context ` , for all of the class ' s methods .
* Binds ` this ` to class , ` context ` , for all of the class ' s methods .
*
*
@ -74,7 +75,7 @@ const ThemeUtils = {
}
}
}
}
}
}
} ,
}
/ * *
/ * *
@ -88,7 +89,51 @@ const ThemeUtils = {
*
*
* @ returns { String [ ] } List of abs paths for the files and directories found in ` path ` .
* @ returns { String [ ] } List of abs paths for the files and directories found in ` path ` .
* /
* /
dirlist ( path ) { } ,
dirlist ( path ) {
let allowed = true ;
if ( '' === path || ! path instanceof String ) {
console . log ( '[ERROR] theme_utils.dirlist(): path must be a non-empty string!' ) ;
allowed = false ;
} else if ( null !== path . match ( /^[^/].+/ ) ) {
console . log ( '[ERROR] theme_utils.dirlist(): path must not include be absolute!' ) ;
allowed = false ;
}
if ( null !== path . match ( /\/\.+(?=\/)/ ) ) {
// No special directory names allowed (eg ../../)
path = path . replace ( /\/\.+(?=\/)/g , '' ) ;
}
if ( null === allowed _dirs ) {
let user = lightdm . users . pop ( ) ;
allowed _dirs = {
themes _dir : greeter _config . get _str ( user . username , 'lightdm_data_dir' ) ,
backgrounds _dir : greeter _config . get _str ( 'greeter' , 'themes_dir' ) ,
lightdm _data _dir : greeter _config . get _str ( 'branding' , 'background_images' ) ,
tmpdir : '/tmp'
} ;
}
if ( ! Object . keys ( allowed _dirs ) . some ( dir => path . startsWith ( allowed _dirs [ dir ] ) ) ) {
console . log ( ` [ERROR] theme_utils.dirlist(): path is not allowed: ${ path } ` ) ;
allowed = false ;
}
if ( ! allowed ) {
return [ ] ;
}
try {
return _ _ThemeUtils . dirlist ( path ) ;
} catch ( err ) {
console . log ( ` [ERROR] theme_utils.dirlist(): ${ err } ` ) ;
return [ ] ;
}
}
/ * *
/ * *
* Escape HTML entities in a string .
* Escape HTML entities in a string .
@ -97,7 +142,9 @@ const ThemeUtils = {
*
*
* @ returns { String }
* @ returns { String }
* /
* /
esc _html ( text ) { } ,
esc _html ( text ) {
return this . txt2html ( text ) ;
}
/ * *
/ * *
@ -132,23 +179,29 @@ const ThemeUtils = {
}
}
return local _time ;
return local _time ;
} ,
}
/ * *
/ * *
* @ deprecated Use { @ link theme _utils . esc _html ( ) } instead .
* @ deprecated Use { @ link theme _utils . esc _html ( ) } instead .
* /
* /
txt2html ( text ) { } ,
txt2html ( text ) {
} ;
try {
return _ _ThemeUtils . txt2html ( text ) ;
} catch ( err ) {
console . log ( ` [ERROR] theme_utils.dirlist(): ${ err } ` ) ;
return text ;
}
}
}
/ * *
/ * *
* @ memberOf window
* @ memberOf window
* @ type { LightDM . ThemeUtils }
* @ type { LightDM . ThemeUtils }
* /
* /
window . theme _utils = _ _ThemeUtils ;
window . theme _utils = new ThemeUtils ( ) ;
window . theme _utils . bind _this = ThemeUtils . bind _this ;
window . theme _utils . get _current _localized _time = ThemeUtils . get _current _localized _time ;
/ * *
/ * *
* @ deprecated
* @ deprecated