Project

General

Profile

Download (3.96 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php-cgi -f
2
<?php
3
/*
4
 * rc.banner
5
 *
6
 * part of pfSense
7
 * Copyright (c) 2005 Colin Smith
8
 * Copyright (c) 2005-2013 BSD Perimeter
9
 * Copyright (c) 2013-2016 Electric Sheep Fencing
10
 * Copyright (c) 2014-2025 Rubicon Communications, LLC (Netgate)
11
 * All rights reserved
12
 *
13
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

    
26
/* parse the configuration and include all functions used below */
27
require_once("config.inc");
28
require_once("gwlb.inc");
29
require_once("interfaces.inc");
30

    
31
$hostname = config_get_path('system/hostname');
32
$machine = trim(`uname -m`);
33

    
34
/* Export the product variable. */
35
if (is_writable("/etc")) {
36
	$handle = NULL;
37
	if (!file_exists("/etc/product_name") || is_writable("/etc/product_name"))
38
		$handle = fopen("/etc/product_name", 'w');
39
	if ($handle != NULL)
40
		fwrite($handle, $g['product_name']);
41
	if ($handle != NULL)
42
		fclose($handle);
43

    
44
	$handle = NULL;
45
	if (!file_exists("/etc/product_label") || is_writable("/etc/product_label"))
46
		$handle = fopen("/etc/product_label", 'w');
47
	if ($handle != NULL)
48
		fwrite($handle, $g['product_label']);
49
	if ($handle != NULL)
50
		fclose($handle);
51
}
52

    
53
$platform = system_identify_specific_platform();
54
$serial = system_get_serial();
55
if (isset($platform['descr'])) {
56
	printf("%s - ", $platform['descr']);
57
}
58
if (!empty($serial)) {
59
	printf("%s: %s - ", gettext("Serial"), $serial);
60
}
61
printf("%s: %s\n\n", gettext("Netgate Device ID"), system_get_uniqueid());
62

    
63
print "*** Welcome to {$g['product_label']} {$g['product_version_string']} ({$machine}) on {$hostname} ***\n";
64

    
65
$iflist = get_configured_interface_with_descr(true);
66

    
67
// calculate max string widths for the banner
68
$realif_wdith = 1;
69
$tobanner_wdith = 1;
70
foreach ($iflist as $ifname => $friendly) {
71
	$realif = get_real_interface($ifname);
72
	$realif_length = strlen($realif);
73
	if ($realif_length > $realif_wdith) {
74
		$realif_wdith = $realif_length;
75
	}
76
	$tobanner = "{$friendly} ({$ifname})";
77
	$tobanner_length = strlen($tobanner);
78
	if ($tobanner_length > $tobanner_wdith) {
79
		$tobanner_wdith = $tobanner_length;
80
	}
81
}
82
$v6line_width = $realif_wdith + $tobanner_wdith + 9;
83

    
84
// print the banner
85
foreach ($iflist as $ifname => $friendly) {
86
	/* point to this interface's config */
87
	$ifconf = config_get_path("interfaces/{$ifname}");
88
	/* look for 'special cases' */
89
	switch ($ifconf['ipaddr']) {
90
		case "dhcp":
91
			$class = "/DHCP4";
92
			break;
93
		case "pppoe":
94
			$class = "/PPPoE";
95
			break;
96
		case "pptp":
97
			$class = "/PPTP";
98
			break;
99
		case "l2tp":
100
			$class = "/L2TP";
101
			break;
102
		default:
103
			$class = "";
104
			break;
105
	}
106
	switch ($ifconf['ipaddrv6']) {
107
		case "dhcp6":
108
			$class6 = "/DHCP6";
109
			break;
110
		case "slaac":
111
			$class6 = "/SLAAC";
112
			break;
113
		case "6rd":
114
			$class6 = "/6RD";
115
			break;
116
		case "6to4":
117
			$class6 = "/6to4";
118
			break;
119
		case "track6":
120
			$class6 = "/t6";
121
			break;
122
		default:
123
			$class6 = "";
124
			break;
125
	}
126
	$ipaddr = get_interface_ip($ifname);
127
	$subnet = get_interface_subnet($ifname);
128
	$ipaddr6 = get_interface_ipv6($ifname);
129
	$subnet6 = get_interface_subnetv6($ifname);
130
	$realif = get_real_interface($ifname);
131
	$tobanner = "{$friendly} ({$ifname})";
132

    
133
	printf("\n %-{$tobanner_wdith}s -> %-{$realif_wdith}s -> ",
134
		$tobanner,
135
		$realif
136
	);
137
	$v6first = false;
138
	if (!empty($ipaddr) && !empty($subnet)) {
139
		printf("v4%s: %s/%s",
140
			$class,
141
			$ipaddr,
142
			$subnet
143
		);
144
	} else {
145
		$v6first = true;
146
	}
147
	if (!empty($ipaddr6) && !empty($subnet6)) {
148
		if (!$v6first) {
149
			printf("\n%s", str_repeat(" ", $v6line_width));
150
		}
151
		printf("v6%s: %s/%s",
152
			$class6,
153
			$ipaddr6,
154
			$subnet6
155
		);
156
	}
157
}
158
printf("\n");
159
?>
(20-20/84)