├── README ├── README.md ├── bash └── bashrc-funcs ├── db └── schema.sql └── web ├── download.php └── index.php /README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fredsmith/history-db/34045a5bb6cf0cad00faf46bf03f28a5ee5ddc7a/README -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # history-db 2 | 3 | ## About 4 | 5 | History DB is very similar to the shell-sink project (https://github.com/joshuacronemeyer/shellsink), but with the goal of being as easy to install, and as portable, as possible. 6 | 7 | It consists of 2 parts 8 | 9 | - A server component built on a very simple mysql database and php installation 10 | - A pair of bash functions that can be included in a bashrc file to automatically post commands run to the web server, and to download and sync the local bash history file with the server. 11 | 12 | ## Configuration 13 | 14 | - Create the MySQL database on your central server using `db/schema.sql` and grant your web server appropriate access to that database. 15 | 16 | - make the `web` directory accessible on a web server with php and php-mysql. 17 | 18 | - Modify the php files to include a new download password (for download.php) and the MySQL connection parameters (for both `download.php` and `index.php`) 19 | 20 | - include `bash/bashrc-funcs` in your bashrc somehow, either with a `source` statement, or copy+paste 21 | 22 | - add the following to your bash $PROMPT_COMMAND variable: 23 | `post_history; history -a` 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /bash/bashrc-funcs: -------------------------------------------------------------------------------- 1 | function post_history { LAST_COMMAND=$(history 1 | sed -e 's/^ *[0-9]* *[0-9]*-[0-9]*-[0-9]* *[0-9]*:[0-9]*:[0-9]* *- *//g'); curl -d hostname="$HOSTNAME" -d command="$LAST_COMMAND" http://yourserver.example.tld/history/; } 2 | function get_history { echo -n "enter password: "; read -s HISTPASS; history -c; rm ~/.bash_history; curl -s http://yourserver.example.tld/history/download.php?passwd=$HISTPASS > ~/.bash_history; history -r; } 3 | -------------------------------------------------------------------------------- /db/schema.sql: -------------------------------------------------------------------------------- 1 | 2 | CREATE DATABASE `history` /*!40100 DEFAULT CHARACTER SET latin1 */ 3 | 4 | CREATE TABLE `history` ( 5 | `id` int(11) NOT NULL AUTO_INCREMENT, 6 | `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 7 | `command` text, 8 | `hostname` text, 9 | `count` int(11) DEFAULT NULL, 10 | PRIMARY KEY (`id`) 11 | ) ENGINE=MyISAM AUTO_INCREMENT=11521 DEFAULT CHARSET=latin1 12 | -------------------------------------------------------------------------------- /web/download.php: -------------------------------------------------------------------------------- 1 | 23 | -------------------------------------------------------------------------------- /web/index.php: -------------------------------------------------------------------------------- 1 | 33 | --------------------------------------------------------------------------------