r/ScriptSwap • • Dec 28 '17

[Ruby]Script to encrypt or decrypt a file

3 Upvotes

This is a script adapted from "Wicked Cool Ruby Scripts". I put two together.

#!/usr/bin/env ruby
#
# crypt.rb
# 2017-12-28

require 'crypt/blowfish'

unless ARGV.length == 2
  puts "missing argument"
  puts "Usage: ruby crypt.rb encrypt/decrypt <filename>"
  puts "Example: ruby crypt.rb encrypt test.txt"
  exit
end

routine = ARGV[0].chomp
filename  = ARGV[1].chomp
puts routine, filename


ARGV.clear

print "Enter your encryption key: "
encrypt_key = gets.chomp

def decrypt(filename,encrypt_key)
  filename_new = "decrypted_#{filename}"
  if File.exists?(filename_new)
    puts "file exists"
    exit
  end
  begin
    blowfish = Crypt::Blowfish.new(encrypt_key)
    blowfish.decrypt_file(filename.to_s, filename_new)
    puts "decrypted"
  rescue Exception => e
    puts "an error has occured: \n #{e}"
  end
end

def encrypt(filename,encrypt_key)
  filename_new = "encrypted_#{filename}"
  if File.exists?(filename_new)
    puts "file exists"
    exit
  end
  begin
    blowfish = Crypt::Blowfish.new(encrypt_key)
    blowfish.encrypt_file(filename.to_s, filename_new)
    puts "encrypted"
  rescue
    puts "an error has occured: \n #{e}"
  end
end

if routine == "decrypt"
  decrypt(filename,encrypt_key)
 else
  encrypt(filename,encrypt_key)
end

r/ScriptSwap • • Oct 17 '17

ubuntu-gnome ~/.wallpapers tool

3 Upvotes

This is a simple tool to integrate images found in ~/.wallpapers to the gnome wallpaper switcher.

Depending upon your own preference you may wish to call the script one of the following ways.

  • manually execute the script when you add more wallpapers to the directory (no excess resources)

  • use one of the various 'watching' tools such as inotify-tools, incron (some excess resources)

  • cron, this will mean waiting for the tool to execute before the wallpapers will be visible (less excess resources)

  • some other way I guess.

https://gist.github.com/CalebWhiting/7016c58747e7a3d3ef4db5e9b2bbfc78

This probably works on some other distributions but I have only tested ubuntu-gnome on 16.04 LTS


r/ScriptSwap • • Mar 13 '17

[Bash] Firefox bookmarks backup

3 Upvotes

Firefox creates daily backups of bookmarks, this script copies them to your chosen folder. it will work for multiple profiles.

#!/bin/bash

# Choose backup folder
backup_dest="$HOME/Documents/bookmarkbackups"

# Copy bookmarkbackups, which Firefox creates automatically
rsync -am --include "*/" --include "bookmarkbackups/*" --exclude "*" \
  "$HOME/.mozilla/firefox/" "$backup_dest"

Edit: I know find needs xargs instead of exec, for issues with spaces in file names, but I'm not familiar enough with the find command to alter it, so the following section should be removed or changed so it isn't a risk.

# Delete backup bookmarks files older than 30 days
#find "$backup_dest" -type f -mtime +5 -exec rm -rf {} \;

r/ScriptSwap • • Jul 18 '16

Javascript Script for RES. The "expando" button sets more links as visited

3 Upvotes

When navigating Reddit with RES I like to see links turn purple when using the expand button to see an image, twitter link or a text-post.

This script adds the link to your history thus making it purple.

Not working with some external links like youtube or i.reddituploads.com

I hope you find it useful and any advice is appreciated.

The script: https://github.com/esantini/Reddit_Set_Visited_Links/blob/master/script.js

Put it on the console or in your scripts in Tampermonkey or other extensions like that

// Reddit: on expando-button click: set visited link by modifying the history
document.getElementById('siteTable').addEventListener('click', function(ev){
	try {
		if(ev.target.classList.contains('expando-button')) {
			var url = ev.target.parentElement.querySelector('.title a').href;
			var currUrl = window.location.href;

			// set clicked URL in the browser URL bar.
			history.replaceState({}, '', url);

			// reSet current URL
			history.replaceState({}, '', currUrl);
		}
	}
	catch (e) {
		// fails with some external links like youtube
	}
});    

r/ScriptSwap • • Jun 26 '16

C++ Ip Generator / Finder

3 Upvotes

