SKGleba

get new client apps eset

Mar 29th, 2022 (edited)
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.19 KB | None | 0 0
  1. import csv
  2.  
  3. whitelisted_apps = [] # app
  4. blacklisted_apps = []  # app
  5. restrict_list = {} # app:[user1, ...]
  6. new_apps = {} # app:[user1, ...]
  7.  
  8. # read the restrict list to an app:[users] array dict
  9. try:
  10.     restrict_list_reader = csv.reader(open('restricted_apps.csv'), delimiter=";")
  11.     for row in restrict_list_reader:
  12.         app = row[0]
  13.         user = row[1]
  14.         restrict_list.setdefault(app, [])
  15.         restrict_list[app].append(user)
  16. except:
  17.     pass
  18.  
  19. # read the blacklisted app list to an array
  20. ## BUGFIX: must be CSV to support BS formatting
  21. try:
  22.     blacklist_reader = csv.reader(open('blacklisted_apps.csv'), delimiter=";")
  23.     for row in blacklist_reader:
  24.         blacklisted_apps.append(row[0])
  25. except:
  26.     pass
  27.  
  28. # read the whitelisted app list to an array
  29. ## BUGFIX: must be CSV to support BS formatting
  30. try:
  31.     whitelist_reader = csv.reader(open('whitelisted_apps.csv'), delimiter=";")
  32.     for row in whitelist_reader:
  33.         whitelisted_apps.append(row[0])
  34. except:
  35.     pass
  36.  
  37. # read the current app list to an app:[users] array dict, print if blacklisted or restricted
  38. print("\nSpecial events:\n")
  39. newlist_reader = csv.reader(open('all_apps_full.csv'), delimiter=";")
  40. for row in newlist_reader:
  41.     app = row[0]
  42.     user = row[1]
  43.     if not app in whitelisted_apps:  # not already whitelisted
  44.         if not app in blacklisted_apps:  # not blacklisted
  45.             if not app in restrict_list: # not restricted to certain users (selective whitelist)
  46.                 new_apps.setdefault(app, [])
  47.                 new_apps[app].append(user)
  48.             elif not user in restrict_list[app]:
  49.                 print("Restricted: " + app + " on " + user)
  50.         else:
  51.             print("Blacklisted: " + app + " on " + user)
  52.  
  53. # print all new apps
  54. print("\nNew apps list:\n")
  55. for entry in new_apps:
  56.     print(entry + "\ton " + ", ".join(new_apps[entry][0:]))
  57.  
  58. # write all apps to a temp whitelist csv
  59. ## BUGFIX: must be CSV to support BS formatting
  60. try:
  61.     with open('tmp_whitelisted_apps.csv', 'w') as temp_whitelist:
  62.         for entry in new_apps:
  63.             temp_whitelist.write("%s;\n" % entry)
  64. except:
  65.     print("\nwarning: failed to create a temp whitelist\n")
Add Comment
Please, Sign In to add comment