-
Notifications
You must be signed in to change notification settings - Fork 1
/
netconfig1.php
73 lines (50 loc) · 1.27 KB
/
netconfig1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
include("header.php");
if($_SESSION['flag']=="allowed")
{
$type=$_POST['netconfig'];
if($type == "static")
{
$type = $_POST['netconfig'];
$ip = $_POST['ip'];
$mask = $_POST['mask'];
$gateway = $_POST['gateway'];
$valid_ip;
$valid_gate;
$y = explode(".",$gateway);
$x = explode(".",$ip);
if(($x[0]>=1 && $x[0]<=255) && ($x[1]>=0 && $x[1]<=255) && ($x[2]>=0 && $x[2]<=255) && ($x[3]>=0 && $x[3]<=255) && $x[4]=="")
{
$valid_ip = "true";
}
else
{
$valid_ip = "false";
}
if(($y[0]>=1 && $y[0]<=255) && ($y[1]>=0 && $y[1]<=255) && ($y[2]>=0 && $y[2]<=255) && ($y[3]>=0 && $y[3]<=255) && $y[4]=="")
{
$valid_gate = "true";
}
else
{
$valid_gate = "false";
}
if($valid_ip=="true" && $valid_gate=="true")
{
$cmd = `sudo echo "
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway" > /etc/sysconfig/network-scripts/ifcfg-eth0`;
echo '<label class="alert alert-success">IP has been set.</label>';
}
else
{
echo '<label class="alert alert-danger">Invalid IP Address OR Gateway Address.</label>';
}
}
}
else
header("location:index.php");