2022-12-20 21:17:03 +01:00
< ? php
if ( ! isset ( $_POST [ 'delete' ]))
2023-01-21 01:27:52 +01:00
output ( 403 , _ ( 'Account deletion must be confirmed.' ));
2022-12-20 21:17:03 +01:00
2023-03-09 01:35:30 +01:00
$user_services = explode ( ',' , query ( 'select' , 'users' , [ 'username' => $_SESSION [ 'id' ]], 'services' )[ 0 ]);
2022-12-20 21:17:03 +01:00
2023-03-09 01:35:30 +01:00
foreach ( SERVICES_USER as $service )
if ( in_array ( $service , $user_services , true ) AND CONF [ 'common' ][ 'services' ][ $service ] !== 'enabled' )
output ( 503 , sprintf ( _ ( 'Your account can\'t be deleted because the %s service is currently unavailable.' ), '<em>' . PAGES [ $service ][ 'index' ][ 'title' ] . '</em>' ));
2022-12-20 21:17:03 +01:00
2023-03-09 01:35:30 +01:00
if ( in_array ( 'reg' , $user_services , true ))
foreach ( query ( 'select' , 'registry' , [ 'username' => $_SESSION [ 'id' ]], 'domain' ) as $domain )
regDeleteDomain ( $domain );
2022-12-20 21:17:03 +01:00
2023-03-09 01:35:30 +01:00
if ( in_array ( 'ns' , $user_services , true ))
foreach ( query ( 'select' , 'zones' , [ 'username' => $_SESSION [ 'id' ]], 'zone' ) as $zone )
nsDeleteZone ( $zone );
2022-12-20 21:17:03 +01:00
2023-03-09 01:35:30 +01:00
if ( in_array ( 'ht' , $user_services , true )) {
foreach ( query ( 'select' , 'sites' , [ 'username' => $_SESSION [ 'id' ]]) as $site )
htDeleteSite ( $site [ 'address' ], $site [ 'type' ]);
2022-12-20 21:17:03 +01:00
2023-03-09 01:35:30 +01:00
exec ( CONF [ 'ht' ][ 'sudo_path' ] . ' -u ' . CONF [ 'ht' ][ 'tor_user' ] . ' ' . CONF [ 'ht' ][ 'rm_path' ] . ' --recursive ' . CONF [ 'ht' ][ 'tor_keys_path' ] . '/' . $_SESSION [ 'id' ], result_code : $code );
if ( $code !== 0 )
output ( 500 , 'Can\'t remove Tor keys directory.' );
removeDirectory ( CONF [ 'ht' ][ 'tor_config_path' ] . '/' . $_SESSION [ 'id' ]);
exec ( CONF [ 'ht' ][ 'sudo_path' ] . ' -u ' . CONF [ 'ht' ][ 'sftpgo_user' ] . ' ' . CONF [ 'ht' ][ 'rm_path' ] . ' --recursive ' . CONF [ 'ht' ][ 'ht_path' ] . '/' . $_SESSION [ 'id' ], result_code : $code );
if ( $code !== 0 )
output ( 500 , 'Can\'t remove user\'s directory.' );
}
2022-12-20 21:17:03 +01:00
query ( 'delete' , 'users' , [ 'id' => $_SESSION [ 'id' ]]);
logout ();
2023-01-21 01:27:52 +01:00
output ( 200 , _ ( 'Account deleted.' ));