Properties.ui.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*_############################################################################
  2. _##
  3. _## Properties.ui.h
  4. _##
  5. _## SNMP++v3.2.23
  6. _## -----------------------------------------------
  7. _## Copyright (c) 2001-2007 Jochen Katz, Frank Fock
  8. _##
  9. _## This software is based on SNMP++2.6 from Hewlett Packard:
  10. _##
  11. _## Copyright (c) 1996
  12. _## Hewlett-Packard Company
  13. _##
  14. _## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
  15. _## Permission to use, copy, modify, distribute and/or sell this software
  16. _## and/or its documentation is hereby granted without fee. User agrees
  17. _## to display the above copyright notice and this license notice in all
  18. _## copies of the software and any documentation of the software. User
  19. _## agrees to assume all liability for the use of the software;
  20. _## Hewlett-Packard and Jochen Katz make no representations about the
  21. _## suitability of this software for any purpose. It is provided
  22. _## "AS-IS" without warranty of any kind, either express or implied. User
  23. _## hereby grants a royalty-free license to any and all derivatives based
  24. _## upon this software code base.
  25. _##
  26. _## Stuttgart, Germany, Sun Nov 11 15:10:59 CET 2007
  27. _##
  28. _##########################################################################*/
  29. /****************************************************************************
  30. ** ui.h extension file, included from the uic-generated form implementation.
  31. **
  32. ** If you wish to add, delete or rename functions or slots use
  33. ** Qt Designer which will update this file, preserving your code. Create an
  34. ** init() function in place of a constructor, and a destroy() function in
  35. ** place of a destructor.
  36. *****************************************************************************/
  37. #include <qstringlist.h>
  38. #include <DialogAddUser.h>
  39. void Properties::combo_box_sec_name_activated(const QString &sec_name)
  40. {
  41. OctetStr sname(sec_name);
  42. // Get the properties of the user with the given sec_name from USM
  43. // dont forget to lock/unlock the user table
  44. usm->lock_user_table();
  45. const struct UsmUserNameTableEntry *user = usm->get_user(sname);
  46. if (!user)
  47. {
  48. line_edit_auth_pass->setEnabled(false);
  49. line_edit_priv_pass->setEnabled(false);
  50. combo_box_auth_prot->setEnabled(false);
  51. combo_box_priv_prot->setEnabled(false);
  52. usm->unlock_user_table();
  53. return;
  54. }
  55. line_edit_auth_pass->setText(QString::fromLatin1(
  56. (const char*)user->authPassword,
  57. user->authPasswordLength));
  58. line_edit_priv_pass->setText(QString::fromLatin1(
  59. (const char*)user->privPassword,
  60. user->privPasswordLength));
  61. line_edit_auth_pass->setEnabled(true);
  62. line_edit_priv_pass->setEnabled(true);
  63. combo_box_auth_prot->setEnabled(true);
  64. combo_box_priv_prot->setEnabled(true);
  65. switch (user->usmUserAuthProtocol)
  66. {
  67. case SNMP_AUTHPROTOCOL_HMACSHA:
  68. combo_box_auth_prot->setCurrentItem(2); break;
  69. case SNMP_AUTHPROTOCOL_HMACMD5:
  70. combo_box_auth_prot->setCurrentItem(1); break;
  71. case SNMP_AUTHPROTOCOL_NONE:
  72. default:
  73. combo_box_auth_prot->setCurrentItem(0);
  74. line_edit_auth_pass->setEnabled(false);
  75. break;
  76. }
  77. switch (user->usmUserPrivProtocol)
  78. {
  79. case SNMP_PRIVPROTOCOL_AES256:
  80. combo_box_priv_prot->setCurrentItem(5); break;
  81. case SNMP_PRIVPROTOCOL_AES192:
  82. combo_box_priv_prot->setCurrentItem(4); break;
  83. case SNMP_PRIVPROTOCOL_AES128:
  84. combo_box_priv_prot->setCurrentItem(3); break;
  85. case SNMP_PRIVPROTOCOL_IDEA:
  86. combo_box_priv_prot->setCurrentItem(2); break;
  87. case SNMP_PRIVPROTOCOL_DES:
  88. combo_box_priv_prot->setCurrentItem(1); break;
  89. case SNMP_PRIVPROTOCOL_NONE:
  90. default:
  91. combo_box_priv_prot->setCurrentItem(0);
  92. line_edit_priv_pass->setEnabled(false);
  93. break;
  94. }
  95. if (user->usmUserAuthProtocol == SNMP_AUTHPROTOCOL_NONE)
  96. {
  97. combo_box_priv_prot->setEnabled(false);
  98. }
  99. // unlock user table!
  100. usm->unlock_user_table();
  101. }
  102. void Properties::set_snmp( Snmp *s )
  103. {
  104. snmp = s;
  105. // until now, there can be only one v3MP instance
  106. v3mp = v3MP::I;
  107. usm = v3mp->get_usm();
  108. combo_box_sec_name->clear();
  109. // get all security names
  110. usm->lock_user_name_table(); // lock table for peek_XXX()
  111. const struct UsmUserNameTableEntry *user = usm->peek_first_user();
  112. QStringList names;
  113. QString initial("initial");
  114. QString to_add;
  115. while (user)
  116. {
  117. to_add.setAscii((const char*)(user->usmUserSecurityName.data()),
  118. user->usmUserSecurityName.len());
  119. if (!names.contains(to_add) && (to_add != initial))
  120. names += to_add;
  121. user = usm->peek_next_user(user);
  122. }
  123. usm->unlock_user_name_table(); // unlock table
  124. combo_box_sec_name->insertStringList(names);
  125. if (combo_box_sec_name->count())
  126. {
  127. combo_box_sec_name->setCurrentItem(0);
  128. combo_box_sec_name_activated(combo_box_sec_name->currentText());
  129. }
  130. }
  131. void Properties::push_button_reset_clicked()
  132. {
  133. combo_box_sec_name_activated(combo_box_sec_name->currentText());
  134. }
  135. void Properties::push_button_apply_clicked()
  136. {
  137. int auth_prot = 0;
  138. int priv_prot = 0;
  139. switch (combo_box_auth_prot->currentItem())
  140. {
  141. // here are all supportet authentcation protocols
  142. case 0: auth_prot = SNMP_AUTHPROTOCOL_NONE; break;
  143. case 1: auth_prot = SNMP_AUTHPROTOCOL_HMACMD5; break;
  144. case 2: auth_prot = SNMP_AUTHPROTOCOL_HMACSHA; break;
  145. }
  146. if (line_edit_auth_pass->text().isEmpty())
  147. auth_prot = SNMP_AUTHPROTOCOL_NONE;
  148. if (auth_prot == SNMP_AUTHPROTOCOL_NONE)
  149. {
  150. priv_prot = SNMP_PRIVPROTOCOL_NONE;
  151. line_edit_priv_pass->clear();
  152. }
  153. else
  154. {
  155. switch (combo_box_priv_prot->currentItem())
  156. {
  157. // here are all supported priv protocols
  158. case 0: priv_prot = SNMP_PRIVPROTOCOL_NONE; break;
  159. case 1: priv_prot = SNMP_PRIVPROTOCOL_DES; break;
  160. case 2: priv_prot = SNMP_PRIVPROTOCOL_IDEA; break;
  161. case 3: priv_prot = SNMP_PRIVPROTOCOL_AES128; break;
  162. case 4: priv_prot = SNMP_PRIVPROTOCOL_AES192; break;
  163. case 5: priv_prot = SNMP_PRIVPROTOCOL_AES256; break;
  164. }
  165. }
  166. if (line_edit_priv_pass->text().isEmpty())
  167. priv_prot = SNMP_PRIVPROTOCOL_NONE;
  168. else if (priv_prot == SNMP_PRIVPROTOCOL_NONE)
  169. line_edit_priv_pass->clear();
  170. // first delete all occurences of that user
  171. usm->delete_usm_user((const char*)combo_box_sec_name->currentText());
  172. // then add the user with the new properties
  173. usm->add_usm_user((const char*)combo_box_sec_name->currentText(),
  174. auth_prot, priv_prot,
  175. (const char*)line_edit_auth_pass->text(),
  176. (const char*)line_edit_priv_pass->text());
  177. combo_box_sec_name_activated(combo_box_sec_name->currentText());
  178. }
  179. void Properties::combo_box_auth_prot_activated( int auth_prot)
  180. {
  181. if (auth_prot)
  182. {
  183. line_edit_auth_pass->setEnabled(true);
  184. combo_box_priv_prot->setEnabled(true);
  185. if (combo_box_priv_prot->currentItem())
  186. line_edit_priv_pass->setEnabled(true);
  187. else
  188. line_edit_priv_pass->setEnabled(false);
  189. }
  190. else
  191. {
  192. combo_box_priv_prot->setEnabled(false);
  193. line_edit_priv_pass->setEnabled(false);
  194. }
  195. }
  196. void Properties::combo_box_priv_prot_activated(int priv_prot)
  197. {
  198. if (priv_prot)
  199. line_edit_priv_pass->setEnabled(true);
  200. else
  201. line_edit_priv_pass->setEnabled(false);
  202. }
  203. /// Someone clicked th ebutton to add a new user
  204. void Properties::push_button_add_user_clicked()
  205. {
  206. DialogAddUser dau;
  207. dau.exec();
  208. QString name = dau.line_edit_new_name->text();
  209. if (name.isEmpty())
  210. return;
  211. // first delete the user with that name
  212. usm->delete_usm_user((const char*)name);
  213. // then add a user wthout auth and priv
  214. usm->add_usm_user((const char*)name,
  215. SNMP_AUTHPROTOCOL_NONE,
  216. SNMP_PRIVPROTOCOL_NONE, "", "");
  217. for (int i=0; i < combo_box_sec_name->count(); ++i)
  218. {
  219. if (combo_box_sec_name->text(i) == name)
  220. {
  221. combo_box_sec_name->removeItem(i);
  222. i--;
  223. }
  224. }
  225. combo_box_sec_name->insertItem(name, 0);
  226. combo_box_sec_name->setCurrentItem(0);
  227. combo_box_sec_name_activated(combo_box_sec_name->currentText());
  228. }
  229. /// delete the displayed user
  230. void Properties::push_button_del_user_clicked()
  231. {
  232. // delete the user from USM
  233. usm->delete_usm_user((const char*)combo_box_sec_name->currentText());
  234. combo_box_sec_name->removeItem(combo_box_sec_name->currentItem());
  235. combo_box_sec_name->setCurrentItem(0);
  236. combo_box_sec_name_activated(combo_box_sec_name->currentText());
  237. }