Some Code - Counter Strike Source Server Administration


There are several scripts that I've written and have been using for quite some time to automate some auditing tasks. I've decided to share some of these scripts in hopes that it helps you manage your own Source Dedicated server.

I get daily e-mails that show any commands used by the admins on my server. If someone swaps teams, burns a user, kicks or bans someone, it will show up in your e-mail every morning. This can be useful to track anybody who may be abusing their powers. Use this information with caution; logs only tell half the story.

First part is the scrubbing script. The Mani Admin logs do generate a ton of noise so this script will clean some of that up to make them a bit more readable. My server runs as a unprivileged user. If this is the case on your server, you will need to stick the user in the /etc/cron.allow file in order to allow the user to take advantage as cron.

Last thing is that this script requires a python interpreter.

#!/usr/bin/python
# scrubs any logs from CONSOLE in mani_admin_plugin and also archives the copy
# with yesterday's date.  Should be run via cron every day
#
# This file is called from steam's crontab
#
# By vsrz - vsritual.com 03/23/2011


MANI_ADMLOG_PATH =  '/home/steam/css/cstrike/cfg/mani_admin_plugin/mani_logs' 

import datetime, os
from datetime import timedelta,date

# open admin log from local folder
f = open(MANI_ADMLOG_PATH + '/adminlog.log', 'r')

# grab yesterday's date and formulate new filename
y = date.today() - timedelta(days=1)
ystr =  str(y.year) +  str(y.month).zfill(2)  + str(y.day).zfill(2)
newfn = MANI_ADMLOG_PATH + '/adminlog-' + ystr + '.txt'

# open new file for appending, in case we are overwriting another file
newf = open(newfn, 'a')

# loop through each and only copy stuff that doesn't have CONSOLE in it
for each in f:
  if each.find("CONSOLE") < 0 and each.find("bot_") < 0:
    newf.write(each)

# close both files
f.close()
newf.close()

# delete old adminlog file
os.system('cat /dev/null > ' + MANI_ADMLOG_PATH + '/adminlog.log')



This script is actually a one-liner that is called by crontab several hours after the logs are rolled over. The reason for this is crontab has a line length limit.


#!/bin/bash
#
# send mail with mani log. 
#
# this file is called from crontab
#

EMAIL_DST='your@email.com'
EMAIL_SUBJECT='Adminlog for vsrc `date -d yesterday +%m/%d/%Y`'
cat mani_logs/adminlog-`date -d yesterday +%Y%m%d`.txt | mail -s $EMAIL_SUBJECT $EMAIL_DST



Finally, this is how I have my cron configured. I generate the logs at 3am since the server is generally empty around that time. I chose not to send the e-mail shortly after the logs have rolled over since at the time I was receiving e-mails on my phone and it would cause my phone to buzz at 3am. Instead I send the mail at 8am. It's convenient for me to quickly glance at the logs when it comes in at that time.

steam@vsrz:~$ crontab -l
# m h  dom mon dow   command
# rotate mani logs every morning at 3am
0 3 * * * /usr/bin/python ~/scrub_mani_logs.py
 

# e-mail copy of rotated logs every morning at 8am
# -- change to a decent hour so my phone doesn't go off every morning at 3am
0 8 * * * /home/steam/mail_send.sh


If you have any questions, feel free to contact me!

vsrz

BackTrack 5 R2 Wireless SMC and Touchpad drivers for the MacBook Pro 6,1


So I upgraded to BT5r2 a while back and most of my drivers stayed in-tact. A few days ago I had the brilliant idea of recompiling the kernel to add PAE support so I can take advantage of all the memory in my system. For a while now, I've pretty much completely shifted over to BT as the main OS on my Mac. It took some time to get right but it was fully worth it.

I ran into some issues after recompiling the kernel to add PAE. Here's the short list:

