Permalink
Browse files

Anzeige bzw. togglen des Dienstmermal Anklopfen (callwaiting) mit ein…

…er Taste am Telefon (Tastenbelegung BLF, als Nummer cwait{Rufnummer})
  • Loading branch information...
1 parent e80b2f8 commit f91e21bf79848530a8c8e7f5b521b4a5d5719946 @sebastianertz sebastianertz committed Mar 15, 2012
@@ -78,6 +78,7 @@
echo 'hint(SIP/', $r['name'] ,') ', $r['name'] ,' => {}', "\n";
echo 'hint(SIP/', $r['name'] ,') ***', $r['name'] ,' => {}', "\n";
echo 'hint(Custom:fwd',$r['name'],') fwd', $r['name'] ,' => {}', "\n";
+ echo 'hint(Custom:cwait', $r['name'] ,') cwait', $r['name'] ,' => {}', "\n";
}
} else {
echo "//ERROR\n";
@@ -79,16 +79,39 @@ context user-config {
//-------------------------------------------------------------
// Call Waiting (Anklopfen)
//-------------------------------------------------------------
+
+ _cwaitX. => jump *92;
*92 => {
+ AGI(/opt/gemeinschaft/dialplan-scripts/get-user-language,${user_name});
&caller-count();
- Set(CDR(amaflags)=OMIT);
- &user-config-call-waiting(1);
+ //toggle callwaiting
+ AGI(/opt/gemeinschaft/dialplan-scripts/get-callwaiting.agi,${user_name});
+ if ("${callwaiting}" = "1") {
+ Set(CDR(amaflags)=OMIT);
+ &user-config-call-waiting(0);
+ TryExec(Set(DEVICE_STATE(Custom:cwait${user_name})=NOT_INUSE));
+ Wait(0.5);
+ Playback(/opt/gemeinschaft/sounds/${gs_userlang_gs}/anklopfen&/opt/gemeinschaft/sounds/${gs_userlang_gs}/ausgeschaltet);
+ Hangup();
+ } else {
+ Set(CDR(amaflags)=OMIT);
+ &user-config-call-waiting(1);
+ TryExec(Set(DEVICE_STATE(Custom:cwait${user_name})=BUSY));
+ Wait(0.5);
+ Playback(/opt/gemeinschaft/sounds/${gs_userlang_gs}/anklopfen&/opt/gemeinschaft/sounds/${gs_userlang_gs}/eingeschaltet);
+ Hangup();
+ }
}
*92* => {
&caller-count();
Set(CDR(amaflags)=OMIT);
+ AGI(/opt/gemeinschaft/dialplan-scripts/get-user-language,${user_name});
&user-config-call-waiting(0);
+ TryExec(Set(DEVICE_STATE(Custom:cwait${user_name})=NOT_INUSE));
+ Wait(0.5);
+ Playback(/opt/gemeinschaft/sounds/${gs_userlang_gs}/anklopfen&/opt/gemeinschaft/sounds/${gs_userlang_gs}/ausgeschaltet);
+ Hangup();
}
@@ -386,7 +409,6 @@ macro user-config-clir( mdest, mactive_num ) {
macro user-config-call-waiting( mactive_num ) {
- AGI(/opt/gemeinschaft/dialplan-scripts/get-user-language,${user_name});
&usercode-by-ext(${user_name});
if ("${user_code}" = "")
Hangup();
@@ -398,15 +420,6 @@ macro user-config-call-waiting( mactive_num ) {
Verbose(1,### User ${user_name}: set Call Waiting: ${mactive});
Answer();
TrySystem(/opt/gemeinschaft/scripts/gs-callwaiting-activate --user='${user_code}' --active='${mactive}');
- Wait(0.5);
- //Playback(beep);
- Playback(/opt/gemeinschaft/sounds/${gs_userlang_gs}/anklopfen);
- if ("${mactive}" = "yes") {
- Playback(/opt/gemeinschaft/sounds/${gs_userlang_gs}/eingeschaltet);
- } else {
- Playback(/opt/gemeinschaft/sounds/${gs_userlang_gs}/ausgeschaltet);
- }
- Hangup();
return;
}
@@ -1216,6 +1216,28 @@ context toggle-cfwd-hint {
}
}
+
+//--------------------------------------------------------------------
+// Set the Custom-Hints if there is set an callwaiting from the GUI
+//--------------------------------------------------------------------
+
+context toggle-cwait-hint {
+ toggle => {
+ //toggle callwaiting
+ AGI(/opt/gemeinschaft/dialplan-scripts/get-callwaiting.agi,${user_name});
+ if ("${callwaiting}" = "1") {
+ Set(CDR(amaflags)=OMIT);
+ TryExec(Set(DEVICE_STATE(Custom:cwait${user_name})=BUSY));
+ Hangup();
+ } else {
+ Set(CDR(amaflags)=OMIT);
+ TryExec(Set(DEVICE_STATE(Custom:cwait${user_name})=NOT_INUSE));
+ Hangup();
+ }
+ }
+}
+
+
//---------------------------------------------------------------------
// Contexts for IVRs
//---------------------------------------------------------------------
@@ -53,6 +53,16 @@ function gs_callwaiting_activate( $user, $active )
if (! $user_id)
return new GsError( 'Unknown user.' );
+ # get user_ext
+ $user_ext = $db->executeGetOne('SELECT `s`.`name` `ext`
+FROM
+ `users` `u` JOIN
+ `ast_sipfriends` `s` ON (`s`.`_user_id`=`u`.`id`)
+WHERE `u`.`user`=\''. $db->escape($user) .'\''
+ );
+ if (! $user_ext)
+ return new GsError( 'Unknown user.' );
+
# (de)activate
#
$num = $db->executeGetOne( 'SELECT COUNT(*) FROM `callwaiting` WHERE `user_id`='. $user_id );
@@ -64,6 +74,70 @@ function gs_callwaiting_activate( $user, $active )
if (! $ok)
return new GsError( 'Failed to set call waiting.' );
+ $call //= "Channel: Local/". $from_num_dial ."\n"
+ = "Channel: local/toggle@toggle-cwait-hint\n"
+ . "MaxRetries: 0\n"
+ . "WaitTime: 15\n"
+ . "Context: toggle-cwait-hint\n"
+ . "Extension: toggle\n"
+ . "Callerid: $user <Toggle>\n"
+ . "Setvar: __user_id=". $user_id ."\n"
+ . "Setvar: __user_name=". $user_ext ."\n"
+ . "Setvar: CHANNEL(language)=". gs_get_conf('GS_INTL_ASTERISK_LANG','de') ."\n"
+ . "Setvar: __is_callfile_origin=1\n" # no forwards and no mailbox on origin side
+ . "Setvar: __callfile_from_user=". $user_ext ."\n"
+ . "Setvar: __record_file=". $filename ."\n"
+ ;
+
+ $filename = '/tmp/gs-'. $user_id .'-'. time() .'-'. rand(10000,99999) .'.call';
+
+ $cf = @fOpen( $filename, 'wb' );
+ if (! $cf) {
+ gs_log( GS_LOG_WARNING, 'Failed to write call file "'. $filename .'"' );
+ return new GsError( 'Failed to write call file.' );
+ }
+ @fWrite( $cf, $call, strLen($call) );
+ @fClose( $cf );
+ @chmod( $filename, 00666 );
+
+ $spoolfile = '/var/spool/asterisk/outgoing/'. baseName($filename);
+
+
+ if (! gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) {
+ $our_host_ids = @gs_get_listen_to_ids();
+ if (! is_array($our_host_ids)) $our_host_ids = array();
+ $user_is_on_this_host = in_array( $_SESSION['sudo_user']['info']['host_id'], $our_host_ids );
+ } else {
+ $user_is_on_this_host = true;
+ }
+
+ if ($user_is_on_this_host) {
+ # the Asterisk of this user and the web server both run on this host
+ $err=0; $out=array();
+ @exec( 'sudo mv '. qsa($filename) .' '. qsa($spoolfile) .' 1>>/dev/null 2>>/dev/null', $out, $err );
+ if ($err != 0) {
+ @unlink( $filename );
+ gs_log( GS_LOG_WARNING, 'Failed to move call file "'. $filename .'" to "'. $spoolfile .'"' );
+ return new GsError( 'Failed to move call file.' );
+ }
+ } else {
+ $cmd = 'sudo scp -o StrictHostKeyChecking=no -o BatchMode=yes '. qsa( $filename ) .' '. qsa( 'root@'. $user['host'] .':'. $filename );
+ //echo $cmd, "\n";
+ @exec( $cmd .' 1>>/dev/null 2>>/dev/null', $out, $err );
+ @unlink( $filename );
+ if ($err != 0) {
+ gs_log( GS_LOG_WARNING, 'Failed to scp call file "'. $filename .'" to '. $user['host'] );
+ return new GsError( 'Failed to scp call file.' );
+ }
+ //remote_exec( $user['host'], $cmd, 10, $out, $err ); // <-- does not use sudo!
+ $cmd = 'sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root '. qsa( $user['host'] ) .' '. qsa( 'mv '. qsa( $filename ) .' '. qsa( $spoolfile ) );
+ //echo $cmd, "\n";
+ @exec( $cmd .' 1>>/dev/null 2>>/dev/null', $out, $err );
+ if ($err != 0) {
+ gs_log( GS_LOG_WARNING, 'Failed to mv call file "'. $filename .'" on '. $user['host'] .' to "'. $spoolfile .'"' );
+ return new GsError( 'Failed to mv call file on remote host.' );
+ }
+ }
# reload phone config

0 comments on commit f91e21b

Please sign in to comment.