Ip Generator / Finder, written in C++ using random number generators and system ping commands to check if the host is alive then logs each live host into a text file. When it is done scanning if you specify you have Nmap installed it will then scan each IP and log the Nmap output to a separate file.

Download:

https://drive.google.com/file/d/0BzsVS8tZRvI7cnFDcUUtZTM4OEE/view?usp=sharing

Source:

http://pastebin.com/A7VGZ7YB

Virustotal:

https://www.virustotal.com/en/file/03df4825af9c947dd0f37df3fd5ceb81f0591115d4705b6466c3c33c898820a1/analysis/1466824605/


r/ScriptSwap • • Apr 16 '16

A simple script that adds a next episode button when watching a tv show on putlocker.is

3 Upvotes

This script checks to see if you are watching a tv show (vs a movie) and then adds a button that will direct you to the tv show's next episode. If you are watching the season finale, the button directs you to the 404 page, but provides a button to go to the first episode of the next season.

Code:

// ==UserScript==
// @name          	Putlocker next episode				
// @description    Adds next episode button
// @author         CATHO_LICK_MY_BALLS
// @include        http://putlocker.is
// @version        1.0
// ==/UserScript==

var url = window.location.href;
var body = document.body.innerHTML;
var index = body.indexOf("This movie doesn't exist!");
if(index > -1){
	index = url.indexOf("season");
	var beginningUrl;
	if(index > -1){
		index += 7;
		var beginningUrl = url.substring(0,index);
		var endingUrl = url.substring(index, url.length);
		index = endingUrl.indexOf("-");
		var seasonNumber = endingUrl.substring(0, index);
		endingUrl = endingUrl.substring(index, endingUrl.length);
		seasonNumber = parseInt(seasonNumber);
		seasonNumber ++;
		beginningUrl += seasonNumber;
		beginningUrl += endingUrl;

		index = beginningUrl.indexOf("episode");
		index += 8;
		var beginningUrl = beginningUrl.substring(0,index);
		var endingUrl = url.substring(index, url.length);
		index = endingUrl.indexOf("-");
		var episodeNumber = endingUrl.substring(0, index);
		endingUrl = endingUrl.substring(index, endingUrl.length);
		episodeNumber = parseInt(episodeNumber);
		episodeNumber = 1;
		beginningUrl += episodeNumber;
		beginningUrl += endingUrl;

		var aButton = document.createElement("BUTTON");
		aButton.innerHTML = "Next Season";
		aButton.onclick = function(){window.location.href = beginningUrl;}
		document.body.appendChild(aButton);
	}
}else{
	index = url.indexOf("episode");
	var beginningUrl;
	if(index > -1){
		index += 8;
		var beginningUrl = url.substring(0,index);
		var endingUrl = url.substring(index, url.length);
		index = endingUrl.indexOf("-");
		var episodeNumber = endingUrl.substring(0, index);
		endingUrl = endingUrl.substring(index, endingUrl.length);
		episodeNumber = parseInt(episodeNumber);
		episodeNumber ++;
		beginningUrl += episodeNumber;
		beginningUrl += endingUrl;

		var node = document.createElement("LI");
		var navBarElement = document.getElementById("nav");
		var aButton = document.createElement("BUTTON");
		aButton.innerHTML = "Next Episode";
		aButton.onclick = function(){window.location.href = beginningUrl;}
		node.appendChild(aButton);
		navBarElement.appendChild(node);
	}
}

r/ScriptSwap • • Jan 21 '16

[Request] Script to set desktop wallpaper on multiple monitors (Windows 10)

3 Upvotes

I have a 3 monitor setup, and like to have a separate desktop background on my main monitor than on my 2 side monitors, which is simple enough to do in the settings. For gaming, I have a macro that I use to disable my side monitors (some games get cranky), but when i reenable them, all 3 monitors have the same background. I'm looking for a script (or some guidance) that I can run in conjunction with turning the side monitors back on that will reset their backgrounds to a specified image. Batch, VBS, Powershell, as long as I can run it, I'm not picky. If someone could just point me to the right commands, I'll piece it together. Thank you in advance.


r/ScriptSwap • • Jan 05 '16

[python] Windows search and destroy files

3 Upvotes

Recently had to find and remove a certain type of file. Found out there are 4k+ and added a remove function. Feedback welcome :)

https://github.com/Durandaul/EsriScripts/tree/master/ff


r/ScriptSwap • • Oct 28 '15

[BASH] Change behavior when closing lid for Ubuntu

