@@ -104,6 +104,42 @@ def init_db_opts_workspace(xopts)
104
104
return opts , opts [ :workspace ]
105
105
end
106
106
107
+ def get_notes ( xopts )
108
+ ::ActiveRecord ::Base . connection_pool . with_connection {
109
+ opts , wspace = init_db_opts_workspace ( xopts )
110
+
111
+ ret = { }
112
+ ret [ :note ] = [ ]
113
+
114
+ host = self . framework . db . get_host ( opts )
115
+
116
+ return ret if not host
117
+ notes = [ ]
118
+ if opts [ :proto ] && opts [ :port ]
119
+ services = [ ]
120
+ nret = host . services . find_by_proto_and_port ( opts [ :proto ] , opts [ :port ] )
121
+ return ret if nret == nil
122
+ services << nret if nret . class == ::Mdm ::Service
123
+ services |= nret if nret . class == Array
124
+
125
+ services . each do |s |
126
+ nret = nil
127
+ if opts [ :ntype ]
128
+ nret = s . notes . find_by_ntype ( opts [ :ntype ] )
129
+ else
130
+ nret = s . notes
131
+ end
132
+ next if nret == nil
133
+ notes << nret if nret . class == ::Mdm ::Note
134
+ notes |= nret if nret . class == Array
135
+ end
136
+ else
137
+ notes = host . notes
138
+ end
139
+ notes
140
+ }
141
+ end
142
+
107
143
public
108
144
109
145
@@ -769,10 +805,12 @@ def rpc_get_service(xopts)
769
805
}
770
806
end
771
807
772
-
773
808
# Returns a note.
774
809
#
775
810
# @param [Hash] xopts Options.
811
+ # @option xopts [String] :addr Host address.
812
+ # @option xopts [String] :address Same as :addr.
813
+ # @option xopts [String] :host Same as :address.
776
814
# @option xopts [String] :proto Protocol.
777
815
# @option xopts [Fixnum] :port Port.
778
816
# @option xopts [String] :ntype Note type.
@@ -794,37 +832,8 @@ def rpc_get_service(xopts)
794
832
# @example Here's how you would use this from the client:
795
833
# rpc.call('db.get_note', {:proto => 'tcp', :port => 80})
796
834
def rpc_get_note ( xopts )
797
- ::ActiveRecord ::Base . connection_pool . with_connection {
798
- opts , wspace = init_db_opts_workspace ( xopts )
835
+ notes = get_notes ( xopts )
799
836
800
- ret = { }
801
- ret [ :note ] = [ ]
802
-
803
- host = self . framework . db . get_host ( opts )
804
-
805
- return ret if ( not host )
806
- notes = [ ]
807
- if ( opts [ :proto ] && opts [ :port ] )
808
- services = [ ]
809
- nret = host . services . find_by_proto_and_port ( opts [ :proto ] , opts [ :port ] )
810
- return ret if nret == nil
811
- services << nret if nret . class == ::Mdm ::Service
812
- services |= nret if nret . class == Array
813
-
814
- services . each do |s |
815
- nret = nil
816
- if opts [ :ntype ]
817
- nret = s . notes . find_by_ntype ( opts [ :ntype ] )
818
- else
819
- nret = s . notes
820
- end
821
- next if nret == nil
822
- notes << nret if nret . class == ::Mdm ::Note
823
- notes |= nret if nret . class == Array
824
- end
825
- else
826
- notes = host . notes
827
- end
828
837
notes . each do |n |
829
838
note = { }
830
839
host = n . host
@@ -842,7 +851,6 @@ def rpc_get_note(xopts)
842
851
ret [ :note ] << note
843
852
end
844
853
ret
845
- }
846
854
end
847
855
848
856
@@ -1144,58 +1152,8 @@ def rpc_del_vuln(xopts)
1144
1152
# @example Here's how you would use this from the client:
1145
1153
# rpc.call('db.del_note', {:workspace=>'default', :host=>ip, :port=>443, :proto=>'tcp'})
1146
1154
def rpc_del_note ( xopts )
1147
- ::ActiveRecord ::Base . connection_pool . with_connection {
1148
- opts , wspace = init_db_opts_workspace ( xopts )
1149
- hosts = [ ]
1150
- services = [ ]
1151
- notes = [ ]
1152
-
1153
- if opts [ :host ] or opts [ :address ] or opts [ :addresses ]
1154
- hosts = opts_to_hosts ( xopts )
1155
- end
1156
-
1157
- if opts [ :port ] or opts [ :proto ]
1158
- if opts [ :host ] or opts [ :address ] or opts [ :addresses ]
1159
- services = opts_to_services ( hosts , opts )
1160
- else
1161
- services = opts_to_services ( [ ] , opts )
1162
- end
1163
- end
1155
+ notes = get_notes ( xopts )
1164
1156
1165
- if opts [ :port ] or opts [ :proto ]
1166
- services . each do |s |
1167
- nret = nil
1168
- if opts [ :ntype ]
1169
- nret = s . notes . find_by_ntype ( opts [ :ntype ] )
1170
- else
1171
- nret = s . notes
1172
- end
1173
- next if nret == nil
1174
- notes << nret if nret . class == ::Mdm ::Note
1175
- notes |= nret if nret . class == Array
1176
- end
1177
- elsif opts [ :address ] or opts [ :host ] or opts [ :addresses ]
1178
- hosts . each do |h |
1179
- nret = nil
1180
- if opts [ :ntype ]
1181
- nret = h . notes . find_by_ntype ( opts [ :ntype ] )
1182
- else
1183
- nret = h . notes
1184
- end
1185
- next if nret == nil
1186
- notes << nret if nret . class == ::Mdm ::Note
1187
- notes |= nret if nret . class == Array
1188
- end
1189
- else
1190
- nret = nil
1191
- if opts [ :ntype ]
1192
- nret = wspace . notes . find_by_ntype ( opts [ :ntype ] )
1193
- else
1194
- nret = wspace . notes
1195
- end
1196
- notes << nret if nret . class == ::Mdm ::Note
1197
- notes |= nret if nret . class == Array
1198
- end
1199
1157
deleted = [ ]
1200
1158
notes . each do |n |
1201
1159
dent = { }
@@ -1208,7 +1166,6 @@ def rpc_del_note(xopts)
1208
1166
end
1209
1167
1210
1168
return { :result => 'success' , :deleted => deleted }
1211
- }
1212
1169
end
1213
1170
1214
1171
0 commit comments