__author__ = 'Trevor Bramwell'
import click
+import requests
def checkmark(truthy):
return u'\u2717'
-def print_plugin(plugin, namefield='longName'):
- """Print the plugin longName and version."""
+def print_plugin(plugin, namefield='shortName'):
+ """Print the plugin shortName and version."""
print("%s:%s" % (plugin[namefield], plugin['version']))
print_plugin(plugin)
+@click.command()
+@click.pass_context
+def sec(ctx):
+ """List plugins with a known vulnerability.
+
+ Output is in the format:
+
+ Vulnerable Version\t Installed Version\t Link.
+ """
+ r = requests.get('http://updates.jenkins-ci.org/update-center.actual.json')
+ warn = r.json()['warnings']
+
+ # create a dict of relevant info from jenkins update center
+ secdict = {}
+ for w in warn:
+ name = (w['name'])
+ url = (w['url'])
+ for version in w['versions']:
+ lastversion = version.get('lastVersion')
+ nv = {name: lastversion}
+ secdict.update(nv)
+
+ # create a dict of our active plugins
+ activedict = {}
+ plugins = ctx.obj['plugins']
+ for key in plugins.keys():
+ _, plugin_name = key
+ plugin = plugins[plugin_name]
+ if plugin['active']:
+ name = plugin['shortName']
+ version = plugin['version']
+ nv = {name: version}
+ activedict.update(nv)
+
+ # find the delta
+ shared = []
+ for key in set(secdict.keys()) & set(activedict.keys()):
+ shared.append(key)
+ ourversion = (activedict[key])
+ theirversion = (secdict[key])
+ t1 = tuple([ourversion])
+ t2 = tuple([theirversion])
+ if (t1) <= (t2):
+ # Print Vulnerable Version\t Installed Version\t Link
+ for w in warn:
+ name = (w['name'])
+ url = (w['url'])
+ for version in w['versions']:
+ lastversion = version.get('lastVersion')
+ if name == key and secdict[key] == lastversion:
+ print("{0}:{1}\t{0}:{2}\t{3}".format(key, secdict[key], activedict[key], url))
+
+
plugins_init.add_command(list_plugins, name='list')
plugins_init.add_command(pinned)
plugins_init.add_command(dynamic)
plugins_init.add_command(active)
plugins_init.add_command(enabled)
plugins_init.add_command(disabled)
+plugins_init.add_command(sec)