📄 upgrade-v130-v140.c
字号:
/* * This file is part of the IPCop Firewall. * * IPCop 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. * * IPCop 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 IPCop; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Copyright 2002: Mark Wormgoor <mark@wormgoor.com> * * $Id: upgrade-v130-v140.c,v 1.12.2.35 2004/11/11 09:40:03 alanh Exp $ * */#include "install.h"extern char **ctr; int _handledomainname(void){ char domainname[STRING_SIZE] = "localdomain"; struct keyvalue *kv = initkeyvalues(); char *values[] = { domainname, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { "", &values[0], 0,}, { NULL, NULL, 0 } }; int rc; int result; if (!(readkeyvalues(kv, "/harddisk" CONFIG_ROOT "/main/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } findkey(kv, "DOMAINNAME", domainname); /* already have a domainname */ if (strlen(domainname)) return 0; for (;;) { rc = newtWinEntries(ctr[TR_DOMAINNAME], ctr[TR_ENTER_DOMAINNAME], 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 1) { strcpy(domainname, values[0]); if (strchr(domainname, ' ')) errorbox(ctr[TR_DOMAINNAME_CANNOT_CONTAIN_SPACES]); else { replacekeyvalue(kv, "DOMAINNAME", domainname); writekeyvalues(kv, "/harddisk" CONFIG_ROOT "/main/settings"); result = 1; break; } } else { result = 0; break; } } free(values[0]); freekeyvalues(kv); return result;} int _add_logwatch_user() { mysystem("/bin/chroot /harddisk /usr/sbin/userdel logwatch"); mysystem("/bin/chroot /harddisk /usr/sbin/groupdel logwatch"); mysystem("/bin/chroot /harddisk /usr/sbin/groupadd -g 102 logwatch"); mysystem("/bin/chroot /harddisk /usr/sbin/useradd -u 102 -g logwatch -d /var/log/logwatch -s /bin/false logwatch"); return 0;}int _fixsquid() { FILE *squidreadfile; FILE *squidwritefile; FILE *aclreadfile; char hostname[STRING_SIZE] = ""; char domainname[STRING_SIZE] = ""; char squidtemp[STRING_SIZE]; struct keyvalue *kv = initkeyvalues(); int already_upgraded = 0; int updated = 0; if (!(squidreadfile = fopen ("/harddisk" CONFIG_ROOT "/proxy/squid.conf", "r"))) return 1; if (!(squidwritefile = fopen ("/harddisk" CONFIG_ROOT "/proxy/squid.conf.new", "w"))) { fclose(squidreadfile); return 1; } if (!(readkeyvalues(kv, "/harddisk" CONFIG_ROOT "/main/settings"))) { fclose (squidwritefile); fclose (squidreadfile); freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 1; } findkey(kv, "HOSTNAME", hostname); findkey(kv, "DOMAINNAME", domainname); freekeyvalues(kv); while (fgets (squidtemp, STRING_SIZE, squidreadfile) != NULL) { /* this will fail if we've already been upgraded, which is ok */ if (!strncmp(squidtemp, "reply_body_max_size 0 KB", 24)) { sprintf(squidtemp, "reply_body_max_size 0 allow all\n"); } if (!strncmp(squidtemp, "cache_store_log /var/log/squid/store.log", 40)) { sprintf(squidtemp, "cache_store_log none\n"); } fputs(squidtemp, squidwritefile); /* so for us developers we skip already upgraded squiddies */ if (!strncmp(squidtemp, "visible_hostname", 16)) { already_upgraded = 1; } /* Check for the new acl's */ if (!strncmp(squidtemp, "__GREEN_IP__", 12)) { updated = 1; } } if (!already_upgraded) { sprintf(squidtemp, "visible_hostname %s.%s\n", hostname, domainname); fputs(squidtemp, squidwritefile); } fclose (squidwritefile); fclose (squidreadfile); rename ("/harddisk" CONFIG_ROOT "/proxy/squid.conf.new", "/harddisk" CONFIG_ROOT "/proxy/squid.conf"); replace("/harddisk" CONFIG_ROOT "/proxy/squid.conf", "cache_dir ufs", "cache_dir aufs"); if (!updated) { rename ("/harddisk" CONFIG_ROOT "/proxy/acl", "/harddisk" CONFIG_ROOT "/proxy/acl.old"); rename ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4", "/harddisk" CONFIG_ROOT "/proxy/acl"); } else { if (!(aclreadfile = fopen ("/harddisk" CONFIG_ROOT "/proxy/acl", "r"))) { rename ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4", "/harddisk" CONFIG_ROOT "/proxy/acl"); } else { unlink ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4"); fclose(aclreadfile); } } chown ("/harddisk" CONFIG_ROOT "/proxy/squid.conf", 99, 99); chown ("/harddisk" CONFIG_ROOT "/proxy/acl", 99, 99); return 0;}int _fixeagleusb() { FILE *eaglereadfile; FILE *eaglewritefile; char eagletemp[STRING_SIZE]; int already_upgraded = 0; if (!(eaglereadfile = fopen ("/harddisk" CONFIG_ROOT "/eagle-usb/eagle-usb.conf", "r"))) return 1; if (!(eaglewritefile = fopen ("/harddisk" CONFIG_ROOT "/eagle-usb/eagle-usb.conf.new", "w"))) { fclose(eaglereadfile); return 1; } while (fgets (eagletemp, STRING_SIZE, eaglereadfile) != NULL) { /* so for us developers we skip already upgraded configs */ if (!strncmp(eagletemp, "<eaglectrl>", 11)) { already_upgraded = 1; } } rewind(eaglereadfile); if (!already_upgraded) fprintf(eaglewritefile, "<eaglectrl>\n"); while (fgets (eagletemp, STRING_SIZE, eaglereadfile) != NULL) fputs(eagletemp, eaglewritefile); if (!already_upgraded) fprintf(eaglewritefile, "</eaglectrl>\n"); fclose (eaglewritefile); fclose (eaglereadfile); rename ("/harddisk" CONFIG_ROOT "/eagle-usb/eagle-usb.conf.new", "/harddisk" CONFIG_ROOT "/eagle-usb/eagle-usb.conf"); replace("/harddisk" CONFIG_ROOT "/eagle-usb/eagle-usb.conf", "Linetype=00000001", "Linetype=0A"); chown ("/harddisk" CONFIG_ROOT "/eagle-usb/eagle-usb.conf", 99, 99); unlink("/harddisk" CONFIG_ROOT "/eagle-usb/dsp_code_pots.bin"); unlink("/harddisk" CONFIG_ROOT "/eagle-usb/dsp_code_isdn.bin"); return 0;}int _fixdhcp_30() { FILE *dhcpreadfile; FILE *dhcpwritefile; char dhcptemp[STRING_SIZE]; if (!(dhcpreadfile = fopen ("/harddisk" CONFIG_ROOT "/dhcp/dhcpd.conf", "r"))) return 1; if (!(dhcpwritefile = fopen ("/harddisk" CONFIG_ROOT "/dhcp/dhcpd.conf.new", "w"))) { fclose(dhcpreadfile); return 1; } fprintf (dhcpwritefile, "authoritative;\n"); fprintf (dhcpwritefile, "deny bootp;\n"); fprintf (dhcpwritefile, "ddns-update-style none;\n"); while (fgets (dhcptemp, STRING_SIZE, dhcpreadfile) != NULL) { int write = 1; /* so for us developers we skip already upgraded dhcp files */ if (!strncmp(dhcptemp, "authoritative", 13)) { write = 0; } /* so for us developers we skip already upgraded dhcp files */ if (!strncmp(dhcptemp, "ddns-update-style", 17)) { write = 0; } /* so for us developers we skip already upgraded dhcp files */ if (!strncmp(dhcptemp, "deny bootp", 10)) { write = 0; } if (write) fputs(dhcptemp, dhcpwritefile); } fclose(dhcpreadfile); fclose(dhcpwritefile); rename ("/harddisk" CONFIG_ROOT "/dhcp/dhcpd.conf.new", "/harddisk" CONFIG_ROOT "/dhcp/dhcpd.conf"); chown ("/harddisk" CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99); /* This one will get converted again furthur down */ replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "WINS=", "WINS1="); replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "START_ADDR=", "START_ADDR_GREEN="); replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "END_ADDR=", "END_ADDR_GREEN="); replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "DOMAIN_NAME=", "DOMAIN_NAME_GREEN="); replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "DEFAULT_LEASE_TIME=", "DEFAULT_LEASE_TIME_GREEN="); replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "MAX_LEASE_TIME=", "MAX_LEASE_TIME_GREEN="); replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "DNS1=", "DNS1_GREEN="); replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "DNS2=", "DNS2_GREEN="); replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "WINS1=", "WINS1_GREEN="); replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "WINS2=", "WINS2_GREEN="); replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "ENABLE=", "ENABLE_GREEN="); replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "range dynamic-bootp", "range"); chown ("/harddisk" CONFIG_ROOT "/dhcp/settings", 99, 99); if ((dhcpreadfile = fopen ("/harddisk" CONFIG_ROOT "/dhcp/enable", "r"))) { fclose(dhcpreadfile); rename ("/harddisk" CONFIG_ROOT "/dhcp/enable", "/harddisk" CONFIG_ROOT "/dhcp/enable_green"); chown ("/harddisk" CONFIG_ROOT "/dhcp/enable_green", 99, 99); } return 0;}int _add_sshd_user() { mysystem("/bin/chroot /harddisk /usr/sbin/userdel sshd"); mysystem("/bin/chroot /harddisk /usr/sbin/groupdel sshd"); mysystem("/bin/chroot /harddisk /usr/sbin/groupadd -g 74 sshd"); mysystem("/bin/chroot /harddisk /usr/sbin/useradd -u 74 -g sshd -d /var/empty/sshd -s /bin/false -M sshd");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -