-
-
Save hinklefoxmail/586ef176bf29887e89cce63e17392976 to your computer and use it in GitHub Desktop.
IP Shutdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkIps() { | |
//Get sheet | |
var ss = SpreadsheetApp.openById('1gufH3xiGZGdnzbyZkh_tkjPh98d8RZ6DO7NInAj2lDo'); | |
var sheet = ss.getSheetByName('info'); | |
var exportSheet = ss.getSheetByName('IP Activity'); | |
//get start and end times | |
var lastRunMs = sheet.getRange(1, 2).getValue(); | |
var lastRun = new Date(lastRunMs); | |
Logger.log(lastRun); | |
var now = new Date(); | |
sheet.getRange(1, 2).setValue(now.getTime()-2800000); | |
var startTime = lastRun.toISOString(); | |
var endTime = now.toISOString(); | |
//get report logs | |
var page = AdminReports.Activities.list('all', 'login', { | |
startTime: startTime, | |
endTime: endTime, | |
maxResults: 500, | |
}); | |
exportSheet.appendRow(['','',now]); | |
//if page items is empty update sheet | |
var items=page.items; | |
try{ | |
Logger.log(items.length) | |
} | |
catch(e){ | |
exportSheet.appendRow(['No Logins']) | |
return; | |
} | |
//otherwise add ips | |
var noSus = true; | |
for (var i = 0; i < items.length; i++){ | |
var email = items[i].actor.email; | |
var ip = items[i].ipAddress; | |
if (ip != '196.216.4.1'){ | |
exportSheet.appendRow([email, ip]); | |
suspendAccount(email); | |
var noSus = false; | |
} | |
} | |
if (noSus){ | |
exportSheet.appendRow(['Only School IPs']) | |
} | |
} | |
//every day checks if important accounts are 2 step verified and writes the results to a spreadsheet | |
function check2step(){ | |
var ss = SpreadsheetApp.openById('1gufH3xiGZGdnzbyZkh_tkjPh98d8RZ6DO7NInAj2lDo'); | |
var sheet = ss.getSheetByName('Important Accounts'); | |
var data = sheet.getDataRange().getValues(); | |
for(var i=1; i<data.length; i++){ | |
var email = data[i][0]; | |
var user = AdminDirectory.Users.get(email); | |
Logger.log(user); | |
sheet.getRange(i+1, 2).setValue(user.isEnrolledIn2Sv); | |
} | |
} | |
//checks if an account is 2 step verified using the sheet in check2step and shuts down the account if it is not | |
function suspendAccount(email){ | |
var ss = SpreadsheetApp.openById('1gufH3xiGZGdnzbyZkh_tkjPh98d8RZ6DO7NInAj2lDo'); | |
var sheet = ss.getSheetByName('Important Accounts'); | |
var export = ss.getSheetByName('lockdown'); | |
var data = sheet.getDataRange().getValues(); | |
var foundAccount = false; | |
for (var i = 0; i < data.length; i++){ | |
if (email == data[i][0]){ | |
foundAccount = true; | |
var is2step = data[i][1]; | |
if(is2step){ | |
Logger.log(email+' is 2 step'); | |
return foundAccount; | |
} | |
else{ | |
var resource = {suspended: true} | |
AdminDirectory.Users.update(resource, email); | |
export.appendRow([email, 'Suspended for suspicious IP']) | |
MailApp.sendEmail('john.hinkle@aisabuja.com', 'Account Suspended', email+' has been suspended.'); | |
Logger.log(email+' has been suspended'); | |
return foundAccount; | |
} | |
} | |
} | |
Logger.log('The account was not found'); | |
return foundAccount; | |
} | |
function testSus(){ | |
var email = 'aisa3@aisabuja.com'; | |
suspendAccount(email); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment