[asterisk-users] Custom PHP for Call Files

Dale Noll dnoll at wi.rr.com
Mon Dec 28 07:12:52 CST 2015

1. The 'Total' line that is displayed with the 'ls -l' command output is
NOT the total number of files, it is the total number of system blocks used
by the files in the directory.

2. In order to truly understand the situation you need to understand the
Linux file system permissions.,,, Every file in Linux has 3 basic
permissions for 3 types of users.  The basic permissions are  Read, Write,
eXecute.  The types of users are User, Group and Other.  The permission
'mode' is displayed in the 'ls -l' output in the first column.  In your
example of the callfile... '-rw-r--r--'.  This gives the User Read and
Write to the file while Group and Other have Read to the file.

Directories are simply special kinds of files. A directory (very short
explanation) is a file that contains the names of other files and a pointer
the the place on disk where each file's data is stored(blocks in Question
1).  With that understanding... in order to create and delete files in a
directory, you need write permission to the directory. This you may have
figured out since you changed the permissions on the outgoing directory to
get PHP to be able to delete the files.  Now, you may not be able to get
Asterisk to properly handle the files if Asterisk is not running as root.

There are several ways to handle this, each with pros and cons, but how I
probably would do it is change the permissions on the
/var/spool/asterisk/outgoing directory so that the User and Group both have
write access to the directory.

There are two commands to do that.

To change the permission mode, use the chmod command as root

chmod u=rwx,g=rwx,o=rx /var/spool/asterisk/outgoing

To change the ownership of the directory, use the chown command as root

chown asterisk:apache /var/spool/asterisk/outgoing

This will allow both the 'asterisk' User and the 'apache' group to create
and delete files in the directory.

You may also find it beneficial to change the ownership of the call file
when you move them into the outgoing directory.  Asterisk will modify the
files as it make call attempts. Therefore the asterisk user should be able
to write to the call file itself.  In your script that moves the files, you
may want to add a 'chown asterisk:apache {callfile pathname}'.

I don't know if your perl cron job does other things, but I would simply do
it all using a set of bash commands.

chown asterisk:apache /tmp/*.call && mv /tmp/*.call

That can be put into a shell script or run directly in a crontab entry.

On Sun, Dec 27, 2015 at 9:14 PM, er ic <email.eherr9633 at gmail.com> wrote:

> I am hoping to get some help here with building custom PHP to manage a
> 'wake up call' system.
> I have the script where the user can set the schedule for an extension
> wake up call.
> It appears to write to the /var/spool/asterisk/outgoing/ directory.
> My two issues:
> 1 - when the files do get moved over to outgoing/ directory via a cron
> job, the permissions show "-rw-r--r-- 1 apache apache 100 Jan  1  2016
> 5680a312a28b2.call" and the calls get sent when the date comes to pass. But
> my question is, if I mv 3 files from my php script,  'll
> /var/spool/asterisk/outgoing/' shows 'total 12' when there are only three
> files in the directory. What does total mean? Is my perl script doing
> something that I am not aware of and really there are 12 files overlapped
> or something funky?
> --- cron job perl script
> my @list = glob("/tmp/*.call");
> for( 0 .. $#list )
> {
>         system "mv $list[$_] /var/spool/asterisk/outgoing/";
> }
> -------------------------------
> 2 - I would like to view and delete call files but as it currently stands,
> php gets a permission denied.
> obviously php is running as apache and the outgoing/ directory is
> asterisk:asterisk but the call files are apache:apache. My question is,
> what is the best way, without risking security, to allow php to list and
> delete the files? I know my scripts themselves work because when I chown
> apache:apache /var/spool/asterisk/outgoing the script works. I have seen
> front ends work with all the same permissions on outgoing/ and the files
> but I dont know how they are able to read/delete the files for monitor/
> which is the same as the outgoing/ directory.
> Thanks for your help in advance all!
> --Eric
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
> New to Asterisk? Join us for a live introductory webinar every Thurs:
>                http://www.asterisk.org/hello
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20151228/8c2a90d6/attachment.html>

More information about the asterisk-users mailing list