Billedredigering med imagemagick

Rotate pictures?

mogrify -rotate 90/180 */001.jpg

Resizing picture
mogrify -size 120×120 -resize 120×120 +profile “*” *.jpg

Udgivet i Knowledge Base, Linux, Old Base | Skriv en kommentar

putty tunnels from system tray

This is how to connect some ssh forwarded ports without having any unused putty windows in the taskbar.

First download and install putty and configure pageant to start with windows.
(use the installer package, not the standalone putty.exe)
Make som keyfiles for authentication.

Now, the tunnel can be established by using plink, that comes with putty.
plink.exe -ssh -batch -l black -L 2401:10.0.3.129:2401 -L 25:10.0.3.129:25 -L 143:10.0.3.129:143 -N munin.btworld.dk

Now this nice little program, will send all output from the ssh session to stdout, which we can catch with our own little C# program, that minimizes to tray.

(code for C# program will be uploaded when I’m done)

Udgivet i Knowledge Base, Old Base, Programmering | Skriv en kommentar

C# write XML to stream with XmlDocument

Stream outputStream = new MemoryStream();
XmlDocument doc = new XmlDocument();

XmlElement root = doc.CreateElement("packet");
XmlElement type = doc.CreateAttribute("type");
if (this.request)
  type.Value = "request";
else
  type.Value = "response";

root.AppendChild(type);

XmlElement callElement = doc.CreateElement("call");
XmlAttribute funcAttr = doc.CreateAttribute("func");
funcAttr.Value = this.func;
callElement.AppendChild(funcAttr);
root.AppendChild(call);

XmlElement errElement = doc.CreateElement("error");
XmlAttribute noAttr = doc.CreateAttribute("no");
noAttr.Value = this.errorNumber;
XmlAttribute msgAttr = doc.CreateAttribute("msg");
msgAttr.Value = this.errorMessage;
errElement.AppendChild(noAttr);
errElement.AppendChild(msgAttr);
root.AppendChild(errElement);

XmlElement[] parameterList = new XmlElement[parameterNames.Count];
for (int i = 0; i < this.parameterNames.Count; i++)
{
  parameterList[i] = doc.CreateElement("parameter");
  XmlAttribute nameAttr = doc.CreateAttribute("name");
  nameAttr.Value = parameterNames[i];
  XmlAttribute valueAttr = doc.CreateAttribute("value");
  valueAttr.Value = parameterValues[i];
  parameterList[i].AppendChild(nameAttr);
  parameterList[i].AppendChild(valueAttr);
  root.AppendChild(parameterList[i]);
}

doc.AppendChild(root);
XmlWriter writer = new System.Xml.XmlTextWriter(outputStream, System.Text.Encoding.UTF8);
doc.WriteTo(writer);

 

Udgivet i Knowledge Base, Old Base, Programmering | Skriv en kommentar

how to edit strings with mysql

Mysql replace is nice

UPDATE `users` SET homedir = REPLACE(homedir, ‘/home/daemons’, ‘/home/vmail/’), maildir = REPLACE(maildir, ‘/home/daemons’, ‘/home/vmail/’);

Udgivet i Knowledge Base, Old Base | Skriv en kommentar

how to add a user to a group

This is a nice way to add a user to a new group,
from any script or other non-interactive metod:

usermod -G $(id -nG root | sed -e “s/ /,/g”),vmail root

Udgivet i Knowledge Base, Linux, Old Base | Skriv en kommentar

proftpd bandwith limit

<Directory />
  AllowOverwrite                on
  TransferRate                  APPE,RETR,STOR,STOU 25:1024 user !black
</Directory>

limits to 25KB/s with a 1024KB fullspeed limit, excludes the user black

 

Udgivet i Apache, Knowledge Base, Old Base | Skriv en kommentar

PHP XML Parsing

<pre>

<?php
$file = "artikel.xml";
$depth = array();

function startElement($parser, $name, $attrs)
{
   global $depth;
   for ($i = 0; $i < $depth[$parser]; $i++) {
       echo "  ";
   }
   echo "$name ";

        if (sizeof($attrs))
        {
                while (list($k,$v) = each($attrs))
                {
//                      print "$k -> $v  --";
                }
                print $attrs['AUTHOR'];
        }

   echo "\n";
   $depth[$parser]++;
}

function endElement($parser, $name)
{
   global $depth;
   $depth[$parser]--;
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!($fp = fopen($file, "r"))) {
   die("could not open XML input");
}

while ($data = fread($fp, 4096)) {
   if (!xml_parse($xml_parser, $data, feof($fp))) {
       die(sprintf("XML error: %s at line %d",
                   xml_error_string(xml_get_error_code($xml_parser)),
                   xml_get_current_line_number($xml_parser)));
   }
}
xml_parser_free($xml_parser);
?>

</pre>
Copyright(c) Unifix.org 2002-2011

 

Udgivet i Knowledge Base, Old Base, Programmering | Skriv en kommentar

How to use Squid to stop computer worms and vira

[My credit goes to this clever hacker: http://www.aub.dk/~misak/index.php/archives/2004/10/27/35/]

I am a one of the administrators for a network with about 900 residential users. We have no control over what people are running on their computer and therefor we get our share (and more) of worms and vira on the network. Some of theese are wery agressive and slows the whole network down with arp broadcasts.

We are using squid as a proxy and I came up with a good idea (at least I think so) on how to use squid to force the users to clean their computers if it is infected.

The method is not bulletproof. The Squid server listen after arp broadcasts on the LAN and if a computer is sending more of theese than normal the IP address get in a ACL and the computer is prevented from accessing the internet except from a few selected sites such as windowsupdate and housecall.antivirus.com. The deny_info function in squid is used to notice the users that their computers are infected and that they need to clean it in order to get their normal internet access back. When the stops sending arp requests the IP is removed from the ACL.

#!/bin/sh
# Make sure the /etc/worms.txt file have at least one line of text
echo “10.0.0.1″ > /tmp/worms.txt
tcpdump -n -c 1000 arp 2> /dev/null | cut -d ” ” -f 6 | sort | uniq -c | perl -n
e ‘/s+(d+).(S+).*/; print “$2n” if $1>200′ >> /tmp/worms.txt
/usr/local/squid/sbin/squid -k reconfigure

Is run every 10 minutes or so and in squid.conf the following is added:

acl worms src “/tmp/worms.txt”
acl trend dstdomain .trendmicro.com .antivirus.com .akamai.net .microsoft.com
http_access allow trend worms
http_access deny worms
deny_info ERR_WORMS worms

Udgivet i Knowledge Base, Linux, Networking, Old Base | Skriv en kommentar

Mike keder sig og Riis tåger

#include <stdio.h>
int findlastword(char *string,char *buffer)
{
        int i,c;
        c=0;
        for (i=0; i<=strlen(string); i++)
        {
                buffer[c]=string[i];
                c++;
                if (string[i]==' ') {c=0;}
        }
}
int main(void)
{
        char buffer[255],input[255];
        int inputsize;

        inputsize=0;

        while  ((input[inputsize] = getchar() ) != EOF)   
        { 
                if (inputsize<sizeof(input)) {  inputsize++;}
        }
        input[inputsize]=0;

        findlastword(input,buffer);
        printf("%s",buffer);
}

mike@workstation ~ $ cc lw.c -o lw
mike@workstation ~ $ echo Riis er en ost med salsa | ./lw    
salsa

 

Udgivet i Knowledge Base, Old Base | Skriv en kommentar

Windows LIVE CD’s

http://www.nu2.nu/pebuilder/

What is BartPE and PE Builder?

Bart’s PE Builder helps you build a “BartPE” (Bart Preinstalled Environment) bootable Windows CD-Rom or DVD from the original Windows XP or Windows Server 2003 installation/setup CD, very suitable for PC maintenance tasks.

It will give you a complete Win32 environment with network support, a graphical user interface (800×600) and FAT/NTFS/CDFS filesystem support. Very handy for burn-in testing systems with no OS, rescuing files to a network share, virus scan and so on.
This will replace any Dos bootdisk in no time!

PE Builder is not a Microsoft product and does not create Microsoft Windows Preinstallation Environment (“WinPE”). Using PE Builder does not grant you a license to Microsoft WinPE or to use the Windows XP or Server 2003 binaries in a manner other than stated in the End-User License Agreement included in your version of Microsoft Windows XP or Windows Server 2003. Microsoft has not reviewed or tested PE Builder and does not endorse its use.

Please do not contact Microsoft for support on the preinstallation environment that has been created by PE Builder!
Microsoft does not provide support for PE Builder or for the preinstallation environment created by PE Builder.

The PE Builder program (pebuilder.exe) runs on Windows 2000/XP/2003/BartPE. It does not run on Windows NT4/ME/9x.

To avoid any confusion, the bootable CD generated by PE Builder should be called by its nickname “BartPE”!

Udgivet i Knowledge Base, Old Base, Windows | Skriv en kommentar