Arkiv

Arkiv för maj, 2011

Remove åäö from file names and folders

maj 30th, 2011 Inga kommentarer
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
import os

def syntax(item):
# åäö->aao
nn=item.replace('å','a').replace('ä','a').replace('ö','o')
nn=nn.replace('Å','A').replace('Ä','A').replace('Ö','O')
nn=nn.replace('ü','u').replace('Ü','U')
nn=nn.replace('é','e').replace('É','E')

#special chars -> underscore
#    for uscore in ("'",'`',"'",'^','"','¨','(',')','[',']','=',
#                   ',',':',';','*','!','@','£','#','¤','$','%','&','{','}'):
#      nn=nn.replace(uscore,'_')

return nn

for root,dirs,files in os.walk('./',topdown=False):
for name in files: # First change name of the files
newname=os.path.join(root,syntax(name))
name=os.path.join(root,name)
os.rename(name,newname)

for name in dirs: # Then change name of the folders
newname=os.path.join(root,syntax(name))
name=os.path.join(root,name)
os.rename(name,newname)
Categories: Bash, Linux, Programmering Taggar:

Read and write to registry in Windows 7 with VBS

maj 16th, 2011 Inga kommentarer

Here’s an example of how you can use VBS script to access the registry in Windows. Tested in Win7.

'_____________________________________________________________________________
' REMOVE POP-UP'S
'
' v1.00 2011-05-16 Lenovo Fingerprint software /Tobias Holm / http://xpro.se
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
lRet = RegWriteW7("HKEY_CURRENT_USER\Software\Protector Suite\Control Center\1.0\ShowOnStartup", "0", "REG_DWORD")
msgbox "WRITE:" & lRet & " ERR:" & Err
lRet = RegReadW7("HKEY_CURRENT_USER\Software\Protector Suite\Control Center\1.0\ShowOnStartup")
msgbox "READ:" & lRet & " ERR:" & Err
lRet = RegDelW7("HKEY_CURRENT_USER\Software\Protector Suite\Control Center\1.0\ShowOnStartup")
msgbox "DEL:" & lRet & " ERR:" & Err

'______________________________________________________________________________________
' WRITE TO REGISTRY / Tobias Holm 2011-05-16 / http://xpro.se
' Original idea Guy Thomas http://computerperformance.co.uk (Version 1.2 - March 2007)
' Creates the registry keys if they doesn't exists.
' Ex: lRet = RegWriteW7("HKEY_CURRENT_USER\Software\Intel\Count", "35", "REG_DWORD")
' Returns the exit code from Shell.RegWrite
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Function RegWriteW7(x_sPath, x_sValue, x_sType)
On Error Resume Next
Dim x_objShell
Set x_objShell = CreateObject("WScript.Shell")
Err.Clear
RegWriteW7 = x_objShell.RegWrite(x_sPath, x_sValue, x_sType)
Set x_objShell = Nothing
End Function

'______________________________________________________________________________________
' READ FROM REGISTRY / Tobias Holm 2011-05-16 / http://xpro.se
' Original idea Guy Thomas http://computerperformance.co.uk (Version 1.2 - March 2007)
' Ex: lRet = RegReadW7("HKEY_CURRENT_USER\Software\Intel\Count")
' Returns the value from Shell.RegRead
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Function RegReadW7(x_sPath)
On Error Resume Next
Dim x_objShell
Set x_objShell = CreateObject("WScript.Shell")
Err.Clear
RegReadW7 = x_objShell.RegRead(x_sPath)
Set x_objShell = Nothing
End Function

'______________________________________________________________________________________
' DELETE FROM REGISTRY / Tobias Holm 2011-05-16 / http://xpro.se
' Original idea Guy Thomas http://computerperformance.co.uk (Version 1.2 - March 2007)
' Deletes a registry value. Doesn't delete the registry keys though.
' Ex: lRet = RegDelW7("HKEY_CURRENT_USER\Software\Intel\Count")
' Returns the exit code from Shell.RegDelete
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Function RegDelW7(x_sPath)
On Error Resume Next
Dim x_objShell
Set x_objShell = CreateObject("WScript.Shell")
Err.Clear
RegDelW7 = x_objShell.RegDelete(x_sPath)
Set x_objShell = Nothing
End Function
Categories: Programmering, Windows Taggar:

Reset MySQL root Password

maj 8th, 2011 Inga kommentarer

Ref: http://www.debian-administration.org/articles/442

Posted by Steve on Thu 28 Sep 2006 at 09:12

Resetting the root password of a MySQL database is trivial if you know the current password if you don’t it is a little tricker. Thankfully it isn’t too difficult to fix, and here we’ll show one possible way of doing so.

If you’ve got access to the root account already, because you know the password, you can change it easily:

steve@steve:~$ mysql --user=root --pass mysql
Enter password:

mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';
Query OK, 2 rows affected (0.04 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql> exit
Bye

However if you don’t know the current password this approach will not work – you need to login to run any commands and without the password you’ll not be able to login!

Thankfully there is a simple solution to this problem, we just need to start MySQL with a flag to tell it to ignore any username/password restrictions which might be in place. Once that is done you can successfully update the stored details.

First of all you will need to ensure that your database is stopped:

root@steve:~# /etc/init.d/mysql stop

Now you should start up the database in the background, via the mysqld_safe command:

root@steve:~# /usr/bin/mysqld_safe --skip-grant-tables &
[1] 6702
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6763]: started