1. My NVIDIA drivers were no longer valid for the current kernel, so I had to get those again.
This was a pretty painless install as usual. You download the drivers from their website (current version is 295.40), exit X, then run the installer. It takes care of the building and modprobing.

2. Apple SMC drivers were also not valid.
This also was pretty painless. Most of the buttons worked but the fan ended up going a bit whacky, and the keyboard backlight controls did not work anymore. To fix this I ran these commands:

root@mbpbt:~# apt-get purge applesmc-dkms
...
This removes applesmc
root@mbpbt:~# apt-get install applesmc-dkms
...
This reinstalls applesmc
...
root@mbpbt:~# modprobe applesmc && echo applesmc >> /etc/modules


So that's all there is there.

3. The touchpad stopped working in X. I think I had to force the drivers to load again at boot. I'm not entirely sure what happened here but I just ran these commands:

root@mbpbt:~# modprobe bcm5974 && echo mbcm5974 >> /etc/modules


4. Finally, my wireless drivers again, were not working. I originally used this method to install the open source drivers. It worked fine at the time, but doesn't seem to work anymore. I had to rebuild the kernel a second time in order to accomplish this :(

Here's how I did it:

root@mbpbt:~# prepare-kernel-sources
root@mbpbt:~# cd /usr/src/linux
root@mbpbt:/usr/src/linux# zcat /proc/config.gz > .config
root@mbpbt:/usr/src/linux# make menuconfig


Ok, so here, you'll need to select the BRCMSMAC drivers. Follow this menu:

Device Drivers >> Network device support >> Wireless LAN

You'll want support for the drivers below:
Broadcom IEEE802.11n PCIe SoftMAC WLAN driver
Broadcom IEEE802.11n embedded FullMAC WLAN driver

Now, ESC a bunch of times, save and begin recompiling the kernel:

root@mbpbt:/usr/src/linux# make prepare
root@mbpbt:/usr/src/linux# make
...
This step takes a long time.  At least an hour on my Mac.  Be prepared to wait!
...
root@mbpbt:/usr/src/linux# make modules_install
root@mbpbt:/usr/src/linux# make install
root@mbpbt:/usr/src/linux# update-initramfs -k 3.2.6 -u
root@mbpbt:/usr/src/linux# update-grub2


When you update grub, make sure you are paying close attention to what it updates. From here you should be able to tell which kernel to boot when the system is loaded.

After you reboot, wireless may not come up immediately. I forced the module to load and stuck it in etc/modules to load on boot:

root@mbpbt:~# modprobe brcmsmac && echo brcmsmac >> /etc/modules


Well, good luck. If you have any questions, feel free to ask!

vsr

Pyrit CUDA on MacBook Pro 6,1 / BT5r2


Now we're cooking with gas folks! I installed Pyrit on my 17" Macbook Pro 6,1 with CUDA just to see what this little beast could do. As you would expect, it's a bit underwhelming. Either way, it does get the job done!

root@bt5mbpz:/usr/local/pyrit/cpyrit_cuda# pyrit list_cores
Pyrit 0.4.1-dev (svn r308) (C) 2008-2011 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+

The following cores seem available...
#1:  'CUDA-Device #1 'GeForce GT 330M''
#2:  'CPU-Core (SSE2/AES)'
#3:  'CPU-Core (SSE2/AES)'
#4:  'CPU-Core (SSE2/AES)'

root@bt5mbpz:/usr/local/pyrit/cpyrit_cuda# pyrit benchmark
Pyrit 0.4.1-dev (svn r308) (C) 2008-2011 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+

Running benchmark (2810.6 PMKs/s)... / 

Computed 2810.56 PMKs/s total.
#1: 'CUDA-Device #1 'GeForce GT 330M'': 2069.1 PMKs/s (RTT 2.9)
#2: 'CPU-Core (SSE2/AES)': 343.5 PMKs/s (RTT 3.0)
#3: 'CPU-Core (SSE2/AES)': 337.3 PMKs/s (RTT 3.4)
#4: 'CPU-Core (SSE2/AES)': 320.0 PMKs/s (RTT 3.3)


