Node-Red configuration
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

receiver-lcd.js 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2013 Stephen Vickers
  2. var snmp = require ("../");
  3. var cb = function(error, trap) {
  4. if ( error ) {
  5. console.error (error);
  6. } else {
  7. console.log (JSON.stringify(trap, null, 2));
  8. }
  9. };
  10. var options = {
  11. disableAuthorization: true,
  12. accessControlModelType: snmp.AccessControlModelType.Simple,
  13. port: 1162
  14. };
  15. var receiver = snmp.createReceiver (options, cb);
  16. var authorizer = receiver.getAuthorizer ();
  17. console.log ("\nCommunity tests");
  18. console.log ("===============\n");
  19. console.log ("Initial communities:");
  20. console.log ("communities =", authorizer.getCommunities () );
  21. authorizer.addCommunity ("public");
  22. authorizer.addCommunity ("private");
  23. console.log ("After adding 'public' and 'private' communities:");
  24. console.log ("communities =", authorizer.getCommunities () );
  25. console.log ("Fetch existing 'public' community:");
  26. console.log (authorizer.getCommunity("public"));
  27. console.log ("Fetch non-existent community 'notfound':");
  28. console.log (authorizer.getCommunity("notfound"));
  29. console.log ("Delete non-existent community 'notfound':");
  30. authorizer.deleteCommunity("notfound");
  31. console.log ("communities =", authorizer.getCommunities () );
  32. console.log ("Delete existing community 'private':");
  33. authorizer.deleteCommunity("private");
  34. console.log ("communities =", authorizer.getCommunities () );
  35. var fred = {
  36. name: "fred",
  37. level: snmp.SecurityLevel.noAuthNoPriv
  38. };
  39. var wilma = {
  40. name: "wilma",
  41. level: snmp.SecurityLevel.authPriv,
  42. authProtocol: snmp.AuthProtocols.sha,
  43. authKey: "illhavesomeauth",
  44. privProtocol: snmp.PrivProtocols.des,
  45. privKey: "andsomepriv"
  46. };
  47. var newWilma = {
  48. name: "wilma",
  49. level: snmp.SecurityLevel.authNoPriv,
  50. authProtocol: snmp.AuthProtocols.sha,
  51. authKey: "illhavesomeauth"
  52. };
  53. console.log ("\nUser tests");
  54. console.log ("==========\n");
  55. console.log ("Initial users:");
  56. console.log ("users =", authorizer.getUsers () );
  57. authorizer.addUser (fred);
  58. authorizer.addUser (wilma);
  59. console.log ("After adding 'fred' and 'wilma' users:");
  60. console.log ("users =", authorizer.getUsers () );
  61. console.log ("Fetch existing user 'fred':");
  62. console.log (authorizer.getUser("fred"));
  63. console.log ("Fetch non-existent user 'barney':");
  64. console.log (authorizer.getUser("barney"));
  65. console.log ("Add existing user 'wilma' (should replace existing 'wilma'):");
  66. authorizer.addUser (newWilma);
  67. console.log ("users =", authorizer.getUsers () );
  68. console.log ("Delete non-existent user 'barney':");
  69. authorizer.deleteUser("barney");
  70. console.log ("users =", authorizer.getUsers () );
  71. console.log ("Delete existing user 'wilma':");
  72. authorizer.deleteUser("wilma");
  73. console.log ("users =", authorizer.getUsers () );
  74. console.log ("\nAccess control");
  75. console.log ("==============\n");
  76. var acm = authorizer.getAccessControlModel ();
  77. acm.setCommunityAccess ("public", snmp.AccessLevel.ReadOnly);
  78. acm.setCommunityAccess ("private", snmp.AccessLevel.ReadWrite);
  79. console.log ("private = ", acm.getCommunityAccess ("private"));
  80. console.log (acm.getCommunitiesAccess ());
  81. acm.setUserAccess ("fred", snmp.AccessLevel.ReadOnly);
  82. acm.setUserAccess ("barney", snmp.AccessLevel.ReadWrite);
  83. acm.removeUserAccess ("fred");
  84. console.log ("barney = ", acm.getUserAccess ("barney"));
  85. console.log (acm.getUsersAccess ());
  86. //receiver.close();