3 Upvotes

This is my first script ever, so I'm sure is not perfect. I recently found out that there is bug on Ubuntu, the power setting for when closing the lid is not working. I saw a solution on this site http://ubuntuhandbook.org/index.php/tag/lid-closed-behavior/ The solution is to change a line on the logind.conf. So I made a script to do it more quickly since I change this option a lot depending if I use two monitors or one.

https://github.com/andreshazard/lidBehaviourScript


r/ScriptSwap • • Jun 26 '15

[Request] Auto Forward in Outlook and Add text in the body

3 Upvotes

I receive serveral emails at work informing me of devices that need reset. Once I complete the task, I need to forward the email to a specific group with just the word "Rebooted."

This is in Outlook 2013

Is there a script that I can trigger on a specific group of messages and forward them all with the word "Rebooted." added to them? The text from the original message still needs to be in the forwarded message


r/ScriptSwap • • Jun 07 '14

[Powershell] Add domains from malware hosts.txt list to DNS

3 Upvotes
# download http://www.malwaredomainlist.com/hostslist/hosts.txt
# store it in C:\scripts\hosts.txt
$url = "http://www.malwaredomainlist.com/hostslist/hosts.txt" 
$path = "C:\scripts\hosts.txt" 
# param([string]$url, [string]$path) 

# test that C:\scripts exists and that it is a folder
if(!(Split-Path -parent $path) -or !(Test-Path -pathType Container (Split-Path -parent $path))) { 
      Write-Output "Error! c:\scripts must exist and must be a folder not a file." 
} 
else {
    "Downloading [$url]`nSaving at [$path]" 
    $client = new-object System.Net.WebClient 
    $client.DownloadFile($url, $path) 
    #$client.DownloadData($url, $path) 
  
    $path

    #name of DNS server for your domain
    $dnsserver="dc"
 
    # parse each line in hosts.txt and add a new zone to the DNS server
    # in each zone add a wildcard pointing to 127.0.0.1
    #
    # this will quickly create an entry for each host in the hosts file as a zone
    # rather than an A record, and a wildcard A record within that zone.
    # if you have a host in the hosts file called q.baddomain.com this will block
    # q.baddomain.com and also any subdomain name like www.q.baddomain.com
 
 
    Get-Content "C:\scripts\hosts.txt" | Foreach-Object {
        $data = $_.split()
        $domain = $data[2]
        if ($data[0] -eq "127.0.0.1"){
           Write-Output "Adding to DNS: " $domain 
           dnscmd $dnsserver /zoneadd $domain  /dsprimary
           dnscmd $dnsserver /recordadd $domain * A 127.0.0.1
        }
    }
} 

r/ScriptSwap • • Jun 04 '14

[REQUEST] Paste to cool but crappy MP3 Player in sorted order and VBR files to CBR....

3 Upvotes

I'd like to have Zenity open a particular folder and allow me to sort files, top to bottom, in listening order and then save them top to bottom to my MP3 Player, because if I cut & paste them one at a time, they won't play in order. I can't work out what order they do play in. It's not date and it's not name (I've tried thing slike 01*.mp3 etc) I'd like every file to be copied in that order and at the same time VBR files saved to CBR as well. Because this device won't play VBR's very well as well.


r/ScriptSwap • • Jan 10 '13

[request] htaccess maintenance script

3 Upvotes

I'm wanting to write a script that will loop through each of my web roots, check for a .htaccess file AND a .htaccess_maintenance file.

  • This script will have a stdin variable of either "on" or "off".

  • If "on" it will find the production .htaccess rename it to .htaccess_live then rename .htaccess_maintenance to .htaccess.

  • If for some reason .htaccess_maintenance doesn't exist it'll create it then rename it to .htaccess

  • If for some reason the site doesn't have a live .htaccess file, it will only rename .htaccess_maintenance to .htaccess.

  • This will all reverse if stdin is "off"

Here's the caveat, I'm a noob at shell and perl scripting. I can read it and understand it 100%, but I just don't know enough to write from scratch. I would much rather write this script myself in either language than have someone write it for me.

My ultimate question is, how can you help me write this with specific examples or resources?


r/ScriptSwap • • Jan 04 '13

[Request] [X-Post AskScriptSwap] Help with find-replace for multiple files in Linux

3 Upvotes

Hi, I'm new to bash scripting and am trying to do the following:

Create 25 files with template content

Modify part of the content in the file to change a common value

Modify each file to change one value in each file with another value from a list

I've been able to get #1 and #2 done.

3 is failing.

I've tried scouring the internet, but am unable to find out how to do #3. My script is pasted below:

	#!/bin/bash
	set change='cat change.list'
	#Creating 5 files with template content

	for I in {1..5}
	do
	touch $I
	cat randomContent > $I
	done

	#Some of the common content in the template is changed
	grep -rl '120456' ./ | xargs sed -i 's;120456;test;g'

	#Some of the content in the template is file specific
	#Here $change is a list of file specific content
	#Trying to find replace the common content with file specfic content

	echo $change
	for x in $change
	do
	echo $x
	grep -rl 'testing' ./ | xargs sed -i 's;testing;$x;g'
	done

Could someone help me with this?


r/ScriptSwap • • Dec 22 '12

[PYTHON] Basic Port Scanning Utility

3 Upvotes
import socket
import argparse
import csv

# Invoke argparse() as object 'parser' to catch commandline        arguments.  
parser = argparse.ArgumentParser(
	description='Scan for open ports on targethost.')
parser.add_argument(
	'ipaddress', help="Enter the IP address of the host you want to scan.")
parser.add_argument(
	'port', help="Enter the Port you would like to scan on the host.",
	type=int, nargs='?', default=0)
parser.add_argument(
	"-s", "--silent", help="silencec printed output", action="store_true")

# Define function for creating and opening socket connections to targets.  
def create_socket(address, port):	
s = socket.socket()
try:
	s.connect((address, port))
	return True
except:
	return False
	
# Define CSV writer function.
def writer(address, port, status):
with open('results.csv', 'ab') as f: # Append, must delete csv manually
	writer = csv.writer(f)
	writer.writerows([(address, port, status)])

# Define function for silent scanning of all ports  .
def scan_all_silent(address, port):
for x in range(1, 65536):
	s = create_socket(address, x)
	if s == True:
		write_csv = writer(address, x, 'open')
	if s == False:
		write_csv = writer(address, x, 'closed')

# Define function for scanning specific port silently.
def scan_spec_port_silent(address, port):
s = create_socket(address, port)
if s == True:
	write_csv = writer(address, port, 'open')
if s == False:
	write_csv = writer(address, port, 'closed')
	
# Define function for scanning all ports with print output.
def scan_all_with_print(address, port):
for x in range(1, 65536):
	s = create_socket(address, x)
	if s == True:
		print "IP: %s PORT: %d STATUS: Open" % (address, x)
	if s == False:
		print "IP: %s PORT: %d STATUS: Closed" % (address, x)

# Define function for scanning specific port with print output.
def scan_spec_port_with_print(address, port):
s = create_socket(address, port)
if s == True:
	print "IP: %s PORT: %d STATUS: Open" % (address, port)
if s == False:
	print "IP: %s PORT: %d STATUS: Closed" % (address, port)

# Main program logic and command line argument parsing.
args = parser.parse_args()
address = args.ipaddress
port = args.port
silence = args.silent

if silence == True:
if port == 0:
	scan = scan_all_silent(address, port)
else:
	scan = scan_spec_port_silent(address, port)
else:
if port == 0:
	scan = scan_all_with_print(address, port)
else:
	scan = scan_spec_port_with_print(address, port)

r/ScriptSwap • • Oct 26 '12

[Ruby] Convert terminal colorscheme configuration in .Xresources to Konsole colorscheme file

3 Upvotes

https://gist.github.com/3962003

Colors must be in the form like:

*color0: #000000

or

*color1: rgb:ff/ff/ff

The script was originally written to use colours from xcolors.net, so that site's default background and foreground are used if the .Xresources does not contain one. It also does not support transparency, as that is not dealt with in Konsole's colorschemes

This is my first Ruby program, and so is probably not a shining example of Ruby code, especially having been ported from Java originally.

This code is released under the GNU General Public License version 3.


r/ScriptSwap • • Oct 25 '12

[Bash] imgur scripts

3 Upvotes

various horrible scripts i once made for imgur

may be updated later based on interest.

https://github.com/sakaoka/imgur-scripts


r/ScriptSwap • • Oct 25 '12

[Bash] Various imgur scripts

3 Upvotes

These scripts are something i did to help me learn bash better, so be warned, they are pretty sloppy, but they do work (i think, they have not been tested in a few weeks, and they barely ran when i used them).

Yes I see a few other imgur and such scripts, but mine is so called "aware" that not all of the links to imgur are simple jpg links.

I guess ill be updating this a bit more to clean it up, after i figure out this git thing, i think i have the hang of it, and have not learned much at all about ssh yet, so i am pretty much just copying and pasting anything to do with it.

well, here it is.

I had the idea of trying to have the various functions separate in various files, where one bit would real a temp file that was made by another script. This script would obviously work great with another script grabbing imgur links from reddit.

enjoy :D


r/ScriptSwap • • Oct 24 '12

[Perl] Creates a new git repository and satellite repository for a web or rails based application (really basic "github" for team environment)

3 Upvotes

Awhile ago I stumbled upon an article that I've kept in common use. I wrote a quick perl script to handle the dirty work of setting everything up for each project. It's nothing fancy and this was my first attempt at anything with Perl.

https://github.com/tlackemann/auto-git-project


r/ScriptSwap • • Oct 24 '12

[Bash] Wallpaper changer with support for google images

3 Upvotes

https://github.com/theredbaron1834/Wallpaper-Changer

A little wallpaper changer with support for google images, deviantart, and anime galleries. Works for Mate, Gnome, XFCE, LXDE, and even Feh. If you have Zenity installed, it will use it to notify you of changes. Other then that, which you don't need, the only real depends is wget, grep, and sed. All of which, I believe, are defaults in most distro's.


r/ScriptSwap • • Oct 18 '12

[Bash] flac to mp3 conversion

3 Upvotes
#!/bin/bash  

die () {
  echo >&2 "$@"
  exit 1
}

[ "$#" -eq 1 ] || die "Error: 1 argument required, $# provided."

command -v flac >/dev/null 2>&1 || die "Error: command 'flac' must be installed."
command -v lame >/dev/null 2>&1 || die "Error: command 'lame' must be installed."

flac -cd "$1" | lame -b 320 -h - "${1%.flac}.mp3";

r/ScriptSwap • • Oct 15 '12

[Request] Has anyone written their own text expansion script?

3 Upvotes

I've never heard of any free and/or open source text expansion apps. Has anyone tried to implement one themselves?


r/ScriptSwap • • Oct 03 '12

[notepad++] list into a class (not really a script)

3 Upvotes

in notepad++, go to replace and set search mode to regular expression.

Find What:(\w+)

Replace With: private string _\1 = string.empty;\r\npublic string \1\r\n{ \r\n\tget\r\n\t{\r\n\t\treturn \1;\r\n\t}\r\n\tset\r\n\t{\r\n\t\t\1 = value;\r\n\t}\r\n}\r\n\r\n

this will turn your list into the body of a class.

you may now down vote.


r/ScriptSwap • • Jul 26 '12

queue installs

3 Upvotes

I hope that you guys like this because I'm very new to interactive scripting.

http://pastebin.com/CL9u6Avk

Thanks guys


r/ScriptSwap • • May 01 '12

[Bash/git] Script to simplify git-cvsimport.

3 Upvotes

I work with CVS systems a lot and prefer to wrap my CVS interactions git for all the useful git (branching/tags/history/bisect/etc) features that cvs lacks or is a total pain to use. The following function uses git-cvsimport to set up both a working and shared git repository that mirrors the main CVS one.

# Create a git-controlled mirror of a CVS module
# Assumes CVSROOT has been set up correctly.
function git-cvs-mirror {
    if [ $# -lt 2 ] ; then
        echo "Found $# arguments, needed 2"
        echo "Usage git-cvs-mirror <module-name> <repo-name>"
        return 1
    fi

    if [ ! -n "$CVSROOT" ] ; then
        echo "CVSROOT not set. Set to location of the cvsroot"
        return 1
    fi

    GI_FLAGS="-p -x -v -d"
    GI="git cvsimport"    
    CVS_MOD=$1
    REPO_NAME=$2
    CVSIMPORT="$GI -C $REPO_NAME $GI_FLAGS $CVSROOT $CVS_MOD"

    #GIT CVSIMPORT the module
    $CVSIMPORT
    #Create a bare clone to be the central version of truth
    git clone --bare "$REPO_NAME" "$REPO_NAME.git"

    #Create a branch to handle the CVS integration.
    pushd .
    if [ -d "$REPO_NAME" ] ; then
        cd "$REPO_NAME"
    else 
        echo "Could not find dir $REPO_NAME. Did the cvsimport fail?"
        return 1
    fi
    git checkout -b cvsintegration
    git checkout master
    popd 
}