Posts Tagged ‘string’
Monday, October 16th, 2017Reading Time: < 1minute

How to change / reset OSCommerce lost / forgotten admin password?
The password in OSCommerce is kept in table "admin", so to reset password connect to MySQL with mysql cli client.
First thing to do is to generate the new hash string, you can do that with a simple php script using the md5(); function
root@pcfreak:/var/www/files# cat 1.php
<?
$pass=md5('password');
echo $pass;
?>
root@pcfreak:/var/www/files# php 1.php
5f4dcc3b5aa765d61d8327deb882cf99
root@pcfreak:/var/www/files#
Our just generated string (for text password password) is hash: 5f4dcc3b5aa765d61d8327deb882cf99
Next to update the new hash string into SQL, we connect to MySQL:
$ mysql -u root -p
And issue following command to modify the encrypted hash string:
UPDATE `DB`.`admin` SET `admin_password` = '5f4dcc3b5aa765d61d8327deb882cf99' WHERE `admin`.`admin_id` = 6;
Tags: cat, echo, hash, How to, pcfreak, php script, root, string, var, www
Posted in System Administration, Various, Web and CMS | 1 Comment »
Tuesday, March 15th, 2016Reading Time: 2minutes

If you're already used too using grep -v "sometring" filename to print everything from a file without the certain grepped string output and you want to do the same to delete lines based on strings without having to output the grepped string to a file and then overwritting the original file:
grep -v 'whatever' filename > filename1
mv filename1 filename
A much better way to delete an whole line containing a string match from a file is to use sed
sed should be the tool of choice especially if you're scripting because sed is especially made for such batch edittings.
Here is how to do delete an entire line based on a given string:
sed –in-place '/some string to search and delete/d' myfilename
It might be a good idea to also create backups just to make sure something doesn't get deleted incidently to do use:
sed –in-place=.bak '/some string to search and delete/d' myfilename
If you need to wipe out an exact string from all files within a folder you might use a for loop or perl (some good examples check my previous article here)
In short to use bash's for loop here is how to backup and remove all lines with a string match within all files within a Linux directory:
for f in *.txt; do sed –in-place '/some string/d'
"$f"; done
find -name '*.txt' -exec sed –in-place=.bak '/some
string/d' "{}" ';'
BTW SED is really rich editor and some people got so much into it that there is even a sed written text (console) version of arkanoid 🙂

If you want to break the ice and get some fun in your boring sysadmin life get sed arkanoid code from here.
I have it installed under pc-freak.net free ASCII Games entertainment service, so if you want to give it a try just login and give a try.
Enjoy 🙂
Tags: bak, file, good, life, line, loop, make, match, string, use
Posted in Linux, Remote System Administration, System Administration, Various | No Comments »
Thursday, March 19th, 2015Reading Time: 3minutes
If you're a sysadmin (like me) or a programmer and love working on console most of the time on a recently bought Apple (Mac) PC, probably not like that by default Terminal App lacks nice color highlighting, color highlighly is already standard on Ubuntu / Debian / Mint and many of the streamline Linux distros for years, so it's weird that the shiny Mac lacks that in console 🙂
I'm not blaming Mac OS developers for shipping by default Mac's console so much greyish as most Mac userbase almost never use terminals, however adding some appearance candy makes my boring digital life much more entertaining.

Put in your home directory $HOME/.profile or in .bash_profile file below code:
vim ~/.profile
PS1='\[\e[0;33m\]\u\[\e[0m\]@\[\e[0;32m\]\h\[\e[0m\]:\[\e[0;34m\]\w\[\e[0m\]\$ '
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'
echo "PS1='\[\e[0;33m\]\u\[\e[0m\]@\[\e[0;32m\]\h\[\e[0m\]:\[\e[0;34m\]\w\[\e[0m\]\$ '
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"" >> ~/.profile
echo "export CLICOLOR=1" >> ~/.profile
echo "export LSCOLORS=ExFxBxDxCxegedabagacad" >> ~/.profile
echo "alias ls='ls -GFh'" >> ~/.profile
PS1 with above string do colorize Terminal's default “username@hostname:cwd $” following alias makes by default ls (dir) command to have colors enabled (show files and folders in shiny colors like on GNU / Linux). As you see the ls command perameter -G which actually adds colors is the same like in FreeBSD (since very big part of Mac OS is based on BSD UNIX utils), -F makes directories to be marked with / and -h (stands for human readable).
If you want to enable terminal ls colors for all existing Mac computer users open /etc/profile and (uncomment) / include:
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
If you want to customize further Mac OS's default Terminal App (add different Colorize Theme), change default shell, change default Title, add Transparency, Change Term Encoding etc. go and check settings in:
Terminal -> Settings

