1. ast_control.php
<?php
session_start();
include('header.php');
if( exec('./asterisk/ast_is_ast') )
{
$_SESSION['ast_id'] = 1;
}
else
{
$_SESSION['ast_id'] = 0;
}
if (isset($_POST[ 'submit1']) && $_POST[ 'submit1'] == '启动asterisk')
{
system('./asterisk/ast_start');
$_SESSION['ast_id'] = 1;
echo "<script type='text/javascript'>
alert( 'asterisk启动成功!' );
window.location.href = 'ast_control.php';
</script>";
}
if (isset($_POST[ 'submit2']) && $_POST[ 'submit2'] == '退出asterisk')
{
system('./asterisk/ast_stop');
$_SESSION['ast_id'] = 0;
echo "<script type='text/javascript'>
alert( 'asterisk退出成功!' );
window.location.href = 'ast_control.php';
</script>";
}
?>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<form name="form1" action="ast_control.php" method="post">
<table align="center">
<tr>
<td>
<?php
if($_SESSION['ast_id']!=1)
{
echo '<input type="submit" οnclick="check.disabled=!(this.checked)" name="submit1" id="submit1" value="启动asterisk" />
<span id=check disabled>
<input type="submit" name="submit2" id="submit2" value="退出asterisk"/>
</span>';
}
else
{
echo '<span id=check disabled>
<input type="submit" name="submit1" id="submit1" value="启动asterisk" />
</span>
<input type="submit" οnclick="check.disabled=!(this.checked)" name="submit2" id="submit2" value="退出asterisk"/>';
}
?>
</td>
</tr>
</table>
</form>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<?php require_once("footer.php");?>
///
2. ast_start.c //启动asterisk
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
uid_t uid ,euid;
int id;
uid = getuid() ;
euid = geteuid();
if(setreuid(euid, uid)) //交换这两个id
{
perror("setreuid");
}
system( "asterisk" );
return 0;
}
///
3. ast_stop.c //停止asterisk
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
uid_t uid ,euid;
int id;
uid = getuid() ;
euid = geteuid();
if(setreuid(euid, uid)) //交换这两个id
{
perror("setreuid");
}
system( "kill -9 $(pidof asterisk)" );
return 0;
}
//
4. ast_is_ast.c //检查asterisk是否启动
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
system( "pidof asterisk" );
return 0;
}