Search This Blog

Friday, December 07, 2012

Add all Domain Users to Local Administrators (French or English)

Option Explicit
Dim owShell, oWMI, colOperatingSystems, oOS, strComputer, strUser, strDomain, objLocalAdminGroup, sComputer, iOSLang, strAdmins  
On Error Resume Next
Set oWShell = CreateObject("Wscript.Shell")
strComputer = oWShell.ExpandEnvironmentStrings("%computername%")
strDomain = oWShell.ExpandEnvironmentStrings("%userdomain%")
'strUser = strDomain & "\" & oWShell.ExpandEnvironmentStrings("%username%")
strUser = strDomain & "\Domain Users"
Set oWMI = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer _
    & "\root\cimv2")
Set colOperatingSystems = oWMI.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each oOS in colOperatingSystems
  iOSLang = oOS.OSLanguage
If iOSLang = "1033" Then
strAdmins = "/Administrators"
strAdmins = "/Administrateurs"
End if
Set objLocalAdminGroup = GetObject("WinNT://" & strComputer & strAdmins)
objLocalAdminGroup.Add("WinNT://" & Chr(34) & strUser & Chr(34))
Set objLocalAdminGroup = Nothing

Saturday, November 17, 2012

BES - enable http auth

Because the BlackBerry browser uses the BES server to render the pages, the default user for integrated authentication is always "besadmin"
In order to allow the user to authentify itself, we must enable Authentication support on the MDS. Follow KB15642 on bb site  or just

 For BlackBerry Enterprise Server 4.1:
         1. In BlackBerry Manager, select <BlackBerry_Enterprise_Server_name>_MDS-CS_1.
         2. Click Edit Properties. 
         3. In the Properties window, click HTTP.
         4. Under Authentication set the Support HTTP Authentication to True.

  For BlackBerry Enterprise Server 5.0
         1. Open the BlackBerry Administration Service.
         2. Expand the BlackBerry Solution topology.
         3. Expand the component view.
         4. Select MDS connection service.
         5. Select the http tab.
         6. Set authentication support enabled to yes.
         7. If you change this configuration, you will need to restart the BlackBerry MDS service in the Windows Services window.

Configure the MDSLogin.conf file to include your domain name. This will populate the domain field for the BlackBerry smartphone user when they are prompted for credentials on their BlackBerry smartphone. Complete the following steps:

1.On the BlackBerry Enterprise Server, go to C:\Program Files\Research In Motion\BlackBerry Enterprise Server\MDS\Servers\servername\config. 
2.Open the MDSLogin.conf file in a text editor. 
3.Edit the MDS_Default section by replacing COMPANY.COM with your domain name.

Note: If the domain name starts with a number, surround the domain name with quotes ("")

4.If you wish to force a particular authentication type you can change the relevant optional entry to required. 
 Save and close the file.
C. Configure the krb5.conf file to include details relevant to your specific Microsoft Active Directory environment as follows:
    On the BlackBerry Enterprise Server navigate to C:\Program Files\Research In Motion\BlackBerry Enterprise Server\MDS\Servers\servername\config. 

1.Open and edit the krb5.conf in a text editor.

The default sections and entries contained within this file are as follows:
default_tkt_enctypes = des-cbc-md5 ; or des-cbc-crc
default_tgs_enctypes = des-cbc-md5 ; or des-cbc-crc
# change COMPANY.COM to your Kerberos realm
# change KDC:88 to the hostname:port of KDC
kdc =} 
2.Replace the COMPANY.COM entry under the [realms] section with your domain name. Ensure this entry is in UPPER case.  
3.Enter the Fully Qualified Domain Name (FQDN) of the KDC within your Microsoft Active Directory environment and port number (if changed from the default of 88). Ensure host names and domain names are in lower case.  
4.Restart the BlackBerry MDS Connection Server service in Windows Services

Wednesday, October 17, 2012


- putem dezgropa mortii acum :)

Saturday, October 06, 2012

Remove weird characters from filenames

paste <(find . -print | awk '{print "\042"$0"\042"}') <(find . -print | sed -e 's/\o300/A/g' -e 's/\o301/A/g' -e 's/\o302/A/g' -e 's/\o340/a/g' -e 's/\o341/a/g' -e 's/\o342/a/g' -e 's/\o307/C/g' -e 's/\o347/c/g' -e 's/\o310/E/g' -e 's/\o311/E/g' -e 's/\o312/E/g' -e 's/\o350/e/g' -e 's/\o351/e/g' -e 's/\o352/e/g' -e 's/\o316/I/g' -e 's/\o356/i/g' -e 's/\o322/O/g' -e 's/\o323/O/g' -e 's/\o324/O/g' -e 's/\o362/o/g' -e 's/\o363/o/g' -e 's/\o364/o/g' -e 's/\o331/N/g' -e 's/\o361/n/g' -e 's/\o331/U/g' -e 's/\o332/U/g' -e 's/\o333/U/g' -e 's/\o371/u/g' -e 's/\o372/u/g' -e 's/\o373/u/g' -e 's/\o357/i/g' -e 's/\o317/I/g' -e 's/\o264/_/g' -e 's/\o250/_/g' -e 's/[)(]/-/g' -e 's/^\(.*\)$/"\1"/') | sed -e 's/^/mv /'