Sadly, the desktop I originally set this up on (and frankly, costs a lot less than this laptop) still dominates it.

First Quarter Complete!


Congrats to the top scores listed below:

RankNameTotal PointsKillsHeadshotsHours Online
1.Smiley158602741812093128
2.Cookie14935195691081392
3.[NHSO] Cyrus1447012505562176
4.Nan140776091736943301
5..#Gerrard-8#135862158310978159
6.RetardedBatman (Dubstep)13449188391087775
7.Butterknife1335013790741077
8.TralerTrash1299810776522257
9.Sittinduck129242797512194135
10.[Generals]*****star1203811667541546


A special thanks to all the admins, Cookie, Copycat, Sqwizgaar, Teknoid, NHSO Aceman, Cyrus and J-Day!

We'll be promoting some new admins very soon so stay tuned!

vsr

Ubuntu Keyboard Controls on a MacBook Pro


There are dozens of tutorials online getting Ubuntu to work properly on a MacBook Pro. It took me quite a while to get all the components working completely. I have a 17" MacBook Pro 6,1 but the tutorials online only cover the 6,2 on Maverick, so most of the stuff works great.

For the life of me, I still couldn't get the brightness, volume, and keyboard backlight controls working properly on the keyboard, so I decided to set out to script them myself. I took the original concept from Francisco Dieguez Souto's backlight script and added the rest of the keys myself.

It is very easy to use, just copy it to your /usr/bin/ folder and then chmod 4755 the file (needs setuid permissions). Next, you'll need to set your keyboard type to MacBook Pro/MacBook, then you can start configuring custom keys in the Keyboard Shortcut control panel. You can test the script to make sure it's working in a terminal window. "mbpkbctl vol toggle" will toggle the volume, "mbpkbctl scr toggle" will toggle the screen backlight, and "mbpkbctl kb toggle" should toggle the keyboard backlight.

Hope this helps someone out there. Let me know what you think or if you have any improvements or questions!

vsr





#!/bin/bash
# # #
# Original Concept by
# Francisco Diéguez Souto (frandieguez@ubuntu.com)
# This script is licensed under MIT License.
# ritual@vsritual.com 2012/03/09
# www.vsritual.com
#
# Allows smc controls from the command line via keyboard shortcuts
# 
# Installation:
# Copy this script (as root) to /usr/bin/mbpkbctl
# Use chmod 4775 /usr/bin/mbpkbctl to allow any user to run it (setuid method)
#
# Comments:
# I could never get the keyboard shortcuts to work properly in 
# Ubuntu on my macbook pro, so I wrote this to set the buttons specifically
# Make sure you set your keyboard to type Macbook / Macbook Pro in 
# the keyboard settings screen, then you can bind individual keys to each 
# command as desired.
#
# # #
#
# Screen Backlight Settings
# MIN=0 will allow the backlight to be turned off completely
SCRBL_PATH=/sys/class/backlight/apple_backlight
SCRBL_MAX=`cat $SCRBL_PATH/max_brightness`
SCRBL_MIN=1
SCRBL_STEP=1

# Keyboard Backlight Settings
KBBL_PATH=/sys/class/leds/smc\:\:kbd_backlight/brightness
KBBL_STEP=10

# Volume Control Settings
VOL_AMIXER_PATH=/usr/bin/amixer
VOL_STEP=10
VOL_UNMUTE_VAL=60

