Jon's FOSS Blog

Anything networking, programming, crypto and security related

Monthly Archives: February 2012

Small Update — New Links

Hey all, nothing special here, just wanted to make a small post on some new links under my name now. The first is my fedora-people public storage and the other is my initial package request for the installer script. http://fossjon.fedorapeople.org/ https://bugzilla.redhat.com/show_bug.cgi?id=798071

Fedora ARM Image Installer (FAII)

So my third "git-worthy" project is called the Fedora ARM Image Installer. It will basically allow one to "easily" convert an SD-Card into a bootable ARM media device. It is written in Python (2 & 3 for Linux & Windows) and it is based on the PyQt4 GUI framework giving it a more native feel [...]

Fedora Losing My WiFi Inet…

So Fedora has been disconnecting me a lot lately from my home wifi and I think it’s because I have disabled a lot of background services that I don’t need. Anyway, I’m trying something new: yum remove NetworkManager mkdir /etc/wifi wpa_passphrase “your_ssid_here” > /etc/wifi/home.conf Run this script as root when wanting to connect to wifi [...]

Bored And Off Topic!

Just wanted to see how many lines of Python it took me to make a generalized password bruteforce script… import time slst = “abcdefghijklmnopqrstuvwxyz” slen = (len(slst) – 1) dwrd = [0] dlen = 1 numb = 0 last = time.time() wait = 2 while (1): # process password i = 0 s = “” [...]

Formatting Flat Files As Block Devices

Here’s a small shell script based on dd’s output which helps to partition a flat file, split it up into its respective partitions so they can be formatted and put them all back together again. #!/bin/bash if [ "${1}" == "c" ] then if [ "${3}" == "" ] then echo "Usage: $0 $1 <filename> <filesize>" exit 1 fi echo "Creating new file [${2}]..." dd if=/dev/zero of=${2} bs=${3}G count=1 > /dev/null 2>&1 echo "Partition the new flat file ( fdisk ${2} )" echo fi if [ "${1}" == "s" ] then if [ "${2}" == "" ] then echo "Usage: $0 $1 <filename>" exit 1 fi unit=`fdisk -l "${2}" | grep -i '^Units' | sed -e 's/^.* \([0-9][0-9]*\) bytes.*$/\1/g'` lase="-1" numb=0 fdisk -l "${2}" | sed -e 's/^[ \t]*//g' -e 's/\*//g' | grep -i "^${2}[0-9][0-9]*" | while read line do curb=`echo "${line}" | awk '{ print $2 }'` cure=`echo "${line}" | awk '{ print $3 }'` let size="${cure} - ${curb} + 1" let diff="${curb} - ${lase} - 1" if [ ${diff} -gt 0 ] then let endi="${curb} - 1" let skip="${lase} + 1" echo "[${numb}] Unused space [${skip} - ${endi}] [${diff} blocks]..." dd if=${2} bs=${unit} skip=${skip} count=${diff} of=${2}${numb} > /dev/null 2>&1 let numb="${numb} + 1" fi echo "[${numb}] Carving partition [${curb} - ${cure}] [${size} blocks]..." dd if=${2} bs=${unit} skip=${curb} count=${size} of=${2}${numb} > /dev/null 2>&1 let numb="${numb} + 1" lase="${cure}" done fdisk -l "${2}" | sed -e 's/^[ \t]*//g' -e 's/\*//g' | grep -i "^${2}[0-9][0-9]*" | tail -n 1 | while read line do endi=`echo "${line}" | awk '{ print $3 }'` let rest="${endi} + 1" numb="9" echo "[${numb}] Copying ending [${rest} - <end>]..." dd if=${2} bs=${unit} skip=${rest} of=${2}${numb} > /dev/null 2>&1 done echo echo "Create any filesystem needed ( mkfs.* ${2}[0-9] )" echo "Mount any filesystem needed ( mount -o loop ${2}[0-9] /mnt/tmp[0-9] )" echo "Copy any files needed ( cp -r source/* /mnt/tmp[0-9]/ )" echo "Unmount any filesystem needed ( umount /mnt/tmp[0-9] )" echo fi if [ "${1}" == "j" ] then if [ "${2}" == "" ] then echo "Usage: $0 $1 <filename>" exit 1 fi echo "Writing to file [${2}.join]..." cat ${2}[0-9]* > ${2}.join echo fi

Simple Monitoring Shell Script & PHP Page

So, you would run this on a Koji builder: monitor.sh #!/bin/bash while true do filename="/tmp/stat.txt" machname=`hostname | strings | tr '\n' ' '` machrels=`cat /etc/fedora-release | sed -e 's/release//g' -e 's/[ \t]*([^)]*)[ \t]*//g' | strings | tr '\n' ' '` machvers=`uname -r | strings | tr '\n' ' '` machipv4=`ifconfig | grep -i 'inet[ :]' | sed -e 's/addr://g' | awk '{ print $2 }' | strings | tr '\n' ' '` machipv6=`ifconfig | grep -i 'inet6[ :]' | sed -e 's/addr://g' | awk '{ print $2 }' | strings | tr '\n' ' '` dnsserve=`cat /etc/resolv.conf | grep '^nameserver' | sed -e 's/^[^0-9]*//g' | strings | tr '\n' ' '` gatewaya=`netstat -nr | sed -e 's/default/0.0.0.0/g' | grep -i '^0.0.0.0' | awk '{ print $2 }' | strings | tr '\n' ' '` pingcomd=`ping -c 1 google.ca 2>&1 | grep -i '0% packet loss'` if [ "$pingcomd" != "" ] ; then netusage="Yes" ; else netusage="No" ; fi cpuusage=`top -bn 3 2>&1 | grep -i '^cpu' | sed -e 's/^.*[ \t][ \t]*\([^%]*%\)[^,]*\(us\),.*$/\1\2/g' | sort -nr | head -n 1 | strings | tr '\n' ' '` hddusage=`df -h / | grep -iv '^file' | awk '{ print "/("$6")="$4"/"$2"(free)" }' | strings | tr '\n' ' '` ramusage=`free -m | grep -i '^mem' | awk '{ print $4"M/"$2"M(free)" }' | strings | tr '\n' ' '` swapused=`free -m | grep -i '^swap' | awk '{ print $4"M/"$2"M(free)" }' | strings | tr '\n' ' '` mockfold=`(df -h /var/lib/mock/ | grep -iv '^file' | awk '{ print "/var/lib/mock("$6")="$4"/"$2"(free)" }' ; ls -al /var/lib/mock/ 2> /dev/null | grep -i ' \.$' | sed -e 's/^.\(...\)\(...\)\(...\).[ \t]*[^ \t]*[ \t]*\([^ \t]*\)[ \t]*\([^ \t]*\).*$/\1(\4):\2(\5):\3(o)/g') | strings | tr '\n' ' '` kojimoni=`service kojid status | grep -Ei '(active|running)'` if [ "$kojimoni" == "" ] ; then kojistat="Not running" ; else kojistat="Running" ; fi pkgsvers=`rpm -q koji koji-builder mock rpm yum | strings | tr '\n' ' '` #echo "$machname" > $filename date > $filename echo "$machrels" >> $filename echo "$machvers" >> $filename echo "$machipv4" >> $filename echo "$machipv6" >> $filename echo "$dnsserve" >> $filename echo "$gatewaya" >> $filename echo "$netusage" >> $filename echo "$cpuusage" >> $filename echo "$hddusage" >> $filename echo "$ramusage" >> $filename echo "$swapused" >> $filename echo "$kojistat" >> $filename echo "$mockfold" >> $filename echo "$pkgsvers" >> $filename curl -F "pass=qwerty" -F "name=$machname" -F "data=@$filename" http://hongkong.proximity.on.ca/~jchiappetta/monitor.php sleep 300 done And you run this on the server-side: monitor.php <?php /* CREATE TABLE stat (name VARCHAR(256), data VARCHAR(4096)); */ function safe($inpt) { $srch = array("<", ">", "&", ";", "'", "\"", "\\"); $inpt = trim($inpt); $inpt = str_replace($srch, "", $inpt); return $inpt; } if ($_POST["pass"] == "qwerty") { if (isset($_POST["name"]) and isset($_FILES["data"])) { $fobj = fopen($_FILES["data"]["tmp_name"], "r"); $_POST["data"] = fread($fobj, 4000); fclose($fobj); $_POST["name"] = safe($_POST["name"]); $_POST["data"] = safe($_POST["data"]); $dobj = new PDO("sqlite:monitor.db"); $dobj->exec("DELETE FROM stat WHERE name = '".$_POST["name"]."';"); $dobj->exec("INSERT INTO stat VALUES ('".$_POST["name"]."', '".$_POST["data"]."');"); $dobj = NULL; } die; } $dobj = new PDO("sqlite:monitor.db"); $resl = $dobj->query("SELECT * FROM stat ORDER BY name;"); $rows = array(); foreach ($resl as $rowd) { $temp = array(); array_push($temp, safe($rowd["name"])); $data = explode("\n", $rowd["data"]); foreach ($data as $info) { array_push($temp, safe($info)); } array_push($rows, $temp); } $dobj = NULL; ?> <html> <head> <title>Monitor</title> <style> body { background: #E6E6FA; font-family: Courier; font-size: 0.75em; } a { text-decoration: none; } th { text-align: left; } .info { color: #000080; } .inet { color: #006400; } .syst { color: #E56717; } .koji { color: #8B0000; } .hide { display: none; } </style> <script> function more(name) { var x, temp; var objl = document.getElementsByClassName(name); for (x = 0; x < objl.length; ++x) { if (objl[x].className.match(/^.*main.*$/)) { continue; } else if (objl[x].className.match(/^.*hide.*$/)) { temp = objl[x].className.replace(/hide/g, ""); objl[x].className = temp; } else { objl[x].className = (objl[x].className + " hide"); } } } function init() { var x; var tabl = document.getElementById("tabl"); var tout = (10 * 60), numb = 0, temp; var dtls, dtlo = new Date(), dtrs, dtro; for (x = 1; x < tabl.rows.length; ++x) { dtro = new Date(tabl.rows[x].cells[1].innerHTML); dtls = parseInt(dtlo.getTime() / 1000); dtrs = parseInt(dtro.getTime() / 1000); if ((dtls - tout) >= dtrs) { temp = tabl.rows[x].cells[0].innerHTML; temp = ("<font color='red'>" + temp + "</font>"); tabl.rows[x].cells[0].innerHTML = temp; ++numb; } } document.title = ("Monitor [" + numb + "] [" + dtlo.getHours() + ":" + dtlo.getMinutes() + "]"); var elel = document.getElementsByClassName("list"); for (x = 0; x < elel.length; ++x) { temp = elel[x].innerHTML; temp = temp.replace(/ /g, "<br />"); elel[x].innerHTML = temp; } } </script> <meta http-equiv="refresh" content="900"> </head> <body onload="init();"> <table id="tabl" width="100%"> <tr> <th class="info main">Name <a href="javascript:more('info');">[i]</a></th> <th class="info hide">Time</th> <th class="info hide">Release</th> <th class="info hide">Kernel</th> <th class="inet hide">IPv4</th> <th class="inet hide">IPv6</th> <th class="inet hide">DNS</th> <th class="inet hide">Gateway</th> <th class="inet main">Inet <a href="javascript:more('inet');">[i]</a></th> <th class="syst hide">CPU</th> <th class="syst main">Disk <a href="javascript:more('syst');">[i]</a></th> <th class="syst hide">RAM</th> <th class="syst hide">Swap</th> <th class="koji main">Koji <a href="javascript:more('koji');">[i]</a></th> <th class="koji list hide">Mock</th> <th class="koji list hide">Pkgs</th> </tr> <?php foreach ($rows as $rowd) { echo ("<tr>"."\n"); echo ("<td class=\"info main\">".$rowd[0]."</td>"."\n"); echo ("<td class=\"info hide\">".$rowd[1]."</td>"."\n"); echo ("<td class=\"info hide\">".$rowd[2]."</td>"."\n"); echo ("<td class=\"info hide\">".$rowd[3]."</td>"."\n"); echo ("<td class=\"inet hide\">".$rowd[4]."</td>"."\n"); echo ("<td class=\"inet hide\">".$rowd[5]."</td>"."\n"); echo ("<td class=\"inet hide\">".$rowd[6]."</td>"."\n"); echo ("<td class=\"inet hide\">".$rowd[7]."</td>"."\n"); echo ("<td class=\"inet main\">".$rowd[8]."</td>"."\n"); echo ("<td class=\"syst hide\">".$rowd[9]."</td>"."\n"); echo ("<td class=\"syst main\">".$rowd[10]."</td>"."\n"); echo ("<td class=\"syst hide\">".$rowd[11]."</td>"."\n"); echo ("<td class=\"syst hide\">".$rowd[12]."</td>"."\n"); echo ("<td class=\"koji main\">".$rowd[13]."</td>"."\n"); echo ("<td class=\"koji list hide\">".$rowd[14]."</td>"."\n"); echo ("<td class=\"koji list hide\">".$rowd[15]."</td>"."\n"); echo ("</tr>"."\n"); } ?> </table> </body> </html>

Follow

Get every new post delivered to your Inbox.