| 1 |
/* $Id$ */ |
| 2 |
/* |
| 3 |
* Copyright (c) 1995-1996 Sam Leffler |
| 4 |
* Copyright (c) 1995-1996 Silicon Graphics, Inc. |
| 5 |
* HylaFAX is a trademark of Silicon Graphics |
| 6 |
* |
| 7 |
* Permission to use, copy, modify, distribute, and sell this software and |
| 8 |
* its documentation for any purpose is hereby granted without fee, provided |
| 9 |
* that (i) the above copyright notices and this permission notice appear in |
| 10 |
* all copies of the software and related documentation, and (ii) the names of |
| 11 |
* Sam Leffler and Silicon Graphics may not be used in any advertising or |
| 12 |
* publicity relating to the software without the specific, prior written |
| 13 |
* permission of Sam Leffler and Silicon Graphics. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, |
| 16 |
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY |
| 17 |
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. |
| 18 |
* |
| 19 |
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR |
| 20 |
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, |
| 21 |
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
| 22 |
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF |
| 23 |
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 24 |
* OF THIS SOFTWARE. |
| 25 |
*/ |
| 26 |
|
| 27 |
/* |
| 28 |
* Administrative Support. |
| 29 |
*/ |
| 30 |
#include "HylaFAXServer.h" |
| 31 |
#include "Sys.h" |
| 32 |
#include "config.h" |
| 33 |
|
| 34 |
#include <time.h> |
| 35 |
|
| 36 |
/* |
| 37 |
* Abort an active call on the specified modem. |
| 38 |
* The best we can do is send a message to the |
| 39 |
* current process via the FIFO for that modem; |
| 40 |
* we cannot be certain if the abort operation |
| 41 |
* actually takes place. |
| 42 |
*/ |
| 43 |
void |
| 44 |
HylaFAXServer::abortCallCmd(const char* modem) |
| 45 |
{ |
| 46 |
logcmd(T_ABOR, "%s", modem); |
| 47 |
fxStr emsg; |
| 48 |
if (sendModem(modem, emsg, "Z")) |
| 49 |
reply(200, "Modem %s told to abort current call.", modem); |
| 50 |
else |
| 51 |
reply(500, "Abort request failed: %s.", (const char*) emsg); |
| 52 |
} |
| 53 |
|
| 54 |
/* |
| 55 |
* Answer an inbound call on the specified modem. |
| 56 |
* The best we can do is send a message to the |
| 57 |
* faxgetty process via the FIFO for that modem; |
| 58 |
* we cannot be certain if the operation happens |
| 59 |
* or is successful because there is no return |
| 60 |
* channel. |
| 61 |
* |
| 62 |
* The ``how'' parameter should be one of fax, |
| 63 |
* data, voice, or any (note all lower case). |
| 64 |
*/ |
| 65 |
void |
| 66 |
HylaFAXServer::answerCallCmd(const char* modem, const char* how) |
| 67 |
{ |
| 68 |
logcmd(T_ANSWER, "%s %s", modem, how); |
| 69 |
fxStr emsg; |
| 70 |
if (sendModem(modem, emsg, "A%s", how)) |
| 71 |
reply(200, "Modem %s told to answer call as %s.", modem, how); |
| 72 |
else |
| 73 |
reply(500, "Answer request failed: %s.", (const char*) emsg); |
| 74 |
} |
| 75 |
|
| 76 |
/* |
| 77 |
* Disable outbound use of the specified modem. We |
| 78 |
* first try to notify the appropriate faxgetty process |
| 79 |
* and if that fails then go directly to the scheduler. |
| 80 |
* This should handle both send+recv and send-only system |
| 81 |
* configurations. |
| 82 |
* |
| 83 |
* NB: There currently is no place to stash the reason |
| 84 |
* the modem's use is disabled. |
| 85 |
*/ |
| 86 |
void |
| 87 |
HylaFAXServer::disableModemCmd(const char* modem, const char* reason) |
| 88 |
{ |
| 89 |
logcmd(T_DISABLE, "%s %s", modem, reason); |
| 90 |
fxStr emsg; |
| 91 |
if (sendModem(modem, emsg, "SD")) |
| 92 |
reply(200, "Modem %s told to disable outbound use.", modem); |
| 93 |
else if (sendQueuer(emsg, "+%s:D", modem)) |
| 94 |
reply(200, "Scheduler told to disable use of modem %s.", modem); |
| 95 |
else |
| 96 |
reply(500, "Unable to disable use of %s: %s.", |
| 97 |
modem, (const char*) emsg); |
| 98 |
} |
| 99 |
|
| 100 |
/* |
| 101 |
* Enable outbound use of the specified modem. We |
| 102 |
* first try to notify the appropriate faxgetty process |
| 103 |
* and if that fails then go directly to the scheduler. |
| 104 |
* This should handle both send+recv and send-only system |
| 105 |
* configurations. |
| 106 |
*/ |
| 107 |
void |
| 108 |
HylaFAXServer::enableModemCmd(const char* modem) |
| 109 |
{ |
| 110 |
logcmd(T_ENABLE, "%s", modem); |
| 111 |
fxStr emsg; |
| 112 |
if (sendModem(modem, emsg, "SR")) |
| 113 |
reply(200, "Modem %s told to enable outbound use.", modem); |
| 114 |
else if (sendQueuer(emsg, "+%s:R", modem)) |
| 115 |
reply(200, "Scheduler told to enable use of modem %s.", modem); |
| 116 |
else |
| 117 |
reply(500, "Unable to enable use of %s: %s.", |
| 118 |
modem, (const char*) emsg); |
| 119 |
} |
| 120 |
|
| 121 |
/* |
| 122 |
* Shutdown client access to the server machine by installing |
| 123 |
* a shutdown file with the specified reason. The shutdown |
| 124 |
* may be scheduled for some time in the future in which case |
| 125 |
* when indicates when the shutdown is to take place. |
| 126 |
*/ |
| 127 |
void |
| 128 |
HylaFAXServer::shutCmd(const struct tm& when, const char* reason) |
| 129 |
{ |
| 130 |
logcmd(T_SHUT, "%.24s %s", asctime(&when), reason); |
| 131 |
if (shutdownFile == "") { |
| 132 |
reply(503, "Null configured shutdown filename; something is hosed."); |
| 133 |
return; |
| 134 |
} |
| 135 |
const char* msg = "Shutdown failed; "; |
| 136 |
|
| 137 |
const char* templ = FAX_TMPDIR "/shutXXXXXX"; |
| 138 |
char* buff = strcpy(new char[strlen(templ) + 1], templ); |
| 139 |
|
| 140 |
int fd = Sys::mkstemp(buff); |
| 141 |
fxStr tfile = buff; |
| 142 |
delete [] buff; |
| 143 |
if (fd < 0) { |
| 144 |
reply(550, "%serror creating temp file %s: %s.", msg, |
| 145 |
(const char*) tfile, strerror(errno)); |
| 146 |
return; |
| 147 |
} |
| 148 |
FILE* fp = fdopen(fd, "w"); |
| 149 |
if (fp) { |
| 150 |
fprintf(fp, "%d %d %d %d %d 5 1\n" |
| 151 |
, when.tm_year+1900 |
| 152 |
, when.tm_mon |
| 153 |
, when.tm_mday |
| 154 |
, when.tm_hour |
| 155 |
, when.tm_min |
| 156 |
); |
| 157 |
fprintf(fp, "\n%s\n\n", reason); |
| 158 |
if (fclose(fp) != 0) { |
| 159 |
reply(450, "%sI/O error writing %s.", msg, (const char*) tfile); |
| 160 |
(void) Sys::unlink(tfile); |
| 161 |
} else if (Sys::rename(tfile, fixPathname(shutdownFile)) < 0) { |
| 162 |
reply(550, "%srename %s.", msg, strerror(errno)); |
| 163 |
} else { |
| 164 |
reply(200, "System shutdown scheduled for %.24s.", |
| 165 |
asctime(&when)); |
| 166 |
return; |
| 167 |
} |
| 168 |
} else { |
| 169 |
reply(550, "%serror opening file: %s", msg, strerror(errno)); |
| 170 |
Sys::close(fd); |
| 171 |
} |
| 172 |
(void) Sys::unlink(tfile); |
| 173 |
} |
| 174 |
|
| 175 |
void |
| 176 |
HylaFAXServer::addModemCmd(const char* modem) |
| 177 |
{ |
| 178 |
logcmd(T_ADDMODEM, "%s", modem); |
| 179 |
reply(200, "Modem %s added.", modem); // XXX |
| 180 |
} |
| 181 |
|
| 182 |
void |
| 183 |
HylaFAXServer::delModemCmd(const char* modem) |
| 184 |
{ |
| 185 |
logcmd(T_DELMODEM, "%s", modem); |
| 186 |
reply(200, "Modem %s deleted.", modem); // XXX |
| 187 |
} |
| 188 |
|
| 189 |
void |
| 190 |
HylaFAXServer::configQueryCmd(const char* where) |
| 191 |
{ |
| 192 |
logcmd(T_CONFIG, "%s", where); |
| 193 |
lreply(200, "Configuration info for %s.", where); // XXX |
| 194 |
// XXX |
| 195 |
reply(200, "End of configuration info."); |
| 196 |
} |
| 197 |
|
| 198 |
void |
| 199 |
HylaFAXServer::configCmd(const char* where, const char* info) |
| 200 |
{ |
| 201 |
logcmd(T_CONFIG, "%s %s", where, info); |
| 202 |
reply(200, "Config info %s sent to %s.", info, where); // XXX |
| 203 |
} |