pretty neat, heh?
I'm using awk when I define the source because sed -e 's/.*/"&"/' or 's/^\(.*\)$/"\1"/' fails in the weird characters.

 And while being there, find . -type f -regextype posix-extended ! -iregex '.*.(mp3|avi|mkv|wmv|mp4|mp5|flv|M4V|mpeg|mov|m1v|m2v|3gp|avchd)$' -delete will nicely clean up the music folders :)

the characters definitions are found in  /usr/share/X11/locale/iso8859-1/Compose

Monday, September 17, 2012

Clear Win7 UserProfile

' Clear Win7/Win2008 User Profile and registry
' to be executed on each Terminal Server
'(c)2012-2014 sorinakis@gmail

Set WshShell = CreateObject("WScript.Shell")
Set WshNet = WScript.CreateObject("WScript.Network")
Set WMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
set WshFSO = CreateObject("Scripting.FileSystemObject")
const HKEY_LOCAL_MACHINE = &H80000002

dim strUser
strUser = InputBox(vbCrLf & "Please enter the username you wish to reset: ", "Profile Cleaner")

 If TypeName(strUser) = "Empty" Then
 End If
If Len(Trim(strUser)) = 0 Then
     MsgBox "You have to Enter Username To Reset",48
 End If
Loop While Len(Trim(strUser)) = 0
'' debug
'with createobject("")
'.popup "User: " & strUser , 5 , "Info"
'end with
'' end debug
if CStr(CheckUser(strUser)) then
Set Account = WMIService.Get("Win32_UserAccount.Name='" & strUser & "',Domain='" & WshNet.UserDomain & "'")
strRegKey = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" + Account.SID

