Create IPfire DomU (firewall)

Check for latest IPFire version
http://downloads.ipfire.org/

wget https://raw.githubusercontent.com/panticz/xen/master/domains/ipfire.sh -O - | bash -

#!/bin/bash

URL=http://downloads.ipfire.org/releases/ipfire-2.x/2.15-core79/ipfire-2.15.xen.i586-downloader-core79.tar.bz2

# download
wget -q ${URL} -O - | tar -C /tmp -xjf -
bash /tmp/ipfire/xen-image-maker.sh

# copy data to lvm
mkdir -p /tmp/ipfire/mnt/

# copy boot filesystem
lvcreate --name fw-boot --size 256M vg0
mkfs.ext2 /dev/vg0/fw-boot
#mount /tmp/ipfire/ipfire-boot.img /tmp/ipfire/mnt/ -o loop
mount ipfire-boot.img /tmp/ipfire/mnt/ -o loop
mount /dev/vg0/fw-boot /mnt/
cp -a  /tmp/ipfire/mnt/* /mnt/
umount /tmp/ipfire/mnt/
umount /mnt/

# copy root filesystem
lvcreate --name fw-root --size 2G vg0
mkfs.ext4 /dev/vg0/fw-root
#mount /tmp/ipfire/ipfire-root.img /tmp/ipfire/mnt/ -o loop
mount ipfire-root.img /tmp/ipfire/mnt/ -o loop
mount /dev/vg0/fw-root /mnt/
cp -a  /tmp/ipfire/mnt/* /mnt/
umount /tmp/ipfire/mnt/
umount /mnt/

# copy var filesystem
lvcreate --name fw-var --size 2G vg0
mkfs.ext4 /dev/vg0/fw-var
#mount /tmp/ipfire/ipfire-var.img /tmp/ipfire/mnt/ -o loop
mount ipfire-var.img /tmp/ipfire/mnt/ -o loop
mount /dev/vg0/fw-var /mnt/
cp -a  /tmp/ipfire/mnt/* /mnt/
umount /tmp/ipfire/mnt/
umount /mnt/

# create swap
lvcreate --name fw-swap --size 1G vg0
mkswap /dev/vg0/fw-swap


# clean up
rm -r /tmp/ipfire*

# create xen config file
cat <<EOF> /etc/xen/fw
bootloader = '/usr/lib/xen-4.1/bin/pygrub'
memory = 512
name = 'fw'
acpi = 1
apic = 1
vif = [ 'mac=00:17:4e:be:b1:ba' ]
disk = [
    'phy:/dev/vg0/fw-boot,xvda1,w',
    'phy:/dev/vg0/fw-swap,xvda2,w',
    'phy:/dev/vg0/fw-root,xvda3,w',
    'phy:/dev/vg0/fw-var,xvda4,w'
]
pci = ['00:0c.0']
extra = 'iommu=soft'
EOF

# OPTIONAL: autostart
ln -s /etc/xen/fw /etc/xen/auto/01_fw

# TODO (automate)
rmmod e100
rmmod xen-pciback
modprobe xen-pciback 'hide=(00:0c.0)'
xm pci-list-assignable-devices

# start domU
xm create -c fw

# OPTIONAL
sed -i 's|phy:/dev/vg0/fw-|file:/root/ipfire-|g' /etc/xen/fw
sed -i 's|,xvda|.img,xvda|g' /etc/xen/fw

# configure ipfire in terminal

# webinterface
https://YOUR_DOMU_IP:444

# Links
http://wiki.ipfire.org/de/addons/virtualisation/howto/debian_wheezy_xen_4.1?&#debian_wheezy_mit_xen_41_als_dom0
http://wiki.ipfire.org/de/addons/virtualisation/howto/debian_als_dom0_xen#xen_und_kernel_installieren
http://wiki.ipfire.org/de/addons/virtualisation/howto/debian_xen_4.x

Magento Cache

get all cache types
Mage::app()->getCacheInstance()->getTypes();

types
Mage::app()->getCacheInstance()->cleanType('config');
Mage::app()->getCacheInstance()->cleanType('layout');
Mage::app()->getCacheInstance()->cleanType('block_html');
Mage::app()->getCacheInstance()->cleanType('translate');
Mage::app()->getCacheInstance()->cleanType('collections');
Mage::app()->getCacheInstance()->cleanType('eav');
Mage::app()->getCacheInstance()->cleanType('config_api');

clear cache
Mage::app()->cleanCache();

Magento: Update free shipping

PHP script (/root/scripts/set_free_shipping.sh)

#!/usr/bin/php
<?php
if(count($_SERVER['argv']) > 1) {
    $value=$_SERVER['argv'][1];
    
    require '/var/www/app/Mage.php';
    Mage::app(0);

    $config = new Mage_Core_Model_Config();
    $config->saveConfig('carriers/flatrate/active', $value, 'default', 0);
    $config->saveConfig('carriers/matrixrate/active', !$value, 'default', 0);

    Mage::app()->getCacheInstance()->cleanType('config');
} else {
    echo "Usage: " . $_SERVER['argv'][0] . " 0|1\n";
}
?>

Cronjob (/etc/cron.d/newyear)
0 0 1 1 * root /root/scripts/set_free_shipping.sh 0

Magento: Update footer copyright year

PHP script (/root/scripts/update_copyright_year.php)

#!/usr/bin/php
<?php
require '/var/www/app/Mage.php';
Mage::app(0);
  
# update configuration
$config = new Mage_Core_Model_Config();
$config->saveConfig('design/footer/copyright', '&copy; ' . date("Y") . ' YOUR COMPANY INC.', 'default', 0);

# refresh cache
Mage::app()->getCacheInstance()->cleanType('config');
sleep(1);
Mage::app()->getCacheInstance()->cleanType('block_html');
?>

Cronjob (/etc/cron.d/newyear)
0 0 1 1 * root /root/scripts/update_copyright_year.php

Use in CMS block
{{config path='design/footer/copyright'}}

Dep: Update by SQL
update core_config_data
set value = CONCAT('© ', YEAR(CURDATE()), ' YOUR COMPANY INC.')
where path = 'design/footer/copyright';

Links
http://www.panticz.de/Magento-Cache

ZyXEL NSA320

enable telnet
login as admin
http://192.168.2.127/r38571,/adv,/cgi-bin/remote_help-cgi?type=backdoor
telnet 192.168.2.127
root
YOUR_PASS

USB TTL to NSA-320
http://dl.panticz.de/hardware/zyxel_nsa320/nsa320_usb_ttl.jpg

install ssh
wget ftp://ftp.zyxel-tech.de/2.new_mirror/NSA310/4.40/zypkg/web_prefix -O /i-data/d154583a/admin/zy-pkgs/web_prefix
# firmware / package / reload
# install ffp
/i-data/d154583a/admin/zy-pkgs/ffp/ffp.log

#
# NEW
#

DHCPD

Add static DHCP entry
# create new entry
uci add dhcp host
uci set dhcp.@host[-1].name='srv1'
uci set dhcp.@host[-1].mac='00:01:02:25:96:99'
uci set dhcp.@host[-1].ip='192.168.2.55'
uci commit dhcp

# restart dhcpd server
/etc/init.d/dnsmasq restart

Create Debian Wheezy DomU

wget https://raw.githubusercontent.com/panticz/xen/master/domains/debian.wheezy.sh -O - | bash -

#!/bin/bash

# configure domU
DOMAIN_NAME=wheezy
DOMAIN_MAC=00:10:01:01:aa:bb
DOMAIN_RAM=2Gb
DOMAIN_HDD=8Gb
 
# create domU on LVM (for image file use --dir=/root, --pygrub)
xen-create-image \
 --hostname=${DOMAIN_NAME} \
 --dist=wheezy \
 --lvm=vg0 \
 --size=${DOMAIN_HDD} \
 --fs=ext4 \
 --role=udev \
 --memory=${DOMAIN_RAM} \
 --swap=${DOMAIN_RAM} \
 --dhcp \
 --mac=${DOMAIN_MAC} \
 --genpass=0 \
 --password=t00r \
 --apt_proxy=http://apt-cacher:3142/ \
 --vcpus $(cat /proc/cpuinfo | grep processor | wc -l)
 
# rename vm config
mv /etc/xen/${DOMAIN_NAME}.cfg /etc/xen/${DOMAIN_NAME}
 
# OPTIONAL: add to autostart
ln -s /etc/xen/${DOMAIN_NAME} /etc/xen/auto
 
# start domU
xm create -c ${DOMAIN_NAME}

# disable pc speaker
echo 'blacklist snd-pcsp' >> /etc/modprobe.d/blacklist.conf

# check for updates
touch /etc/apt/apt.conf.d/10periodic
if [ $(cat /etc/apt/apt.conf.d/10periodic | grep -c Update-Package-Lists) -eq 0 ]; then
 echo 'APT::Periodic::Update-Package-Lists "1";' >> /etc/apt/apt.conf.d/10periodic
fi

# fix FQDN
sed -i "s|$(hostname) $(hostname)|$(hostname -A)$(hostname)|g" /etc/hosts
 
user: root
password: t00r

OPTIONAL: enable auto updates
http://www.panticz.de/debian-ubuntu-automatic-upgrades

Magento: Update custom core config data and refresh cache to view the changes

#!/usr/bin/php
<?php
require '/var/www/app/Mage.php';
Mage::app(0);

if(count($_SERVER['argv']) == 2) {
  $value = $_SERVER['argv'][1];

  # update magento core config data
  $config = new Mage_Core_Model_Config();
  $config->saveConfig('stocklist/number', $value, 'default', 0);

  # refresh magento configuration cache
  Mage::app()->getCacheInstance()->cleanType('config');
} else {
  echo "Usage: " . $_SERVER['argv'][0] . " LIST_ID\n";
}
?>

Links
http://inchoo.net/ecommerce/magento/how-to-programmatically-change-magentos-core-config-data/
http://makandracards.com/magento/8277-cache-clearing-and-general-information

Ubuntu / Debian: Install and configure lm-sensors

wget -q https://raw.githubusercontent.com/panticz/installit/master/install.lm-sensors.sh -O - | bash -

#!/bin/bash

# ensure that this script is run by root
if [ $(id -u) -ne 0 ]; then
  sudo $0
  exit
fi

# install lm-sensors
apt-get install -y lm-sensors

# install the latest version
if [ "$1" == "-n" ]; then
  wget http://mirrors.kernel.org/ubuntu/pool/universe/l/lm-sensors/lm-sensors_3.3.3-1ubuntu1_amd64.deb -P /tmp/
  dpkg -i /tmp/lm-sensors_*.deb
  rm /tmp/lm-sensors_*.deb
fi

# auto configure
yes | /usr/sbin/sensors-detect

Search for motherboard configuration
sudo dmidecode -t baseboard | grep "Product Name"
http://www.lm-sensors.org/wiki/Configurations/

Motherboard configurations
# MSI X58 Pro-E (MS-7522) / Fintek f71882fg
echo "f71882fg" >> /etc/modules
echo "#coretemp" >> /etc/modules
modprobe f71882fg
wget http://dl.panticz.de/lm-sensors/ms-7522.conf -O /etc/sensors.d/f71882fg.conf
sensors -s

# ASUS M2N32 WS Professional
cat /etc/sensors.d/asus_m2n.conf
wget http://dl.panticz.de/lm-sensors/m2n32_ws_professional.conf -O /etc/sensors.d/m2n32_ws_professional.conf

# SuperMicro PDSMi-LN4+
wget http://dl.panticz.de/lm-sensors/pdsmi-ln4.conf -O /etc/sensors.d/pdsmi-ln4.conf

View raw sensor data
sensors -u

# default config file
/etc/sensors3.conf

# view hardwired? fan alarm value
cat /sys/class/hwmon/hwmon8/device/fan1_alarm

OPTIONAL: check with icinga
/usr/lib/nagios/plugins/check_sensors

Links
http://www.lm-sensors.org/wiki/Configurations/MSI/X58-Pro-E
http://www.lm-sensors.org/wiki/FAQ/Chapter3#HowdoIsetnewlimits

Syndicate content