Monday, November 23, 2015

apache user permisions

ls -l /var/www
sudo groupadd www
sudo usermod -a -G www user-name

// logout and login

to check group : groups
sudo chown -R root:www /var/www
[ec2-user ~]$
sudo chmod 2775 /var/www
[ec2-user ~]$
find /var/www -type d -exec sudo chmod 2775 {} +

Tuesday, October 13, 2015

How To Install No-ip In CentOS

No-ip client; use to update/resolve a server with a dynamic IP.

Prerequisite:

    Create a free no-ip account.  Log in to the no-ip website and create a host.
    Install “Make” compiler program in preparation to compile the no-ip program.  You might also have to install the “GCC” compiler if “Make” compiler don’t work; I have both GCC and Make installed.  The following is the  commands to download &install them:

yum install gcc

yum install make
Now onto the easy step-by-step installation of no-ip client.  Run the following 6 commands from the terminal:

    mkdir noip && cd noip
    wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
    tar zvxf noip-duc-linux.tar.gz
    cd noip-2.1.9-1
    make
    make install

You will then need to answer the following prompts:

Please enter the login/email string for no-ip.com

(Email account that you used to set-up no-ip account from their website)

Please enter the password for user

(Password that you used to login to no-ip website)

Please enter an update interval: [30] 30

(Increments in minutes that you want no-ip client to check if your router’s external dynamic IP address has changed and updates it accordingly.)

Do you wish to run something at successful update? [N] (y/N)

(Enter “N” here)
Now start no-ip client by running the following command:
/usr/local/bin/noip2
Now have no-ip client start every time the computer reboot by issuing the following command:
echo ‘/usr/local/bin/noip2’ >> /etc/rc.local
More useful no-ip commands:

    /usr/local/bin/noip2 -C                                       to configure noip client

    /usr/local/bin/noip2 -S                                       to display info about running noip client

    /usr/local/bin/noip2 -U                                       to set update intervals (in minutes)

Thursday, October 8, 2015

Centos disk space allocation

You need to unmount a filesystem to shrink it. So, for /home you'll want to be log in as root and umount /home. If it's 'busy'. You may need to stop any processes using files here.

Then, shrink the file system to just below your targeted logical volume size.

resize2fs /dev/mapper/vg_nastgweblls01-lv_home 99G

Shrink the logical volume to the targeted size.

lvreduce -L 100G /dev/mapper/vg_nastgweblls01-lv_home

Grow the filesystem to the logical volume's capacity.

resize2fs /dev/mapper/vg_nastgweblls01-lv_home

The reason I do it this so I don't have to do any math and keep the filesystem the size of the container. A bit lazy, but it works great.

Now, you have free space to grow root.

lvextend -L 75G /dev/mapper/vg_nastgweblls01-lv_root
resize2fs /dev/mapper/vg_nastgweblls01-lv_root


* remembered that I need to mount the home drive

mount /home

Tuesday, September 8, 2015

How to make a Case-insensitive url redirect to a case-sensitive url


Ex:
https://example.com/example/index.html to https://example.com/ExamPLe/index.html

RewriteEngine On
RewriteCond %{REQUEST_URI} !/WebMaster/ 
RewriteRule ^/?webmaster/(.*) http://www.example.com/WebMaster/$1 [NC,R=301,L]

Preventing Directory Listing

Preventing Directory Listing

Do you have a directory full of images or zips that you do not want people to be able to browse through? Typically a server is setup to prevent directory listing, but sometimes they are not. If not, become self-sufficient and fix it yourself:

    IndexIgnore *

The * is a wildcard that matches all files, so if you stick that line into an htaccess file in your images directory, nothing in that directory will be allowed to be listed.

On the other hand, what if you did want the directory contents to be listed, but only if they were HTML pages and not images? Simple says I:

    IndexIgnore *.gif *.jpg

This would return a list of all files not ending in .jpg or .gif, but would still list .txt, .html, etc.

And conversely, if your server is setup to prevent directory listing, but you want to list the directories by default, you could simply throw this into an htaccess file the directory you want displayed:

    Options +Indexes

If you do use this option, be very careful that you do not put any unintentional or compromising files in this directory. And if you guessed it by the plus sign before Indexes, you can throw in a minus sign (Options -Indexes) to prevent directory listing entirely--this is typical of most server setups and is usually configured elsewhere in the apache server, but can be overridden through htaccess.

Blocking users/ sites by referrer

Blocking users/ sites by referrer


Blocking users or sites that originate from a particular domain is another useful trick of .htaccess. Lets say you check your logs one day, and see tons of referrals from a particular site, yet upon inspection you can't find a single visible link to your site on theirs. The referral isn't a "legitimate" one, with the site most likely hot linking to certain files on your site such as images, .css files, or files you can't even make out. Remember, your logs will generate a referrer entry for any kind of reference to your site that has a traceable origin.

Before I get to the code itself, it's important to note that blocking access by referrer in .htaccess requires the help of the Apache module mod_rewrite to make out the referrer first. This module is installed by default on most servers (ask your host if you're not sure). So, to deny access all traffic that originate from a particular domain (referrers) to your site, use the following code:

Block traffic from a single referrer:

RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} badsite\.com [NC]
RewriteRule .* - [F]

Block traffic from multiple referrers

RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} badsite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} anotherbadsite\.com
RewriteRule .* - [F]

