Ejemplo n.º 1
0
void MainWindow::slotWindow()
{
  int  ret = 0;
  char buf[4096];
#ifdef PVUNIX
  if(opt.arg_debug) printf("slotWindow opt.newwindow=%s\n",opt.newwindow);
  strcpy(buf,opt.newwindow);
  strcat(buf," ");
  strcat(buf,pvbtab[currentTab].url.toUtf8());
  strcat(buf," &");
  //printf("before system(%s)\n",opt.newwindow);
  if(opt.newwindow[0] == '\0') ret = system("pvbrowser &");
  else                         ret = system(buf);
  //printf("after system ret=%d\n",ret);
#endif

#ifdef __VMS
  strcpy(buf,"spawn/nowait ");
  strcat(buf,opt.newwindow);
  strcat(buf," ");
  strcat(buf,pvbtab[currentTab].url.toUtf8());
  if(opt.newwindow[0] == '\0') ret = system("spawn/nowait pvbrowser");
  else                         ret = system(buf);
#endif

#ifdef PVWIN32
  strcpy(buf,opt.newwindow);
  strcat(buf," ");
  strcat(buf,pvbtab[currentTab].url.toUtf8());
  if(opt.newwindow[0] == '\0') ret = mysystem("pvbrowser");
  else                         ret = mysystem(buf);
#endif
  if(ret < 0) return;
}
Ejemplo n.º 2
0
/* This will rewrite /etc/hosts, /etc/hosts.*, and the apache ServerName file. */
int writehostsfiles(void)
{	
	char address[STRING_SIZE] = "";
	char netaddress[STRING_SIZE] = "";
	char netmask[STRING_SIZE] = "";
	FILE *file;
	struct keyvalue *kv;
	char hostname[STRING_SIZE];
	char commandstring[STRING_SIZE];
	
	kv = initkeyvalues();
	if (!(readkeyvalues(kv, CONFIG_ROOT "ethernet/settings")))
	{
		freekeyvalues(kv);
		errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
		return 0;
	}
	findkey(kv, "GREEN_ADDRESS", address);
	findkey(kv, "GREEN_NETADDRESS", netaddress);
	findkey(kv, "GREEN_NETMASK", netmask);	
	freekeyvalues(kv);
	
	kv = initkeyvalues();
	if (!(readkeyvalues(kv, CONFIG_ROOT "main/settings")))
	{
		freekeyvalues(kv);
		errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
		return 0;
	}
	strcpy(hostname, "smoothwall"); findkey(kv, "HOSTNAME", hostname);
	freekeyvalues(kv);
		
	if (!(file = fopen(CONFIG_ROOT "main/hostname.conf", "w")))
	{
		errorbox(ctr[TR_UNABLE_TO_WRITE_VAR_SMOOTHWALL_MAIN_HOSTNAMECONF]);
		return 0;
	}
	fprintf(file, "ServerName %s\n", hostname);
	fclose(file);
	
	if (mysystem("/usr/bin/smoothwall/writehosts.pl"))
	{
		errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_HOSTS]);
		return 0;
	}
	
	sprintf(commandstring, "/bin/hostname %s", hostname);
	if (mysystem(commandstring))
	{
		errorbox(ctr[TR_UNABLE_TO_SET_HOSTNAME]);
		return 0;
	}
	
	return 1;
}	
Ejemplo n.º 3
0
const char* createDebuggerFile(const char* debugger, int argc, char* argv[]) {
  const char* dbgfilename = genIntermediateFilename(astr(debugger, ".commands"));
  FILE* dbgfile = openfile(dbgfilename);
  int i;

  if (strcmp(debugger, "gdb") == 0) {
    fprintf(dbgfile, "set args");
  } else if (strcmp(debugger, "lldb") == 0) {
    fprintf(dbgfile, "settings set -- target.run-args");
  } else {
      INT_FATAL(astr("createDebuggerFile doesn't know how to handle the given "
                     "debugger: '", debugger, "'"));
  }
  for (i=1; i<argc; i++) {
    if (strcmp(argv[i], astr("--", debugger)) != 0) {
      fprintf(dbgfile, " %s", argv[i]);
    }
  }

  fprintf(dbgfile, "\n");
  closefile(dbgfile);
  mysystem(astr("cat ", CHPL_HOME, "/compiler/etc/", debugger, ".commands >> ",
                dbgfilename),
           astr("appending ", debugger, " commands"),
           false);

  return dbgfilename;
}
Ejemplo n.º 4
0
int scan_network_cards(void)
{
	FILE *fp;
	char driver[STRING_SIZE], description[STRING_SIZE], macaddr[STRING_SIZE], temp_line[STRING_SIZE];
	int count = 0;
	const char _driver[]="driver: ";
	const char _desc[]="desc: ";
	const char _network_hwaddr[]="network.hwaddr: ";
	
	if (!(scanned_nics_read_done))
	{
		mysystem(NULL, "/usr/bin/probenic.sh");
		if( (fp = fopen(SCANNED_NICS, "r")) == NULL )
		{
			fprintf(stderr,"Couldn't open "SCANNED_NICS);
			return 1;
		}
		while (fgets(temp_line, STRING_SIZE, fp) != NULL)
		{
			temp_line[strlen(temp_line) -1] = 0;
			if ( strncmp(temp_line, _driver,         strlen(_driver))         ==  0 ) sprintf(nics[count].driver,      "%s", temp_line+strlen(_driver));
			if ( strncmp(temp_line, _desc,           strlen(_desc))           ==  0 ) sprintf(nics[count].description, "%s", temp_line+strlen(_desc));
			if ( strncmp(temp_line, _network_hwaddr, strlen(_network_hwaddr)) ==  0 ) sprintf(nics[count].macaddr,     "%s", temp_line+strlen(_network_hwaddr));
			if (strlen(nics[count].macaddr) > 15 ) {
				sprintf(nics[count].nic, "%s", find_nic4mac(nics[count].macaddr));
				count++;
			}
		}
		fclose(fp);
		scanned_nics_read_done = count;
	} else fprintf(flog,"Scan Networkcards does read.\n");
	return scanned_nics_read_done;
}
Ejemplo n.º 5
0
int nic_startup(char *nic) {
	char temp[STRING_SIZE];
	
	sprintf(temp,"ip link set %s up", nic);
	mysystem(NULL, temp);

}
Ejemplo n.º 6
0
int main(int argc, char** argv) {
	// First, implement the system() library call
	int BUF_SIZE = 100000;
	char buf[BUF_SIZE];
	int read_bytes;
	
	signal(SIGINT, signore);
	signal(SIGQUIT, signore);
	
	char pwdbuf[2048];
	
	while(1)
	{
		getcwd(pwdbuf, 2048);
		printf("%s: ", pwdbuf);
		fflush(stdout);
		if ((read_bytes = read(STDOUT_FILENO, buf, BUF_SIZE)) == -1)
		{
			perror("Couldn't read from stdout: ");
			exit(EXIT_FAILURE);
		}
		buf[read_bytes-1] = '\0';
		if (strcmp(buf, "exit") == 0){
			printf("Exiting shell.\n");
			exit(EXIT_SUCCESS);
		} else if (read_bytes > 1) {
			mysystem(buf);
		}
	}
	
	return 0;
}
Ejemplo n.º 7
0
static void runCompilerInLLDB(int argc, char* argv[]) {
  const char* lldbCommandFilename = createDebuggerFile("lldb", argc, argv);
  const char* command = astr("lldb -s ", lldbCommandFilename, " ", argv[0]);
  int status = mysystem(command, "running lldb", false);

  clean_exit(status);
}
Ejemplo n.º 8
0
void deleteTmpDir() {
  static int inDeleteTmpDir = 0; // break infinite recursion

  if (inDeleteTmpDir) {
    return;
  }
  inDeleteTmpDir = 1;

#ifndef DEBUGTMPDIR
  if (tmpdirname != NULL) {
    if (strlen(tmpdirname) < 1 ||
        strchr(tmpdirname, '*') != NULL ||
        strcmp(tmpdirname, "//") == 0) {
      INT_FATAL("tmp directory name looks fishy");
    }
    const char* rmdircommand = "rm -r ";
    const char* command = astr(rmdircommand, tmpdirname);

    mysystem(command, "removing temporary directory");
    tmpdirname = NULL;
  }
#endif

  inDeleteTmpDir = 0;
}
Ejemplo n.º 9
0
int is_interface_up(char *card) {	/* Check if the interface is UP */
    char temp[STRING_SIZE];

    sprintf(temp,"ip link show dev %s | grep -q UP", card);
    if (mysystem(NULL, temp)) return 0;
    else return 1;
}
Ejemplo n.º 10
0
static void runCompilerInGDB(int argc, char* argv[]) {
  const char* gdbCommandFilename = createGDBFile(argc, argv);
  const char* command = astr("gdb -q ", argv[0]," -x ", gdbCommandFilename);
  int status = mysystem(command, "running gdb", 0);

  clean_exit(status);
}
Ejemplo n.º 11
0
int rlsystem(const char *command)
{
#ifdef RLWIN32
   return mysystem(command);
#else
  return system(command);
#endif
}
Ejemplo n.º 12
0
int probeisdncard(void)
{
	int c;
	char message[STRING_SIZE];
	char commandstring[STRING_SIZE];
	char moduleparams[STRING_SIZE] = "";
	struct keyvalue *kv = initkeyvalues();
	int result = -1;
	
	if (!(readkeyvalues(kv, CONFIG_ROOT "isdn/settings")))
	{
		freekeyvalues(kv);
		errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
		return  -1;
	}
	findkey(kv, "MODULE_PARAMS", moduleparams);
		
	c = 1;
	while (cards[c].name)
	{
		sprintf(message, ctr[TR_CHECKING_FOR], cards[c].name);

		/* 
		 * For USB ISDN....
		 * just check /proc/bus/usb/devices for our supported device
		 */
		if (cards[c].type == 100) {
			if (probeusbisdncard("Vendor=0483 ProdID=481"))
				sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=1 %s", moduleparams);
			else
				goto CONTINUE;
		} else {
			sprintf(commandstring, "/sbin/modprobe hisax type=%d protocol=1 %s", 
				cards[c].type, moduleparams);
		}
		
		if (runcommandwithstatus(commandstring, message) == 0)
		{
			mysystem("/etc/ppp/isdn-cleanup");
			sprintf(message, ctr[TR_DETECTED], cards[c].name);
			newtWinMessage(TITLE, ctr[TR_OK], message);
			result = cards[c].type;
			goto EXIT;
		}

CONTINUE:
		c++;
	}

	errorbox(ctr[TR_UNABLE_TO_FIND_AN_ISDN_CARD]);
	
EXIT:
	freekeyvalues(kv);
	
	return result;
}
Ejemplo n.º 13
0
int usb_init(CCyUSBDevice* USBDevice)
{
	bool devicePresent = findDevice(USBDevice);
	if (!(devicePresent && (USBDevice->VendorID != 0x0))){
		myprintf("ERROR:Did not find matching device\n");
		mysystem("PAUSE");
		return 0;
	}else 
		return 1;
}
Ejemplo n.º 14
0
int rename_device(char *old_name, char *new_name) {
	char temp[STRING_SIZE];

	sprintf(temp,SYSDIR "/%s", old_name);
	if (!(fmt_exists(temp))) {
		fprintf(flog,"Device not found: %s\n",old_name);
		return 0;
	}
	sprintf(temp,"/sbin/ip link set dev %s name %s",old_name ,new_name );
	mysystem(NULL, temp);

	return 1;
}
Ejemplo n.º 15
0
int chpl_comm_run_in_gdb(int argc, char* argv[], int gdbArgnum, int* status) {
  int i;
  char* command = chpl_glom_strings(2, "gdb -q -ex 'break gdbShouldBreakHere' --args ",
                                    argv[0]);
  for (i=1; i<argc; i++) {
    if (i != gdbArgnum) {
      command = chpl_glom_strings(3, command, " ", argv[i]);
    }
  }
  *status = mysystem(command, "running gdb", 0);

  return 1;
}
void test_system()
{
	int status = mysystem("date") ;
	if(status < 0)
	{
		perror("date") ;
	}
	check_status(status) ;

	status = mysystem("nosuchcmd") ;
	if(status < 0)
	{
		perror("date") ;
	}

	status = mysystem("who ; exit 55") ;
	if(status < 0)
	{
		perror("date") ;
	}
	check_status(status) ;


}
Ejemplo n.º 17
0
void CPlugins::startScriptPlugin(int number)
{
	const char *script = plugin_list[number].pluginfile.c_str();
	
	printf("[CPlugins] executing script %s\n", script);
	
	if (!pluginfile_exists(plugin_list[number].pluginfile))
	{
		printf("[CPlugins] could not find %s,\nperhaps wrong plugin type in %s\n", script, plugin_list[number].cfgfile.c_str());
		return;
	}
	
	//system("script");
	mysystem((char *) plugin_list[number].pluginfile.c_str(), NULL, NULL);
}
Ejemplo n.º 18
0
void ensureDirExists(const char* dirname, const char* explanation) {
#ifdef HAVE_LLVM
  std::error_code err = llvm::sys::fs::create_directories(dirname);
  if (err) {
    USR_FATAL("creating directory %s failed: %s\n",
              dirname,
              err.message().c_str());
  }
#else
  const char* mkdircommand = "mkdir -p ";
  const char* command = astr(mkdircommand, dirname);

  mysystem(command, explanation);
#endif
}
Ejemplo n.º 19
0
int main(int argc, char *argv[])
{
	char command[] = {"echo \"hello,unnamed pipe\""};
	char output[OUT_SIZE] = {'\0',};
	if(mysystem(command, output, OUT_SIZE - 1) == -1)
	{
		perror("excute mysystem failed!\n");
		return 1;
	}
	else
	{
		printf("The command is:\n%s\n", command);
		printf("The output of the command is:\n%s\n", output);
	}
	return 0;
}
Ejemplo n.º 20
0
int rlBrowser(const char *htmlfile)
{
  char buf[4096];
  int ret = 0;

#ifdef RLUNIX
  sprintf(buf,"konqueror %s &", htmlfile);
  ret = system(buf);
#endif
#ifdef RLWIN32
  if(get_iexplore(buf) < 0) return -1;
  strcat(buf," ");
  strcat(buf,htmlfile);
  ret = mysystem(buf);
#endif
  return ret;
}//------------------------------------------------------------------------
Ejemplo n.º 21
0
QWebView *MyTextBrowser::createWindow(QWebPage::WebWindowType type)
{
  QWebHitTestResult r = page()->mainFrame()->hitTestContent(pressPos);
  if(!r.linkUrl().isEmpty() && type == QWebPage::WebBrowserWindow) 
  {
    QString cmd = opt.newwindow;
    if(cmd.isEmpty()) cmd = "pvbrowser";
    cmd += " \"";
    cmd += r.linkUrl().toString();;
    cmd += "\"";
#ifdef PVUNIX
    //cmd += " &";
    int ret = system(cmd.toUtf8());
#endif
#ifdef PVWIN32
    int ret = mysystem(cmd.toUtf8());
#endif
    if(ret < 0) printf("ERROR system(%s)", (const char *) cmd.toUtf8());
  }
  return NULL;
}
Ejemplo n.º 22
0
void MainWindow::slotReconnect()
{
  char buf[MAX_PRINTF_LENGTH],host[MAX_PRINTF_LENGTH],sshstring[MAX_PRINTF_LENGTH],*cptr;
  QString qbuf;
  int iport,i,ssh,max,maxtab;

  if(opt.arg_debug)
  {
    printf("slotReconnect url=%s current=%s isReconnect=%d\n",
           (const char *) url.toUtf8(),
           (const char *) pvbtab[currentTab].url.toUtf8(),
           isReconnect);
  }         
  if(isReconnect == 1) url = pvbtab[currentTab].url;
  else                 pvbtab[currentTab].url = url;
  pvbtab[currentTab].manual_url = "index.html";
  ssh = 0;
  sshstring[0] = '\0';
  url.truncate(sizeof(buf) - 80);
  strcpy(buf,url.toUtf8());
  // eleminate spaces
  for(i=0; buf[i] != '\0'; i++)
  {
    if(buf[i] == ' ' || buf[i] == '\t')
    {
      buf[i] = '\0';
      break;
    }
  }

  if(strncmp(buf,"http://",7) == 0 || strncmp(buf,"https://",8) == 0 || strncmp(buf,"file://",7) == 0) 
  {
    if(pvbtab[currentTab].s != -1) 
    {
      tcp_close(&pvbtab[currentTab].s);
      pvbtab[currentTab].s = -1;
    }  
    pvbtab[currentTab].interpreter.showMyBrowser(buf);
    add_host(buf);
    return;
  }

  do // eliminate windows slosh'es
  {
    cptr = strchr(buf,'\\');
    if(cptr != NULL) *cptr = '/';
  }
  while(cptr != NULL);
  if(buf[strlen(buf)-1] == '/') buf[strlen(buf)-1] = '\0';

  if     (strncmp(buf,"ssh://",6) == 0 || strncmp(buf,"pvssh://",8) == 0)
  {
    char ssh_user_host[MAX_PRINTF_LENGTH];
    char ssh_host[MAX_PRINTF_LENGTH];
    int  ssh_port;
    ssh = 1;
    strcpy(sshstring,buf);
    sprintf(host,"localhost:%d",opt.sshport); // we connect locally
    strcpy(ssh_host,"localhost");
    ssh_port = opt.port;
    cptr = &buf[6]; 
    if(buf[0] == 'p') cptr = &buf[8];
    i = 0;
    while(*cptr != ':' && *cptr != '\0') ssh_user_host[i++] = *cptr++;
    ssh_user_host[i] = '\0';
    if(*cptr == ':')
    {
      cptr++;
      if(isalpha(*cptr) || strchr(cptr,'.') != NULL)
      {
        i = 0;
        while(*cptr != ':' && *cptr != '\0') ssh_host[i++] = *cptr++;
        ssh_host[i] = '\0';
        cptr++;
      }
      if(*cptr != '\0') sscanf(cptr,"%d",&ssh_port);  
    }
    if(isReconnect == 0)
    {
      isReconnect = 1;
      QString qbuf;
#ifdef PVUNIX    
      qbuf.sprintf("xterm -e %s -L %d:%s:%d %s &",opt.ssh,opt.sshport,ssh_host,ssh_port,ssh_user_host);
#endif
#ifdef PVWIN32
      qbuf.sprintf("%s -ssh -L %d:%s:%d %s",opt.ssh,opt.sshport,ssh_host,ssh_port,ssh_user_host);
#endif
      if(opt.arg_debug) printf("mysystem(%s)\n",(const char *) qbuf.toUtf8());
      mysystem(qbuf.toUtf8());
    }
  }
  else if(strncmp(buf,"pv://"  ,5) == 0) 
  {
    strcpy(host,&buf[5]);
  }  
  else
  {
    strcpy(host,buf);
  }  

  if(host[0] == '\0') return;

  if(pvbtab[currentTab].s != -1) 
  {
    tcp_close(&pvbtab[currentTab].s);
    pvbtab[currentTab].s = -1;
  }  
  strcpy(buf,host);
  iport = opt.port;
  if(buf[0] == '[')
  { // plain IPV6 address as number
    strcpy(buf,&host[1]);
    cptr = strchr(buf,']');
    if(cptr != NULL)
    {
      *cptr = '\0';
      cptr++;
      if(*cptr == ':') // port is given
      {
        cptr++;
        sscanf(cptr,"%d",&iport);
      }
    }
  }
  else
  {
    cptr = strchr(buf,':'); // if special port is given
    if(cptr != NULL)
    {
      *cptr++ = '\0';
      sscanf(cptr,"%d",&iport);
    }
  }
  cptr = strstr(buf,"/");
  if(cptr != NULL) *cptr = '\0';
  QApplication::setOverrideCursor( Qt::WaitCursor );
  pvbtab[currentTab].s = tcp_con(buf,iport);
  if(pvbtab[currentTab].s > 0)
  {
    pvbtab[currentTab].in_use = 1;
  }  
  max = maxtab= 0;
  for(i=0; i<MAX_TABS; i++)
  {
    if(pvbtab[i].s > max) max = pvbtab[i].s;
    if(pvbtab[i].in_use)  maxtab = i;
  }
  maxfd = max;
  numTabs = maxtab+1;
  if(opt.arg_debug) printf("slotReconnect tcp_con s=%d host=%s:%d maxfd=%d\n",pvbtab[currentTab].s,buf,iport,maxfd);
  QApplication::restoreOverrideCursor();

  cptr = strstr(host,"/"); // send initial mask
  if(cptr == NULL)
  {
    sprintf(buf,"initial(0,\"\") version=%s",VERSION);
#ifdef PVWIN32  
    strcat(buf, " Windows");
#endif
#ifdef PVUNIX
    strcat(buf, " Unix");
#ifdef PVMAC
    strcat(buf, " OS-X");
#elif defined(USE_ANDROID)
    strcat(buf, " Android");
#elif defined(USE_MAEMO)
    strcat(buf, " Maemo");
#elif defined(USE_SYMBIAN)
    strcat(buf, " Symbian");
#endif
#endif
    QRect maxrect = QApplication::desktop()->availableGeometry();
    char tempbuf[1024];
    sprintf(tempbuf," (%dx%d)", maxrect.width(), maxrect.height());
    strcat(buf, tempbuf);
    strcat(buf, "\n");
    tcp_send(&pvbtab[currentTab].s,buf,strlen(buf));
  }
  else
  {
    cptr++;
    sprintf(buf,"initial(0,\"%s\") version=%s\n",cptr,VERSION);
    tcp_send(&pvbtab[currentTab].s,buf,strlen(buf));
  }

  // send initial url
  sprintf(buf,"@url=%s\n", (const char *) url.toUtf8());
  tcp_send(&pvbtab[currentTab].s,buf,strlen(buf));

  if(pvbtab[currentTab].s != -1)
  {
    if(ssh == 0)
    {
      qbuf  = l_status_connected;
      qbuf += " ";
      qbuf += host;
    }
    else if(ssh == 1)
    {
      qbuf  = l_status_connected;
      qbuf += " ";
      qbuf += sshstring;
    }
    QPalette palette;
    statusBar()->setPalette(palette);
    statusBar()->showMessage(qbuf);
    if     (ssh == 0) add_host(host);
    else if(ssh == 1) add_host(sshstring);
  }
  else
  {
    if(ssh == 0)
    {
      qbuf  = l_status_could_not_connect;
      qbuf += " ";
      qbuf += host;
    }
    else if(ssh == 1)
    {
      qbuf  = l_status_could_not_connect;
      qbuf += " ";
      qbuf += sshstring;
    }
    QPalette palette(QColor(255,0,0));
    statusBar()->setPalette(palette);
    //rlehrig statusBar()->setPaletteBackgroundColor(QColor(255,0,0));
    statusBar()->showMessage(qbuf);
    qApp->beep();
  }
  isReconnect = 1;
}
Ejemplo n.º 23
0
int networkmenu(struct keyvalue *ethernetkv)
{
	int rc;
	char driver[STRING_SIZE] = "";
	char driveroptions[STRING_SIZE] = "";
	struct keyvalue *kv = initkeyvalues();
	int result = 0;
	char commandstring[STRING_SIZE];
	char address[STRING_SIZE], netmask[STRING_SIZE];
	int done;
	char description[1000];
	char message[1000];
	char cardinfo[STRING_SIZE];
	char mac[STRING_SIZE];
	int c = 0;

	done = 0;
	c = 0;
	while (!done)
	{
		rc = newtWinTernary(ctr[TR_CONFIGURE_NETWORKING], ctr[TR_PROBE], 
			ctr[TR_SELECT], ctr[TR_CANCEL], ctr[TR_CONFIGURE_NETWORKING_LONG]);
		
		if (rc == 0 || rc == 1)
		{
			probecards(driver, driveroptions, &c);
			if (!strlen(driver))
				errorbox(ctr[TR_PROBE_FAILED]);
			else
			{
				findnicdescription(driver, description);
				if ((getnicmac(mac, sizeof(mac), "eth0")))
					/* If MAC found put it at the end of nic description. */
					snprintf(cardinfo, STRING_SIZE, "%s [%s]", description, mac);
				else
					/* MAC lookup failed so just display nic description. */
					snprintf(cardinfo, STRING_SIZE, "%s", description);

				sprintf(message, ctr[TR_FOUND_NIC], cardinfo);
				newtWinMessage(TITLE, ctr[TR_OK], message);
			}		
		}			
		else if (rc == 2)
			choosecards(driver, driveroptions);
		else
			done = 1;	
			
		if (strlen(driver))
			done = 1;
	}
	
	if (!strlen(driver))
		goto EXIT;

	/* Default is a GREEN nic only. */
	/* Smoothie is not untarred yet, so we have to delay actually writing the
	 * settings till later. */
	replacekeyvalue(ethernetkv, "CONFIG_TYPE", "0");
	replacekeyvalue(ethernetkv, "GREEN_DRIVER", driver);
	replacekeyvalue(ethernetkv, "GREEN_DRIVER_OPTIONS", driveroptions);
	replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0");
	replacekeyvalue(ethernetkv, "GREEN_DISPLAYDRIVER", driver);
	
	if (!(changeaddress(ethernetkv, "GREEN", 0, "")))
		goto EXIT;
	
	strcpy(address, ""); findkey(ethernetkv, "GREEN_ADDRESS", address);
	strcpy(netmask, ""); findkey(ethernetkv, "GREEN_NETMASK", netmask);

	snprintf(commandstring, STRING_SIZE, "/bin/ifconfig eth0 %s netmask %s up", 
		address, netmask);
	if (mysystem(commandstring))
	{
		errorbox(ctr[TR_INTERFACE_FAILED_TO_COME_UP]);
		goto EXIT;
	}

	result = 1;
	
EXIT:
	freekeyvalues(kv);
	
	return result;
}
Ejemplo n.º 24
0
void  perhapsDoAction()
{
  FILE *fout;
  char buf[2*MAXOPT_DEVELOP];
  int ret = 0;

  if(opt_develop.arg_action[0]=='\0') return;
  if(opt_develop.arg_project[0]=='\0')
  {
    printf("no project given\n");
    usage();
  }
  if(strcmp(opt_develop.arg_action,"writeInitialProject") == 0)
  {
    generateInitialProject(opt_develop.arg_project);
    sprintf(buf,"qmake=%s",opt_develop.arg_project);
    action(buf);
  }
  else if(strcmp(opt_develop.arg_action,"insertMask") == 0)
  {
    sprintf(buf,"insertMask=%s",opt_develop.arg_project);
    action(buf);
  }
  else if(strcmp(opt_develop.arg_action,"make") == 0)
  {
    action("make");
  }
  else if(strcmp(opt_develop.arg_action,"makeModbus") == 0)
  {
    gmodbus("modbusdaemon.mkmodbus");
#ifdef PVUNIX
    ret = system("g++ -c modbusdaemon.cpp -o modbusdaemon.o -I/opt/pvb/rllib/lib  ; g++ modbusdaemon.o /usr/lib/librllib.so -lpthread -o modbusdaemon");
#else
    ret = system("start pvb_make_modbusdaemon.bat");
#endif
  }
  else if(strcmp(opt_develop.arg_action,"makeSiemensTCP") == 0)
  {
    gsiemens("siemensdaemon.mksiemens");
#ifdef PVUNIX
    ret = system("g++ -c siemensdaemon.cpp -o siemensdaemon.o -I/opt/pvb/rllib/lib  ; g++ siemensdaemon.o /usr/lib/librllib.so -lpthread -o siemensdaemon");
#else
    ret = system("start pvb_make_siemensdaemon.bat");
#endif
  }
  else if(strcmp(opt_develop.arg_action,"makePPI") == 0)
  {
    gppi("ppidaemon.mkppi");
#ifdef PVUNIX
    ret = system("g++ -c ppidaemon.cpp -o ppidaemon.o -I/opt/pvb/rllib/lib  ; g++ ppidaemon.o /opt/pvb/rllib/lib/nodave.o /opt/pvb/rllib/lib/setport.o /usr/lib/librllib.so -lpthread -o ppidaemon");
#else
    ret = system("start pvb_make_ppidaemon.bat");
#endif
  }
  else if(strcmp(opt_develop.arg_action,"uncommentRLLIB") == 0)
  {
    sprintf(buf,"%s.pro",opt_develop.arg_project);
    uncommentRllib(buf);
  }
  else if(strcmp(opt_develop.arg_action,"uncommentModbus") == 0)
  {
    uncommentModbus();
  }
  else if(strcmp(opt_develop.arg_action,"uncommentSiemensTCP") == 0)
  {
    uncommentSiemenstcp();
  }
  else if(strcmp(opt_develop.arg_action,"uncommentPPI") == 0)
  {
    uncommentPpi();
  }
  else if(strcmp(opt_develop.arg_action,"writeStartscript") == 0)
  {
    ret = writeStartscript(".", opt_develop.arg_project);
  }
  else if(strncmp(opt_develop.arg_action,"writeDimension:",15) == 0)
  {
    int xmax, ymax;

    xmax = 1280;
    ymax = 1024;
    sscanf(opt_develop.arg_action,"writeDimension:%d:%d",&xmax,&ymax);
    sprintf(buf,"%s.pvproject",opt_develop.arg_project);
    fout = fopen(buf,"w");
    if(fout == NULL)
    {
      printf("could not write %s\n",buf);
      exit(-1);
    }
    fprintf(fout,"target=%s\n",opt_develop.arg_project);
    fprintf(fout,"xmax=%d\n",xmax);
    fprintf(fout,"ymax=%d\n",ymax);

    // add additional language here
    if(opt_develop.script == PV_PYTHON)
    {
      fprintf(fout,"script=Python\n");
    }
    if(opt_develop.script == PV_PERL)
    {
      fprintf(fout,"script=PERL\n");
    }
    if(opt_develop.script == PV_PHP)
    {
      fprintf(fout,"script=PHP\n");
    }
    if(opt_develop.script == PV_TCL)
    {
      fprintf(fout,"script=Tcl\n");
    }
    if(opt_develop.script == PV_LUA)
    {
      fprintf(fout,"script=Lua\n");
    }
    fclose(fout);
  }
  else if(strncmp(opt_develop.arg_action,"importUi:",9) == 0)
  {
    if(strncmp(opt_develop.arg_action,"importUi:mask",13) == 0)
    {
      sscanf(opt_develop.arg_action,"importUi:mask%d", &opt_develop.arg_mask_to_generate);
    }
    else
    {
      const char *cptr = &opt_develop.arg_action[9];
      if(isdigit(*cptr))
      {
        sscanf(cptr,"%d",&opt_develop.arg_mask_to_generate);
      }
      else
      {
        cptr = strstr(cptr,"mask");
        if(cptr != NULL)
        {
          sscanf(cptr,"mask%d",&opt_develop.arg_mask_to_generate);
        }
      }
    }  
    if(opt_develop.arg_mask_to_generate > 0)
    {
      char maskname[80];
      sprintf(maskname,"mask%d", opt_develop.arg_mask_to_generate);
      Designer *designer = new Designer(maskname);
      sprintf(maskname,"mask%d.ui", opt_develop.arg_mask_to_generate);
      importUi(maskname, designer);
      delete designer;
#ifdef PVUNIX
      action("make");
#endif
    }
    else printf("error: arg_mask_to_generate <= 0\n");
  }
  else if(strncmp(opt_develop.arg_action,"exportUi:",9) == 0)
  {
    if(strncmp(opt_develop.arg_action,"exportUi:mask",13) == 0)
    {
      sscanf(opt_develop.arg_action,"exportUi:mask%d", &opt_develop.arg_mask_to_generate);
    }
    else
    {
      const char *cptr = &opt_develop.arg_action[9];
      if(isdigit(*cptr))
      {
        sscanf(cptr,"%d",&opt_develop.arg_mask_to_generate);
      }
      else
      {
        cptr = strstr(cptr,"mask");
        if(cptr != NULL)
        {
          sscanf(cptr,"mask%d",&opt_develop.arg_mask_to_generate);
        }
      }
    }  
    if(opt_develop.arg_mask_to_generate > 0)
    {
      printf("ATTENTION: You are not allowed to export an ui file, define a layout management in Qt Designer and import the ui file again to pvdevelop\n");
      printf("           You must define a possible layout management within pvdevelop instead.\n");
      export_ui(opt_develop.arg_mask_to_generate);
    }
    else printf("error: arg_mask_to_generate <= 0\n");
  }
  else if(strncmp(opt_develop.arg_action,"designerUi:",11) == 0)
  {
    if(strncmp(opt_develop.arg_action,"designerUi:mask",15) == 0)
    {
      sscanf(opt_develop.arg_action,"designerUi:mask%d", &opt_develop.arg_mask_to_generate);
    }
    else
    {
      const char *cptr = &opt_develop.arg_action[11];
      if(isdigit(*cptr))
      {
        sscanf(cptr,"%d",&opt_develop.arg_mask_to_generate);
      }
      else
      {
        cptr = strstr(cptr,"mask");
        if(cptr != NULL)
        {
          sscanf(cptr,"mask%d",&opt_develop.arg_mask_to_generate);
        }
      }
    }  
    if(opt_develop.arg_mask_to_generate > 0)
    {
      char maskname[80];
      sprintf(maskname,"mask%d", opt_develop.arg_mask_to_generate);
      Designer *designer = new Designer(maskname);
      sprintf(maskname,"mask%d.ui", opt_develop.arg_mask_to_generate);
      printf("ATTENTION: You are not allowed to export an ui file, define a layout management in Qt Designer and import the ui file again to pvdevelop\n");
      printf("           You must define a possible layout management within pvdevelop instead.\n");
      export_ui(opt_develop.arg_mask_to_generate);
      char cmd[1024];
#ifdef PVWIN32      
      sprintf(cmd,"wait \"%%QTDIR%%\\bin\\designer.exe\" %s", maskname);
      mysystem(cmd);
#else      
      sprintf(cmd,"designer %s", maskname);
      system(cmd);
#endif      
      importUi(maskname, designer);
      delete designer;
#ifdef PVUNIX
      action("make");
#endif
      printf("ATTENTION: You are not allowed to export an ui file, define a layout management in Qt Designer and import the ui file again to pvdevelop\n");
      printf("           You must define a possible layout management within pvdevelop instead.\n");
    }
    else printf("error: arg_mask_to_generate <= 0\n");
  }
  else if(strcmp(opt_develop.arg_action,"dumpTranslations") == 0)
  {
    action("dumpTranslations");
  }
  else
  {
    printf("unknown action\n");
    usage();
  }
  if(ret != 0)
  {
    printf("error\n");
  }
  exit(0);
}
Ejemplo n.º 25
0
void dlgMyBrowser::slotLinkClicked(const QUrl &url)
{
  if(opt.arg_debug) printf("dlgMyBrowser:slotLinkClicked(%s)\n", (const char *) url.toString().toUtf8());
  if(url.isEmpty()) return;
#ifdef USE_WEBKIT  
  QString text = url.toString();
  QStringList list = text.split("#"); // split anchor
  anchor = url.fragment();
  if(opt.arg_debug) printf("dlgMyBrowser::slotLinkClicked url=%s fragment=%s\n", (const char *) text.toUtf8(), (const char *) anchor.toUtf8());
  QString webpath = url.host() + url.path();
  anchor = url.fragment();
  mainWindow->urlComboBox->setEditText(text);
  if(text.startsWith("pv:") || text.startsWith("pvssh:"))
  {
    return mainWindow->slotUrl(text);
  }
  else if(text.endsWith(".pdf") || text.endsWith(".PDF"))
  {
    QString cmd = opt.view_pdf;
    cmd += " ";
    text.replace(" ","%20");
    cmd += text;
//#ifndef PVWIN32
//    cmd +=  " &";
//#endif
    mysystem(cmd.toUtf8());
    return;
  }
  else if(text.endsWith(".mp3",  Qt::CaseInsensitive) ||
          text.endsWith(".ogg",  Qt::CaseInsensitive) || 
          text.endsWith(".m3u",  Qt::CaseInsensitive) || 
          text.endsWith(".asx",  Qt::CaseInsensitive) || 
          text.contains(".pls?", Qt::CaseInsensitive) || 
          text.contains("mp3e",  Qt::CaseInsensitive) || 
          text.startsWith("http://www.youtube.com/watch?") )
  {
     QString cmd = opt.view_audio;
     cmd += " ";
     text.replace(" ","%20");
     cmd += text;
//#ifndef PVWIN32
//     cmd +=  " &";
//#endif
     mysystem(cmd.toUtf8());
  }
  else if(text.endsWith(".mp4",  Qt::CaseInsensitive) || 
          text.endsWith(".mov",  Qt::CaseInsensitive) || 
          text.endsWith(".ogv",  Qt::CaseInsensitive) || 
          text.endsWith(".avi",  Qt::CaseInsensitive) )
  {
     QString cmd = opt.view_video;
     cmd += " ";
     text.replace(" ","%20");
     cmd += text;
//#ifndef PVWIN32
//     cmd +=  " &";
//#endif
     mysystem(cmd.toUtf8());
  }
  else if(webpath == homepath)
  {
    QString u = list.at(0);
    form->browser->setUrl(QUrl(u));
  }
  else
  {
    QString u = list.at(0);
    form->browser->load(QUrl(u));
    homepath = webpath;
  }
#endif
}
Ejemplo n.º 26
0
Archivo: opt.cpp Proyecto: nrj123/pvb
const char *readIniFile()
{
FILE *fp;
char buf[MAXOPT],buf2[MAXOPT],cmd[MAXOPT];
const char *cptr;
int i;

  opt.port=5050;
  opt.sshport=50500;
  opt.zoom=100;
  opt.fontzoom=100;
  opt.autoreconnect=0;
  opt.exitpassword=0;
  opt.menubar=1;
  opt.toolbar=1;
  opt.statusbar=1;
  opt.scrollbars=1;
  opt.fullscreen=0;
  opt.maximized=0;
  opt.tabs_above_toolbar=0;
  opt.echo_table_updates=0;
  opt.enable_webkit_plugins=1;
  opt.temp[0] = '\0';
  opt.customlogo[0] = '\0';
  opt.newwindow[0] = '\0';
  opt.ssh[0] = '\0';
  opt.i_have_started_servers = 0;
  opt.view_audio[0] = '\0';
  opt.view_video[0] = '\0';
  opt.view_pdf[0] = '\0';
  opt.view_img[0] = '\0';
  opt.view_svg[0] = '\0';
  opt.view_txt[0] = '\0';
  opt.view_html[0] = '\0';
  opt.initialhost[0] = '\0';
  opt.language[0] = '\0';
  opt.codec = pvbUTF8; // strongly advised to use pvbUTF8
  opt.closed = 0;
  opt.cookies = 1; // YES
  strcpy(opt.manual,"index.html");

  while(1)
  {
    fp = fopen(inifile(),"r");
    if(fp != NULL)
    {
      while( fgets(buf,sizeof(buf)-1,fp) != NULL )
      {
        char *ptr = strchr(buf,'\n');
        if(ptr != NULL) *ptr = '\0';
        if(strncmp(buf,"port=",5) == 0)
        {
          sscanf(buf,"port=%d",&opt.port);
        }
        else if(strncmp(buf,"sshport=",8) == 0)
        {
          sscanf(buf,"sshport=%d",&opt.sshport);
        }
        else if(strncmp(buf,"zoom=",5) == 0)
        {
          sscanf(buf,"zoom=%d",&opt.zoom);
        }
        else if(strncmp(buf,"fontzoom=",9) == 0)
        {
          sscanf(buf,"fontzoom=%d",&opt.fontzoom);
        }
        else if(strncmp(buf,"autoreconnect=",14) == 0)
        {
          sscanf(buf,"autoreconnect=%d",&opt.autoreconnect);
        }
        else if(strncmp(buf,"scrollbars=",11) == 0)
        {
          sscanf(buf,"scrollbars=%d",&opt.scrollbars);
        }
        else if(strncmp(buf,"cookies=",8) == 0)
        {
          sscanf(buf,"cookies=%d",&opt.cookies);
        }
        else if(strncmp(buf,"enable_webkit_plugins=",22) == 0)
        {
          sscanf(buf,"enable_webkit_plugins=%d",&opt.enable_webkit_plugins);
        }
        else if(strncmp(buf,"temp=",5) == 0)
        {
          int ret;
          sscanf(buf,"temp=%s",buf2);
#ifdef PVUNIX
          sprintf(cmd,"mkdir -p %s", buf2);
          if(system(cmd) != 0) printf("could not create temporary directory: %s\n", cmd);
#endif
#ifdef PVWIN32
          ExpandEnvironmentStrings(buf2,buf,sizeof(buf)-1);
          if(strstr(buf,"%") != NULL) QMessageBox::warning(NULL,buf,"readIniFile temp directory unknown: adjust pvbrowser.ini temp=");
          strcpy(buf2,buf);
#endif
          ret = chdir(buf2);
          if(ret < 0) 
          {
#ifdef PVUNIX
            QMessageBox::warning(NULL,buf2,"readIniFile could not change to temp dir: adjust ~/.pvbrowser.ini temp=");
            ret = system("xterm -e \"vi ~/.pvbrowser.ini\" &");
#endif
#ifdef PVWIN32
            QMessageBox::warning(NULL,buf2,"readIniFile could not change to temp dir: adjust pvbrowser.ini temp=");
            sprintf(buf,"notepad %s",inifile());
            system(buf);
#endif
            return "Error chdir";
          }
#ifdef PVUNIX
          strcat(buf2,"/");
#endif
#ifdef PVWIN32
          strcat(buf2,"\\");
#endif
          strcpy(opt.temp,buf2);
        }
        else if(strncmp(buf,"toolbar=",8) == 0)
        {
          sscanf(buf,"toolbar=%d",&opt.toolbar);
        }
        else if(strncmp(buf,"statusbar=",10) == 0)
        {
          sscanf(buf,"statusbar=%d",&opt.statusbar);
        }
        else if(strncmp(buf,"menubar=",8) == 0)
        {
          sscanf(buf,"menubar=%d",&opt.menubar);
        }
        else if(strncmp(buf,"initialhost=",12) == 0)
        {
          sscanf(buf,"initialhost=%s",buf2);
          strcpy(opt.initialhost,buf2);
        }
        else if(strncmp(buf,"fullscreen=",11) == 0)
        {
          sscanf(buf,"fullscreen=%d",&opt.fullscreen);
        }
        else if(strncmp(buf,"maximized=",10) == 0)
        {
          sscanf(buf,"maximized=%d",&opt.maximized);
        }
        else if(strncmp(buf,"tabs_above_toolbar=",19) == 0)
        {
          sscanf(buf,"tabs_above_toolbar=%d",&opt.tabs_above_toolbar);
        }
        else if(strncmp(buf,"exitpassword="******"exitpassword=%d",&opt.exitpassword);
        }
        else if(strncmp(buf,"echo_table_updates=",19) == 0)
        {
          sscanf(buf,"echo_table_updates=%d",&opt.echo_table_updates);
        }
        else if(strncmp(buf,"newwindow=",10) == 0)
        {
          sscanf(buf,"newwindow=%s",buf);
          strcpy(opt.newwindow,buf);
        }
        else if(strncmp(buf,"ssh=",4) == 0)
        {
          strcpy(opt.ssh,&buf[4]);
        }
        else if(strncmp(buf,"start=",6) == 0)
        {
          mysystem(&buf[6]);
          opt.i_have_started_servers++;
        }
        else if(strncmp(buf,"fillbackground=1",16) == 0)
        {
          opt.arg_fillbackground = 1;
        }
        else if(strncmp(buf,"view.audio=",11) == 0)
        {
          strcpy(opt.view_audio,&buf[11]);
        }
        else if(strncmp(buf,"view.video=",11) == 0)
        {
          strcpy(opt.view_video,&buf[11]);
        }
        else if(strncmp(buf,"view.pdf=",9) == 0)
        {
          strcpy(opt.view_pdf,&buf[9]);
        }
        else if(strncmp(buf,"view.img=",9) == 0)
        {
          strcpy(opt.view_img,&buf[9]);
        }
        else if(strncmp(buf,"view.svg=",9) == 0)
        {
          strcpy(opt.view_svg,&buf[9]);
        }
        else if(strncmp(buf,"view.txt=",9) == 0)
        {
          strcpy(opt.view_txt,&buf[9]);
        }
        else if(strncmp(buf,"view.csv=",9) == 0)
        {
          strcpy(opt.view_csv,&buf[9]);
        }
        else if(strncmp(buf,"view.html=",10) == 0)
        {
          strcpy(opt.view_html,&buf[10]);
        }
        else if(strncmp(buf,"language =",10) == 0)
        {
          cptr = strchr(buf,'=');
          cptr++;
          if(*cptr == ' ') cptr++;
          sscanf(cptr,"%s",opt.language);
          opt.language[100] = '\0';
        }
        else if(strncmp(buf,"customlogo=",11) == 0)
        {
          cptr = strchr(buf,'=');
          cptr++;
          if(*cptr == ' ') cptr++;
          sscanf(cptr,"%s",opt.customlogo);
        }
        else if(strncmp(buf,"codec=",6) == 0)
        {
          opt.codec = pvbUTF8;
          if(strstr(buf,"=None") != NULL) opt.codec = pvbNone;
        }
        else if(buf[0] != '#' && strchr(buf,'{') != NULL)
        {
          for(i=0; buf[i] != ' ' && buf[i] != '{'; i++)
          {
            opt.language_section[i] = buf[i];
          }
          opt.language_section[i] = '\0';
        }
        else if(buf[0] == '-' && strcmp(opt.language,opt.language_section) == 0)
        {
          getLanguage(buf);
        }
      }
      fclose(fp);
      return NULL;
    }
    else // write a default initialisation file
    {
#ifdef USE_ANDROID
      mkdir("/sdcard/pvbrowser", 0x0fff); // android
      mkdir("/sdcard/pvbrowser/temp", 0x0fff); // android             
#endif
      fp = fopen(inifile(),"w");
      if(fp != NULL)
      {
        fprintf(fp,"###############################################\n");
        fprintf(fp,"# This is the default initialization file for\n");
        fprintf(fp,"# ProcessViewBrowser\n");
        fprintf(fp,"###############################################\n");
        fprintf(fp,"port=5050               # default port\n");
        fprintf(fp,"sshport=50500           # local port for ssh connections\n");
        fprintf(fp,"zoom=100                # zoom factor in percent\n");
        fprintf(fp,"fontzoom=100            # zoom factor for fonts in percent\n");
        fprintf(fp,"fillbackground=0        # 0|1 transparency in dialog boxes\n");
        fprintf(fp,"codec=utf8              # utf8 | None where None uses latin charset\n");
        fprintf(fp,"autoreconnect=0         # 0|1\n");
        fprintf(fp,"exitpassword=0          # 0|1\n");
        fprintf(fp,"menubar=1               # 0|1\n");
        fprintf(fp,"toolbar=1               # 0|1\n");
        fprintf(fp,"statusbar=1             # 0|1\n");
        fprintf(fp,"scrollbars=1            # 0|1\n");
        fprintf(fp,"fullscreen=0            # 0|1\n");
        fprintf(fp,"maximized=0             # 0|1\n");
        fprintf(fp,"tabs_above_toolbar=0    # 0|1\n");
        fprintf(fp,"cookies=1               # 0=No 1=Yes 2=Ask\n");
        fprintf(fp,"echo_table_updates=0    # 0|1\n");
        fprintf(fp,"enable_webkit_plugins=1 # 0|1\n");
        fprintf(fp,"# temporary directory\n");
#ifdef PVUNIX
#ifdef USE_ANDROID
        fprintf(fp,"temp=/sdcard/pvbrowser/temp\n");
#else
        sprintf(buf,"mkdir -p /tmp/pvb-%s", getenv("USER"));
        if(system(buf) != 0) printf("could not create temporary directory: %s\n", buf);
        fprintf(fp,"temp=/tmp/pvb-%s\n", getenv("USER"));
#endif
#endif
#ifdef PVWIN32
        //fprintf(fp,"temp=%%PVBDIR%%\\win\\temp\n");
        fprintf(fp,"temp=%%TEMP%%\n");
#endif
#ifdef __VMS
        fprintf(fp,"temp=sys$login:\n");
#endif
        fprintf(fp,"# your custom logo\n");
#ifdef PVUNIX
        fprintf(fp,"customlogo=/opt/pvb/gamsleiten.png\n");
#endif
#ifdef PVWIN32
        fprintf(fp,"customlogo=%%PVBDIR%%\\gamsleiten.png\n");
#endif
#ifdef __VMS
        fprintf(fp,"customlogo=[ProcessView.processview.processview]gamsleiten.png\n");
#endif
        fprintf(fp,"# howto start \"New Window\", can be commented out\n");
        fprintf(fp,"#newwindow=pvbrowser\n");
        fprintf(fp,"# windows users may put their putty.exe here\n");
        fprintf(fp,"ssh=ssh\n");
        fprintf(fp,"# we will automatically connect to this node\n");
#ifdef USE_MAEMO
        fprintf(fp,"initialhost=pv://pvbrowser.org\n");
#else
        fprintf(fp,"initialhost=pv://localhost\n");
#endif
        fprintf(fp,"# define the programs that handle the following file formats\n");
#ifdef  PVWIN32
        fprintf(fp,"view.pdf=\"c:\\path\\to\\acroread\"\n");
        fprintf(fp,"view.img=mspaint\n");
        fprintf(fp,"view.svg=\"c:\\path\\to\\inkscape\"\n");
        fprintf(fp,"view.txt=\"c:\\windows\\system32\\write\"\n");
        fprintf(fp,"view.csv=\"c:\\path\\to\\ooffice\"\n");
        fprintf(fp,"view.html=\"c:\\path\\to\\firefox\"\n");
        fprintf(fp,"view.audio=\"c:\\path\\to\\vlc\"\n");
        fprintf(fp,"view.video=\"c:\\path\\to\\vlc\"\n");
#elif   defined(PVMAC)
        fprintf(fp,"view.pdf=okular\n");
        fprintf(fp,"view.img=gimp\n");
        fprintf(fp,"view.svg=inkscape\n");
        fprintf(fp,"view.txt=kwrite\n");
        fprintf(fp,"view.csv=ooffice\n");
        fprintf(fp,"view.html=firefox\n");
        fprintf(fp,"view.audio=vlc\n");
        fprintf(fp,"view.video=vlc\n");
#elif   defined(PVUNIX)
        fprintf(fp,"view.pdf=okular\n");
        fprintf(fp,"view.img=gimp\n");
        fprintf(fp,"view.svg=inkscape\n");
        fprintf(fp,"view.txt=kwrite\n");
        fprintf(fp,"view.csv=ooffice\n");
        fprintf(fp,"view.html=firefox\n");
        fprintf(fp,"view.audio=vlc\n");
        fprintf(fp,"view.video=vlc\n");
#endif

        fprintf(fp,"##################################################################\n");
        fprintf(fp,"#\n");
        fprintf(fp,"# Language settings for ProcessViewBrowser\n");
        fprintf(fp,"# you may input your own language (I only know german and english)\n");
        fprintf(fp,"# example: comment out: language = german\n");
        fprintf(fp,"#          comment in:  #language = default\n");
        fprintf(fp,"#          restart ProcessViewBrowser\n");
        fprintf(fp,"##################################################################\n");
        fprintf(fp,"language = default\n");
        fprintf(fp,"#language = german\n");
        fprintf(fp,"#language = french\n");
        fprintf(fp,"#language = spanish\n");
        fprintf(fp,"#language = italian\n");
        fprintf(fp,"#language = chinese\n");
        fprintf(fp,"#---------------------------------------\n");
        fprintf(fp,"german {\n");
        fprintf(fp,"-file               = &Datei\n");
        fprintf(fp,"-options            = &Optionen\n");
        fprintf(fp,"-new_window         = &Neues Fenster\n");
        fprintf(fp,"-new_tab            = Neuer &Tab\n");
        fprintf(fp,"-delete_tab         = Schliesst den aktuellen Tab\n");
        fprintf(fp,"-reconnect          = &Reconnect\n");
        fprintf(fp,"-save_as_bmp        = &Speichere als BMP ...\n");
        fprintf(fp,"-log_as_bmp         = Logge Metafiles als &BMP ...\n");
        fprintf(fp,"-log_as_pvm         = Logge Metafiles als P&VM ...\n");
        fprintf(fp,"-print              = &Drucken\n");
        fprintf(fp,"-exit               = Schli&essen\n");
        fprintf(fp,"-edit               = &Bearbeiten\n");
        fprintf(fp,"-copy               = &Kopieren\n");
        fprintf(fp,"-copy_plus_title    = Ko&pieren mit Titel\n");
        fprintf(fp,"-view               = &Ansicht\n");
        fprintf(fp,"-help               = &Hilfe\n");
        fprintf(fp,"-toolbar            = &Werkzeugleiste\n");
        fprintf(fp,"-statusbar          = &Statuszeile\n");
        fprintf(fp,"-maximized          = &Maximiert\n");
        fprintf(fp,"-fullscreen         = &Vollbildmodus\n");
        fprintf(fp,"-Manual             = &Manual\n");
        fprintf(fp,"-about              = &About ...\n");
        fprintf(fp,"-status_connection_lost    = Verbindung zu Server verloren, CTRL-R fuer erneute Verbindung\n");
        fprintf(fp,"-status_connected          = Verbunden mit Server\n");
        fprintf(fp,"-status_could_not_connect  = Konnte nicht mit Server verbinden, CTRL-R fuer erneute Verbindung\n");
        fprintf(fp,"-status_reconnect          = Erneut mit host verbinden\n");
        fprintf(fp,"-status_options            = Ansehen/Ändern der ProcessViewBrowser Optionen\n");
        fprintf(fp,"-status_new_window         = Öffnet ein neues ProcessViewBrowser Fenster\n");
        fprintf(fp,"-status_new_tab            = Öffnet einen neuen Tab\n");
        fprintf(fp,"-status_save_as_bmp        = Speichert den aktuellen Bildschirm als BMP Datei\n");
        fprintf(fp,"-status_log_as_bmp         = Logge QDrawWidgets als BMP Datei\n");
        fprintf(fp,"-status_log_as_pvm         = Logge QDrawWidgets als PVM Datei\n");
        fprintf(fp,"-status_print              = Druckt den aktuellen Bildschirm\n");
        fprintf(fp,"-status_exit               = Schliesst pvbrowser\n");
        fprintf(fp,"-status_copy               = Kopiere den aktuellen Bildschirm in die Zwischenablage\n");
        fprintf(fp,"-status_toolbar            = Werkzeugleiste (an/aus)\n");
        fprintf(fp,"-status_statusbar          = Statuszeile (an/aus)\n");
        fprintf(fp,"-status_toggle_full_screen = Vollbildmodus (an/aus)\n");
        fprintf(fp,"-status_manual             = Anwendungsspezifische Hilfe\n");
        fprintf(fp,"-status_about              = Aboutbox anzeigen\n");
        fprintf(fp,"-print_header              = Gedruckt von pvbrowser am: \n");
        fprintf(fp,"}\n");
        fprintf(fp,"#---------------------------------------\n");
        fprintf(fp,"french {\n");
        fprintf(fp,"-file               = Fichier\n");
        fprintf(fp,"-options            = Option\n");
        fprintf(fp,"-new_window         = Nouvelle Fenêtre\n");
        fprintf(fp,"-new_tab            = Nouvelle &Tab\n");
        fprintf(fp,"-reconnect          = Reconnection\n");
        fprintf(fp,"-save_as_bmp        = Sauvegarder en BMP ...\n");
        fprintf(fp,"-log_as_bmp         = Enregistrer en BMP ...\n");
        fprintf(fp,"-log_as_pvm         = Enregistrer en PVM ...\n");
        fprintf(fp,"-print              = Imprimer\n");
        fprintf(fp,"-exit               = Sortir\n");
        fprintf(fp,"-edit               = éditer\n");
        fprintf(fp,"-copy               = Copier\n");
        fprintf(fp,"-copy_plus_title    = Copier + title\n");
        fprintf(fp,"-view               = Voir\n");
        fprintf(fp,"-toolbar            = Bare d'outil\n");
        fprintf(fp,"-statusbar          = Bare d'état\n");
        fprintf(fp,"-toggle_full_screen = Permuter la grandeur de fenêtre\n");
        fprintf(fp,"-help               = Aide\n");
        fprintf(fp,"-booklet            = Livret\n");
        fprintf(fp,"-manual             = Manuel\n");
        fprintf(fp,"-about              = à propos\n");
        fprintf(fp,"-recent_urls        = Dernier sites visité\n");
        fprintf(fp,"-status_connection_lost   = Connexion perdu, Faire CTRL-R pour reconnecter en local\n");
        fprintf(fp,"-status_connected         = Connexion\n");
        fprintf(fp,"-status_could_not_connect = Ne peut pas connecter, faire CTRL-R pour reconnecter local\n");
        fprintf(fp,"-status_options     = Options\n");
        fprintf(fp,"-status_new_window  = Nouvelle fenêtre\n");
        fprintf(fp,"-status_save_as_bmp = Sauvegarder au BMP\n");
        fprintf(fp,"-status_log_as_bmp  = QDrawWidgets est enregistrer au BMP\n");
        fprintf(fp,"-status_log_as_pvm  = QDrawWidgets est enregistrer au PVM\n");
        fprintf(fp,"-status_print       = Imprimer\n");
        fprintf(fp,"-status_exit        = Sortie de ProcessViewBrowser\n");
        fprintf(fp,"-status_copy        = Copie\n");
        fprintf(fp,"-status_toolbar     = Bare d'outil\n");
        fprintf(fp,"-status_statusbar   = bare d'état\n");
        fprintf(fp,"-status_toggle_full_screen = Permuter mode pleine écran\n");
        fprintf(fp,"-status_booklet     = Livret sur ProcessViewServer\n");
        fprintf(fp,"-status_manual      = Documentation de ProcessViewServer\n");
        fprintf(fp,"-status_about       = à propos\n");
        fprintf(fp,"-print_header       = Imprimer avec pvbrowser\n");
        fprintf(fp,"}\n");
        fprintf(fp,"#---------------------------------------\n");
        fprintf(fp,"spanish {\n");
        fprintf(fp,"-file               = &Fichero\n");
        fprintf(fp,"-options            = &Opciones\n");
        fprintf(fp,"-new_window         = &Nueva Ventana\n");
        fprintf(fp,"-new_tab            = Nueva &Tab\n");
        fprintf(fp,"-reconnect          = &Reconectar\n");
        fprintf(fp,"-save_as_bmp        = &Guardar como BMP...\n");
        fprintf(fp,"-log_as_bmp         = Log Metafiles como &BMP...\n");
        fprintf(fp,"-log_as_pvm         = Log Metafiles como P&VM...\n");
        fprintf(fp,"-print              = &Imprimir\n");
        fprintf(fp,"-exit               = &Salir\n");
        fprintf(fp,"-edit               = &Editar\n");
        fprintf(fp,"-copy               = &Copiar\n");
        fprintf(fp,"-copy_plus_title    = Co&piar + title\n");
        fprintf(fp,"-view               = &Ver\n");
        fprintf(fp,"-toolbar            = &Barra Herramientas\n");
        fprintf(fp,"-statusbar          = &Barra Estado\n");
        fprintf(fp,"-toggle_full_screen = Pantalla Completa (On/Off)\n");
        fprintf(fp,"-help               = &Ayuda\n");
        fprintf(fp,"-booklet            = &Manuales\n");
        fprintf(fp,"-manual             = &Documentación...\n");
        fprintf(fp,"-about              = &Acerca de...\n");
        fprintf(fp,"-recent_urls        = URLs Recientes\n");
        fprintf(fp,"-status_connection_lost   = Conexión al Servidor perdida, CTRL-R para reconecta\n");
        fprintf(fp,"-status_connected         = Conectado al Servidor\n");
        fprintf(fp,"-status_reconnect   = Reconectar al Servidor\n");
        fprintf(fp,"-status_could_not_connect = No se pudo conectar al Servidor, CTRL-R para reconectar\n");
        fprintf(fp,"-status_options     = Ver/Cambiar las Opciones ProcessViewBrowser\n");
        fprintf(fp,"-status_new_window  = Abrir nueva ventana de ProcessViewBrowser\n");
        fprintf(fp,"-status_save_as_bmp = Guardar pantalla actual como fichero BMP\n");
        fprintf(fp,"-status_log_as_bmp  = Logge QDrawWidgets como fichero BMP\n");
        fprintf(fp,"-status_log_as_pvm  = Logge QDrawWidgets como fichero PVM\n");
        fprintf(fp,"-status_print       = Imprimir la pantalla actual\n");
        fprintf(fp,"-status_exit        = Salir de ProcessViewBrowser\n");
        fprintf(fp,"-status_copy        = Copiar la pantalla al Portapapeles\n");
        fprintf(fp,"-status_toolbar     = Barra de Herramientas (On/Off)\n");
        fprintf(fp,"-status_statusbar   = Barra de Estado (On/Off)\n");
        fprintf(fp,"-status_toggle_full_screen = Pantalla Completa (On/Off)\n");
        fprintf(fp,"-status_booklet     = Mostrar ProcessViewServer Manual\n");
        fprintf(fp,"-status_manual      = Mostrar ProcessViewServer Documentación\n");
        fprintf(fp,"-status_about       = Acerca de...\n");
        fprintf(fp,"-print_header       = Impreso desde ProcessViewBrowser\n");
        fprintf(fp,"}\n");
        fprintf(fp,"#---------------------------------------\n");
        fprintf(fp,"italian {\n");
        fprintf(fp,"-file               = &File\n");
        fprintf(fp,"-options            = &Opzioni\n");
        fprintf(fp,"-new_window         = &Nuova Finestra\n");
        fprintf(fp,"-new_tab            = Nuovo &Tab\n");
        fprintf(fp,"-reconnect          = &Riconnessione\n");
        fprintf(fp,"-save_as_bmp        = &Salva come BMP...\n");
        fprintf(fp,"-log_as_bmp         = Log come &BMP...\n");
        fprintf(fp,"-log_as_pvm         = Log come P&VM...\n");
        fprintf(fp,"-print              = Sta&mpa\n");
        fprintf(fp,"-exit               = &Esci\n");
        fprintf(fp,"-edit               = &Modifica\n");
        fprintf(fp,"-copy               = &Copia\n");
        fprintf(fp,"-view               = &Visualizza\n");
        fprintf(fp,"-toolbar            = &Barra dei tool\n");
        fprintf(fp,"-maximized          = &Massimizza\n");
        fprintf(fp,"-statusbar          = &Barra di stato\n");
        fprintf(fp,"-toggle_full_screen = Schermo Completo (On/Off)\n");
        fprintf(fp,"-help               = &Aiuto\n");
        fprintf(fp,"-booklet            = &Manuali\n");
        fprintf(fp,"-manual             = &Documentazione...\n");
        fprintf(fp,"-about              = &Informazioni su...\n");
        fprintf(fp,"-recent_urls        = URLs Recenti\n");
        fprintf(fp,"-status_connection_lost   = Connessione col Server persa, CTRL-R per riconnettere\n");
        fprintf(fp,"-status_connected         = Connesso al Server\n");
        fprintf(fp,"-status_reconnect         = Reconnettere col Server\n");
        fprintf(fp,"-status_could_not_connect = Connessione col servere fallita, CTRL-R per riconnettere\n");
        fprintf(fp,"-status_options     = Vedere/Modificare le Opzioni di ProcessViewBrowser\n");
        fprintf(fp,"-status_new_window  = Aprire nuova finestra di ProcessViewBrowser\n");
        fprintf(fp,"-status_save_as_bmp = Salvare la schermata attuale come file BMP\n");
        fprintf(fp,"-status_log_as_bmp  = Registrando QDrawWidgets come file BMP\n");
        fprintf(fp,"-status_log_as_pvm  = Registrando QDrawWidgets come file PVM\n");
        fprintf(fp,"-status_print       = Stampare la schermata attuale\n");
        fprintf(fp,"-status_exit        = Uscita da ProcessViewBrowser\n");
        fprintf(fp,"-status_copy        = Copia\n");
        fprintf(fp,"-status_toolbar     = Barra dei Tools (On/Off)\n");
        fprintf(fp,"-status_statusbar   = Barra di Stato (On/Off)\n");
        fprintf(fp,"-status_toggle_full_screen = A Tutto schermo (On/Off)\n");
        fprintf(fp,"-status_booklet     = Visualizza il Manuale di ProcessViewServer\n");
        fprintf(fp,"-status_manual      = Visualizza la Documentazione di ProcessViewServer\n");
        fprintf(fp,"-status_about       = Informazioni su...\n");
        fprintf(fp,"-print_header       = Stampato da ProcessViewBrowser\n");
        fprintf(fp,"}\n");
        fprintf(fp,"\n");
        fprintf(fp,"chinese {\n");
        fprintf(fp,"-file               = &文件\n");
        fprintf(fp,"-options            = &选项\n");
        fprintf(fp,"-new_window         = &新建窗口\n");
        fprintf(fp,"-new_tab            = &新建标签\n");
        fprintf(fp,"-delete_tab         = 关闭当前标签\n");
        fprintf(fp,"-reconnect          = &重新连接\n");
        fprintf(fp,"-save_as_bmp        = &保存为BMP格式 ...\n");
        fprintf(fp,"-log_as_bmp         = &作为BMP图元文件记录 ...?\n");
        fprintf(fp,"-log_as_pvm         = &作为VMP图元文件记录 ...?\n");
        fprintf(fp,"-print              = &打印\n");
        fprintf(fp,"-exit               = &退出\n");
        fprintf(fp,"-edit               = &编辑\n");
        fprintf(fp,"-copy               = &复制\n");
        fprintf(fp,"-copy_plus_title    = &复制(加标题)\n");
        fprintf(fp,"-view               = &查看\n");
        fprintf(fp,"-help               = &帮助\n");
        fprintf(fp,"-toolbar            = &工具栏\n");
        fprintf(fp,"-statusbar          = &状态栏\n");
        fprintf(fp,"-maximized          = &最大化\n");
        fprintf(fp,"-fullscreen         = &全屏\n");
        fprintf(fp,"-Manual             = &帮助手册(手动?)\n");
        fprintf(fp,"-about              = &关于 ...\n");
        fprintf(fp,"-status_connection_lost    = 状态_连接服务器丢失,“CTRL-R”为重新连接\n");
        fprintf(fp,"-status_connected          = 状态_服务器已连接\n");
        fprintf(fp,"-status_could_not_connect  = 状态_无法连接到服务器,“CTRL-R”为重新连接\n");
        fprintf(fp,"-status_reconnect          = 状态_重新连接\n");
        fprintf(fp,"-status_options            = 状态_查看/更改浏览器选项\n");
        fprintf(fp,"-status_new_window         = 状态_打开一个新的浏览器窗口\n");
        fprintf(fp,"-status_new_tab            = 状态_打开一个新标签\n");
        fprintf(fp,"-status_save_as_bmp        = 状态_将当前屏幕保存为BMP文件\n");
        fprintf(fp,"-status_log_as_bmp         = 状态_作为BMP图元文件记录\n");
        fprintf(fp,"-status_log_as_pvm         = 状态_作为PVM图元文件记录\n");
        fprintf(fp,"-status_print              = 状态_打印当前屏幕\n");
        fprintf(fp,"-status_exit               = 状态_关闭pvbrowser\n");
        fprintf(fp,"-status_copy               = 状态_将当前屏幕复制到剪切板\n");
        fprintf(fp,"-status_toolbar            = 状态_工具栏(开/关)\n");
        fprintf(fp,"-status_statusbar          = 状态_状态栏(开/关)\n");
        fprintf(fp,"-status_toggle_full_screen = 状态_全屏模式(开/关)\n");
        fprintf(fp,"-status_manual             = 状态_特殊应用帮助\n");
        fprintf(fp,"-status_about              = 状态_显示\"关于\"\n");
        fprintf(fp,"-print_header              = 状态_打印标题\n");
        fprintf(fp,"}\n");
        fprintf(fp,"# other languages\n");
        fprintf(fp,"##################################################################\n");
        fprintf(fp,"#\n");
        fprintf(fp,"# End of Language settings for pvbrowser\n");
        fprintf(fp,"#\n");
        fprintf(fp,"##################################################################\n");
        fprintf(fp,"#\n");
        fprintf(fp,"# This is the list of recent nodes you have visited\n");
        fprintf(fp,"host=pv://localhost\n");
        fclose(fp);
      }
      else
      {
        return "Could not write initialization file";
      }
    }
  }
}
Ejemplo n.º 27
0
void MyTextBrowser::slotLinkClicked(const QUrl &link)
{
  char buf[MAX_PRINTF_LENGTH];
  QString url;
  int i;

  url = link.toString();

  // replace "href=\"//awite://" by "href=/"
  while(1)
  {
    i = url.indexOf("awite://");
    if(i < 0) break;
    url = url.replace(i,8,"/");
    if(opt.arg_debug) printf("MyTextBrowser::slotLinkClicked::link clicked = %s\n", (const char *) url.toUtf8());
  }

  if(opt.arg_debug) printf("slotLinkClicked(%s)\n", (const char *) url.toUtf8());
  if(url.startsWith("http://") && (url.endsWith(".pdf") || url.endsWith(".PDF")))
  {
    QString cmd = opt.view_pdf;
    cmd += " ";
    url.replace(" ","%20");
    cmd += url;
//#ifndef PVWIN32
//    cmd +=  " &";
//#endif
    mysystem(cmd.toUtf8());
  }
  else if(
         !url.startsWith("http://audio.") &&
          url.startsWith("http://") && (
          url.endsWith(".mp3",  Qt::CaseInsensitive) || 
          url.endsWith(".ogg",  Qt::CaseInsensitive) || 
          url.endsWith(".m3u",  Qt::CaseInsensitive) || 
          url.endsWith(".asx",  Qt::CaseInsensitive) || 
          url.contains(".pls?", Qt::CaseInsensitive) ||
          url.contains("mp3e",  Qt::CaseInsensitive) ||
          url.startsWith("http://www.youtube.com/watch?") ))
  {
    QString cmd = opt.view_audio;
    cmd += " ";
    url.replace(" ","%20");
    cmd += url;
//#ifndef PVWIN32
//    cmd +=  " &";
//#endif
    mysystem(cmd.toUtf8());
  }
  else if(
         !url.startsWith("http://video.") &&
          url.startsWith("http://") && (
          url.endsWith(".mp4",  Qt::CaseInsensitive) || 
          url.endsWith(".mov",  Qt::CaseInsensitive) || 
          url.endsWith(".ogv",  Qt::CaseInsensitive) || 
          url.endsWith(".avi",  Qt::CaseInsensitive) ))
  {
    QString cmd = opt.view_video;
    cmd += " ";
    url.replace(" ","%20");
    cmd += url;
//#ifndef PVWIN32
//    cmd +=  " &";
//#endif
    mysystem(cmd.toUtf8());
  }
  else
  {
    if(url.length()+40 > MAX_PRINTF_LENGTH) return;
    sprintf(buf,"text(%d,\"%s\")\n", id,decode(url));
    tcp_send(s,buf,strlen(buf));
#ifdef NO_WEBKIT
    if     (url.startsWith("http:"))  setSource(QUrl(url));
    else if(url.startsWith("https:")) setSource(QUrl(url));
    else if(!url.contains("://"))     setSource(QUrl(url));
#else    
    load(link);
#endif    
  }  
}
Ejemplo n.º 28
0
int
main(int argc, char *argv[])
{
	int ch, debug, i, magic, n, nargs, rval;
	char buf[4], *cmd, *p;

	if (pledge("stdio proc exec", NULL) == -1)
		err(1, "pledge");

	debug = 0;
	magic = '%';		/* Default magic char is `%'. */
	nargs = -1;
	while ((ch = getopt(argc, argv, "a:d0123456789")) != -1)
		switch (ch) {
		case 'a':
			if (optarg[0] == '\0' || optarg[1] != '\0')
				errx(1,
				    "illegal magic character specification.");
			magic = optarg[0];
			break;
		case 'd':
			debug = 1;
			break;
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			if (nargs != -1)
				errx(1,
				    "only one -# argument may be specified.");
			nargs = ch - '0';
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (argc < 2)
		usage();

	/*
	 * The command to run is argv[0], and the args are argv[1..].
	 * Look for %digit references in the command, remembering the
	 * largest one.
	 */
	for (n = 0, p = argv[0]; *p != '\0'; ++p)
		if (ISMAGICNO(p)) {
			++p;
			if (p[0] - '0' > n)
				n = p[0] - '0';
		}

	/*
	 * If there were any %digit references, then use those, otherwise
	 * build a new command string with sufficient %digit references at
	 * the end to consume (nargs) arguments each time round the loop.
	 * Allocate enough space to hold the maximum command.
	 */
	strset(argv[0]);
	if (n == 0) {
		/* If nargs not set, default to a single argument. */
		if (nargs == -1)
			nargs = 1;

		for (i = 1; i <= nargs; i++) {
			snprintf(buf, sizeof(buf), " %c%d", magic, i);
			stradd(buf);
		}

		/*
		 * If nargs set to the special value 0, eat a single
		 * argument for each command execution.
		 */
		if (nargs == 0)
			nargs = 1;
	} else
		nargs = n;
	if ((cmd = strdup(str)) == NULL)
		err(1, "strdup");

	/*
	 * (argc) and (argv) are still offset by one to make it simpler to
	 * expand %digit references.  At the end of the loop check for (argc)
	 * equals 1 means that all the (argv) has been consumed.
	 */
	for (rval = 0; argc > nargs; argc -= nargs, argv += nargs) {
		strset("exec ");

		/* Expand command argv references. */
		for (p = cmd; *p != '\0'; ++p)
			if (ISMAGICNO(p))
				stradd(argv[*(++p) - '0']);
			else {
				strlcpy(buf, p, 2);
				stradd(buf);
			}

		/* Run the command. */
		if (debug)
			(void)printf("%s\n", str);
		else if (mysystem(str))
			rval = 1;
	}

	if (argc != 1)
		errx(1, "expecting additional argument%s after \"%s\"",
		    (nargs - argc) ? "s" : "", argv[argc - 1]);
	exit(rval);
}
Ejemplo n.º 29
0
int handledhcp(void)
{
	char *results[MAX_BOXES];
	char enabledresult;
	char startenabled;
	struct newtExitStruct es;
	newtComponent header;
	newtComponent labels[MAX_BOXES];
	newtComponent ok, cancel;	
	char message[1000];
	char *labeltexts[MAX_BOXES] = {
		_("Start address:"),
		_("End address:"),
		_("Primary DNS:"),
		_("Secondary DNS:"),
		_("Default lease (mins):"),
		_("Max lease (mins):"),
		_("Domain name suffix:")
	};
	char *varnames[MAX_BOXES] = {
		"START_ADDR_GREEN",
		"END_ADDR_GREEN",
		"DNS1_GREEN",
		"DNS2_GREEN",
		"DEFAULT_LEASE_TIME_GREEN",
		"MAX_LEASE_TIME_GREEN",
		"DOMAIN_NAME_GREEN"
	};
	char defaults[MAX_BOXES][STRING_SIZE]; 
	int result;
	int c;
	char temp[STRING_SIZE];
	struct keyvalue *mainkv = initkeyvalues();
	struct keyvalue *dhcpkv = initkeyvalues();
	struct keyvalue *ethernetkv = initkeyvalues();
	int error;
	FILE *file;
	char greenaddress[STRING_SIZE];	
	char greennetaddress[STRING_SIZE];
	char greennetmask[STRING_SIZE];
	
 	memset(defaults, 0, sizeof(char) * STRING_SIZE * MAX_BOXES);
	
	if (!(readkeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings")))
	{
		freekeyvalues(dhcpkv);
		freekeyvalues(ethernetkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}
	if (!(readkeyvalues(ethernetkv, CONFIG_ROOT "/ethernet/settings")))
	{
		freekeyvalues(dhcpkv);
		freekeyvalues(ethernetkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}
	if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
	{
		freekeyvalues(dhcpkv);
		freekeyvalues(ethernetkv);
		freekeyvalues(mainkv);
		errorbox(_("Unable to open settings file"));
		return 0;
	}

	/* Set default values. */	
	findkey(ethernetkv, "GREEN_ADDRESS", defaults[PRIMARY_DNS]);
	findkey(mainkv, "DOMAINNAME", defaults[DOMAIN_NAME_SUFFIX]);
	strcpy(defaults[DEFAULT_LEASE_TIME], "60");
	strcpy(defaults[MAX_LEASE_TIME], "120");

	newtCenteredWindow(55, 18, _("DHCP server configuration"));

	dhcpform = newtForm(NULL, NULL, 0);

	header = newtTextboxReflowed(1, 1,
		_("Configure the DHCP server by entering the settings information."),
		52, 0, 0, 0);
	newtFormAddComponent(dhcpform, header);

	strcpy(temp, ""); findkey(dhcpkv, "ENABLE_GREEN", temp);
	if (strcmp(temp, "on") == 0)
		startenabled = '*';
	else
		startenabled = ' ';
	enabledcheckbox = newtCheckbox(2, TOP + 0, _("Enabled"), startenabled, " *", &enabledresult);
	newtFormAddComponent(dhcpform, enabledcheckbox);
	newtComponentAddCallback(enabledcheckbox, dhcpdialogcallbackdhcp, NULL);		

	for (c = 0; c < MAX_BOXES; c++)
	{
		labels[c] = newtTextbox(2, TOP + 2 + c, 33, 1, 0);
		newtTextboxSetText(labels[c], labeltexts[c]);
		newtFormAddComponent(dhcpform, labels[c]);				
		strcpy(temp, defaults[c]); findkey(dhcpkv, varnames[c], temp);
		entries[c] = newtEntry(34, TOP + 2 + c, temp, 18, &results[c], 0);
		newtFormAddComponent(dhcpform, entries[c]);		
		if (startenabled == ' ')
			newtEntrySetFlags(entries[c], NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);			
		
	}
	
	ok = newtButton(10, c + 7, _("OK"));
	cancel = newtButton(34, c + 7, _("Cancel"));

	newtFormAddComponents(dhcpform, ok, cancel, NULL);
	
	do {
		error = 0;
		newtFormRun(dhcpform, &es);
	
		if (es.u.co == ok)
		{
			/* OK was pressed; verify the contents of each entry. */		
			if (enabledresult == '*')
			{
				strcpy(message, _("The following fields are invalid:\n\n"));
				if (inet_addr(results[START_ADDRESS]) == INADDR_NONE)
				{
					strcat(message, _("Start address"));
					strcat(message, "\n");
					error = 1;
				}
				if (inet_addr(results[END_ADDRESS]) == INADDR_NONE)
				{
					strcat(message, _("End address"));
					strcat(message, "\n");
					error = 1;
				}
				if (strlen(results[SECONDARY_DNS]))
				{
					if (inet_addr(results[PRIMARY_DNS]) == INADDR_NONE)
					{
						strcat(message, _("Primary DNS"));
						strcat(message, "\n");
						error = 1;
					}
				}
				if (strlen(results[SECONDARY_DNS]))
				{
					if (inet_addr(results[SECONDARY_DNS]) == INADDR_NONE)
					{
						strcat(message, _("Secondary DNS"));
						strcat(message, "\n");
						error = 1;
					}
				}
				if (!(atol(results[DEFAULT_LEASE_TIME])))
				{
					strcat(message, _("Default lease time"));
					strcat(message, "\n");
					error = 1;
				}
				if (!(atol(results[MAX_LEASE_TIME])))
				{
					strcat(message, _("Max. lease time"));
					strcat(message, "\n");
					error = 1;
				}
			}				
			
			if (error)
				errorbox(message);
			else
			{
				for (c = 0; c < MAX_BOXES; c++)
					replacekeyvalue(dhcpkv, varnames[c], results[c]);
				if (enabledresult == '*')
				{
					replacekeyvalue(dhcpkv, "ENABLE_GREEN", "on");
					fclose(fopen(CONFIG_ROOT "/dhcp/enable_green", "w"));
					chown(CONFIG_ROOT "/dhcp/enable_green", 99, 99);
					mysystem(NULL, "/usr/local/bin/dhcpctrl enable");
				}
				else
				{
					replacekeyvalue(dhcpkv, "ENABLE_GREEN", "off");
					unlink(CONFIG_ROOT "/dhcp/enable_green");
					mysystem(NULL, "/usr/local/bin/dhcpctrl disable");
				}
				replacekeyvalue(dhcpkv, "VALID", "yes");
				writekeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings");
				
				findkey(ethernetkv, "GREEN_ADDRESS", greenaddress);				
				findkey(ethernetkv, "GREEN_NETADDRESS", greennetaddress);
				findkey(ethernetkv, "GREEN_NETMASK", greennetmask);
			
				file = fopen(CONFIG_ROOT "/dhcp/dhcpd.conf", "w");
				fprintf(file, "ddns-update-style none;\n");
				fprintf(file, "authoritative;\n");
				fprintf(file, "subnet %s netmask %s\n", greennetaddress, greennetmask);
				fprintf(file, "{\n");
				fprintf(file, "\toption subnet-mask %s;\n", greennetmask);
				fprintf(file, "\toption domain-name \"%s\";\n", results[DOMAIN_NAME_SUFFIX]);		
				fprintf(file, "\toption routers %s;\n", greenaddress);
				if (strlen(results[PRIMARY_DNS]))
				{
					fprintf(file, "\toption domain-name-servers ");
					fprintf(file, "%s", results[PRIMARY_DNS]);
					if (strlen(results[SECONDARY_DNS]))
						fprintf(file, ", %s", results[SECONDARY_DNS]);
					fprintf(file, ";\n");
				}
				
				fprintf(file, "\trange %s %s;\n",	results[START_ADDRESS], results[END_ADDRESS]);
				fprintf(file, "\tdefault-lease-time %d;\n", (int) atol(results[DEFAULT_LEASE_TIME]) * 60);
				fprintf(file, "\tmax-lease-time %d;\n",	(int) atol(results[MAX_LEASE_TIME]) * 60);
				fprintf(file, "}\n");
				fclose(file);
				chown(CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
				if (automode == 0)
					mysystem(NULL, "/usr/local/bin/dhcpctrl enable");
			}
			result = 1;
		}
		else
			result = 0;
	} while (error);
	
	newtFormDestroy(dhcpform);
	newtPopWindow();
	
	freekeyvalues(dhcpkv);
	freekeyvalues(ethernetkv);
	freekeyvalues(mainkv);
	
	return result;
}
Ejemplo n.º 30
0
int main(){
	char command[] = "/bin/ls /home";
	mysystem(command);
	return 0;
}