Here you can see the new job (number ”1”) has started and the server is running with the process ID (PID) of 6702.

Now that the server is running with the --skip-grant-tables flag you can connect to it without a password and complete the job:

root@steve:~$ mysql --user=root mysql
Enter password:

mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';
Query OK, 2 rows affected (0.04 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql> exit
Bye

Now that you’ve done that you just need to stop the server, so that you can go back to running a secure MySQL server with password restrictions in place. First of all bring the server you started into the foreground by typing ”fg”, then kill it by pressing ”Ctrl+c” afterwards.

This will now allow you to start the server:

root@steve:~# /etc/init.d/mysql start
Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..

Now everything should be done and you should have regained access to your MySQL database(s); you should verify this by connecting with your new password:

root@steve:~# mysql --user=root --pass=new-password-here
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 5.0.24a-Debian_4-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit
Bye
Categories: Linux, Programmering Taggar:

Standard Client Ubuntu 10.10/11.04/11.10

maj 6th, 2011 Inga kommentarer

This is the steps I use to configure a new Ubuntu client:

  • Install Ubuntu from USB/CD/PXE

Then add the following programs in the Program Central:

  • Chromium
  • GIMP
  • gscan2pdf
  • PDF Editor
  • Thunderbird
  • Filezilla
  • KVpnc
  • Pidgin
  • Remmina
  • Wireshark
  • XChat IRC
  • Zenmap
  • tn5250
  • Audacity
  • Desktop recorder
  • GNOME MPlayer
  • ISO Master
  • VLC
  • MuseScore
  • OpenShot Video Editor
  • UNetbootin
  • Filelight
  • TrueCrypt
  • Wine + Spotify
  • apt-get packages to source compile ffmpeg

Install the following programs from different sources (Google 😉 )

sudo add-apt-repository ppa:dockbar-main/ppa
sudo apt-get update && sudo apt-get install dockbarx
sudo apt-get install dockbarx-themes-extra

  • Synergy (http://synergy-foss.org/download)
  • BankID (in 64-bit Linux: sudo apt-get install nspluginwrapper && sudo nspluginwrapper -i /usr/local/lib/personal/libplugins.so)

After this it’s time to restore my home folder from a backup.

Files to manually restore:

  • /etc/X11/xorg.conf
sudo nvidia-xconfig --post-tree --twinview

Ref: http://manpages.ubuntu.com/manpages/lucid/man1/alt-nvidia-current-xconfig.1.html

Configs to manually restore:

  • Compiz config, effects
  • X key bindings (Super+Up=Maximize vertically, Super=ScrClip)
  • Startup programs (Synergy)
  • add NAS to fstab
  • crontab (Backup once every hour to NAS + SD-card)
  • crontab for root (apt-get autoclean = free space in /var/cache/apt/archives)
  • Ubuntu One
  • Network printers (DeskJet 970, CLJ2600)

Add link support in Firefox for Second Life:

  • Type about:config in Firefox address field
  • Right-click any item in the list and select New > Boolean
  • Type: network.protocol-handler.external.secondlife
  • Set the value to true. This tells Firefox to use an external program to handle the secondlife:// protocol
  • Right-click any item in the list and select New > String
  • Type: network.protocol-handler.app.secondlife
  • Type the path to the program you want to use for that protocol (e.g. /home/holm/dump/SecondLife-i686-2.6.3.227447/secondlife )

Add the Q700 (TS-219P) printer: smb://nas/naspr2

To enable OpenShot x264 you must install unrestricted codecs:

Install support for CSS encrypted DVD movies:

  • sudo apt-get install libdvdread4
  • sudo /usr/share/doc/libdvdread4/install-css.sh
    Rebooting may be necessary.

Install Java plugin in Firefox (Kubuntu x64):

  • Download Java from Oracle/Sun, unpack bin-file (first set x-flag)
  • cd /usr/lib/mozilla/plugins
  • sudo ln -s /home/user/Downloads/jre1.6.0_29/lib/amd64/libnpjp2.so

If you have a folder with scripts you can add it to the path:

  • Edit the file ”~/.profile” and add the path.

Disable Overlay Scrollbars in Ubuntu Natty:

  • echo ”export LIBOVERLAY_SCROLLBAR=0” | sudo tee /etc/X11/Xsession.d/80overlayscrollbars> /dev/null
  • Or remove the whole package: sudo apt-get remove overlay-scrollbar

Restore debconf backup

According to section 6.4.9 (http://www.debian.org/doc/manuals/reference/ch-package.en.html#s-record) of the Debian Reference Manual (http://www.debian.org/doc/manuals/reference/), the following will save both the list of packages installed and their debconf configuration:

# dpkg –get-selections ”*” >myselections # or use \*
# debconf-get-selections > debconfsel.txt

and the following will reinstall and reconfigure them:

# dselect update
# debconf-set-selections < debconfsel.txt
# dpkg –set-selections <myselections
# apt-get -u dselect-upgrade # or dselect install

Categories: Linux, Ubuntu Taggar:

NTLM authentication in Linux

maj 5th, 2011 Inga kommentarer

If you want to transparently login to a Windows NT server from Linux you can set up Squid Proxy configured with NTLM authentication transparently with your domain.

Linux: Setup a transparent proxy with Squid in three easy steps

Ref: http://www.cyberciti.biz/tips/linux-setup-transparent-proxy-squid-howto.html

Categories: Linux, Windows Taggar: