no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revision Next revision | |||
— | shell_access [2009-12-16 15:45] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | Here's a little hack to allow command-line interaction with our favorite Web Office Suite. It works by executing PHP in the Unix Shell. | ||
+ | Ideal for narrowband on-the-road-interaction from anything that can run SSH. Like, my mobile Phone! | ||
+ | |||
+ | first little attempt only shows a somewhat formatted list of tasks, sorted by tag. To come: Creating new Tasks, marking tasks complete. If Easter then still isn't over, perhaps I'll do something for Contacts & Notes next. | ||
+ | |||
+ | e.g. | ||
+ | |||
+ | PHP OGOO.PHP -u wolf -t tel -w 6 | ||
+ | |||
+ | will dump all tasks for me tagged as " | ||
+ | |||
+ | the output looks like this: | ||
+ | |||
+ | '' | ||
+ | |||
+ | |||
+ | parameters: | ||
+ | -u username | ||
+ | -t tag (currently supports filtering for one tag only) | ||
+ | -w workspace (must supply the workspace number. The number can be found in the dump at the end of each line. | ||
+ | |||
+ | |||
+ | oh, | ||
+ | please be aware that this might pose a severe security risk. Use only if you know what you are doing. I'm absolutely not responsible. | ||
+ | |||
+ | uses a command-line parser function by Tyler Hall found [[http:// | ||
+ | |||
+ | copy the following code as ogoo.php into your opengoo' | ||
+ | |||
+ | |||
+ | <code php> | ||
+ | ''# | ||
+ | |||
+ | <?php | ||
+ | $dbhost = ' | ||
+ | $dbuser = ' | ||
+ | $dbpass = ' | ||
+ | |||
+ | $conn = mysql_connect($dbhost, | ||
+ | |||
+ | $dbname = ' | ||
+ | mysql_select_db($dbname); | ||
+ | |||
+ | $argv[0]==" | ||
+ | |||
+ | $a= new Args(); | ||
+ | |||
+ | $a-> | ||
+ | $a-> | ||
+ | |||
+ | $a-> | ||
+ | $a-> | ||
+ | |||
+ | $a-> | ||
+ | $a-> | ||
+ | |||
+ | // parameters for Tasks | ||
+ | // tag=xxxx due=yyyymmdd | ||
+ | |||
+ | print (" | ||
+ | |||
+ | $result=mysql_query(" | ||
+ | |||
+ | |||
+ | // store the record of the " | ||
+ | $i=0; | ||
+ | while($row = mysql_fetch_array( $result )){ | ||
+ | $i++; | ||
+ | print ($row[' | ||
+ | }; | ||
+ | print ($nl.$user."/" | ||
+ | |||
+ | // | ||
+ | |||
+ | // A quick and dirty command line argument parser. Written in about | ||
+ | // an hour, so you might want to take this with a grain of salt or two. | ||
+ | // | ||
+ | // Single letter options should be prefixed with a single | ||
+ | // dash and can be grouped together. Examples: | ||
+ | // | ||
+ | // cmd -a | ||
+ | // cmd -ab | ||
+ | // | ||
+ | // Values can be assigned to single letter options like so: | ||
+ | // | ||
+ | // cmd -a foo (a will be set to foo.) | ||
+ | // | ||
+ | // cmd -a foo -b (a will be set to foo.) | ||
+ | // | ||
+ | // cmd -ab foo (a and b will simply be set to true. foo is only listed as an argument.) | ||
+ | // | ||
+ | // You can also use the double-dash syntax. Examples: | ||
+ | // | ||
+ | // cmd --value | ||
+ | // | ||
+ | // cmd --value foo (value is set to foo) | ||
+ | // | ||
+ | // cmd --value=foo (value is set to foo) | ||
+ | // | ||
+ | // Single dash and double dash syntax may be mixed. | ||
+ | // | ||
+ | // Trailing arguments are treated as such. Examples: | ||
+ | // | ||
+ | // cmd -abc foo bar (foo and bar are listed as arguments) | ||
+ | // | ||
+ | // cmd -a foo -b bar charlie (only bar and charlie are arguments) | ||
+ | |||
+ | |||
+ | class Args | ||
+ | { | ||
+ | private $flags; | ||
+ | public $args; | ||
+ | |||
+ | public function __construct() | ||
+ | { | ||
+ | $this-> | ||
+ | $this-> | ||
+ | |||
+ | $argv = $GLOBALS[' | ||
+ | array_shift($argv); | ||
+ | |||
+ | for($i = 0; $i < count($argv); | ||
+ | { | ||
+ | $str = $argv[$i]; | ||
+ | |||
+ | // --foo | ||
+ | if(strlen($str) > 2 && substr($str, | ||
+ | { | ||
+ | $str = substr($str, | ||
+ | $parts = explode(' | ||
+ | $this-> | ||
+ | |||
+ | // Does not have an =, so choose the next arg as its value | ||
+ | if(count($parts) == 1 && isset($argv[$i + 1]) && preg_match('/ | ||
+ | { | ||
+ | $this-> | ||
+ | } | ||
+ | elseif(count($parts) == 2) // Has a =, so pick the second piece | ||
+ | { | ||
+ | $this-> | ||
+ | } | ||
+ | } | ||
+ | elseif(strlen($str) == 2 && $str[0] == ' | ||
+ | { | ||
+ | $this-> | ||
+ | if(isset($argv[$i + 1]) && preg_match('/ | ||
+ | $this-> | ||
+ | } | ||
+ | elseif(strlen($str) > 1 && $str[0] == ' | ||
+ | { | ||
+ | for($j = 1; $j < strlen($str); | ||
+ | $this-> | ||
+ | } | ||
+ | } | ||
+ | |||
+ | for($i = count($argv) - 1; $i >= 0; $i--) | ||
+ | { | ||
+ | if(preg_match('/ | ||
+ | $this-> | ||
+ | else | ||
+ | break; | ||
+ | } | ||
+ | |||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | public function flag($name) | ||
+ | { | ||
+ | return isset($this-> | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ?> | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | by --- //[[User Page: Max|max wolf]] 2009-04-17 15:49// |