Sunday, February 28, 2016

Permission Problem again...

Linux is good~ Always having permission problem. Always stopping me from making things work. Damn. Apache, which is the httpd service. Due to the fact that execution of bash script is done by thr "root" account, user Apache, have no permission to do it.

Fix the problem~

Problem is solved... 
By cheating... Damn... Using the command, "system('echo "ROOT PASSWORD" | sudo -u root -S COMMAND')"; will trigger the necessary access needed to run iwlist.


Reference

http://stackoverflow.com/questions/5652986/php-sudo-in-shell-exec

Monday, February 15, 2016

Functionality Consideration


  • The Webpage
    • Access Point (AP)
      • Changing AP SSID
      • Changing DHCP IP range
    • WIFI point
      • Display available wifi scan result
      • Enter WPA password to mouse click select WIFI

WIFI connected to AP

Dumb thing to do but it was done and it worked. Just to prove that the WIFI can connect to the AP.

Let's start and go to the process then~

  1. Run my "testscript2.sh" bash script with root
  2. Follow that, enable the second wireless dongle and follow the reference steps
    • Last step from the reference actually also verified if the wireless dongle is connected to the network

Reference

Thursday, February 11, 2016

AP and WIFI

Currently, the script for bringing up AP and WIFI is done and the NAT is done. The AP and WIFI is working fine, just that there is a need to do up a script for WIFI scanning. All in all is good.

There is also a shutdown script for AP and WIFI for the purpose of flushing the whole operation.

P.S. This is part of my progression journal. Sorry for those who is following the blog... =p

Wednesday, February 10, 2016

Bash Script Comment and in blocks

Here is some bash script troubleshooting technique that can be very useful when applied correctly.

Block comment for bash script in vi editor

  • In vi editor, comment from line n to m
    • <ESC>
    • :n,ms/^/#/
    • From line n to m substitute line start (^) with # sign
  • To remove comment
    • <ESC>
    • :n,ms/^#//
    • From line n to m substitute line start (^) followed by # with nothing //
Almost universal with /bin/bash for vi editor

There seems to be a problem... How are we to determine what line is what line... Count one by one? That's nuts~! But, there is a solution...

vi / vim editor does show line number
  • To display line numbers along the left side of the editor, type in the following command
    • <ESC>
    • :set number OR :set nu
  • To undo the line numbers
    • <ESC>
    • :set nu! OR :set number!
The above is just a one time thing. To make a permanent change for set number
  • Terminal# vi ~/.vimrc
  • In vi/vim editor
    • set number
    • Save and exit
      • Note: if you are curious on where is the file located, it may not be there. So just create the file and where will follow. Note of note: Only the user profile you create/edit the file will have the change.

Reference

http://www.cyberciti.biz/faq/vi-show-line-numbers/
http://stackoverflow.com/questions/947897/block-comments-in-a-shell-script

Saturday, February 6, 2016

Shorten Command line Bash Prompt

So to shorten the Bash Prompt just do the following changes:

  • Change for the current terminal instance only
    • Terminal# PS1='\u:\W\$ '
  • Change permanently
    1. Terminal# vi ~/.bashrc
    2.  Find the line
      • PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    3. Changes needed; of course you can copy a line in case you wanna change back
      • Remove '@h\' and replace '\w' with uppercase '\W'
    4. Save, exit and restart a new terminal

Reference

http://askubuntu.com/questions/145618/how-can-i-shorten-my-command-line-bash-prompt

Tuesday, February 2, 2016

Permission permission permission

It's always about permission, permission and permission.

The thing is the PERMISSION can be of GROUP/USER.

So let's see Users first.
  • root - the O'might one in linux
    • There is also a root group
  • Then there is wheel
    • There are a few places to look at
      • /etc/sudoers or visudo - same file
        • Enable wheel group
        • Search for "# %wheel ALL=(ALL)ALL", and remove hash to enable
      • /etc/passwd
        • Enable user/s in group directory for access and bash login
  • Verify user in which group
    • Terminal# su USERNAME -
    • Terminal# groups
  • There are also users like your administrators, users, APACHE and so on...
So now we come to Groups.
  • Group  : root
    • ## Allow root run any commands anywhere
    • "root ALL=(ALL) ALL"
      • So DO NOT anyhow tamper with anything you DO NOT know~!
  • Group : wheel
    • ## Allow people in group wheel to run all commands
    • "%wheel ALL=(ALL) ALL"
      • OR
    • ## Same thing without a password
    • "%wheel ALL=(ALL) NOPASSWD: ALL"
Linux Command : chown
  • To change user and/or group ownership of file/directory
    • chown owner-user "file"
    • chown owner-user:owner-group "file"
    • chown owner-user:owner-group "directory"
    • chown <options> owner-user:owner-group "file"
For /etc/hostapd and /etc/hostapd/hostapd.conf to be accessible by web server, (user: apache)
  1. Changing the owner-user and owner-group of /etc/hostapd/ (directory) and /etc/hostapd/hostapd.conf (file) to apache:wheel
    1. Terminal# chown apache:wheel /etc/hostapd/
    2. Terminal# chown apache:wheel /etc/hostapd/hostapd.conf
  2. This will enable the webpage to access and make changes to "hostapd.conf"
  • To verify if it works, enable bash login for user apache and adding apache into wheel group
    • Terminal# usermod -aG wheel apache
      • Verify by
        • Terminal# cat /etc/group | grep apache
        • Display : wheel:x:10:...,apache
    • Terminal# chsh -s /bin/bash apache
      • Verify by
        • Terminal# cat /etc/passwd | grep apache
          • OR
        • Just edit the "/etc/passwd"
        • Before => Display : apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
        • After => Display : apache:x:48:48:Apache:/usr/share/httpd:/bin/bash
    • Terminal# su apache
      • Then run any command that will write/read/execute the file in "/etc/hostapd"

Reference