if CheckRegKey(strRegKey) then
strUserProfile = WshShell.ExpandEnvironmentStrings(WshShell.RegRead("HKEY_LOCAL_MACHINE\" + strRegKey + "\ProfileImagePath"))
strRmtFldr = WshShell.ExpandEnvironmentStrings(WshShell.RegRead("HKEY_LOCAL_MACHINE\" + strRegKey + "\CentralProfile"))
MsgBox "  The registry key for user " & strUser & " does not exist! Can NOT backup and clean anything!" & vbCrLf & vbCrLf & "Please manually check for and rename the USERPROFILE and ROAMINGPROFILE Folders.",16
End If
strRegFile = strUserProfile & "\reg_backup.reg"
regCmd = "regedit.exe /E """ & strRegFile & """ " & """HKEY_LOCAL_MACHINE\" & strregKey & """"

If WshFSO.FolderExists (strUserProfile) Then
 '' debug
 'with createobject("")
 '.popup "Backup: " & strUserProfile , 5 , "Info"
 'end with
 '' end debug
WshShell.Run regCmd, 0, True
 WshFSO.MoveFolder strUserProfile , strUserProfile & ".backup"
End If

If WshFSO.FolderExists (strRmtFldr) Then
 '' debug
 'with createobject("")
 '.popup "Backup: " & strRmtFldr , 5 , "Info"
 'end with
 '' end debug
   WshFSO.MoveFolder strRmtFldr , strRmtFldr & ".backup"
End If

 '' debug
 'with createobject("")
 '.popup "Removing: HKEY_LOCAL_MACHINE\" & strRegKey , 5 , "Info"
 'end with
 '' end debug
 DeleteSubkeys HKEY_LOCAL_MACHINE, strRegKey
 Sub DeleteSubkeys(HKEY_LOCAL_MACHINE, strRegKey)
    objRegistry.EnumKey HKEY_LOCAL_MACHINE, strRegKey, arrSubkeys
    If IsArray(arrSubkeys) Then
        For Each strSubkey In arrSubkeys
            DeleteSubkeys HKEY_LOCAL_MACHINE, strRegKey & "\" & strSubkey
    End If
    objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strRegKey
 End Sub

' Open the backed up profile it in explorer...

'strPath = "explorer.exe /e, strRmtFldr" & ".backup"
'WshShell.Run strPath 

  with createobject("")
 .popup "Profile of " & strUser & " has been processed.", 5 , "Info"
 end with
 '' end debug
MsgBox  "USER " & strUser & " NOT FOUND!", 16
End If

Function CheckRegKey(strRegKey)
On Error Resume next 
strUserProfile = WshShell.ExpandEnvironmentStrings(WshShell.RegRead("HKEY_LOCAL_MACHINE\" + strRegKey + "\ProfileImagePath"))
  If Err.Number <> 0 Then
CheckRegKey = false
CheckRegKey = true
End If
end function

Function CheckUser(user)
On Error Resume next
with CreateObject("WScript.Shell")
Set Account = WMIService.Get("Win32_UserAccount.Name='" & User & "',Domain='" & WshNet.UserDomain & "'")
end with
CheckUser = (Err.Number = 0)
On Error Goto 0
end function    

Friday, April 06, 2012

Cyclic paging script

Let's say that we have an emergency voicemail box where our clients can leave us messages if they have a contract for extended hours or a limited response time contract. Let's also suppose that we have a shitty mobile phone provider, whose signal does no goes higher that 3000ft and is not available too far in wilderness, but we still have those old pagers, able to receive the signal even on top of mount Everest. And let's say that we have a bunch of unfortunate enough bastards on call that are supposed to respond to those calls. Now, every week it's some other poor bastard turn to be on call, but just in case he's not available, we might be force to page the other unfortunates, even when it is not their week of duty. And we page them in order, one after another, until one of them login the web interface of our asterisk server or call the emergency mailbox and acknowledge the message.
This is the script that have to be run from cron every */10 minutes on the asterisk server:

# A script that checks for new messages on emergency voicemail and send messages to pagers
# (c) 2012 under the terms of GNU GPL
# 2012/06/23 v0.5 neXt ( - Add names to email
# 2012/06/09 v0.4 neXt ( - Don't send pages during the night
# 2012/05/10 v0.3 neXt ( - Monday morning warn the user on duty
# 2012/04/09 v0.2 neXt ( - Verify if the cycle has been done today
# 2012/04/06 v0.1 neXt ( - Initial release

# Voicemail location

# Paging provider

# Working directory
if [ ! -d $working ] ; then
 mkdir -p $working

# Location of the file containing the pager numbers
if [ ! -f $pagers ] ; then
 # If the pager file does not exist define the defaults - We need a NEW-LINE at the end of the file!
 echo "5140000000 John Doe
5140000001 Jane Doe
5140000002 Jack Doe
" > $pagers

# A temporary file containing a volatile data
if [ ! -f $runvars ] ; then
 # If the variables file does not exist define some sane defaults
 echo "current=1" > $runvars
 echo "oldday=0" > $runvars

# Cycle pager numbers every Monday, the first number will become the last
today=`date +%w`
day=`date +%d%m`
# read the variables
. $runvars 1>&2>/dev/null
# If today is Monday (weekday 1) and the numbers were not already cycled
if [ $today = 1 ] && [ ! $day = $oldday ]; then
 # copy pager numbers to a new file, deleting the first line of this file
 sed -n "2,\$ p;/^ *$/d" $pagers > $
 # read the first line of the old file and put that line at the end of the new file
 head -1 $pagers >> $
 # replace the old file with the new one
 mv -f $ $pagers
 # send an email with the name and number of the current guy on duty
 guy=`head -n1 $pagers | tail -n1
 recipients=`cat $pagers | sed 's/[^@]* \([a-zA-Z0-9.]*@[^ ]*\).*/\1/' | sed ':a;N;$!ba;s/\n/ /g'`
 echo "This week the main pager is $guy" | mail -s "Pager $guy" $recipients
 # page this new guy with a test message, but not in the middle of the night, 07:30AM seems like OK-ish...
 guynr=`echo "$guy" | cut -f1 -d" "`
 wrn="echo '00 10-86 00' | mail -s911 $guynr@$provider"
 echo $wrn | at 07:30
 # keep the today's date into variable oldday - used to see if we've already processed the cycle today
 sed -i "/oldday/d" $runvars
 echo "oldday=$day" >> $runvars

# We DO NOT send paging messages between 10PM and 7AM - there are no contracts between those hours
if [ $((10#$(date +%H%M))) -gt 700 ] && [ $((10#$(date +%H%M))) -lt 2200 ]; then

 # Let's see if there are new messages in the emergency voicemail
 messages=`ls -l $voicemail | wc -l`
 if [ $messages -gt 1 ]; then
  # There is something in the voicemail, read the already defined variables to see to whom we have to send the page
. $runvars 1>&2>/dev/null
   # If we are aleady at the end of the paging list, we have to restart from the beginning and annoy everybody again
   max_current=`wc -l $pagers | cut -f1 -d" "`
   if [ $current -gt $max_current ]; then
   # Hell, let's send a page to the sucker that is on duty today. Extract only the phone number from file.
   current_page=`head -n$current $pagers | tail -n1 | cut -f1 -d" "`
#  echo "msg=$messages max=$max_current cn=$current cur=$current_page" # This line is here for debugging
   echo "10-78 911" | mail -s911 $current_page@$provider
   # Now remember, we've already sent a page to this unfortunate, if he's not available, we'll have to move to the next in line
   current=`expr $current + 1`
   sed -i "/current/d" $runvars
   echo "current=$current" >> $runvars
   # Cleanup the variables, some poor bastard took the message, we reset the counter
   sed -i "/current/d" $runvars
   echo "current=1" >> $runvars

---------------------------------------------------------------------------------------------  Note: This is work in progress. I'll update changes during time.

Blog Archive