PageRenderTime 32ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/syslog-ng/edit_destination.cgi

http://github.com/webmin/webmin
Perl | 173 lines | 144 code | 15 blank | 14 comment | 25 complexity | c05a9e7bc28b1726ac70ded23ab7e15f MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-3.0, CC-BY-SA-3.0
  1. #!/usr/local/bin/perl
  2. # Show a form for editing or creating a log destination
  3. require './syslog-ng-lib.pl';
  4. &ReadParse();
  5. # Show title and get the destination
  6. $conf = &get_config();
  7. if ($in{'new'}) {
  8. &ui_print_header(undef, $text{'destination_title1'}, "");
  9. }
  10. else {
  11. &ui_print_header(undef, $text{'destination_title2'}, "");
  12. @dests = &find("destination", $conf);
  13. ($dest) = grep { $_->{'value'} eq $in{'name'} } @dests;
  14. $dest || &error($text{'destination_egone'});
  15. }
  16. # Form header
  17. print &ui_form_start("save_destination.cgi", "post");
  18. print &ui_hidden("new", $in{'new'}),"\n";
  19. print &ui_hidden("old", $in{'name'}),"\n";
  20. print &ui_table_start($text{'destination_header'}, undef, 2);
  21. # Destination name
  22. print &ui_table_row($text{'destination_name'},
  23. &ui_textbox("name", $dest->{'value'}, 20));
  24. # Work out type
  25. $file = &find("file", $dest->{'members'});
  26. $usertty = &find("usertty", $dest->{'members'});
  27. $program = &find("program", $dest->{'members'});
  28. $pipe = &find("pipe", $dest->{'members'});
  29. $udp = &find("udp", $dest->{'members'});
  30. $tcp = &find("tcp", $dest->{'members'});
  31. $dgram = &find("unix-dgram", $dest->{'members'});
  32. $stream = &find("unix-stream", $dest->{'members'});
  33. $type = $file ? 0 :
  34. $usertty ? 1 :
  35. $program ? 2 :
  36. $pipe ? 3 :
  37. $tcp ? 4 :
  38. $udp ? 5 :
  39. $dgram ? 6 :
  40. $stream ? 7 : 0;
  41. $dtable = "<table>\n";
  42. # File destination
  43. if ($file) {
  44. $file_name = $file->{'value'};
  45. $file_owner = &find_value("owner", $file->{'members'});
  46. $file_group = &find_value("group", $file->{'members'});
  47. $file_perm = &find_value("perm", $file->{'members'});
  48. $file_create_dirs = &find_value("create_dirs", $file->{'members'});
  49. $file_dir_perm = &find_value("dir_perm", $file->{'members'});
  50. $file_fsync = &find_value("fsync", $file->{'members'});
  51. $file_sync_freq = &find_value("sync_freq", $file->{'members'});
  52. }
  53. $dtable .= "<tr> <td valign=top>".&ui_oneradio("type", 0, "<b>$text{'destinations_typef'}</b>", $type == 0)."</td> <td valign=top><table>\n";
  54. $dtable .= "<tr> <td>$text{'destination_file'}</td> <td>".
  55. &ui_textbox("file_name", $file_name, 35)." ".
  56. &file_chooser_button("file_name")."</td> </tr>\n";
  57. $dtable .= "<tr> <td>$text{'destination_owner'}</td> <td>".
  58. &ui_opt_textbox("file_owner", $file_owner, 15, $text{'default'})." ".
  59. &user_chooser_button("file_owner").
  60. "</td> </tr>\n";
  61. $dtable .= "<tr> <td>$text{'destination_group'}</td> <td>".
  62. &ui_opt_textbox("file_group", $file_group, 15, $text{'default'})." ".
  63. &group_chooser_button("file_owner").
  64. "</td> </tr>\n";
  65. $dtable .= "<tr> <td>$text{'destination_perm'}</td> <td>".
  66. &ui_opt_textbox("file_perm", $file_perm, 5, $text{'default'}).
  67. "</td> </tr>\n";
  68. $dtable .= "<tr> <td>$text{'destination_create_dirs'}</td> <td>".
  69. &ui_radio("file_create_dirs", $file_create_dirs,
  70. [ [ 'yes', $text{'yes'} ],
  71. [ 'no', $text{'no'} ],
  72. [ '', $text{'default'} ] ]).
  73. "</td> </tr>\n";
  74. $dtable .= "<tr> <td>$text{'destination_dir_perm'}</td> <td>".
  75. &ui_opt_textbox("file_dir_perm", $file_dir_perm, 5,$text{'default'}).
  76. "</td> </tr>\n";
  77. $dtable .= "<tr> <td>$text{'destination_fsync'}</td> <td>".
  78. &ui_radio("file_fsync", $file_fsync,
  79. [ [ 'yes', $text{'yes'} ],
  80. [ 'no', $text{'no'} ],
  81. [ '', $text{'default'} ] ]).
  82. "</td> </tr>\n";
  83. $dtable .= "<tr> <td>$text{'destination_sync_freq'}</td> <td>".
  84. &ui_opt_textbox("file_sync_freq", $file_sync_freq, 5, $text{'default'}).
  85. "</td> </tr>\n";
  86. $dtable .= "</table></td> </tr>";
  87. # User TTY destination
  88. if ($usertty) {
  89. $usertty_user = $usertty->{'value'};
  90. }
  91. $dtable .= "<tr> <td valign=top>".&ui_oneradio("type", 1, "<b>$text{'destinations_typeu'}</b>", $type == 1)."</td> <td valign=top>\n";
  92. $dtable .= &ui_opt_textbox("usertty_user", $usertty_user eq "*" ? undef : $usertty_user, 20, $text{'destinations_allusers'}, $text{'destination_users'})." ".&user_chooser_button("usertty_user", 1);
  93. $table .= "</td> </tr>";
  94. # Program destination
  95. if ($program) {
  96. $program_prog = $program->{'value'};
  97. }
  98. $dtable .= "<tr> <td valign=top>".&ui_oneradio("type", 2, "<b>$text{'destinations_typep'}</b>", $type == 2)."</td> <td valign=top>\n";
  99. $dtable .= &ui_textbox("program_prog", $program_prog, 50);
  100. $table .= "</td> </tr>";
  101. # Pipe destination
  102. if ($pipe) {
  103. $pipe_name = $pipe->{'value'};
  104. }
  105. $dtable .= "<tr> <td valign=top>".&ui_oneradio("type", 3, "<b>$text{'destinations_typei'}</b>", $type == 3)."</td> <td valign=top>\n";
  106. $dtable .= &ui_textbox("pipe_name", $pipe_name, 30)." ".
  107. &file_chooser_button("pipe_name");
  108. $dtable .= "</td> </tr>";
  109. # TCP or UDP socket
  110. $net = $tcp || $udp;
  111. if ($net) {
  112. $net_host = $net->{'value'};
  113. $net_port = &find_value("port", $net->{'members'});
  114. $net_localip = &find_value("localip", $net->{'members'});
  115. $net_localport = &find_value("localport", $net->{'members'});
  116. }
  117. $dtable .= "<tr> <td valign=top>".&ui_oneradio("type", 4, "<b>$text{'destination_net'}</b>", $type == 4 || $type == 5)."</td> <td valign=top><table>\n";
  118. $dtable .= "<tr> <td>$text{'destination_proto'}</td> ".
  119. "<td>".&ui_select("net_proto", $type == 5 ? "udp" : "tcp",
  120. [ [ "tcp", "TCP" ], [ "udp", "UDP" ] ])."</td> </tr>\n";
  121. $dtable .= "<tr> <td>$text{'destination_host'}</td> ".
  122. "<td>".&ui_textbox("net_host", $net_host, 20)."</td> </tr>\n";
  123. $dtable .= "<tr> <td>$text{'destination_port'}</td> ".
  124. "<td>".&ui_opt_textbox("net_port", $net_port, 5, "$text{'default'} (514)")."</td> </tr>\n";
  125. $dtable .= "<tr> <td>$text{'destination_localip'}</td> ".
  126. "<td>".&ui_opt_textbox("net_localip", $net_localip, 15, $text{'default'})."</td> </tr>\n";
  127. $dtable .= "<tr> <td>$text{'destination_localport'}</td> ".
  128. "<td>".&ui_opt_textbox("net_localport", $net_localport, 5, $text{'default'})."</td> </tr>\n";
  129. $dtable .= "</table></td> </tr>";
  130. # Datagram or stream socket
  131. $unix = $dgram || $stream;
  132. if ($unix) {
  133. $unix_name = $unix->{'value'};
  134. }
  135. $dtable .= "<tr> <td valign=top>".&ui_oneradio("type", 6, "<b>$text{'destination_unix'}</b>", $type == 6 || $type == 7)."</td> <td valign=top><table>\n";
  136. $dtable .= "<tr> <td>$text{'destination_utype'}</td> ".
  137. "<td>".&ui_select("unix_type",
  138. $type == 6 ? "unix-dgram" : "unix-stream",
  139. [ [ "unix-stream", $text{'destinations_types'} ],
  140. [ "unix-dgram", $text{'destinations_typeg'} ] ]).
  141. "</td> </tr>\n";
  142. $dtable .= "<tr> <td>$text{'destination_socket'}</td> ".
  143. "<td>".&ui_textbox("unix_name", $unix_name, 30)."\n".
  144. &file_chooser_button("unix_name")."</td> </tr>\n";
  145. $dtable .= "</table></td> </tr>";
  146. # Actually show the destination
  147. $dtable .= "</table>\n";
  148. print &ui_table_row($text{'destination_type'}, $dtable);
  149. # Form footer and buttons
  150. print &ui_table_end();
  151. if ($in{'new'}) {
  152. print &ui_form_end([ [ "create", $text{'create'} ] ]);
  153. }
  154. else {
  155. print &ui_form_end([ [ "save", $text{'save'} ],
  156. [ "delete", $text{'delete'} ] ]);
  157. }
  158. &ui_print_footer("list_destinations.cgi", $text{'destinations_return'});