You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# once nodes are added, set 'wave' for newly owned nodes
79
+
elsifoptions.spread
80
+
hash['statements'] << {'statement'=>"OPTIONAL MATCH (n1:User {wave:#{options.wave}}) WITH collect(distinct n1) as c1 OPTIONAL MATCH (n2:Computer {wave:#{options.wave}}) WITH collect(distinct n2) + c1 as c2 UNWIND c2 as n OPTIONAL MATCH p=shortestPath((n)-[*..20]->(m)) WHERE not(exists(m.wave)) WITH DISTINCT(m) SET m.wave=#{options.wave} RETURN m.name, #{options.wave}",'includeStats'=>true}
81
+
returnhash.to_json
82
+
70
83
# add 'owned' property to nodes from file
71
84
elsifoptions.add
72
85
File.foreach(options.add)do |node|
73
86
name,method=node.split(',',2)
74
-
putsgreen("[+]") + " Adding #{name.chomp} to wave #{options.wave} via #{method.chomp}"
75
-
hash['statements'] << {'statement'=>"MATCH (n) WHERE (n.name = \"#{name.chomp}\") SET n.owned = \"#{method.chomp}\", n.wave = #{options.wave}"}
87
+
# if -w flag set, then overwrite previous property if it exists, otherwise don't overwrite
88
+
ifoptions.forceWave.nil?
89
+
hash['statements'] << {'statement'=>"MATCH (n) WHERE (n.name = \"#{name.chomp}\") SET n.owned = \"#{method.chomp}\", n.wave = #{options.wave} RETURN \'#{name.chomp}\', \'#{options.wave}\', \'#{method.chomp}\'",'includeStats'=>true}
90
+
else
91
+
# this uses a Cypher hack for doing if/else conditionals
92
+
hash['statements'] << {'statement'=>"MATCH (n) WHERE (n.name = \"#{name.chomp}\") FOREACH (ignoreMe in CASE WHEN exists(n.wave) THEN [1] ELSE [] END | SET n.wave=n.wave) FOREACH (ignoreMe in CASE WHEN not(exists(n.wave)) THEN [1] ELSE [] END | SET n.owned = \"#{method.chomp}\", n.wave = #{options.wave}) RETURN \'#{name.chomp}\',\'#{options.wave}\',\'#{method.chomp}\'",'includeStats'=>true}
93
+
end
76
94
end
77
-
# once nodes are added, set "wave" for newly owned nodes
78
-
putsgreen("[+]") + " Querying and updating new owned nodes"
79
-
hash['statements'] << {'statement'=>"OPTIONAL MATCH (n1:User {wave:#{options.wave}}) WITH collect(distinct n1) as c1 OPTIONAL MATCH (n2:Computer {wave:#{options.wave}}) WITH collect(distinct n2) + c1 as c2 UNWIND c2 as n OPTIONAL MATCH p=shortestPath((n)-[*..20]->(m)) WHERE not(exists(m.wave)) WITH DISTINCT(m) SET m.wave=#{options.wave}"}
80
95
returnhash.to_json
96
+
81
97
# Create SharesPasswordWith relationships between all nodes in file
0 commit comments