Saturday, December 22, 2012

Linkstation enable ssh - LS-X1.0TLJ

How to enable SSH on Linkstation LS-X1.0TLJ

1/ Download acp_commander.jar ( google around to find the JAR)
2/ Assuming the IP on your linkstation is 10.0.1.60 you have to run the following commands
3/ _ADMIN_PASSWORD_ is same password that you user on linkstation HTTP/HTTPS URL with admin id.
4/ _ROOT_PASSWORD_ provide a new root password
 
java -jar acp_commander.jar -t 10.0.1.60 -ip 10.0.1.10 -pw _ADMIN_PASSWORD_ -c "ls /"
java -jar acp_commander.jar -t 10.0.1.60 -ip 10.0.1.60 -pw _ADMIN_PASSWORD_ -c "(echo _ROOT_PASSWORD_;echo _ROOT_PASSWORD_)|passwd"
java -jar acp_commander.jar -t 10.0.1.60 -ip 10.0.1.60 -pw _ADMIN_PASSWORD_ -c "sed -i 's/UsePAM yes/UsePAM no/g' /etc/sshd_config"
java -jar acp_commander.jar -t 10.0.1.60 -ip 10.0.1.60 -pw _ADMIN_PASSWORD_ -c "sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/sshd_config"
java -jar acp_commander.jar -t 10.0.1.60 -ip 10.0.1.60 -pw _ADMIN_PASSWORD_ -c "/etc/init.d/sshd.sh restart"

Sunday, August 5, 2012

SAX 2048 byte issue on Java XML parsing

SAX parser code has an issue for files or messages of greater than 2048 bytes. Parser only reads in 2048 bytes at a time which could lead to an error if the 2048-byte split the data element.

The solution to this is to introduce a temporary variable on the callback method. Here is code snippet.


public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {

public void startElement (String uri, String localName, String qName, Attributes attr) throws SAXException{
     value = new StringBuffer();     if(qName.equalsIgnoreCase("clientDets")) {          ncstClient = new NcstClient();          ncstClient.setType(attributes.getValue("type"));     }}

public void characters(char[] ch, int start, int length) throws SAXException {     value.append(new String(ch, start, length));}

Monday, June 4, 2012

Configure NTP to Synchronize the system clock: Centos 6



Login as root. Type the following command
[root@homeserver]# yum install ntp
Type on the ntpd service
[root@homeserver]# chkconfig ntpd on

Synchronize the system clock with 0.pool.ntp.org server:
[root@homeserver]# ntpdate pool.ntp.org

Start daemon process:
[root@homeserver]# /etc/init.d/ntpd restart

Sunday, June 3, 2012

Install GD Library For PHP5 On CentOS 6


Install GD Library For PHP5 On CentOS

Note: this article only applies if your current PHP version has been installed by yum. If you custom compiled it from source, this will not work.



Verify PHP as installed by yum

An easy task, using yum. First step, see if it's already installed.
[root@homeserver]# rpm -qa | grep php
php-common-5.1.6-15.el5
php-cli-5.1.6-15.el5
php-5.1.6-15.el5
php-pdo-5.1.6-15.el5
php-mysql-5.1.6-15.el5

Install the GD library using yum

If the GD Library isn't present in that list, it wasn't installed on the server yet. Install it using yum.
[root@homeserver]# yum install php-gd
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
epel/metalink                                                                                                                 | 5.0 kB     00:00     
 * base: ftp.iij.ad.jp
 * epel: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
base                                                                                                                          | 3.7 kB     00:00     
extras                                                                                                                        | 3.5 kB     00:00     
updates                                                                                                                       | 3.5 kB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php-gd.x86_64 0:5.3.3-3.el6_2.8 will be installed
--> Processing Dependency: libpng12.so.0(PNG12_0)(64bit) for package: php-gd-5.3.3-3.el6_2.8.x86_64
--> Processing Dependency: libpng12.so.0()(64bit) for package: php-gd-5.3.3-3.el6_2.8.x86_64
--> Processing Dependency: libjpeg.so.62()(64bit) for package: php-gd-5.3.3-3.el6_2.8.x86_64
--> Processing Dependency: libfreetype.so.6()(64bit) for package: php-gd-5.3.3-3.el6_2.8.x86_64
--> Processing Dependency: libXpm.so.4()(64bit) for package: php-gd-5.3.3-3.el6_2.8.x86_64
--> Processing Dependency: libX11.so.6()(64bit) for package: php-gd-5.3.3-3.el6_2.8.x86_64
--> Running transaction check
---> Package freetype.x86_64 0:2.3.11-6.el6_2.9 will be installed
---> Package libX11.x86_64 0:1.3-2.el6 will be installed
--> Processing Dependency: libX11-common = 1.3-2.el6 for package: libX11-1.3-2.el6.x86_64
--> Processing Dependency: libxcb.so.1()(64bit) for package: libX11-1.3-2.el6.x86_64
---> Package libXpm.x86_64 0:3.5.8-2.el6 will be installed
---> Package libjpeg.x86_64 0:6b-46.el6 will be installed
---> Package libpng.x86_64 2:1.2.49-1.el6_2 will be installed
--> Running transaction check
---> Package libX11-common.noarch 0:1.3-2.el6 will be installed
---> Package libxcb.x86_64 0:1.5-1.el6 will be installed
--> Processing Dependency: libXau.so.6()(64bit) for package: libxcb-1.5-1.el6.x86_64
--> Running transaction check
---> Package libXau.x86_64 0:1.0.5-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================
 Package                               Arch                           Version                                  Repository                       Size
=====================================================================================================================================================
Installing:
 php-gd                                x86_64                         5.3.3-3.el6_2.8                          updates                         104 k
Installing for dependencies:
 freetype                              x86_64                         2.3.11-6.el6_2.9                         updates                         359 k
 libX11                                x86_64                         1.3-2.el6                                base                            582 k
 libX11-common                         noarch                         1.3-2.el6                                base                            188 k
 libXau                                x86_64                         1.0.5-1.el6                              base                             22 k
 libXpm                                x86_64                         3.5.8-2.el6                              base                             59 k
 libjpeg                               x86_64                         6b-46.el6                                base                            134 k
 libpng                                x86_64                         2:1.2.49-1.el6_2                         updates                         182 k
 libxcb                                x86_64                         1.5-1.el6                                base                            100 k

Transaction Summary
=====================================================================================================================================================
Install       9 Package(s)

Total download size: 1.7 M
Installed size: 5.9 M
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 1.7 M
(1/9): freetype-2.3.11-6.el6_2.9.x86_64.rpm  | 359 kB     00:00     
(2/9): libX11-1.3-2.el6.x86_64.rpm           | 582 kB     00:00     
(3/9): libX11-common-1.3-2.el6.noarch.rpm    | 188 kB     00:00     
(4/9): libXau-1.0.5-1.el6.x86_64.rpm         |  22 kB     00:00     
(5/9): libXpm-3.5.8-2.el6.x86_64.rpm         |  59 kB     00:00     
(6/9): libjpeg-6b-46.el6.x86_64.rpm          | 134 kB     00:00     
(7/9): libpng-1.2.49-1.el6_2.x86_64.rpm      | 182 kB     00:00     
(8/9): libxcb-1.5-1.el6.x86_64.rpm           | 100 kB     00:00     
(9/9): php-gd-5.3.3-3.el6_2.8.x86_64.rpm     | 104 kB     00:00     
--------------------------------------------------------------------
Total                                                                                                                736 kB/s | 1.7 MB     00:02     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 2:libpng-1.2.49-1.el6_2.x86_64    1/9 
  Installing : libX11-common-1.3-2.el6.noarch    2/9 
  Installing : libXau-1.0.5-1.el6.x86_64         3/9 
  Installing : libxcb-1.5-1.el6.x86_64           4/9 
  Installing : libX11-1.3-2.el6.x86_64           5/9 
  Installing : libXpm-3.5.8-2.el6.x86_64         6/9 
  Installing : libjpeg-6b-46.el6.x86_64          7/9 
  Installing : freetype-2.3.11-6.el6_2.9.x86_64  8/9 
  Installing : php-gd-5.3.3-3.el6_2.8.x86_64     9/9 
Installed:
  php-gd.x86_64 0:5.3.3-3.el6_2.8                                                                                                                    

Dependency Installed:
  freetype.x86_64 0:2.3.11-6.el6_2.9       
  libX11.x86_64 0:1.3-2.el6
  libX11-common.noarch 0:1.3-2.el6
  libXau.x86_64 0:1.0.5-1.el6      
  libXpm.x86_64 0:3.5.8-2.el6 
  libjpeg.x86_64 0:6b-46.el6
  libpng.x86_64 2:1.2.49-1.el6_2  
  libxcb.x86_64 0:1.5-1.el6        

Complete!

Easy going, isn't it?

Restart Lighttpd

Restart your lighted, and you're ready to rock.
[root@srv]# service httpd restart
Stopping lighttpd:                                            [  OK ]
Starting lighttpd:                                            [  OK ]

Saturday, June 2, 2012

Installing SSH2 extension for PHP on Centos 6


Installing the SSH2 PHP extension on CentOS is actually pretty simple. 


Although it isn’t available as a straight yum install, it boils down to a few short steps.


Firstly, we’re going to install the dependencies:
yum install gcc php-devel php-pear libssh2 libssh2-devel

These will allow us to build the SSH2 extension using pecl.
pecl install -f ssh2

After running that command, it should stop at a line like:
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading ssh2-0.11.3.tgz ...
Starting to download ssh2-0.11.3.tgz (23,062 bytes)
........done: 23,062 bytes
5 source files, building
running: phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
libssh2 prefix? [autodetect] : 

All you have to do is hit Enter and it should detect the proper path. 


Once the install is completed, you just have to tell PHP to load the extension when it boots.
touch /etc/php.d/ssh2.ini
echo extension=ssh2.so > /etc/php.d/ssh2.ini

Now restart your webserver and test to see if the changes took effect.
/etc/init.d/lighttpd restart
php -m | grep ssh2

You should get a line returned with ‘ssh2′.

lighttpd doesn't start - selinux

Lighttpd doesn't start due to a conflict with file descriptors:

Issue
# /etc/init.d/lighttpd restart
Stopping lighttpd:                                         [FAILED]
Starting lighttpd: 2012-06-03 00:57:12: (server.c.722) couldn't set 'max filedescriptors' Permission denied
                                                           [FAILED]

Solution:

Install SE utils

yum install policycoreutils-python
Create SELinux module to allow lighttpd to set its own open file descriptors limit
/usr/sbin/semodule -DB
# /etc/init.d/auditd restart
Stopping auditd:                                           [  OK  ]
Starting auditd:                                           [  OK  ]
#grep lighttpd /var/log/audit/audit.log | audit2allow -M lighttpdmaxfds
#/usr/sbin/semodule -i lighttpdmaxfds.pp 
 # /etc/init.d/lighttpd restart
Stopping lighttpd:                                         [FAILED]
Starting lighttpd:                                         [  OK  ]
# /usr/sbin/semodule -B

Saturday, May 19, 2012

HOWTO: Change your default user account to a system account



When you deploy a new Ubuntu installation, the first user it creates (uid=1000) will be given sudo privileges. Sometimes it is desirable to have a specific "admin" user on your system that is separate from your normal user accounts which are located in the uid=1000+ range. For example, if you are setting up an LDAP network. Unfortunately, you can't set the uid manually during the initial installation process but you can change it afterwards.


Note:
If you make a mistake during this procedure it is possible to lock yourself out of the system completely. This is not such an issue if this is a freshly installed system but if it is already up and running in some sort of role, then you need to be extra careful. You have been warned!


I am working here with a fresh Lucid server install, and my uid=1000 user is called "sysadmin".


Login to a console session as root;


~$ sudo -i


Manually edit your passwd file;


~# vi /etc/passwd


At the end of the file will be the entry for the "sysadmin" account;


sysadmin:x:1000:1000:system admin,,,:/home/sysadmin:/bin/bash


Change the two "1000"'s to "999";


sysadmin:x:999:999:system admin,,,:/home/sysadmin:/bin/bash


Make the same change in the "group" file;


vi /etc/group


Change the "sysadmin" line to;


sysadmin:x:999:


Changing the uid of a user will break the permissions in their home directory;
~# ls -al /home/sysadmin
total 32
drwxr-xr-x 3 1000     1000     4096 2012-05-13 13:34 .
drwxr-xr-x 3 1000     1000     4096 2012-05-13 13:32 ..
-rw------- 1 1000     1000       48 2012-05-13 13:34 .bash_history
-rw-r--r-- 1 1000     1000      220 2012-05-13 13:32 .bash_logout
-rw-r--r-- 1 1000     1000     3103 2012-05-13 13:32 .bashrc
drwx------ 2 1000     1000     4096 2012-05-13 13:33 .cache
-rw-r--r-- 1 1000     1000      675 2012-05-13 13:32 .profile
-rw-r--r-- 1 1000     1000        0 2012-05-13 13:33 .sudo_as_admin_successful
-rw------- 1 1000     1000      663 2012-05-13 13:34 .viminfo


You can fix that by issuing the following commands;


~# chown sysadmin:sysadmin /home/sysadmin
~# chown sysadmin:sysadmin /home/sysadmin/.*


When we setup LDAP later we will want to mount /home to an NFS share. Unfortunately, when we do this we will overwrite our sysadmin's home folder! Let's move it to the root ("/") directory.


~# mv /home/sysadmin /


We will need to change the path in the passwd file;


~# vi /etc/passwd


Change it from;


sysadmin:x:999:999:sysadmin,,,:/home/sysadmin:/bin/bash


to this;


sysadmin:x:999:999:sysadmin,,,:/sysadmin:/bin/bash


Check that all is well;
~# ls -al /sysadmin
total 32
drwxr-xr-x 3  sysadmin sysadmin 4096 2012-05-13 13:34 .
drwxr-xr-x 23 root     root     4096 2012-05-14 11:29 ..
-rw------- 1  sysadmin sysadmin   48 2012-05-13 13:34 .bash_history
-rw-r--r-- 1  sysadmin sysadmin  220 2012-05-13 13:32 .bash_logout
-rw-r--r-- 1  sysadmin sysadmin 3103 2012-05-13 13:32 .bashrc
drwx------ 2  sysadmin sysadmin 4096 2012-05-13 13:33 .cache
-rw-r--r-- 1  sysadmin sysadmin  675 2012-05-13 13:32 .profile
-rw-r--r-- 1  sysadmin sysadmin    0 2012-05-13 13:33 .sudo_as_admin_successful
-rw------- 1  sysadmin sysadmin  663 2012-05-13 13:34 .viminfo




On another console, confirm that you can login as the sysadmin user.


You should get a proper bash prompt;


sysadmin@ldapds:~$


Note:
If your system has a GUI login, be aware that the logon screen will not display usernames for users with a UID of less than 1000. To login using the "sysadmin" account in such a case, you would need to type the name in to the username field manually.