Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
f8f35d7e59
|
|
@ -0,0 +1,39 @@
|
|||
(ns hacker-scripts.coffee
|
||||
(:require [environ.core :refer [env]])
|
||||
(:import
|
||||
(java.net Socket)
|
||||
(java.io BufferedReader PrintWriter InputStreamReader)))
|
||||
|
||||
(def my-username "my-username")
|
||||
(def my-password "my-password")
|
||||
|
||||
(def coffee-machine-ip "10.10.42.42")
|
||||
(def password-prompt "Password: ")
|
||||
(def connection-port 23)
|
||||
|
||||
(def sec-delay-before-brew 17)
|
||||
(def sec-delay-before-pour 24)
|
||||
|
||||
(defn logged-in? [] (= (:USER env) my-username))
|
||||
|
||||
(defn auth [in-stream out-stream]
|
||||
(if (= (.readLine in-stream) password-prompt)
|
||||
(.println out-stream my-password)
|
||||
(throw (RuntimeException.
|
||||
"Failed to authenticate with coffee machine"))))
|
||||
|
||||
(defn command-brew-pour [out-stream]
|
||||
(do
|
||||
(Thread/sleep (* 1000 sec-delay-before-brew))
|
||||
(.println out-stream "sys brew")
|
||||
(Thread/sleep (* 1000 sec-delay-before-pour))
|
||||
(.println out-stream "sys pour")))
|
||||
|
||||
(defn coffee []
|
||||
(if (logged-in?)
|
||||
(with-open [socket (Socket. coffee-machine-ip connection-port)
|
||||
out-stream (PrintWriter. (.getOutputStream socket) true)
|
||||
in-stream (BufferedReader. (InputStreamReader. (.getInputStream socket)))]
|
||||
(do
|
||||
(auth in-stream out-stream)
|
||||
(command-brew-pour out-stream)))))
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
(ns hacker-scripts.hangover
|
||||
(:import
|
||||
(com.twilio Twilio)
|
||||
(com.twilio.rest.api.v2010.account Message)
|
||||
(com.twilio.type PhoneNumber)))
|
||||
|
||||
(def acc-sid "my twilio account SID")
|
||||
(def acc-tkn "my twilio secret token")
|
||||
|
||||
(def my-num (PhoneNumber. "+10001112222"))
|
||||
(def boss-num (PhoneNumber. "+19998887777"))
|
||||
|
||||
(def reasons ["Receiving delivery"
|
||||
"Waiting for repairman"
|
||||
"Nasty cold"])
|
||||
|
||||
(defn twilio-init []
|
||||
(Twilio/init acc-sid acc-tkn))
|
||||
|
||||
(defn send-sms [to-num from-num message]
|
||||
(.. Message (creator to-num from-num message) create))
|
||||
|
||||
(def send-sms-boss (partial send-sms boss-num my-num))
|
||||
|
||||
(defn hangover []
|
||||
(twilio-init)
|
||||
(let [message (rand-nth reasons)]
|
||||
(send-sms-boss message)))
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
(ns hacker-scripts.kumar
|
||||
(:import
|
||||
(java.util Properties)
|
||||
(javax.mail Session Authenticator PasswordAuthentication Message$RecipientType Transport Folder Flags Flags$Flag)
|
||||
(javax.mail.internet MimeMessage InternetAddress)
|
||||
(javax.mail.search FlagTerm FromTerm AndTerm OrTerm SubjectTerm BodyTerm SearchTerm)))
|
||||
|
||||
(def host "smtp.gmail.com")
|
||||
(def my-email "my-email@gmail.com")
|
||||
(def my-password "my-gmail-password")
|
||||
(def kumar-email "kumar@gmail.com")
|
||||
|
||||
(def seen-flag (Flags. (Flags$Flag/SEEN)))
|
||||
|
||||
(def unread-term (FlagTerm. seen-flag false))
|
||||
|
||||
(defn get-session []
|
||||
(let [authenticator (proxy [Authenticator] []
|
||||
(getPasswordAuthentication []
|
||||
(PasswordAuthentication. my-email my-password)))
|
||||
props (Properties.)]
|
||||
(.put props "mail.smtp.host" "smtp.gmail.com")
|
||||
(.put props "mail.smtp.port" "587")
|
||||
(.put props "mail.smtp.auth" "true")
|
||||
(.put props "mail.smtp.starttls.enable" "true")
|
||||
(.. Session (getInstance props authenticator))))
|
||||
|
||||
(defn get-inbox [session]
|
||||
(let [store (.getStore session "imaps")
|
||||
inbox (do
|
||||
(.connect store host my-email my-password)
|
||||
(.getFolder store "inbox"))]
|
||||
(.open inbox Folder/READ_WRITE)
|
||||
inbox))
|
||||
|
||||
(defn get-no-worries-message [session]
|
||||
(let [message (MimeMessage. session)]
|
||||
(.setFrom message (InternetAddress. my-email))
|
||||
(.addRecipient message Message$RecipientType/TO (InternetAddress. kumar-email))
|
||||
(.setSubject message "Database fixes")
|
||||
(.setText message "No worries mate, be careful next time")
|
||||
message))
|
||||
|
||||
(defn search-term [pattern]
|
||||
(OrTerm. (into-array SearchTerm [(SubjectTerm. pattern) (BodyTerm. pattern)])))
|
||||
|
||||
(defn any-of-search-term [& patterns]
|
||||
(OrTerm. (into-array (map search-term patterns))))
|
||||
|
||||
(defn from-term [addr]
|
||||
(FromTerm. (InternetAddress. addr)))
|
||||
|
||||
(defn get-unread-sos-from-kumar [inbox]
|
||||
(let [flag (AndTerm. (into-array SearchTerm [unread-term
|
||||
(from-term kumar-email)
|
||||
(any-of-search-term "help" "sorry" "trouble")]))]
|
||||
(.search inbox flag)))
|
||||
|
||||
(defn mark-as-read [inbox messages]
|
||||
(.setFlags inbox messages seen-flag true))
|
||||
|
||||
(defn kumar-asshole []
|
||||
(let [session (get-session)
|
||||
inbox (get-inbox session)
|
||||
unread-sos-from-kumar (get-unread-sos-from-kumar inbox)]
|
||||
(when (seq unread-sos-from-kumar)
|
||||
(mark-as-read inbox unread-sos-from-kumar)
|
||||
(Transport/send (get-no-worries-message session)))))
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
(ns hacker-scripts.smack
|
||||
(:import
|
||||
(com.twilio Twilio)
|
||||
(com.twilio.rest.api.v2010.account Message)
|
||||
(com.twilio.type PhoneNumber)))
|
||||
|
||||
(def acc-sid "my twilio account SID")
|
||||
(def acc-tkn "my twilio secret token")
|
||||
|
||||
(def my-num (PhoneNumber. "+10001112222"))
|
||||
(def her-num (PhoneNumber. "+19998887777"))
|
||||
|
||||
(def reasons ["Working hard"
|
||||
"Gotta ship this feature"
|
||||
"Someone fucked the system again"])
|
||||
|
||||
(defn twilio-init []
|
||||
(Twilio/init acc-sid acc-tkn))
|
||||
|
||||
(defn send-sms [to-num from-num message]
|
||||
(.. Message (creator to-num from-num message) create))
|
||||
|
||||
(def send-sms-girlfriend (partial send-sms her-num my-num))
|
||||
|
||||
(defn smack []
|
||||
(twilio-init)
|
||||
(let [message (rand-nth reasons)]
|
||||
(send-sms-girlfriend message)))
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
import java.io.PrintWriter
|
||||
import java.net.Socket
|
||||
|
||||
private const val MY_USERNAME = "my_username"
|
||||
private const val PASSWORD_PROMPT = "Password: "
|
||||
private const val PASSWORD = "1234"
|
||||
private const val COFFEE_MACHINE_IP = "10.10.42.42"
|
||||
private const val DELAY_BEFORE_BREW = 17
|
||||
private const val DELAY = 24
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
for (i in 1 until args.size) {
|
||||
if (!args[i].contains(MY_USERNAME)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
val telnet = Socket(COFFEE_MACHINE_IP, 23)
|
||||
val out = PrintWriter(telnet.getOutputStream(), true)
|
||||
val reader = BufferedReader(InputStreamReader(telnet.getInputStream()))
|
||||
Thread.sleep((DELAY_BEFORE_BREW * 1000).toLong())
|
||||
if (reader.readLine() != PASSWORD_PROMPT) {
|
||||
return
|
||||
}
|
||||
out.println(PASSWORD)
|
||||
out.println("sys brew")
|
||||
Thread.sleep((DELAY * 1000).toLong())
|
||||
out.println("sys pour")
|
||||
out.close()
|
||||
reader.close()
|
||||
telnet.close()
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import com.twilio.sdk.TwilioRestClient
|
||||
import com.twilio.sdk.TwilioRestException
|
||||
import com.twilio.sdk.resource.factory.MessageFactory
|
||||
import com.twilio.sdk.resource.instance.Message
|
||||
import org.apache.http.NameValuePair
|
||||
import org.apache.http.message.BasicNameValuePair
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.Random
|
||||
|
||||
private val ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID")
|
||||
private val AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN")
|
||||
|
||||
private const val YOUR_NUMBER = "1231231231"
|
||||
private const val BOSS_NUMBER = "3213213213"
|
||||
|
||||
private val randomMessages = arrayOf(
|
||||
"Locked out",
|
||||
"Pipes broke",
|
||||
"Food poisoning",
|
||||
"Not feeling well"
|
||||
)
|
||||
|
||||
|
||||
fun main() {
|
||||
|
||||
val client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
|
||||
|
||||
val finalMessage = randomMessages.random()
|
||||
|
||||
val params = ArrayList<NameValuePair>().apply {
|
||||
add(BasicNameValuePair("Body", "Gonna work from home. $finalMessage"))
|
||||
add(BasicNameValuePair("From", YOUR_NUMBER))
|
||||
add(BasicNameValuePair("To", BOSS_NUMBER))
|
||||
}
|
||||
|
||||
val messageFactory = client.getAccount().getMessageFactory()
|
||||
val message = messageFactory.create(params)
|
||||
System.out.println(message.getSid())
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.util.*
|
||||
import java.util.regex.*
|
||||
|
||||
import javax.mail.*
|
||||
import javax.mail.internet.*
|
||||
import javax.mail.search.FlagTerm
|
||||
|
||||
//modify below properties to your details
|
||||
private const val host = "smtp.gmail.com"
|
||||
private const val username = "yourmailaddress@example.com goes here"
|
||||
private const val password = "your password goes here "
|
||||
private const val Kumar_mail = "the mail address to be replied to !"
|
||||
|
||||
|
||||
//Dependencies- Java mail API
|
||||
fun main() {
|
||||
val asshole = KumarAsshole()
|
||||
asshole.read()
|
||||
}
|
||||
|
||||
object KumarAsshole {
|
||||
|
||||
fun read() {
|
||||
val props = Properties()
|
||||
|
||||
try {
|
||||
|
||||
val session = Session.getDefaultInstance(props, null)
|
||||
|
||||
val store = session.getStore("imaps")
|
||||
store.connect(host, username, password)
|
||||
|
||||
val inbox = store.getFolder("inbox")
|
||||
inbox.open(Folder.READ_ONLY)
|
||||
|
||||
val messages = inbox.search(FlagTerm(Flags(Flags.Flag.SEEN), false))
|
||||
|
||||
for (i in messages.indices) {
|
||||
|
||||
if (messages[i].getFrom()[0].toString().contains(Kumar_mail)) {
|
||||
|
||||
var bodytext: String? = null
|
||||
val content = messages[i].getContent()
|
||||
if (content is String) {
|
||||
bodytext = content
|
||||
|
||||
} else if (content is Multipart) {
|
||||
|
||||
val mp = content as Multipart
|
||||
|
||||
val bp = mp.getBodyPart(mp.getCount() - 1)
|
||||
bodytext = bp.getContent()
|
||||
|
||||
}
|
||||
|
||||
val pattern = Pattern.compile("sorry|help|wrong", Pattern.CASE_INSENSITIVE)
|
||||
val matcher = pattern.matcher(bodytext!!)
|
||||
// check all occurance
|
||||
|
||||
if (matcher.find()) {
|
||||
|
||||
val props1 = Properties()
|
||||
val tomail: Array<Address>
|
||||
|
||||
val msg = MimeMessage(session)
|
||||
msg.setFrom(InternetAddress(username))
|
||||
tomail = messages[i].getFrom()
|
||||
val t1 = tomail[0].toString()
|
||||
msg.addRecipient(Message.RecipientType.TO, InternetAddress(t1))
|
||||
msg.setSubject("Database fixes")
|
||||
msg.setText("No problem. I've fixed it. \n\n Please be careful next time.")
|
||||
var t: Transport? = null
|
||||
t = session.getTransport("smtps")
|
||||
t!!.connect(host, username, password)
|
||||
t!!.sendMessage(msg, msg.getAllRecipients())
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
inbox.close(true)
|
||||
store.close()
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
import com.twilio.sdk.TwilioRestClient
|
||||
import com.twilio.sdk.TwilioRestException
|
||||
import com.twilio.sdk.resource.factory.MessageFactory
|
||||
import com.twilio.sdk.resource.instance.Message
|
||||
import org.apache.http.NameValuePair
|
||||
import org.apache.http.message.BasicNameValuePair
|
||||
|
||||
import java.util.ArrayList
|
||||
import java.util.Random
|
||||
|
||||
//Pre-requisite apache http and twilio java libraries
|
||||
|
||||
private const val ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID")
|
||||
private const val AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN")
|
||||
|
||||
private const val YOUR_NUMBER = "1231231231"
|
||||
private const val HER_NUMBER = "3213213213"
|
||||
|
||||
private val randomMessages = arrayOf(
|
||||
"Working hard",
|
||||
"Gotta ship this feature",
|
||||
"Someone fucked the system again"
|
||||
)
|
||||
|
||||
|
||||
@Throws(TwilioRestException::class)
|
||||
fun main() {
|
||||
|
||||
val client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
|
||||
|
||||
val finalMessage = randomMessages.random()
|
||||
|
||||
val params = mutableListOf<NameValuePair>().apply {
|
||||
add(BasicNameValuePair("Body", "Late at work. $finalMessage"))
|
||||
add(BasicNameValuePair("From", YOUR_NUMBER))
|
||||
add(BasicNameValuePair("To", HER_NUMBER))
|
||||
}
|
||||
|
||||
val messageFactory = client.getAccount().getMessageFactory()
|
||||
val message = messageFactory.create(params)
|
||||
System.out.println(message.getSid())
|
||||
}
|
||||
Loading…
Reference in New Issue