One really annoying thing about Mac OS X terminal for being users is that by default Command + D which is like CTRL + D on a non-Mac PC sends Split Window command, splitting the screen by two, if you're a new Mac user like me you will have to get used to Command + Shift + D which is the Mac equivalent of regular PC keyboard CTRL + D. Note that it is not possible to move between Splitted screens but instead the upper part of the split screen is just like a buffer where old output from terminal is put and can be used to keep an eye constantly on old content displayed on terminal …
If you're too lazy to edit files and stuff and just want to receive already well configured Terminal which has many of the features of gnome-terminal / konsole which are not there in Mac's default Terminal App, just download and use iTerm2 (OS X Terminal Replacement)

Once over with Terminal customizations if you happen to use VI Improved (VIM) text editor as an editor of choice on Mac create at least following .vimrc in your HOME directory
$ vim ~/.vimrc
" End
map <C-E> <End>
imap <C-E> <C-O><End>
" Home
map <C-A> <Home>
map <C-A> <C-O><Home>
This maps Command + A / Command + E to (emulate) act like normal PC Home / End Keyboard key button, to emulate Page Up / Page Down keys on Mac OS keyboard inside Terminal app use Fn (key) + Up / Down arrows.
To make HOME / END buttons answer to Control + A / E on a Terminal App level:
Inside Terminal.app
Open the Preferences window (CMD+,)
Click the Settings tab
Select your current Settings theme, and click on the Keyboard tab
Edit (or Add) the entry for Home
Set Action: to send string to shell:
Set the string to \001 (or press Ctrl+a)
Edit (or Add) the entry for End
Set Action: to send string to shell:
Set the string to \005 (or press Ctrl+e)
Edit (or Add) the entry for Page Up
Set Action: to send string to shell:
Set the string to \033[5~ (copy and paste this in)
Edit (or Add) the entry for Page Down
Set Action: to send string to shell:
Set the string to \033[6~ (copy and paste this in)
Close the settings window.
Tags: Click, colors, copy and paste, home, How to, Open, Select, Set Action, string, Terminal App
Posted in Curious Facts, Entertainment, Everyday Life, Mac OS X, Various | 1 Comment »
Wednesday, April 2nd, 2014Reading Time: 3minutes

On a project there are some issues with root admin user unable to access the server from remote host and the most probable reason was there is no access to the server from that host thus it was necessary check mysql root user privilegse and allowed hosts to connect, here SQL query to do it:
mysql> select * from `user` where user like 'root%';
+——————————–+——+——————————————-+————-+————-+————-+————-+————-+———–+————-+—————+————–+———–+————+—————–+————+————+————–+————+———————–+——————+————–+—————–+——————+——————+—————-+———————+——————–+——————+————+————–+———-+————+————-+————–+—————+————-+—————–+———————-+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections |
+——————————–+——+——————————————-+————-+————-+————-+————-+————-+———–+————-+—————+————–+———–+————+—————–+————+————+————–+————+———————–+——————+————–+—————–+——————+——————+—————-+———————+——————–+——————+————+————–+———-+————+————-+————–+—————+————-+—————–+———————-+
| localhost | root | *5A07790DCF43AC89820F93CAF7B03DE3F43A10D9 | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
| server737 | root | *5A07790DCF43AC89820F93CAF7B03DE3F43A10D9 | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
| 127.0.0.1 | root | *5A07790DCF43AC89820F93CAF7B03DE3F43A10D9 | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
| server737.server.myhost.net | root | *5A07790DCF43FC89820A93CAF7B03DE3F43A10D9 | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
| server4586 | root | *5A07790DCF43AC89820F93CAF7B03DE3F43A10D9 | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 |
| server4586.myhost.net | root | *5A07790DCF43AC89820F93CAF7B03DE3F43A10D9 | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 |
+——————————–+——+——————————————-+————-+————-+————-+————-+————-+———–+————-+—————+————–+———–+————+—————–+————+————+————–+————+———————–+——————+————–+—————–+——————+——————+—————-+———————+——————–+——————+————+————–+———-+————+————-+————–+—————+————-+—————–+———————-+
6 rows in set (0.00 sec)
mysql> exit
Here is query explained:
select * from `user` where user like 'root%'; query means:
select * – show all
from `user` – from user database
where user like 'root%' – where there is match in user column to any string starting with 'root*',
Tags: admin user, check, cli, exit, host, hosts, How to, localhost, match, net, project, root, root admin, root user, server, string
Posted in MySQL, System Administration | No Comments »
Monday, March 9th, 2015Reading Time: 2minutes

My site pictures are stored on webserver (blog) folder under /images/and all my links from this blog are linking to pc-freak.net/images/.. however recently I decided to run my own Content Delivery Network (CDN) to serve images with NGINX instead of Apache because this will save me a lot of Memory and increases significantly image picture download speed. For that purpose the easiest way is to of course redirect all images requests to NGINX server running on separate port 8080. But as the redirecting /images/ requests will have a minor negative effect on static content serve speed, I thought the best way will be to create / run a separate subdomain cdn.pc-freak.net on a separate IP address to serve blog linked images.
Then to achieve that, I needed a way to convert all my blog posts https://pc-freak.net/images/ string to http://cdn.pc-freak.net/ luckily there is a wordpress plugin to search and replace a string:
"SA simple search for find strings in your database and replace the string. You can search in ID, post-content, GUID, titel, excerpt, meta-data, comments, comment-author, comment-e-mail, comment-url, tags/categories and categories-description. It is possible to replace the user-ID in all tables and the user-login."
Using the plugin is straight forward:
cd /var/www/blog/wp-content/plugins
wget -q http://thedeadone.net/wp-content/sw/Wordpress/searchandreplace.zip
unzip searchandreplace.zip
Archive: searchandreplace.zip
warning [searchandreplace.zip]: 15 extra bytes at beginning or within zipfile
(attempting to process anyway)
inflating: searchandreplace.php
To substitute any string within wordpress database login to WP-Admin Panel you will notice in:
“Tools” (section) -> "Search and Replace”

I've also made a download mirror of Search and Replace current latest 2.7 WP plugins here.
Tags: blog, download, images, login, net, nginx, php, Posts Wordpress, running, speed, static content, string, substitute, webserver, www
Posted in System Administration, Various, Web and CMS, Wordpress | 1 Comment »
Wednesday, March 12th, 2014Reading Time: < 1minute

If you need to do some basic batch scripting sooner or later you will have to insert input from command line to a variable. In Linux this is done with read command, i.e.:
$ echo -n "Type a password for admin:";
$ read line;
$ echo $line;
So here is how to do the same if you need it for a Windows Batch (.BAT) file
C:\\Users\\> Set /p string='What do you want to ask?:'
'What do you want to ask?:'
This will define the string variable, to later print out the variable use:
> echo %string%
variable input output
Tags: admin, basic, BAT, command, echo, input output, line, Linux, need, password, read, string, Windows
Posted in Everyday Life, Various, Windows | No Comments »
Tuesday, May 13th, 2014Reading Time: 2minutes

GNU Grep is equipped with a special option "-r" to grep recursively. Looking for string in a file in a sub-directories tree with the -r option is a piece of cake. You just do:
grep -r 'string' /directory/
or if you want to search recursively non-case sensitive for text
grep -ri 'string' .
Another classic GNU grep use (I use almost daily) is whether you want to match all files containing (case insensitive) string among all files:
grep -rli 'string' directory-name
Now if you want to grep whether a string is contained in a file or group of files in directory recursively on some other UNIX like HP-UX or Sun OS / Solaris where there is no GNU grep installed by default here is how to it:
find /directory -exec grep 'searched string' {} dev/null ;
Note that this approach to look for files containing string on UNIX is very slowThus on not too archaic UNIX systems for some better search performance it is better to use xargs;
find . | xargs grep searched-string
A small note to open here is by using xargs there might be weird results when run on filesystems with filenames starting with "-".
Thus comes the classical (ultimate) way to grep for files containing string with find + grep, e.g.
find / -exec grep grepped-string {} dev/null ;
Another way to search a string recursively in files is by using UNIX OS '*' (star) expression:
grep pattern * */* */*/* 2>/dev/null
Talking about recursive directory text search in UNIX, should mention another good GNU GREP alternative ACK – check it on betterthangrep.com 🙂 . Ack is perfect for programmers who have to dig through large directory trees of code for certain variables, functions, objects etc.
Tags: cake, code, directory, file, filesystems, GNU, grep, How to, Linux, look, match, note, piece, piece of cake, recursively, string, text, unix, variables, xargs
Posted in Programming, System Administration, Various | 1 Comment »
Thursday, December 11th, 2014Reading Time: 2minutes

Recently I had a task to delete number of set variables (listed parameters) from URL address on a Apache webserver serving as Reverse Proxy.
To make it more clear exact task was when customers call the URL https://companywebsite-url.com (all subdomains included) the following URL parameters should always be deleted by the reverse proxy:
– ebppMode
– ebppObjectKey
– ebppObjectType
– ebppSystem
– logSys
The paramets are part of SAP Biller Direct in a Portal (based on the famous SAP database) which is often deployed as a component of Internet Sales (ISA) / Supplier Relationship Management (SRM) / CRM
, if a user is logged in with his Credentials (KID (Key ID) / Admin KID) into the system. The EBPP part of most variables stands for (Electronic Bill Presentment and Payment).
By passing above parameters to Website, modes of use, user accounts switched with which user is logged into the system system logs read and other stuff which can turn to be a severe security hole.
As most of Big Companies, does pass there web traffic via a "transparent" Reverse Proxy,it is a good security practice for SAP Biller Direct (including CRM systems( to wipe out this variables
Here is the mod_rewrite working rules that I used to achieve the delete variable from URL address task:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)bebppMode=(w*)b(.*)
RewriteRule (.*) $1?%1%3
RewriteCond %{QUERY_STRING} ^(.*)bebppObjectKey=(w*)b(.*)
RewriteRule (.*) $1?%1%3
RewriteCond %{QUERY_STRING} ^(.*)bebppObjectType=(w*)b(.*)
RewriteRule (.*) $1?%1%3
RewriteCond %{QUERY_STRING} ^(.*)bebppSystem=(w*)b(.*)
RewriteRule (.*) $1?%1%3
RewriteCond %{QUERY_STRING} ^(.*)logSys=(w*)b(.*)
RewriteRule (.*) $1?%1%3
RewriteCond %{QUERY_STRING} ^(.*)&&(.*)
RewriteRule (.*) $1?%1%3
P.S. I've implemented above Rewrite rules into all Virtualhosts of Applications (in that case all living in the same httpd.conf on SuSE (SLES) 11 SP1 Enterprise Linux server).
To make changes affective, restarted HTTPD Webserver:
/etc/init.d/httpd restart
The sesult is:
https://companywebsite-url.com/start.html?page=start&ebppMode=A&ebppSystem=Test
leads to a internal URL redirection
https://companywebsite-url.com/start.html?page=start
without parameters ebppSystem, ebppMode, ebppObjectKey, ebppSystem, logSys .
Other mod_rewrite rule that works but is too ugly and when I tried it on Debian Linux host was behaving strange (including in the rewrited URL address the directory address of the PHP twice):
RewriteCond %{QUERY_STRING} (.*)(^|&|%26|%20)ebppMode(=|%3D)([^&]+)(.*)$ [OR]
RewriteCond %{QUERY_STRING} (.*)(^|&|%26|%20)ebppObjectKey(=|%3D)([^&]+)(.*)$ [OR]
RewriteCond %{QUERY_STRING} (.*)(^|&|%26|%20)ebppObjectType(=|%3D)([^&]+)(.*)$ [OR]
RewriteCond %{QUERY_STRING} (.*)(^|&|%26|%20)ebppSystem(=|%3D)([^&]+)(.*)$ [OR]
RewriteCond %{QUERY_STRING} (.*)(^|&|%26|%20)logSys(=|%3D)([^&]+)(.*)$
RewriteRule (.*) /$1?%1%5 [R=307]
Well anyways, with the first bunch of mod_rewrite rule it works fine.
Thanks God Problem Solved 🙂
Tags: apache reverse proxy, Big Companies, delete parameter web url, delete string from url, good security, How to, make, page, SAP, sap database security, sap security, security practice, set variables, string, system, url
Posted in Computer Security, System Administration, Web and CMS | No Comments »
Saturday, July 17th, 2010Reading Time: < 1minute
There is a quick way to achieve a a full url redirect from a normal unencrypted HTTP request to a SSL crypted HTTPS
This is achieved through mod_rewrite using the RedirectMatch directive.
For instance let’s say we’d like to redirect https://pc-freak.net/blog to https://pc-freak.net/blog.
We simply put in our .htacess file the following rule:
Redirect permanent /blog https://www.cadiabank.com/login
Of course this rule assumes that the current working directory where the .htacess file is stored is the main domain directory e.g. / .
However this kind of redirect is a way inflexible so for more complex redirect, you might want to take a look at mod rewrite’s RedirectMatch directive.
For instance if you inted to redirect all urls (https://pc-freak.net/blog/something/asdf/etc.) which as you see includes the string blog/somestring/asdf/etc. to (https://pc-freak.net/blog/something/asdf/etc then you might use some htaccess RedirectMatch rule like:
RedirectMatch permanent ^/blog/(.*)$ https://pc-freak.net.net$1
or
RedirectMatch permanent ^/blog/(.*)$ https://pc-freak.net.net/$1
Hopefully your redirect from the http protocol to https protocol with mod_rewrite rule should be completed.
Also consider that the Redirect directive which by the way is an Apache directive should be faster to process requests, so everywhere you can I recommend using instead of RedirectMatch which calls the external Apache mod_rewrite and will probably be times slower.
Tags: blog, directory, HTTP, HTTPS, instance, net, port, redirect, Redirect http URL folder to https e.g. redirect (http://example.com to https://www.example.com) with mod_rewrite, something, SSL, string, url, www
Posted in Linux, SEO, System Administration | 3 Comments »