In the "single referrer" case above, "badsite\.com" is the domain you wish to block. Note the backslash proceeding the period (".") to actually donate a period, as in Regular Expressions, a period donates any character, which is not what we want. The flag "[NC]" is added to the end of the domain to make it case insensitive, so whether the domain is "badsite.com", "Badsite.com" etc, however bad it gets, it gets blocked. Finally, the last line in the .htaccess file specifies that the action to take when a match is found is to fail the request, meaning the referrer traffic will hit a 403 Forbidden error. The only difference between blocking a single referrer and multiple referrers is the modified [NC, OR] flag in the later case to every domain but the last.

Friday, April 24, 2015

Change previouly commited svn commit message log

committed a change into SVN (subversion) and found that you used the wrong messages file - meaning that the log message for the revision is wrong?

If so: it's good to know that subversion allows you to change the message - possibly with some help from the administrator. If that's you - so much the better.

Here's one process that could help. This example is for a linux system, but can easily be adapted to others.

When in the working copy folder, try the command (replacing "1234" with the revision number you want to edit the message for).

    export SVN_EDITOR=vim
    svn propedit -r 1234 --revprop svn:log

This will launch "vim" and allow you to edit the message text. When you're done and you save the updated file svn will attempt to apply the change to the server repository.

It is possible that the svn server is not set up to allow this, in which case you may see something like this..

    svn: E165006: Repository has not been enabled to accept revision propchanges;
    ask the administrator to create a pre-revprop-change hook

If you see this message then you (assuming you are the admin) can check the "hooks" directory of the server's repository. For example (your repository will almost certainly be in a different place)..

    cd /opt/svn/myrepos/hooks
    ls -l

Check to see whether there is a file called "pre-revprop-change" listed with execute permissions. If not, and there is a "pre-revprop-change.tmpl" file then review it's contents and if you are happy with the logic it contains, copy it into place. If the file already exists then stop here (dont do the copy) - and investigate why it is preventing your request to update the log.

So, if the file is missing...

    cp pre-revprop-change.tmpl pre-revprop-change
    chmod +x pre-revprop-change

On my system, the template file has the default contents - namely (excluding comments)..

    REPOS="$1"
    REV="$2"
    USER="$3"
    PROPNAME="$4"
    ACTION="$5"

    if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi

    echo "Changing revision properties other than svn:log is prohibited" >&2
    exit 1

This allows the log to be modified, but blocks all other edits on revision properties. For our situation, this is perfectly fine.

Once the file is in place, return to the working copy and try again. Hopefully, this time your change will be accepted.

Monday, February 23, 2015

How to: Spreadtrum ADB (Android Debug Bridge) Drivers / Setup – ZTE U791 – Windows 7 64Bit and MAC

 recently bought a very cheap ZTE U791 that I wanted to use as a debugging device while developing an Android app.

It took me a whole day to find the correct drivers that would work, Windows 7 64Bit made it even harder.

Like every Android phone, you have to install ADB and its drivers to access the Android Debug Bridge.

To install the ADB intereface simple install the Android SDK if how have not already.

http://developer.android.com/sdk/installing/index.html

You will then have to install the Phone drivers on Windows:

You can check in the Device manager to make sure there are no devices with exclamation marks once you have installed the drivers below!

I tried tons of drivers to get it to work – the one that worked for me was the Debug Drivers below – but you might need to install both:



ADB Drivers: https://www.dropbox.com/s/r50r39o2ia6pmkt/Spreadtrum-Drivers.7z?dl=0

Debug Drivers: https://www.dropbox.com/s/kjt76ecr786zvke/SCI-android-usb-driver-jungo-v4.7z?dl=0



Then the VERY IMPORTANT STEP:

 Then you will have to tell ADB what phone to use. By that I mean adding the PCI ID to a text file to tell ADB that this peripheral is compatible.

The Spreadtrum PCI ID is 0x1782

add this line to “Your user directory/.android/adb_usb.ini”

for example

C:\Users\drk\.android\adb_usb.ini

If the file does not exist create it.

Add this Code:
1    0x1782

 Then the phone should work and be detected by your PC:

To test navigate to your Android SDK Directory and run: adb devices
1    C:\sdk\platform-tools adb devices
2    List of devices attached
3    19761202 device



On a Mac you would also need to add this Vendor ID – it is however easier and you also have the ability to FIND the Vendor ID for the specific phone.

Add the Vendor ID to the following file:
1    ~/.android/adb_usb.ini

You might have to kill and start the ADB server with
1    adb kill-server<br /><br />adb start-server



To find the Vendor ID on a Mac all you need to do is

1. Plug in the Phone

2. Click the Apple Logo

3. Hold the Control Button and Click on System Information

4. Open the USB and then the USB Phone Section

You should see something like this

MAC Spreadtrum Vendor ID

Monday, February 16, 2015

How to set up a proxy server with XAMPP on Windows

1. Set up Apache

    Open your apache config file C:\xampp\apache\conf\httpd.conf. Make sure the following lines are uncommented:

      Include "conf/extra/httpd-proxy.conf"
      LoadModule proxy_module modules/mod_proxy.so
      LoadModule proxy_connect_module modules/mod_proxy_connect.so
      LoadModule proxy_http_module modules/mod_proxy_http.so

2. Open your proxy config file C:\xampp\apache\conf\extra\httpd-proxy.conf. Edit it to match the following:

<IfModule proxy_module>
  <IfModule proxy_http_module>
    ProxyRequests On
    ProxyVia On
    <Proxy *>
      Order deny,allow
      Allow from 127.0.0.1
    </Proxy>
    ProxyBlock some-website-you-want-to-block.com another-website-you-want-to-block.com
  </IfModule>
  </IfModule>
 
3. Restart Apache