-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_file.php
More file actions
98 lines (87 loc) · 2.74 KB
/
parse_file.php
File metadata and controls
98 lines (87 loc) · 2.74 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
require_once('connect.php');
$file = "/Users/nassim/.ssh/config_tmp";
$lines = file($file);
for( $i = 0; $i < sizeof($lines); $i++ )
{
// Recupere le host
if (preg_match("/^host/", $lines[$i]) )
{
if (!empty($id_zone) && !empty($id_infra) && !empty($hostname))
{
$query = "INSERT INTO sg_hosts(hostname,id_zone,id_infra,id_srv,user,port,identityfile,proxycommand) VALUES (\"".$hostname."\",\"".$id_zone."\",\"".$id_infra."\",\"".$id_srv."\",\"".$user."\",".$port.",\"".$identityfile."\",\"".$proxycommand."\")";
$bdd->query($query);
if($bdd->errorCode() > 0)
{
$errs = $bdd->errorInfo();
print_r($errs);
echo $query."\n";
}
}else{
echo "Aie sur $id_zone.$id_infra.$id_srv !\n";
echo "INSERT INTO sg_hosts(hostname,id_zone,id_infra,id_srv,user,port,identityfile,proxycommand) VALUES (\"".$hostname."\",\"".$id_zone."\",\"".$id_infra."\",\"".$id_srv."\",\"".$user."\",".$port.",\"".$identityfile."\",\"".$proxycommand."\")";
}
$id_zone = "";
$id_infra = "";
$id_srv = "";
$hostname = "";
$user = "";
$port = 22;
$identityfile = "";
$proxycommand = "";
$str = ereg_replace( "^(.*) ", "", $lines[$i] );
$exp_str = explode(".",$str);
switch($exp_str[0])
{
case "ftv":
$id_zone = $exp_str[0].".".$exp_str[1];
$id_infra = $exp_str[2];
$id_srv = str_replace("\n","",$exp_str[3]);
break;
case "own":
$id_zone = $exp_str[0].".".$exp_str[1];
$id_infra = $exp_str[2];
$id_srv = str_replace("\n","",$exp_str[3]);
break;
default:
$id_zone = "";
$id_infra = "";
$id_srv = "";
break;
}
}
// Hostname (if present)
if (preg_match("/hostname/", $lines[$i]) )
{
$hostname = ereg_replace( "^(.*) ", "", $lines[$i] );
$hostname = str_replace(" ","",$hostname);
$hostname = str_replace("\n","",$hostname);
}
// User (if present)
if (preg_match("/user/", $lines[$i]) )
{
$user = ereg_replace( "^(.*)user ", "", $lines[$i] );
$user = str_replace(" ","",$user);
$user = str_replace("\n","",$user); }
// Port (if present)
if (preg_match("/port/", $lines[$i]) )
{
$port = ereg_replace( "^(.*)port ", "", $lines[$i] );
$port = str_replace(" ","",$port);
$port = str_replace("\n","",$port);
}
// Proxycommand (if present)
if (preg_match("/proxycommand/", $lines[$i]) )
{
$proxycommand = ereg_replace( "^(.*)proxycommand ", "", $lines[$i] );
$proxycommand = str_replace("\n","",$proxycommand);
}
// Identityfile (if present)
if (preg_match("/identityfile/", $lines[$i]) )
{
$identityfile = ereg_replace( "^(.*)identityfile ", "", $lines[$i] );
$identityfile = str_replace(" ","",$identityfile);
$identityfile = str_replace("\n","",$identityfile);
}
}
?>