@@ -457,16 +457,12 @@ export class Message {
457457 await this . DumpClients ( cli , span ) ;
458458 break ;
459459 case "dumprabbitmq" :
460- await this . DumpRabbitmq ( cli , span ) ;
461460 break ;
462461 case "getrabbitmqqueue" :
463- await this . GetRabbitmqQueue ( cli ) ;
464462 break ;
465463 case "deleterabbitmqqueue" :
466- await this . DeleterabbitmqQueue ( cli ) ;
467464 break ;
468465 case "pushmetrics" :
469- await this . PushMetrics ( cli ) ;
470466 break ;
471467 default :
472468 span . recordException ( "Unknown command " + command ) ;
@@ -507,6 +503,9 @@ export class Message {
507503 this . Reply ( ) ;
508504 let msg : RegisterQueueMessage ;
509505 try {
506+ if ( ! NoderedUtil . IsNullEmpty ( msg . queuename ) && msg . queuename . toLowerCase ( ) == "openflow" ) {
507+ throw new Error ( "Access denied" ) ;
508+ }
510509 msg = RegisterQueueMessage . assign ( this . data ) ;
511510 msg . queuename = await cli . CreateConsumer ( msg . queuename , parent ) ;
512511 } catch ( error ) {
@@ -549,6 +548,12 @@ export class Message {
549548 } catch ( error ) {
550549 }
551550 }
551+ if ( ! NoderedUtil . IsNullEmpty ( msg . queuename ) && msg . queuename . toLowerCase ( ) == "openflow" ) {
552+ throw new Error ( "Access denied" ) ;
553+ } else if ( NoderedUtil . IsNullEmpty ( msg . queuename ) && NoderedUtil . IsNullEmpty ( msg . exchange ) ) {
554+ throw new Error ( "queuename or exchange must be given" ) ;
555+ }
556+
552557
553558 if ( msg . queuename . length == 24 && Config . amqp_force_sender_has_read ) {
554559 const tuser = Crypt . verityToken ( msg . jwt ) ;
@@ -3583,124 +3588,6 @@ export class Message {
35833588 Logger . otel . endSpan ( span ) ;
35843589 this . Send ( cli ) ;
35853590 }
3586- async DumpRabbitmq ( cli : WebSocketServerClient , parent : Span ) {
3587- this . Reply ( ) ;
3588- const span : Span = Logger . otel . startSubSpan ( "message.DumpRabbitmq" , parent ) ;
3589- try {
3590- const kickstartapi = amqpwrapper . getvhosts ( Config . amqp_url ) ;
3591- const jwt = Crypt . rootToken ( ) ;
3592- const known = await Config . db . query ( { _type : "queue" } , null , 5000 , 0 , null , "configclients" , jwt , undefined , undefined , span ) ;
3593- const queues = await amqpwrapper . getqueues ( Config . amqp_url ) ;
3594- for ( let i = 0 ; i < queues . length ; i ++ ) {
3595- let queue = queues [ i ] ;
3596- let exists = known . filter ( ( x : any ) => ( x && x . queuename == queue . name ) ) ;
3597- let item : any = {
3598- name : queue . id , consumers : queue . consumers , consumer_details : queue . consumer_details , _type : "queue"
3599- } ;
3600- let consumers : number = 0 ;
3601- if ( queue . consumers > 0 ) { consumers = queue . consumers ; }
3602- if ( consumers == 0 ) {
3603- if ( queue . consumer_details != null && queue . consumer_details . length > 0 ) {
3604- consumers = queue . consumer_details . length ;
3605- }
3606- }
3607- item . queuename = queue . name ;
3608- item . consumers = consumers ;
3609- item . name = queue . name + "(" + consumers + ")" ;
3610- if ( exists . length == 0 ) {
3611- try {
3612- await Config . db . InsertOne ( item , "configclients" , 1 , false , jwt , span ) ;
3613- } catch ( error ) {
3614- await handleError ( cli , error ) ;
3615- }
3616- } else {
3617- item . _id = exists [ 0 ] . _id ;
3618- try {
3619- await Config . db . _UpdateOne ( null , item , "configclients" , 1 , false , jwt , span ) ;
3620- } catch ( error ) {
3621- await handleError ( cli , error ) ;
3622- }
3623- }
3624- }
3625- for ( let i = 0 ; i < known . length ; i ++ ) {
3626- let queue : any = known [ i ] ;
3627- let id = queue . id ;
3628- let exists = queues . filter ( ( x : any ) => x . name == queue . queuename ) ;
3629- if ( exists . length == 0 ) {
3630- try {
3631- await Config . db . DeleteOne ( queue . _id , "configclients" , jwt , span ) ;
3632- } catch ( error ) {
3633- await handleError ( cli , error ) ;
3634- }
3635- }
3636- }
3637- } catch ( error ) {
3638- span . recordException ( error ) ;
3639- this . data = "" ;
3640- await handleError ( cli , error ) ;
3641- }
3642- Logger . otel . endSpan ( span ) ;
3643- this . Send ( cli ) ;
3644- }
3645- async GetRabbitmqQueue ( cli : WebSocketServerClient ) {
3646- this . Reply ( ) ;
3647- try {
3648- let msg : any = JSON . parse ( this . data ) ;
3649- const kickstartapi = amqpwrapper . getvhosts ( Config . amqp_url ) ;
3650- try {
3651- msg . data = await amqpwrapper . getqueue ( Config . amqp_url , '/' , msg . name ) ;
3652- this . data = JSON . stringify ( msg ) ;
3653- } catch ( error ) {
3654- await handleError ( cli , error ) ;
3655- }
3656- } catch ( error ) {
3657- this . data = JSON . stringify ( error ) ;
3658- await handleError ( cli , error ) ;
3659-
3660- }
3661- this . Send ( cli ) ;
3662- }
3663- async DeleterabbitmqQueue ( cli : WebSocketServerClient ) {
3664- this . Reply ( ) ;
3665- try {
3666- let msg : any = JSON . parse ( this . data ) ;
3667- const kickstartapi = amqpwrapper . getvhosts ( Config . amqp_url ) ;
3668- try {
3669- msg . data = await amqpwrapper . deletequeue ( Config . amqp_url , '/' , msg . name ) ;
3670- this . data = JSON . stringify ( msg ) ;
3671- } catch ( error ) {
3672- await handleError ( cli , error ) ;
3673- }
3674- } catch ( error ) {
3675- this . data = JSON . stringify ( error ) ;
3676- await handleError ( cli , error ) ;
3677-
3678- }
3679- this . Send ( cli ) ;
3680- }
3681- async PushMetrics ( cli : WebSocketServerClient ) {
3682- this . Reply ( ) ;
3683- // let msg: PushMetricsMessage;
3684- // try {
3685- // msg = PushMetricsMessage.assign(this.data);
3686- // cli.metrics = msg.metrics;
3687- // if (NoderedUtil.IsNullUndefinded(msg.jwt)) msg.jwt = cli.jwt;
3688- // } catch (error) {
3689- // if (error == null) new Error("Unknown error");
3690- // await handleError(cli, error);
3691- // if (NoderedUtil.IsNullUndefinded(msg)) { (msg as any) = {}; }
3692- // if (msg !== null && msg !== undefined) {
3693- // msg.error = (error.message ? error.message : error);
3694- // }
3695- // }
3696- // try {
3697- // this.data = JSON.stringify(msg);
3698- // } catch (error) {
3699- // this.data = "";
3700- // await handleError(cli, error);
3701- // }
3702- this . Send ( cli ) ;
3703- }
37043591}
37053592
37063593export class JSONfn {
0 commit comments