Exemple #1
0
void update_minidlna_conf(const char *link_path, const char *conf_path)
{
	FILE *fp;
	int dlna_disc, dlna_root;
	char *computer_name;
	char *dlna_src1 = "V,/media/AiDisk_a1/Video";
	char *dlna_src2 = "P,/media/AiDisk_a1/Photo";
	char *dlna_src3 = "A,/media/AiDisk_a1/Audio";

	fp = fopen(conf_path, "w");
	if (!fp)
		return;

	computer_name = get_our_hostname();

	dlna_disc = nvram_get_int("dlna_disc");
	dlna_root = nvram_get_int("dlna_root");
	dlna_src1 = nvram_safe_get("dlna_src1");
	dlna_src2 = nvram_safe_get("dlna_src2");
	dlna_src3 = nvram_safe_get("dlna_src3");

	if (!*dlna_src1 && !*dlna_src2 && !*dlna_src3)
		dlna_src1 = "/media";

	if (dlna_disc < 10) dlna_disc = 10;
	if (dlna_disc > 10800) dlna_disc = 10800;

	fprintf(fp, "port=%d\n", 8200);
	fprintf(fp, "network_interface=%s\n", IFNAME_BR);
	fprintf(fp, "notify_interval=%d\n", dlna_disc);
	if (*dlna_src1)
		fprintf(fp, "media_dir=%s\n", dlna_src1);
	if (*dlna_src2)
		fprintf(fp, "media_dir=%s\n", dlna_src2);
	if (*dlna_src3)
		fprintf(fp, "media_dir=%s\n", dlna_src3);
	fprintf(fp, "merge_media_dirs=%s\n", "no");
	if (dlna_root == 1)
		fprintf(fp, "root_container=%s\n", "B");
	else if (dlna_root == 2)
		fprintf(fp, "root_container=%s\n", "M");
	else if (dlna_root == 3)
		fprintf(fp, "root_container=%s\n", "V");
	else if (dlna_root == 4)
		fprintf(fp, "root_container=%s\n", "P");
	if (nvram_get_int("dlna_sort") > 0)
		fprintf(fp, "force_sort_criteria=%s\n", "+upnp:class,+upnp:originalTrackNumber,+dc:title");
	fprintf(fp, "friendly_name=%s\n", computer_name);
	fprintf(fp, "db_dir=%s\n", link_path);
	fprintf(fp, "log_dir=%s\n", link_path);
	fprintf(fp, "album_art_names=%s\n", "Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg");
	fprintf(fp, "inotify=%s\n", "yes");
	fprintf(fp, "enable_tivo=%s\n", "no");
	fprintf(fp, "strict_dlna=%s\n", "no");
	fprintf(fp, "model_number=%d\n", 1);

	fclose(fp);
}
Exemple #2
0
static int
create_vpns_pppd_options(int vpns_type)
{
	FILE *fp;
	int i_mppe, i_auth, i_vuse, i_dhcp, i_items;
	char *vpns_opt, *lanip, *wins, *dns1, *dns2;

	i_auth = nvram_get_int("vpns_auth");
	i_mppe = nvram_get_int("vpns_mppe");
	i_vuse = nvram_get_int("vpns_vuse");
	i_dhcp = is_dhcpd_enabled(0);

	lanip  = nvram_safe_get("lan_ipaddr");

	vpns_opt = VPN_SERVER_PPPD_OPTIONS;
	if (!(fp = fopen(vpns_opt, "w")))
		return -1;

	fprintf(fp, "lock\n");
	fprintf(fp, "name %s\n", get_our_hostname());
	fprintf(fp, "auth\n");
	fprintf(fp, "refuse-eap\n");
	fprintf(fp, "refuse-pap\n");
	fprintf(fp, "refuse-mschap\n");

	if (i_auth == 0) {
		fprintf(fp, "refuse-chap\n");
		fprintf(fp, "require-mschap-v2\n");
	}

	fprintf(fp, "default-asyncmap\n");

	/* looks like pptp also likes them */
	fprintf(fp, "nopcomp noaccomp\n");

	/* ccp should still be enabled - mppe/mppc requires this */
	fprintf(fp, "novj nobsdcomp nodeflate\n");

	if (i_mppe == 3) {
		fprintf(fp, "nomppe nomppc\n");
	} else {
		if (i_mppe == 1) {
			fprintf(fp, "+mppe\n");
			fprintf(fp, "-mppe-40\n");
			fprintf(fp, "+mppe-128\n");
		} else if (i_mppe == 2) {
			fprintf(fp, "+mppe\n");
			fprintf(fp, "+mppe-40\n");
			fprintf(fp, "-mppe-128\n");
		} else {
			fprintf(fp, "+mppe-40\n");
			fprintf(fp, "+mppe-128\n");
		}
		fprintf(fp, "nomppe-stateful\n");
	}

	// DNS Server
	i_items = 0;
	if (i_dhcp) {
		dns1 = nvram_safe_get("dhcp_dns1_x");
		dns2 = nvram_safe_get("dhcp_dns2_x");
		if (is_valid_ipv4(dns1) && (strcmp(dns1, lanip))) {
			i_items++;
			fprintf(fp, "ms-dns %s\n", dns1);
		}
		if (is_valid_ipv4(dns2) && (strcmp(dns2, lanip)) && (strcmp(dns2, dns1))) {
			i_items++;
			fprintf(fp, "ms-dns %s\n", dns2);
		}
	}

	if (i_items < 2)
		fprintf(fp, "ms-dns %s\n", lanip);

	// WINS Server
	i_items = 0;
	if (i_dhcp) {
		wins = nvram_safe_get("dhcp_wins_x");
		if (is_valid_ipv4(wins)) {
			i_items++;
			fprintf(fp, "ms-wins %s\n", wins);
		}
	}

#if defined(APP_SMBD) || defined(APP_NMBD)
	if ((i_items < 1) && nvram_get_int("wins_enable"))
		fprintf(fp, "ms-wins %s\n", lanip);
#endif

	fprintf(fp, "mtu %d\n", nvram_safe_get_int("vpns_mtu", 1450, 1000, 1460));
	fprintf(fp, "mru %d\n", nvram_safe_get_int("vpns_mru", 1450, 1000, 1460));
	fprintf(fp, "ipcp-accept-remote ipcp-accept-local\n");
	fprintf(fp, "nodefaultroute\n");

	if (i_vuse == 0)
		fprintf(fp, "proxyarp\n");

	if (vpns_type == 1) {
		// L2TP: Don't wait for LCP term responses; exit immediately when killed
		fprintf(fp, "lcp-max-terminate %d\n", 0);
	}

	/* echo failures (6*20s) */
	fprintf(fp, "lcp-echo-interval %d\n", 20);
	fprintf(fp, "lcp-echo-failure %d\n", 6);
	fprintf(fp, "lcp-echo-adaptive\n");

	fprintf(fp, "ip-up-script %s\n", VPNS_PPP_UP_SCRIPT);
	fprintf(fp, "ip-down-script %s\n", VPNS_PPP_DW_SCRIPT);
	fprintf(fp, "minunit %d\n", VPN_SERVER_PPP_UNIT);

	fclose(fp);

	chmod(vpns_opt, 0644);

	return 0;
}