diff --git a/CSharp/Hangover.cs b/CSharp/Hangover.cs new file mode 100644 index 00000000..fe7a5888 --- /dev/null +++ b/CSharp/Hangover.cs @@ -0,0 +1,34 @@ +namespace Hacker_Scripts +{ + using System; + using Twilio; + using System.Linq; + + class Hangover + { + public static string TWILIO_ACCOUNT_SID = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); + public static string AUTH_TOKEN = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); + + public static string YOUR_NUMBER = "9879789978"; + public static string BOSS_NUMBER = "3213213233"; + + static void Main(string[] args) + { + var twilio = new TwilioRestClient(TWILIO_ACCOUNT_SID, AUTH_TOKEN); + + string[] randomMessages = { + "Locked out", + "Pipes broke", + "Food poisoning", + "Not feeling well" + }; + + int randomIndex = new Random().Next(randomMessages.Count()); + String messageToSend = (randomMessages[randomIndex]); + + var message = twilio.SendMessage(YOUR_NUMBER, BOSS_NUMBER, messageToSend); + Console.WriteLine(message.Sid); + } + } +} + diff --git a/CSharp/SmackMyBitch.cs b/CSharp/SmackMyBitch.cs new file mode 100644 index 00000000..d5c13fc1 --- /dev/null +++ b/CSharp/SmackMyBitch.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Twilio; + +namespace Hacker_Scripts +{ + class SmackMyBitch + { + public static string TWILIO_ACCOUNT_SID = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); + public static string AUTH_TOKEN = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); + + public static string YOUR_NUMBER = "9879789978"; + public static string HER_NUMBER = "3213213233"; + + static void Main(string[] args) + { + var twilio = new TwilioRestClient(TWILIO_ACCOUNT_SID, AUTH_TOKEN); + + string[] randomMessages = { + "Working hard", + "Gotta ship this feature", + "Someone fucked the system again" + }; + + int randomIndex = new Random().Next(randomMessages.Count()); + String messageToSend = (randomMessages[randomIndex]); + + var message = twilio.SendMessage(YOUR_NUMBER, HER_NUMBER, messageToSend); + Console.WriteLine(message.Sid); + } + } +} diff --git a/README.md b/README.md index bfda095d..00d6deef 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ + +English | [简体中文](./README.zh-CN.md) + # Hacker Scripts Based on a _[true @@ -19,7 +22,7 @@ story](https://www.jitbit.com/alexblog/249-now-thats-what-i-call-a-hacker/)_: > xxx: holy sh*t I'm keeping those -Original: http://bash.im/quote/436725 (in Russian) +Original: http://bash.im/quote/436725 (in Russian) (Archive.org [link](https://web.archive.org/web/20210226092253/http://bash.im/quote/436725)) Pull requests with other implementations (Python, Perl, Shell, etc) are welcome. ## Usage diff --git a/README.zh-CN.md b/README.zh-CN.md new file mode 100644 index 00000000..b3f184d6 --- /dev/null +++ b/README.zh-CN.md @@ -0,0 +1,59 @@ +# Hacker Scripts + +根据 *[真实故事](https://www.jitbit.com/alexblog/249-now-thats-what-i-call-a-hacker/)* 改编: + +> xxx: 是这样的,我们的构建工程师离职去了另外一家公司,这货基本算是生活在终端里。 你知道么,这人热爱Vim,用Dot作图,甚至用MarkDown来写维基帖子...,如果有什么事情要花上他超过90秒,他一定会整个脚本来让这件事变得“自动化”。 + +> xxx: 我们现在坐在他的工位上,看着他留下来的这些,呃,“遗产”? + +> xxx: 我觉得你们会喜欢这些的 + +> xxx: [`smack-my-bitch-up.sh(拍老婆马屁脚本)`](https://github.com/NARKOZ/hacker-scripts/blob/master/smack-my-bitch-up.sh) - 它会给他的老婆(很明显是他老婆)发送一条“今晚要加班了”的短信,再自动从文本库中随机地选择一条理由。这个脚本被设置为定时触发,而且只有在工作日晚9点以后,服务器上还有他登陆的SSH进程在运行时才会执行。 + +> xxx: [`kumar-asshole.sh(库马尔个傻*)`](https://github.com/NARKOZ/hacker-scripts/blob/master/kumar-asshole.sh) - 这个脚本会自动扫描邮箱,如果发现其中有库马尔(库马尔是我们客户公司的一位数据库管理员)发来的邮件,就会在其中寻找关键字如“求助”,“遇到麻烦了”,“抱歉”等等,如果发现了这些关键字,这个脚本会通过SSH连接上客户公司的服务器,把中间数据库(staging database)回滚到最新一次的可用备份。然后它会给邮件发送回复,“没事了哥们,下次小心点哈”。 + +> xxx: [`hangover.sh(宿醉)`](https://github.com/NARKOZ/hacker-scripts/blob/master/hangover.sh) - 同样是个定时执行的任务,被设置为在特定日期触发,它会自动发送诸如“今天不太舒服”或“今天我在家上班”之类的邮件,同样会从文本库里随机选取一条理由。这个任务会在工作日清晨8点45分以后服务器上仍然没有可交互的SSH进程时真正执行。 + +> xxx: (最牛的就是接下来这个) [`fucking-coffee.sh(**的咖啡)`](https://github.com/NARKOZ/hacker-scripts/blob/master/fucking-coffee.sh) - 这个脚本在启动之后,会先等待恰好17秒(!),然后启动一个登录进程连接到我们的咖啡机(淦,我们之前完全不知道我们的咖啡机是联网的,上面还运行着Linux系统,甚至还跑着TCP socket连接!),然后它会发送类似“系统!开始煮咖啡!”之类的消息,结果这条消息会让咖啡机开始工作,煮一杯 中杯大小、半咖啡因的拿铁,再等待恰好24秒(!)后,才倒进咖啡杯里。这些时间加起来刚好就是这位程序员从自己的工位走到机器前要的时间。 + +> xxx: 天了噜我要把这些保留下来。 + +原文: http://bash.im/quote/436725 (俄语) + +欢迎使用其它语言来实现 (Python, Perl, Shell等等)并提交PR。 + +## 用法 + +你需要以下这些环境变量: + +```bash +# used in `smack-my-bitch-up` and `hangover` scripts +TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +TWILIO_AUTH_TOKEN=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy + +# used in `kumar_asshole` script +GMAIL_USERNAME=admin@example.org +GMAIL_PASSWORD=password +``` + +为了执行Ruby脚本,你需要安装gems: `gem install dotenv twilio-ruby gmail` + +## 定时任务 + +```bash +# Runs `smack-my-bitch-up.sh` monday to friday at 9:20 pm. +20 21 * * 1-5 /path/to/scripts/smack-my-bitch-up.sh >> /path/to/smack-my-bitch-up.log 2>&1 + +# Runs `hangover.sh` monday to friday at 8:45 am. +45 8 * * 1-5 /path/to/scripts/hangover.sh >> /path/to/hangover.log 2>&1 + +# Runs `kumar-asshole.sh` every 10 minutes. +*/10 * * * * /path/to/scripts/kumar-asshole.sh + +# Runs `fucking-coffee.sh` hourly from 9am to 6pm on weekdays. +0 9-18 * * 1-5 /path/to/scripts/fucking-coffee.sh +``` + +------ + +代码的使用遵循WTFPL(Do What The Fuck You Want To Public License)协议。 diff --git a/clojure/coffee.clj b/clojure/coffee.clj new file mode 100644 index 00000000..96d87eb2 --- /dev/null +++ b/clojure/coffee.clj @@ -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))))) diff --git a/clojure/hangover.clj b/clojure/hangover.clj new file mode 100644 index 00000000..7a71372a --- /dev/null +++ b/clojure/hangover.clj @@ -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))) diff --git a/clojure/kumar.clj b/clojure/kumar.clj new file mode 100644 index 00000000..e406ce95 --- /dev/null +++ b/clojure/kumar.clj @@ -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))))) diff --git a/clojure/smack.clj b/clojure/smack.clj new file mode 100644 index 00000000..232a0b1e --- /dev/null +++ b/clojure/smack.clj @@ -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))) diff --git a/go/fucking-coffee.go b/go/fucking-coffee.go new file mode 100644 index 00000000..23149d83 --- /dev/null +++ b/go/fucking-coffee.go @@ -0,0 +1,50 @@ +package main + +import ( + "fmt" + "log" + "os" + "regexp" + "time" + + "github.com/codeskyblue/go-sh" + "github.com/google/goexpect" +) + +func main() { + // exit early if no sessions with my username are found + currentUser, _ := sh.Command("who").Command("grep", "my_username").Output() + if currentUser == nil { + os.Exit(1) + } + + // info about the coffee machine + coffeeMachineIP := "10.10.42.42" + password := "1234" + passwordPrompt := "Password: " + delayBeforeBrew := 17 * time.Second + delay := 24 * time.Second + + // timeout for the telnet prompts + timeout := 10 * time.Minute + + // sleep 17 seconds before brewing coffee + time.Sleep(delayBeforeBrew) + + // spawn a new telnet session with the coffee machine + t, _, err := expect.Spawn(fmt.Sprintf("telnet %s", coffeeMachineIP), -1) + if err != nil { + log.Fatal(err) + } + defer t.Close() + + t.Expect(regexp.MustCompile(passwordPrompt), timeout) + t.Send(password + "\n") + t.Expect(regexp.MustCompile("telnet>"), timeout) + t.Send("sys brew\n") + time.Sleep(delay) + t.Expect(regexp.MustCompile("telnet>"), timeout) + t.Send("sys pour\n") + t.Expect(regexp.MustCompile("telnet>"), timeout) + t.Send("exit\n") +} diff --git a/go/smack_my_bitch_up.go b/go/smack_my_bitch_up.go index 7e7fb7a3..41966881 100755 --- a/go/smack_my_bitch_up.go +++ b/go/smack_my_bitch_up.go @@ -1,39 +1,38 @@ package main -import( - "os/exec" - "fmt" - "strings" - "os" - "math/rand" - "time" - ) - -func main(){ - output1,err := exec.Command("who").Output() - output2 := os.Getenv("USER") - users := string(output1[:]) - current_user := string(output2[:]) - if(!strings.Contains(users,current_user)){ - return - } - - - reasons := []string {"Working hard","Gotta ship this feature","Someone fucked the system again"} - - rand.Seed(time.Now().UTC().UnixNano()) - message := "Late at work. " + reasons[rand.Intn(len(reasons))] - - TWILIO_ACCOUNT_SID := string(os.Getenv("TWILIO_ACCOUNT_SID")) - TWILIO_AUTH_TOKEN := string(os.Getenv("TWILIO_AUTH_TOKEN")) - MY_NUMBER := string(os.Getenv("MY_NUMBER")) - HER_NUMBER := string(os.Getenv("HER_NUMBER")) - - response,err := exec.Command("curl","-fSs","-u",TWILIO_ACCOUNT_SID + ":" + TWILIO_AUTH_TOKEN, "-d", "From=" + MY_NUMBER, "-d", "To=" + HER_NUMBER, "-d" , "Body=" + message, "https://api.twilio.com/2010-04-01/Accounts/" + TWILIO_ACCOUNT_SID + "/Messages").Output() - if(err != nil){ - fmt.Printf("Failed to send SMS: %s",err) - return - } - - fmt.Printf("Message Sent Successfully with response: %s ",response) +import ( + "fmt" + "math/rand" + "os" + "os/exec" + "strings" + "time" +) + +func main() { + output1, err := exec.Command("who").Output() + output2 := os.Getenv("USER") + users := string(output1[:]) + current_user := string(output2[:]) + if !strings.Contains(users, current_user) { + return + } + + reasons := []string{"Working hard", "Gotta ship this feature", "Someone fucked the system again"} + + rand.Seed(time.Now().UTC().UnixNano()) + message := "Late at work. " + reasons[rand.Intn(len(reasons))] + + TWILIO_ACCOUNT_SID := string(os.Getenv("TWILIO_ACCOUNT_SID")) + TWILIO_AUTH_TOKEN := string(os.Getenv("TWILIO_AUTH_TOKEN")) + MY_NUMBER := string(os.Getenv("MY_NUMBER")) + HER_NUMBER := string(os.Getenv("HER_NUMBER")) + + response, err := exec.Command("curl", "-fSs", "-u", TWILIO_ACCOUNT_SID+":"+TWILIO_AUTH_TOKEN, "-d", "From="+MY_NUMBER, "-d", "To="+HER_NUMBER, "-d", "Body="+message, "https://api.twilio.com/2010-04-01/Accounts/"+TWILIO_ACCOUNT_SID+"/Messages").Output() + if err != nil { + fmt.Printf("Failed to send SMS: %s", err) + return + } + + fmt.Printf("Message Sent Successfully with response: %s ", response) } diff --git a/java/KumarAsshole.java b/java/KumarAsshole.java index 24471c9e..cbbd97a4 100644 --- a/java/KumarAsshole.java +++ b/java/KumarAsshole.java @@ -1,4 +1,3 @@ - import java.io.File; import java.io.FileInputStream; import java.util.*; @@ -19,15 +18,13 @@ public static void main(String[] args) { public void read() { Properties props = new Properties(); - - //modify below properties to your details - String host = "smtp.gmail.com"; - String username = "yourmailaddress@example.com goes here"; - String password = "your password goes here "; - String Kumar_mail = "the mail address to be replied to !"; - - try { + //modify below properties to your details + String host = "smtp.gmail.com"; + String username = "yourmailaddress@example.com goes here"; + String password = "your password goes here "; + String Kumar_mail = "the mail address to be replied to !"; + try { Session session = Session.getDefaultInstance(props, null); Store store = session.getStore("imaps"); @@ -39,21 +36,16 @@ public void read() { Message messages[] = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); for (int i = 0; i < messages.length; i++) { - if (messages[i].getFrom()[0].toString().contains(Kumar_mail)) { - String bodytext = null; Object content = messages[i].getContent(); if (content instanceof String) { bodytext = (String) content; - } else if (content instanceof Multipart) { - Multipart mp = (Multipart) content; BodyPart bp = mp.getBodyPart(mp.getCount() - 1); bodytext = (String) bp.getContent(); - } Pattern pattern = Pattern.compile("sorry|help|wrong", Pattern.CASE_INSENSITIVE); @@ -61,7 +53,6 @@ public void read() { // check all occurance if (matcher.find()) { - Properties props1 = new Properties(); Address[] tomail; @@ -73,23 +64,18 @@ public void read() { msg.setSubject("Database fixes"); msg.setText("No problem. I've fixed it. \n\n Please be careful next time."); Transport t = null; - t = session.getTransport("smtps"); - t.connect(host, username, password); - t.sendMessage(msg, msg.getAllRecipients()); - - + t = session.getTransport("smtps"); + t.connect(host, username, password); + t.sendMessage(msg, msg.getAllRecipients()); + } + } } - - } - } inbox.close(true); store.close(); - }catch(Exception e) - { - + } catch(Exception e) { e.printStackTrace(); } } -} \ No newline at end of file +} diff --git a/kotlin/FuckingCoffee.kt b/kotlin/FuckingCoffee.kt new file mode 100644 index 00000000..f775ea93 --- /dev/null +++ b/kotlin/FuckingCoffee.kt @@ -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) { + 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() +} \ No newline at end of file diff --git a/kotlin/Hangover.kt b/kotlin/Hangover.kt new file mode 100644 index 00000000..35f13ef5 --- /dev/null +++ b/kotlin/Hangover.kt @@ -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().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()) +} + diff --git a/kotlin/KumarAsshole.kt b/kotlin/KumarAsshole.kt new file mode 100644 index 00000000..75c23988 --- /dev/null +++ b/kotlin/KumarAsshole.kt @@ -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
+ + 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() + } + + } +} \ No newline at end of file diff --git a/kotlin/SmackMyBitch.kt b/kotlin/SmackMyBitch.kt new file mode 100644 index 00000000..9a73bb34 --- /dev/null +++ b/kotlin/SmackMyBitch.kt @@ -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().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()) +} \ No newline at end of file diff --git a/powershell/fucking_coffee.psm1 b/powershell/fucking_coffee.psm1 index 55b12898..980eb621 100644 --- a/powershell/fucking_coffee.psm1 +++ b/powershell/fucking_coffee.psm1 @@ -1,7 +1,7 @@ <# .SYNOPSIS Simple script to connect to a coffee part using TelNet then issue specific commands that - brew and pourt a cup of coffee for the user. + brew and pour a cup of coffee for the user. .DESCRIPTION This script was converted using the ruby version of the fucking_coffee script. In this script, I left the use of environment variables since its only use was to determine if the user was @@ -59,4 +59,4 @@ Function Send-TelNetCommands $writer.WriteLine($command) $writer.Flush() Start-Sleep -Milliseconds $WaitTime -} \ No newline at end of file +} diff --git a/python/fucking_coffee.py b/python/fucking_coffee.py index c19572f3..82609323 100755 --- a/python/fucking_coffee.py +++ b/python/fucking_coffee.py @@ -10,6 +10,8 @@ if 'my_username' not in output: sys.exit() +time.sleep(17) + coffee_machine_ip = '10.10.42.42' password = '1234' password_prompt = 'Password: ' @@ -20,7 +22,7 @@ # Make some coffee! con.write("sys brew\n") -time.sleep(64) +time.sleep(24) # love the smell! con.write("sys pour\n") diff --git a/python3/fucking_coffee.py b/python3/fucking_coffee.py index 0268b79a..b3007804 100755 --- a/python3/fucking_coffee.py +++ b/python3/fucking_coffee.py @@ -24,7 +24,7 @@ def main(): conn.write(COFFEE_MACHINE_PASS) conn.write('sys brew') - time.sleep(64) + time.sleep(24) conn.write('sys pour') conn.close() diff --git a/python3/kumar_asshole.py b/python3/kumar_asshole.py index c85155b7..a66b255a 100755 --- a/python3/kumar_asshole.py +++ b/python3/kumar_asshole.py @@ -16,7 +16,7 @@ KUMAR_EMAIL = 'kumar.a@example.com' KEYWORDS_REGEX = re.compile(r'sorry|help|wrong', re.IGNORECASE) -REPLY_BODY = "No problem. I've fixed it. \n\n Please be careful next time." +REPLY_BODY = "No problem. I've fixed it. \n\nPlease be careful next time." yagmail.register(GMAIL_USERNAME, GMAIL_PASSWORD)