2024-11-04 04:09:11 -05:00
import { promisify } from 'node:util'
2024-10-18 07:04:57 -04:00
import Settings from '@overleaf/settings'
import AdminController from '../app/src/Features/ServerAdmin/AdminController.js'
import minimist from 'minimist'
2024-11-04 04:09:11 -05:00
import { fileURLToPath } from 'node:url'
2021-09-24 04:32:05 -04:00
2024-10-18 07:04:57 -04:00
const args = minimist ( process . argv . slice ( 2 ) , {
2023-11-09 04:54:55 -05:00
string : [ 'confirm-site-url' , 'delay-in-seconds' ] ,
default : {
'delay-in-seconds' : 10 ,
'confirm-site-url' : '' ,
} ,
} )
2024-10-18 07:04:57 -04:00
2023-11-09 04:54:55 -05:00
const sleep = promisify ( setTimeout )
async function main ( ) {
if ( args . help ) {
console . error ( )
console . error (
2024-10-18 07:04:57 -04:00
' usage: node disconnect_all_users.mjs [--delay-in-seconds=10] --confirm-site-url=https://www....\n'
2023-11-09 04:54:55 -05:00
)
2021-09-24 04:32:05 -04:00
process . exit ( 1 )
}
2024-06-17 04:10:04 -04:00
const isSaaS = Boolean ( Settings . overleaf )
if ( isSaaS && args [ 'confirm-site-url' ] !== Settings . siteUrl ) {
2023-11-09 04:54:55 -05:00
console . error ( )
console . error (
'Please confirm the environment you want to disconnect ALL USERS from by specifying the site URL aka PUBLIC_URL, e.g. --confirm-site-url=https://www.dev-overleaf.com for the dev-env'
)
console . error ( )
console . error (
` !!! --confirm-site-url= ${
args [ 'confirm-site-url' ] || "''"
} does not match the PUBLIC _URL in this environment . `
)
console . error ( )
console . error ( ' Are you running this script in the correct environment?' )
process . exit ( 1 )
}
2023-11-24 07:02:42 -05:00
const delay = parseInt ( args [ 'delay-in-seconds' ] || '10' , 10 )
if ( ! ( delay >= 0 ) ) {
console . error (
` --delay-in-seconds=' ${ args [ 'delay-in-seconds' ] } ' should be a number >=0 `
)
process . exit ( 1 )
}
2023-11-09 04:54:55 -05:00
console . log ( )
console . log (
` Disconnect all users from ${ args [ 'confirm-site-url' ] } , with delay ${ delay } `
)
2024-06-17 04:10:04 -04:00
if ( isSaaS ) {
console . error ( ' Use CTRL+C in the next 5s to abort.' )
await sleep ( 5 * 1000 )
}
2023-11-09 04:54:55 -05:00
await AdminController . _sendDisconnectAllUsersMessage ( delay )
}
2024-10-18 07:04:57 -04:00
if ( fileURLToPath ( import . meta . url ) === process . argv [ 1 ] ) {
try {
await main ( )
console . error ( 'Done.' )
process . exit ( 0 )
} catch ( error ) {
console . error ( 'Error' , error )
process . exit ( 1 )
}
2021-09-24 04:32:05 -04:00
}