Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
require 'time'
require 'json'
(ENV.fetch("OHURI") and ENV.fetch("OHAUTH"))
min_time =,05,13)
# This will automatically transform valid JSON into a Ruby data type, in this case an array of hashes. USEFUL!
all_servers = JSON.parse(`openhosting -j servers info`)
# The "type" key for a server object is misleading. Versions of the API (which
# are not versioned so there is no way to determine which version we use other
# than by building a bunch of tests) either include or exclude the "type" key.
# Virtual Machines created prior to the upgrade to Containers lack this key,
# whereas those created after have a key with a value of "vm". So we look to
# reject an explicit value rather than check for existance. Wouldn't it be nice if we
# could trust the "type" key to actually contain useful data all of the time?
# Yup. but we can't so, think of the "container" value as /the only useful value
# for filtering by type./
v = all_servers.reject{|server| server["type"] == "container"}
# We are also only interested in running servers, so again we include a select block to include the existance of the "started" key, which is the UNIX epoch timestamp of when the server was started.
vms ={|server| server.has_key? "started"}
# finally, we select those which have been started prior to the patch to the CVE disclosure was applied, which is the min_time. Use UNIX epoch for fast-ness
server_list ={|server| server["started"].to_i < min_time.to_i}
# now we need to find the unique user UUIDs from this list, and output them to the screen because then we can copy + paste. Yea!
uids = server_list.collect{|server| server["user"]}
uuids = uids.uniq
# BUT HEY! The results here are stupid since the notifier form in the GUI only has the ability to accept...well, it seems everything EXCEPT a user UUID. So This requires a trip to the database to copy + paste SQL to get the email address for each UUID. Then we can copy + paste THAT EMAIL ADDRESS LIST into the notifier form. copy + paste. Powerful for programming^TM
if ( uuids.size == 0 )
puts "all good here. nothing to do"
if ( uuids.first.split("@").size == 1)
puts "No email addresses in my list. You have useless data"
puts ":("
puts "Time to do unecessary work. Here is some SQL. Does that help?"
where = " "
uuids.each{|u| where << "'#{u}', " }
where = where.chop.chop
sql = "SELECT email FROM accounts_user WHERE id IN (#{where});"
puts sql
# puts uuids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment