#!/usr/bin/php
<?php
/*
  vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
  Codificación: UTF-8
  +----------------------------------------------------------------------+
  | Elastix version 2.0                                                  |
  | http://www.elastix.org                                               |
  +----------------------------------------------------------------------+
  | Copyright (c) 2006 Palosanto Solutions S. A.                         |
  +----------------------------------------------------------------------+
  | Cdla. Nueva Kennedy Calle E 222 y 9na. Este                          |
  | Telfs. 2283-268, 2294-440, 2284-356                                  |
  | Guayaquil - Ecuador                                                  |
  | http://www.palosanto.com                                             |
  +----------------------------------------------------------------------+
  | The contents of this file are subject to the General Public License  |
  | (GPL) Version 2 (the "License"); you may not use this file except in |
  | compliance with the License. You may obtain a copy of the License at |
  | http://www.opensource.org/licenses/gpl-license.php                   |
  |                                                                      |
  | Software distributed under the License is distributed on an "AS IS"  |
  | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See  |
  | the License for the specific language governing rights and           |
  | limitations under the License.                                       |
  +----------------------------------------------------------------------+
  | The Original Code is: Elastix Open Source.                           |
  | The Initial Developer of the Original Code is PaloSanto Solutions    |
  +----------------------------------------------------------------------+
  $Id: ryum.php,v 1.1 2007/01/09 23:49:36 alex Exp $
*/

/* Restricted yum - can only check-update, install, remove, will not accept 
 * local filenames or other parameters */

if (count($argv) < 2) error_exit("ERR: must specify [check-update, install, remove]\n");
$args = array();
switch ($argv[1]) {
case 'check-update':
    $args[] = $argv[1];
    break;
case 'install':
case 'remove':
    $args[] = '-y';
    $args[] = $argv[1];
    if (count($argv) < 3) error_exit("ERR: must specify package to install or remove\n");
    if (!preg_match('/^[\w\.\-]+$/', $argv[2])) error_exit("ERR: invalid package to install or remove\n");
    $args[] = $argv[2];
    break;
default:
    error_exit("ERR: invalid operation\n");
}
pcntl_exec('/usr/bin/yum', $args);
error_exit("FATAL: unable to execve yum!\n");

function error_exit($sMsg, $errorcode = 1)
{
    fwrite(STDERR, $sMsg);
    exit($errorcode);
}
?>