Wednesday, August 28, 2013

Worst Php Code EVER!





Quote from reddit PHP

Creating a user from the web problem.
I have a form that creates a user by entering the username and their password. The code I'm using in php is:
shell_exec("sudo useradd -p $encpass -g groupname -s /bin/bash $username");
I have used a whoami and have confirmed that it runs as http. In /etc/sudoers I have
http ALL=(ALL) NOPASSWD: ALL
root ALL=(ALL) ALL
%wheel ALL=(ALL) NOPASSWD: ALL
%sudo ALL=(ALL) ALL
I also added http to group wheel. The problem I am having is it's not setting the password correctly. The user is created, just the password isn't set. I know that $encpass has a value because I can display it. I also know the command works because it runs fine in command line. This was working before, but I had to reinstall Arch Linux, so does anyone have an idea for why this doesn't work?
Go check out the comments!!!
http://www.reddit.com/r/PHP/comments/1l7baq/creating_a_user_from_the_web_problem/

 

Wednesday, August 7, 2013

WinSCP and Cygwin


Most people believe Cygwin will not work with WinSCP.

I am not a fan of believing something will not work, so I setup "Custom Commands" in WinSCP to startup Cygwin mintty terminals.

SSH KEYS

First of all you should have ssh keys to allow auto login to server.
With the following Custom command added to WinSCP you can auto add an ssh key. I setup this command with hotkey Ctrl+0.

C:\cygwin\bin\mintty.exe /bin/bash -ile /cygdrive/c/Dropbox/WinSCP/ssh.sh !U !@ !P
 This is the ssh.sh script.

echo "USE THIS PASSWORD: $3"
cat /.ssh/id_dsa.pub | ssh $1@$2 'cat - >>~/.ssh/authorized_keys2'
 Which will echo the password for entry via WinSCP and allow you to setup your ssh key on the server you are connected to.

STARTING A CYGWIN TERMINAL (Mintty)


Now you need a command to launch Cygwin mintty.exe and log you into that server. This command I setup with hotkey Ctrl+1, which is very easy to use.

C:\cygwin\bin\mintty.exe /bin/ssh !U@!@

SSHPASS

And that is all you need to use Cygwin with WinSCP.
If you really wanted to you could avoid ssh keys by installing sshpass into Cygwin.

I created another file, sshpass.sh like this.
/usr/local/bin/sshpass.exe -p '$3' ssh $1@$2
And added the Custom Command pointed at that bash script. I setup this command with hotkey Ctrl+2.

C:\cygwin\bin\mintty.exe /bin/bash -ile /cygdrive/c/Dropbox/WinSCP/sshpass.sh !U !@ !P