case $1 in
        kb)
                KBBL_VAL=`cat $KBBL_PATH`
                case $2 in

                    up)
                        TOTAL=`expr $KBBL_VAL + $KBBL_STEP`
                        if [ $KBBL_VAL -eq "255" ]; then
                                exit 1
                        fi
                        if [ $TOTAL -gt "255" ]; then
                            TOTAL="255"
                        fi
                        echo $TOTAL > $KBBL_PATH
                        ;;
                    down)
                        TOTAL=`expr $KBBL_VAL - $KBBL_STEP`
                        if [ $KBBL_VAL -eq "0" ]; then

                                exit 1
                        fi
                        if [ $TOTAL -lt "0" ]; then
                            TOTAL="0"
                        fi
                        echo $TOTAL > $KBBL_PATH
                        ;;
                    off)
                        echo 0 > $KBBL_PATH
                        ;;
                    on)
                        echo 255 > $KBBL_PATH
                        ;;
                    toggle)
                        TOTAL="0"
                        if [ $KBBL_VAL -eq "0" ]; then
                                TOTAL="255"
                        fi
                                echo $TOTAL > $KBBL_PATH
                        ;;
                        *)
                                echo "Usage: $0 $1 up|down|on|off|toggle"
                        ;;
                esac
        ;;
        scr)
                SCRBL_VAL=`cat $SCRBL_PATH/brightness`
                case $2 in

                        up)
                                TOTAL=`expr $SCRBL_VAL + $SCRBL_STEP`
                                if [ $SCRBL_VAL -eq $SCRBL_MAX ]; then
                                        exit 1
                                fi
                                if [ $TOTAL -gt $SCRBL_MAX ]; then
                                        let TOTAL=$SCRBL_MAX
                                fi
                                echo $TOTAL > /sys/class/backlight/apple_backlight/brightness
                        ;;
                        down)
                                TOTAL=`expr $SCRBL_VAL - $SCRBL_STEP`
                                if [ $SCRBL_VAL -eq "$SCRBL_MIN" ]; then
                                        exit 1
                                fi
                                if [ $TOTAL -lt "$SCRBL_MIN" ]; then
                                        let TOTAL=$SCRBL_MIN
                                fi
                                echo $TOTAL > /sys/class/backlight/apple_backlight/brightness
                        ;;

                        off)
                                echo 0 > /sys/class/backlight/apple_backlight/brightness
                        ;;
                        on)
                                echo $SCRBL_MAX > /sys/class/backlight/apple_backlight/brightness
                        ;;
                        toggle)
                                TOTAL="0"
                                if [ $SCRBL_VAL -eq "0" ]; then
                                        TOTAL=$SCRBL_MAX
                                fi
                                echo $TOTAL > /sys/class/backlight/apple_backlight/brightness
                        ;;
                    *)
                                echo "Usage: $0 $1 up|down|on|off|toggle"
                        ;;
                esac
        ;;
        vol)
                case $2 in
                        up)
                                amixer set Master $VOL_STEP%+ -q
                        ;;
                        down)
                                amixer set Master $VOL_STEP%- -q
                        ;;
                        off)
                                amixer set Master 0% -q
                        ;;
                        mute)
                                amixer set Master 0% -q
                        ;;
                        unmute)
                                amixer set Master $VOL_UNMUTE_VAL% -q
                        ;;
                        on)
                                amixer set Master $VOL_UNMUTE_VAL% -q
                        ;;
                        toggle)
                                VOL=`$VOL_AMIXER_PATH get Master | grep "Mono\: Playback" | cut -f2 -d\[ | cut -f1 -d\] | cut -f1 -d% | tr -s ''`
                                TOTAL=0
                                if [ $VOL -eq "0" ]; then
                                        TOTAL=$VOL_UNMUTE_VAL
                                fi
                                amixer set Master $TOTAL% -q
                        ;;
                        *)
                        echo "Use: $0 $1 up|down|mute|full|toggle"
                        ;;
                esac

        ;;
        *)
                echo "Usage: $0 kb|scr|vol up|down|on|off|toggle"
        ;;
esac
# www.vsritual.com
<< newer
1 | 2 | 3 | 4 | 5 | 6 | 7 older >>
Copyright © vsritual.com. All rights reserved.