diff --git a/voip/downloadvoipclient.php b/voip/downloadvoipclient.php new file mode 100644 index 00000000..47a53706 --- /dev/null +++ b/voip/downloadvoipclient.php @@ -0,0 +1,103 @@ + + * @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2007,2008,2009,2010,2011 + * @package queXS + * @subpackage voip + * @link http://www.acspri.org.au/software queXS was writen for ACSPRI + * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2 + * + */ + + +include_once("../config.inc.php"); +include_once("../db.inc.php"); +include_once("../functions/functions.operator.php"); + +//--------------------- +// Comes from http://fr2.php.net/tempnam +function tempdir($dir, $prefix='', $mode=0700) +{ + if (substr($dir, -1) != '/') $dir .= '/'; + + do + { + $path = $dir.$prefix.mt_rand(0, 9999999); + } while (!mkdir($path, $mode)); + + return $path; +} + +$tempdir = realpath(dirname(__FILE__) . '/tmp'); +$operator_id = get_operator_id(); + +if ($operator_id) +{ + + $sql = "SELECT *,SUBSTRING_INDEX(extension, '/', -1) as ext + FROM operator + WHERE operator_id = $operator_id"; + + $rs = $db->GetRow($sql); + + if (!empty($rs)) + { + $zipdir=tempdir($tempdir); + + $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']); + if (preg_match('/linux/', $userAgent)) { + //assume linux + copy(realpath(dirname(__FILE__) . '/../voipclient'),"$zipdir/voipclient"); + $f1 = "$zipdir/voipclient"; + $f2 = "$zipdir/startvoip"; + file_put_contents($f2, "./voipclient -i -u {$rs['ext']} -p {$rs['extension_password']} -h " . $_SERVER['SERVER_ADDR']); + + } + else + { + //assume windows + copy(realpath(dirname(__FILE__) . '/../voipclient.exe'),"$zipdir/voipclient.exe"); + $f1 = "$zipdir/voipclient.exe"; + $f2 = "$zipdir/startvoip.bat"; + file_put_contents($f2, "voipclient.exe -i -u {$rs['ext']} -p {$rs['extension_password']} -h " . $_SERVER['SERVER_ADDR']); + + } + + require_once(dirname(__FILE__) . "/../include/limesurvey/admin/classes/phpzip/phpzip.inc.php"); + $z = new PHPZip(); + $zipfile="$tempdir/voipclient.zip"; + $z->Zip($zipdir, $zipfile); + + unlink($f1); + unlink($f2); + rmdir($zipdir); + + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="voipclient.zip"'); + header('Content-Transfer-Encoding: binary'); + // load the file to send: + readfile($zipfile); + unlink($zipfile); + } +} +exit();