Skip to content

Instantly share code, notes, and snippets.

@pandeybk
pandeybk / SimpleAuthServer.py
Created July 28, 2016 18:40 — forked from fxsjy/SimpleAuthServer.py
SimpleAuthServer: A SimpleHTTPServer with authentication
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
import sys
import base64
key = ""
class AuthHandler(SimpleHTTPRequestHandler):
''' Main class to present webpages and authentication. '''
def do_HEAD(self):
@pandeybk
pandeybk / reboot_system.py
Last active June 23, 2016 21:51
Reboot system if telnet connection is failed for certain time
#!/usr/bin/env python
import telnetlib
import time
import os
HOST="some.host.com"
PORT=22
@pandeybk
pandeybk / reverse tunne, autossh, cron
Last active June 20, 2016 16:29
Create reverse tunnel using autossh, add pub keys using password base authenication
TUNNEL_PORT1=$1
TUNNEL_PORT2=$2
wget http://www.harding.motd.ca/autossh/autossh-1.4e.tgz
gunzip -c autossh-1.4e.tgz | tar xvf -
cd autossh-1.4e
./configure
make
sudo make install
@pandeybk
pandeybk / gist:304b80ad0955cb4550d4be0baa95c80d
Created June 7, 2016 23:49
nginx redirect multiple domains
server {
listen 80;
server_name dgmates.com dgmates.com.sg www.dgmates.com.sg dgmates.sg www.dgmates.sg;
return 301 http://www.dgmates.com$request_uri;
}
server {
server_name www.dgmates.com;
access_log /var/log/nginx/dgmates.access.log;
file=id_rsa.pub
bucket=com.dgmates.public.bucket
resource="/${bucket}/${file}"
contentType="text/plain"
dateValue="$(LC_ALL=C date -u +"%a, %d %b %Y %X %z")"
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
s3Key=<AWS_ACCESS_KEY_ID>
s3Secret=<AWS_ACCESS_KEY_SECRET>
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
curl -k -X PUT -T "${file}" \
@pandeybk
pandeybk / hello-revinate.pl
Last active April 5, 2016 21:24
Hello Revinate
use re 'eval';
'?'
=~( '('
.'?'. '{'.
('`'| '%').
('[' ^'-'
).''. ('`'|
'!') .''.
('`'| ',').
(( '"')) . ( ('[')^
@pandeybk
pandeybk / get_links.js
Last active April 5, 2016 20:46
get all links and post to console
import ansible.module_utils.one
import kitchen.text, ansible.module_utils.two, docutils, ansible.module_utils.three, distutils.sysconfig
import ansible.module_utils.four.parse
from ansible.module_utils.five import *
from ansible.module_utils.six import parse
from ansible.module_utils import seven
from ansible.module_utils import eight, nine
from ansible.module_utils.ten.foo import parse
b = 1 ; import ansible.module_utils.eleven
@pandeybk
pandeybk / password.py
Created April 5, 2016 20:26 — forked from henkjanverkerk/password.py
Simple password generator
import random
def main():
length = int(raw_input('How long should your password be?\n'))
print("Here's the password I generated: " + "".join(random.sample('QWERTYUIOPASDFGHJKLZXCVBNM1234567890abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_+', length)))
main()
@pandeybk
pandeybk / aws_security_group_alert.py
Last active December 5, 2017 11:49
Lambda function, trigger email using SES and alert publicly open security group
import boto3
ec2 = boto3.client('ec2')
ses = boto3.client('ses')
def email_service(email_title, email_body):
fromaddr = '[email protected]'
toaddr = '[email protected]'
bcc = '[email protected]'