@@ -22,26 +22,26 @@ |
||
22 | 22 | |
23 | 23 | # print result |
24 | 24 | if( (!isset($errors['tableError'])) && (!isset($errors['fieldError'])) ) { |
25 | - print 'All tables and fields are installed properly'. "\n"; |
|
25 | + print 'All tables and fields are installed properly'. "\n"; |
|
26 | 26 | } |
27 | 27 | else { |
28 | - # missing tables |
|
29 | - if (isset($errors['tableError'])) { |
|
30 | - print 'Missing tables:'. "\n"; |
|
31 | - |
|
32 | - foreach ($errors['tableError'] as $table) { |
|
33 | - print " - ".$table."\n"; |
|
34 | - } |
|
35 | - } |
|
36 | - |
|
37 | - # missing fields |
|
38 | - if (isset($errors['fieldError'])) { |
|
39 | - print "\n".'Missing fields'. "\n"; |
|
40 | - |
|
41 | - foreach ($errors['fieldError'] as $table=>$field) { |
|
42 | - print 'Table `'. $table .'`: missing field `'. $field .'`;'."\n"; |
|
43 | - } |
|
44 | - } |
|
28 | + # missing tables |
|
29 | + if (isset($errors['tableError'])) { |
|
30 | + print 'Missing tables:'. "\n"; |
|
31 | + |
|
32 | + foreach ($errors['tableError'] as $table) { |
|
33 | + print " - ".$table."\n"; |
|
34 | + } |
|
35 | + } |
|
36 | + |
|
37 | + # missing fields |
|
38 | + if (isset($errors['fieldError'])) { |
|
39 | + print "\n".'Missing fields'. "\n"; |
|
40 | + |
|
41 | + foreach ($errors['fieldError'] as $table=>$field) { |
|
42 | + print 'Table `'. $table .'`: missing field `'. $field .'`;'."\n"; |
|
43 | + } |
|
44 | + } |
|
45 | 45 | } |
46 | 46 | print "\n"; |
47 | 47 | ?> |
48 | 48 | \ No newline at end of file |
@@ -8,7 +8,7 @@ |
||
8 | 8 | |
9 | 9 | /* redirect */ |
10 | 10 | if($User->settings->version < VERSION) { |
11 | - header("Location: ".create_link("upgrade")); |
|
12 | - die(); |
|
11 | + header("Location: ".create_link("upgrade")); |
|
12 | + die(); |
|
13 | 13 | } |
14 | 14 | ?> |
15 | 15 | \ No newline at end of file |
@@ -14,23 +14,23 @@ discard block |
||
14 | 14 | $untranslated = explode("\n",shell_exec("cd ".dirname(__FILE__)."/../../ && grep -r '_(' * ")); |
15 | 15 | // loop and search |
16 | 16 | foreach ($untranslated as $u) { |
17 | - // find string |
|
18 | - $str = get_string_between($u, "_('", "')"); |
|
19 | - // remove "" and ' |
|
20 | - $str = trim($str, "',\""); |
|
21 | - // search for invalud content and remove |
|
22 | - if (substr($str, 0, 1)!="$") { |
|
23 | - $all_translations[] = $str; |
|
24 | - } |
|
17 | + // find string |
|
18 | + $str = get_string_between($u, "_('", "')"); |
|
19 | + // remove "" and ' |
|
20 | + $str = trim($str, "',\""); |
|
21 | + // search for invalud content and remove |
|
22 | + if (substr($str, 0, 1)!="$") { |
|
23 | + $all_translations[] = $str; |
|
24 | + } |
|
25 | 25 | |
26 | - // find string |
|
27 | - $str = get_string_between($u, '_("', '")'); |
|
28 | - // remove "" and ' |
|
29 | - $str = trim($str, "',\""); |
|
30 | - // search for invalud content and remove |
|
31 | - if (substr($str, 0, 1)!="$") { |
|
32 | - $all_translations[] = $str; |
|
33 | - } |
|
26 | + // find string |
|
27 | + $str = get_string_between($u, '_("', '")'); |
|
28 | + // remove "" and ' |
|
29 | + $str = trim($str, "',\""); |
|
30 | + // search for invalud content and remove |
|
31 | + if (substr($str, 0, 1)!="$") { |
|
32 | + $all_translations[] = $str; |
|
33 | + } |
|
34 | 34 | } |
35 | 35 | //unique |
36 | 36 | $all_translations = array_unique($all_translations); |
@@ -40,25 +40,25 @@ discard block |
||
40 | 40 | $untranslated = explode("\n",shell_exec("cd ".dirname(__FILE__)."/../../ && more functions/locale/en/LC_MESSAGES/phpipam.po")); |
41 | 41 | // loop and create |
42 | 42 | foreach ($untranslated as $u) { |
43 | - // search for string |
|
44 | - if (substr($u, 0, 7)=='msgid "') { |
|
45 | - $u = str_replace("msgid ", "", $u); |
|
46 | - $u = trim($u, '"'); |
|
47 | - $translated[] = $u; |
|
48 | - } |
|
43 | + // search for string |
|
44 | + if (substr($u, 0, 7)=='msgid "') { |
|
45 | + $u = str_replace("msgid ", "", $u); |
|
46 | + $u = trim($u, '"'); |
|
47 | + $translated[] = $u; |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | // remove existing from unique |
52 | 52 | foreach ($all_translations as $tr) { |
53 | - if (!in_array($tr, $translated)) { |
|
54 | - $new[] = $tr; |
|
55 | - } |
|
53 | + if (!in_array($tr, $translated)) { |
|
54 | + $new[] = $tr; |
|
55 | + } |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | // format |
59 | 59 | foreach ($new as $tr) { |
60 | - $text[] = "msgid \"$tr\""; |
|
61 | - $text[] = "msgstr \"\"\n"; |
|
60 | + $text[] = "msgid \"$tr\""; |
|
61 | + $text[] = "msgstr \"\"\n"; |
|
62 | 62 | } |
63 | 63 | // join text |
64 | 64 | $text = implode("\n",$text); |
@@ -15,9 +15,9 @@ discard block |
||
15 | 15 | /* settings */ |
16 | 16 | $resolve_config['emptyonly'] = true; # if true it will only update the ones without DNS entry! |
17 | 17 | $resolve_config['subnets'] = array(); # which subnets to check - by id |
18 | - # example -> array(1,3,5) will only update subnets with id 1,3,5 |
|
19 | - # you can get id's and descriptions with following MySQL query: |
|
20 | - # select `id`,`description` from `subnets`; |
|
18 | + # example -> array(1,3,5) will only update subnets with id 1,3,5 |
|
19 | + # you can get id's and descriptions with following MySQL query: |
|
20 | + # select `id`,`description` from `subnets`; |
|
21 | 21 | $resolve_config['verbose'] = true; # verbose response - prints results, cron will email it to you! |
22 | 22 | |
23 | 23 | # include required scripts |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | |
40 | 40 | # set subnet |
41 | 41 | if (isset($argv[1])) { |
42 | - $req_subnets = explode(",", $argv[1]); |
|
43 | - foreach ($req_subnets as $s) { |
|
44 | - if (!is_numeric($s)) { $Result->show_cli("Invalid subnetId provided - $s\n", true); } |
|
45 | - else { |
|
46 | - $resolve_config['subnets'][] = $s; |
|
47 | - } |
|
48 | - } |
|
42 | + $req_subnets = explode(",", $argv[1]); |
|
43 | + foreach ($req_subnets as $s) { |
|
44 | + if (!is_numeric($s)) { $Result->show_cli("Invalid subnetId provided - $s\n", true); } |
|
45 | + else { |
|
46 | + $resolve_config['subnets'][] = $s; |
|
47 | + } |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | |
@@ -56,29 +56,29 @@ discard block |
||
56 | 56 | |
57 | 57 | # check all subnets |
58 | 58 | if(sizeof($resolve_config['subnets']) == 0) { |
59 | - # get ony ip's with empty DNS |
|
60 | - if($resolve_config['emptyonly'] == 1) { $query = 'select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` where `dns_name` = "" or `dns_name` is NULL order by `ip_addr` ASC;'; } |
|
61 | - else { $query = 'select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` order by `ip_addr` ASC;'; } |
|
59 | + # get ony ip's with empty DNS |
|
60 | + if($resolve_config['emptyonly'] == 1) { $query = 'select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` where `dns_name` = "" or `dns_name` is NULL order by `ip_addr` ASC;'; } |
|
61 | + else { $query = 'select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` order by `ip_addr` ASC;'; } |
|
62 | 62 | } |
63 | 63 | # check selected subnets |
64 | 64 | else { |
65 | - $query[] = "select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` where "; |
|
66 | - //go through subnets |
|
67 | - $m=1; |
|
68 | - foreach($resolve_config['subnets'] as $k=>$subnetId) { |
|
69 | - // last |
|
70 | - if($m==sizeof($resolve_config['subnets'])) { $query[] = '`subnetId` = "'. $subnetId .'" '; } |
|
71 | - else { $query[] = '`subnetId` = "'. $subnetId .'" or '; } |
|
72 | - $m++; |
|
73 | - } |
|
74 | - # get ony ip's with empty DNS |
|
75 | - if($resolve_config['emptyonly'] == 1) { |
|
76 | - $query[] = ' and (`dns_name` = "" or `dns_name` is NULL ) '; |
|
77 | - } |
|
78 | - $query[] = 'order by `ip_addr` ASC;'; |
|
79 | - |
|
80 | - //join |
|
81 | - $query = implode("\n", $query); |
|
65 | + $query[] = "select `id`,`ip_addr`,`dns_name`,`subnetId` from `ipaddresses` where "; |
|
66 | + //go through subnets |
|
67 | + $m=1; |
|
68 | + foreach($resolve_config['subnets'] as $k=>$subnetId) { |
|
69 | + // last |
|
70 | + if($m==sizeof($resolve_config['subnets'])) { $query[] = '`subnetId` = "'. $subnetId .'" '; } |
|
71 | + else { $query[] = '`subnetId` = "'. $subnetId .'" or '; } |
|
72 | + $m++; |
|
73 | + } |
|
74 | + # get ony ip's with empty DNS |
|
75 | + if($resolve_config['emptyonly'] == 1) { |
|
76 | + $query[] = ' and (`dns_name` = "" or `dns_name` is NULL ) '; |
|
77 | + } |
|
78 | + $query[] = 'order by `ip_addr` ASC;'; |
|
79 | + |
|
80 | + //join |
|
81 | + $query = implode("\n", $query); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | # fetch records |
@@ -86,31 +86,31 @@ discard block |
||
86 | 86 | |
87 | 87 | # try to update dns records |
88 | 88 | if (sizeof($ipaddresses)>0) { |
89 | - foreach($ipaddresses as $ip) { |
|
90 | - # fetch subnet |
|
91 | - $subnet = $Subnets->fetch_subnet ("id", $ip->subnetId); |
|
92 | - $nsid = $subnet===false ? false : $subnet->nameserverId; |
|
93 | - # try to resolve |
|
94 | - $hostname = $DNS->resolve_address ($ip->ip_addr, null, true, $nsid); |
|
95 | - |
|
96 | - # update if change |
|
97 | - if($hostname['class']=="resolved") { |
|
98 | - # values |
|
99 | - $values = array("dns_name"=>$hostname['name'], |
|
100 | - "id"=>$ip->id |
|
101 | - ); |
|
102 | - # execute |
|
103 | - if(!$Admin->object_modify("ipaddresses", "edit", "id", $values)) { $Result->show_cli("Failed to update address ".$Subnets->transform_to_dotted($ip->ip_addr)); } |
|
104 | - |
|
105 | - # set text |
|
106 | - $res[] = 'updated ip address '. $Subnets->transform_to_dotted($ip->ip_addr) . ' with hostname '. $hostname['name']; |
|
107 | - } |
|
108 | - } |
|
89 | + foreach($ipaddresses as $ip) { |
|
90 | + # fetch subnet |
|
91 | + $subnet = $Subnets->fetch_subnet ("id", $ip->subnetId); |
|
92 | + $nsid = $subnet===false ? false : $subnet->nameserverId; |
|
93 | + # try to resolve |
|
94 | + $hostname = $DNS->resolve_address ($ip->ip_addr, null, true, $nsid); |
|
95 | + |
|
96 | + # update if change |
|
97 | + if($hostname['class']=="resolved") { |
|
98 | + # values |
|
99 | + $values = array("dns_name"=>$hostname['name'], |
|
100 | + "id"=>$ip->id |
|
101 | + ); |
|
102 | + # execute |
|
103 | + if(!$Admin->object_modify("ipaddresses", "edit", "id", $values)) { $Result->show_cli("Failed to update address ".$Subnets->transform_to_dotted($ip->ip_addr)); } |
|
104 | + |
|
105 | + # set text |
|
106 | + $res[] = 'updated ip address '. $Subnets->transform_to_dotted($ip->ip_addr) . ' with hostname '. $hostname['name']; |
|
107 | + } |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | |
112 | 112 | # if verbose print result so it can be emailed via cron! |
113 | 113 | if($resolve_config['verbose'] == true && isset($res)) { |
114 | - print implode("\n", $res); |
|
114 | + print implode("\n", $res); |
|
115 | 115 | } |
116 | 116 | ?> |
117 | 117 | \ No newline at end of file |
@@ -78,18 +78,18 @@ discard block |
||
78 | 78 | $addresses_tmp = array(); |
79 | 79 | // loop |
80 | 80 | foreach($scan_subnets as $s) { |
81 | - // if subnet has slaves dont check it |
|
82 | - if ($Subnets->has_slaves ($s->id) === false) { |
|
83 | - $addresses_tmp[$s->id] = $Scan-> prepare_addresses_to_scan ("discovery", $s->id, false); |
|
84 | - } |
|
81 | + // if subnet has slaves dont check it |
|
82 | + if ($Subnets->has_slaves ($s->id) === false) { |
|
83 | + $addresses_tmp[$s->id] = $Scan-> prepare_addresses_to_scan ("discovery", $s->id, false); |
|
84 | + } |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | //reindex |
88 | 88 | if(sizeof($addresses_tmp)>0) { |
89 | 89 | foreach($addresses_tmp as $s_id=>$a) { |
90 | - foreach($a as $ip) { |
|
91 | - $addresses[] = array("subnetId"=>$s_id, "ip_addr"=>$ip); |
|
92 | - } |
|
90 | + foreach($a as $ip) { |
|
91 | + $addresses[] = array("subnetId"=>$s_id, "ip_addr"=>$ip); |
|
92 | + } |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | } |
@@ -110,101 +110,101 @@ discard block |
||
110 | 110 | |
111 | 111 | //different scan for fping |
112 | 112 | if($Scan->icmp_type=="fping") { |
113 | - //run per MAX_THREADS |
|
114 | - for ($m=0; $m<=$size_subnets; $m += $Scan->settings->scanMaxThreads) { |
|
115 | - // create threads |
|
116 | - $threads = array(); |
|
117 | - //fork processes |
|
118 | - for ($i = 0; $i <= $Scan->settings->scanMaxThreads && $i <= $size_subnets; $i++) { |
|
119 | - //only if index exists! |
|
120 | - if(isset($scan_subnets[$z])) { |
|
121 | - //start new thread |
|
122 | - $threads[$z] = new Thread( 'fping_subnet' ); |
|
123 | - $threads[$z]->start_fping( $Subnets->transform_to_dotted($scan_subnets[$z]->subnet)."/".$scan_subnets[$z]->mask ); |
|
124 | - $z++; //next index |
|
125 | - } |
|
126 | - } |
|
127 | - // wait for all the threads to finish |
|
128 | - while( !empty( $threads ) ) { |
|
129 | - foreach($threads as $index => $thread) { |
|
130 | - $child_pipe = "/tmp/pipe_".$thread->getPid(); |
|
131 | - |
|
132 | - if (file_exists($child_pipe)) { |
|
133 | - $file_descriptor = fopen( $child_pipe, "r"); |
|
134 | - $child_response = ""; |
|
135 | - while (!feof($file_descriptor)) { |
|
136 | - $child_response .= fread($file_descriptor, 8192); |
|
137 | - } |
|
138 | - //we have the child data in the parent, but serialized: |
|
139 | - $child_response = unserialize( $child_response ); |
|
140 | - //store |
|
141 | - $scan_subnets[$index]->discovered = $child_response; |
|
142 | - //now, child is dead, and parent close the pipe |
|
143 | - unlink( $child_pipe ); |
|
144 | - unset($threads[$index]); |
|
145 | - } |
|
146 | - } |
|
147 | - usleep(200000); |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - //fping finds all subnet addresses, we must remove existing ones ! |
|
152 | - foreach($scan_subnets as $sk=>$s) { |
|
153 | - if(isset($s->discovered)) { |
|
154 | - foreach($s->discovered as $rk=>$result) { |
|
155 | - if(!in_array($Subnets->transform_to_decimal($result), $addresses_tmp[$s->id])) { |
|
156 | - unset($scan_subnets[$sk]->discovered[$rk]); |
|
157 | - } |
|
158 | - } |
|
113 | + //run per MAX_THREADS |
|
114 | + for ($m=0; $m<=$size_subnets; $m += $Scan->settings->scanMaxThreads) { |
|
115 | + // create threads |
|
116 | + $threads = array(); |
|
117 | + //fork processes |
|
118 | + for ($i = 0; $i <= $Scan->settings->scanMaxThreads && $i <= $size_subnets; $i++) { |
|
119 | + //only if index exists! |
|
120 | + if(isset($scan_subnets[$z])) { |
|
121 | + //start new thread |
|
122 | + $threads[$z] = new Thread( 'fping_subnet' ); |
|
123 | + $threads[$z]->start_fping( $Subnets->transform_to_dotted($scan_subnets[$z]->subnet)."/".$scan_subnets[$z]->mask ); |
|
124 | + $z++; //next index |
|
125 | + } |
|
126 | + } |
|
127 | + // wait for all the threads to finish |
|
128 | + while( !empty( $threads ) ) { |
|
129 | + foreach($threads as $index => $thread) { |
|
130 | + $child_pipe = "/tmp/pipe_".$thread->getPid(); |
|
131 | + |
|
132 | + if (file_exists($child_pipe)) { |
|
133 | + $file_descriptor = fopen( $child_pipe, "r"); |
|
134 | + $child_response = ""; |
|
135 | + while (!feof($file_descriptor)) { |
|
136 | + $child_response .= fread($file_descriptor, 8192); |
|
137 | + } |
|
138 | + //we have the child data in the parent, but serialized: |
|
139 | + $child_response = unserialize( $child_response ); |
|
140 | + //store |
|
141 | + $scan_subnets[$index]->discovered = $child_response; |
|
142 | + //now, child is dead, and parent close the pipe |
|
143 | + unlink( $child_pipe ); |
|
144 | + unset($threads[$index]); |
|
145 | + } |
|
146 | + } |
|
147 | + usleep(200000); |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + //fping finds all subnet addresses, we must remove existing ones ! |
|
152 | + foreach($scan_subnets as $sk=>$s) { |
|
153 | + if(isset($s->discovered)) { |
|
154 | + foreach($s->discovered as $rk=>$result) { |
|
155 | + if(!in_array($Subnets->transform_to_decimal($result), $addresses_tmp[$s->id])) { |
|
156 | + unset($scan_subnets[$sk]->discovered[$rk]); |
|
157 | + } |
|
158 | + } |
|
159 | 159 | //rekey |
160 | 160 | $scan_subnets[$sk]->discovered = array_values($scan_subnets[$sk]->discovered); |
161 | - } |
|
162 | - } |
|
161 | + } |
|
162 | + } |
|
163 | 163 | } |
164 | 164 | //ping, pear |
165 | 165 | else { |
166 | - //run per MAX_THREADS |
|
166 | + //run per MAX_THREADS |
|
167 | 167 | for ($m=0; $m<=$size_addresses; $m += $Scan->settings->scanMaxThreads) { |
168 | 168 | // create threads |
169 | 169 | $threads = array(); |
170 | 170 | |
171 | 171 | //fork processes |
172 | 172 | for ($i = 0; $i <= $Scan->settings->scanMaxThreads && $i <= $size_addresses; $i++) { |
173 | - //only if index exists! |
|
174 | - if(isset($addresses[$z])) { |
|
175 | - //start new thread |
|
176 | - $threads[$z] = new Thread( 'ping_address' ); |
|
177 | - $threads[$z]->start( $Subnets->transform_to_dotted($addresses[$z]['ip_addr']) ); |
|
178 | - $z++; //next index |
|
179 | - } |
|
173 | + //only if index exists! |
|
174 | + if(isset($addresses[$z])) { |
|
175 | + //start new thread |
|
176 | + $threads[$z] = new Thread( 'ping_address' ); |
|
177 | + $threads[$z]->start( $Subnets->transform_to_dotted($addresses[$z]['ip_addr']) ); |
|
178 | + $z++; //next index |
|
179 | + } |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // wait for all the threads to finish |
183 | 183 | while( !empty( $threads ) ) { |
184 | 184 | foreach( $threads as $index => $thread ) { |
185 | 185 | if( ! $thread->isAlive() ) { |
186 | - //unset dead hosts |
|
187 | - if($thread->getExitCode() != 0) { |
|
188 | - unset($addresses[$index]); |
|
189 | - } |
|
186 | + //unset dead hosts |
|
187 | + if($thread->getExitCode() != 0) { |
|
188 | + unset($addresses[$index]); |
|
189 | + } |
|
190 | 190 | //remove thread |
191 | 191 | unset( $threads[$index]); |
192 | 192 | } |
193 | 193 | } |
194 | 194 | usleep(200000); |
195 | 195 | } |
196 | - } |
|
197 | - |
|
198 | - //ok, we have all available addresses, rekey them |
|
199 | - foreach($addresses as $a) { |
|
200 | - $add_tmp[$a['subnetId']][] = $Subnets->transform_to_dotted($a['ip_addr']); |
|
201 | - } |
|
202 | - //add to scan_subnets as result |
|
203 | - foreach($scan_subnets as $sk=>$s) { |
|
204 | - if(isset($add_tmp[$s->id])) { |
|
205 | - $scan_subnets[$sk]->discovered = $add_tmp[$s->id]; |
|
206 | - } |
|
207 | - } |
|
196 | + } |
|
197 | + |
|
198 | + //ok, we have all available addresses, rekey them |
|
199 | + foreach($addresses as $a) { |
|
200 | + $add_tmp[$a['subnetId']][] = $Subnets->transform_to_dotted($a['ip_addr']); |
|
201 | + } |
|
202 | + //add to scan_subnets as result |
|
203 | + foreach($scan_subnets as $sk=>$s) { |
|
204 | + if(isset($add_tmp[$s->id])) { |
|
205 | + $scan_subnets[$sk]->discovered = $add_tmp[$s->id]; |
|
206 | + } |
|
207 | + } |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | |
@@ -226,31 +226,31 @@ discard block |
||
226 | 226 | $discovered = 0; //for mailing |
227 | 227 | |
228 | 228 | foreach($scan_subnets as $s) { |
229 | - if(sizeof(@$s->discovered)>0) { |
|
230 | - foreach($s->discovered as $ip) { |
|
231 | - // fetch subnet |
|
232 | - $subnet = $Subnets->fetch_subnet ("id", $s->id); |
|
233 | - $nsid = $subnet===false ? false : $subnet->nameserverId; |
|
234 | - // try to resolve hostname |
|
235 | - $hostname = $DNS->resolve_address ($ip, false, true, $nsid); |
|
236 | - |
|
237 | - //set update query |
|
238 | - $values = array("subnetId"=>$s->id, |
|
239 | - "ip_addr"=>$Subnets->transform_address($ip, "decimal"), |
|
240 | - "dns_name"=>$hostname['name'], |
|
241 | - "description"=>"-- autodiscovered --", |
|
242 | - "note"=>"This host was autodiscovered on ".$nowdate, |
|
243 | - "lastSeen"=>$nowdate, |
|
244 | - "state"=>"2", |
|
245 | - "action"=>"add" |
|
246 | - ); |
|
247 | - //insert |
|
248 | - $Addresses->modify_address($values); |
|
249 | - |
|
250 | - //set discovered |
|
251 | - $discovered++; |
|
252 | - } |
|
253 | - } |
|
229 | + if(sizeof(@$s->discovered)>0) { |
|
230 | + foreach($s->discovered as $ip) { |
|
231 | + // fetch subnet |
|
232 | + $subnet = $Subnets->fetch_subnet ("id", $s->id); |
|
233 | + $nsid = $subnet===false ? false : $subnet->nameserverId; |
|
234 | + // try to resolve hostname |
|
235 | + $hostname = $DNS->resolve_address ($ip, false, true, $nsid); |
|
236 | + |
|
237 | + //set update query |
|
238 | + $values = array("subnetId"=>$s->id, |
|
239 | + "ip_addr"=>$Subnets->transform_address($ip, "decimal"), |
|
240 | + "dns_name"=>$hostname['name'], |
|
241 | + "description"=>"-- autodiscovered --", |
|
242 | + "note"=>"This host was autodiscovered on ".$nowdate, |
|
243 | + "lastSeen"=>$nowdate, |
|
244 | + "state"=>"2", |
|
245 | + "action"=>"add" |
|
246 | + ); |
|
247 | + //insert |
|
248 | + $Addresses->modify_address($values); |
|
249 | + |
|
250 | + //set discovered |
|
251 | + $discovered++; |
|
252 | + } |
|
253 | + } |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | # update scan time |
@@ -261,84 +261,84 @@ discard block |
||
261 | 261 | # send mail |
262 | 262 | if($discovered>0 && $send_mail) { |
263 | 263 | |
264 | - # check for recipients |
|
265 | - foreach($Admin->fetch_multiple_objects ("users", "role", "Administrator") as $admin) { |
|
266 | - if($admin->mailNotify=="Yes") { |
|
267 | - $recepients[] = array("name"=>$admin->real_name, "email"=>$admin->email); |
|
268 | - } |
|
269 | - } |
|
270 | - # none? |
|
271 | - if(!isset($recepients)) { die(); } |
|
272 | - |
|
273 | - # fetch mailer settings |
|
274 | - $mail_settings = $Admin->fetch_object("settingsMail", "id", 1); |
|
275 | - # fake user object, needed for create_link |
|
276 | - $User = new StdClass(); |
|
277 | - @$User->settings->prettyLinks = $Scan->settings->prettyLinks; |
|
278 | - |
|
279 | - # initialize mailer |
|
280 | - $phpipam_mail = new phpipam_mail($Scan->settings, $mail_settings); |
|
281 | - $phpipam_mail->initialize_mailer(); |
|
282 | - |
|
283 | - |
|
284 | - |
|
285 | - // set subject |
|
286 | - $subject = "phpIPAM new addresses detected ".date("Y-m-d H:i:s"); |
|
287 | - |
|
288 | - //html |
|
289 | - $content[] = "<h3>phpIPAM found $discovered new hosts</h3>"; |
|
290 | - $content[] = "<table style='margin-left:10px;margin-top:5px;width:auto;padding:0px;border-collapse:collapse;border:1px solid gray;'>"; |
|
291 | - $content[] = "<tr>"; |
|
292 | - $content[] = " <th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>IP</th>"; |
|
293 | - $content[] = " <th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>Subnet</th>"; |
|
294 | - $content[] = " <th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>Section</th>"; |
|
295 | - $content[] = "</tr>"; |
|
296 | - //plain |
|
297 | - $content_plain[] = "phpIPAM found $discovered new hosts\r\n------------------------------"; |
|
298 | - //Changes |
|
299 | - foreach($scan_subnets as $s) { |
|
300 | - if(sizeof(@$s->discovered)>0) { |
|
301 | - foreach($s->discovered as $ip) { |
|
302 | - //set subnet |
|
303 | - $subnet = $Subnets->fetch_subnet(null, $s->id); |
|
304 | - //set section |
|
305 | - $section = $Admin->fetch_object("sections", "id", $s->sectionId); |
|
306 | - |
|
307 | - $content[] = "<tr>"; |
|
308 | - $content[] = " <td style='padding:3px 8px;border:1px solid silver;'>$ip</td>"; |
|
309 | - $content[] = " <td style='padding:3px 8px;border:1px solid silver;'><a href='".rtrim($Scan->settings->siteURL, "/")."".create_link("subnets",$section->id,$subnet->id)."'>".$Subnets->transform_to_dotted($subnet->subnet)."/".$subnet->mask." - ".$subnet->description."</a></td>"; |
|
310 | - $content[] = " <td style='padding:3px 8px;border:1px solid silver;'><a href='".rtrim($Scan->settings->siteURL, "/")."".create_link("subnets",$section->id)."'>$section->name $section->description</a></td>"; |
|
311 | - $content[] = "</tr>"; |
|
312 | - |
|
313 | - //plain content |
|
314 | - $content_plain[] = "\t * $ip (".$Subnets->transform_to_dotted($subnet->subnet)."/".$subnet->mask.")"; |
|
315 | - } |
|
316 | - } |
|
317 | - } |
|
318 | - $content[] = "</table>"; |
|
319 | - |
|
320 | - |
|
321 | - # set content |
|
322 | - $content = $phpipam_mail->generate_message (implode("\r\n", $content)); |
|
323 | - $content_plain = implode("\r\n",$content_plain); |
|
324 | - |
|
325 | - # try to send |
|
326 | - try { |
|
327 | - $phpipam_mail->Php_mailer->setFrom($mail_settings->mAdminMail, $mail_settings->mAdminName); |
|
328 | - //add all admins to CC |
|
329 | - foreach($recepients as $admin) { |
|
330 | - $phpipam_mail->Php_mailer->addAddress(addslashes($admin['email']), addslashes($admin['name'])); |
|
331 | - } |
|
332 | - $phpipam_mail->Php_mailer->Subject = $subject; |
|
333 | - $phpipam_mail->Php_mailer->msgHTML($content); |
|
334 | - $phpipam_mail->Php_mailer->AltBody = $content_plain; |
|
335 | - //send |
|
336 | - $phpipam_mail->Php_mailer->send(); |
|
337 | - } catch (phpmailerException $e) { |
|
338 | - $Result->show_cli("Mailer Error: ".$e->errorMessage(), true); |
|
339 | - } catch (Exception $e) { |
|
340 | - $Result->show_cli("Mailer Error: ".$e->errorMessage(), true); |
|
341 | - } |
|
264 | + # check for recipients |
|
265 | + foreach($Admin->fetch_multiple_objects ("users", "role", "Administrator") as $admin) { |
|
266 | + if($admin->mailNotify=="Yes") { |
|
267 | + $recepients[] = array("name"=>$admin->real_name, "email"=>$admin->email); |
|
268 | + } |
|
269 | + } |
|
270 | + # none? |
|
271 | + if(!isset($recepients)) { die(); } |
|
272 | + |
|
273 | + # fetch mailer settings |
|
274 | + $mail_settings = $Admin->fetch_object("settingsMail", "id", 1); |
|
275 | + # fake user object, needed for create_link |
|
276 | + $User = new StdClass(); |
|
277 | + @$User->settings->prettyLinks = $Scan->settings->prettyLinks; |
|
278 | + |
|
279 | + # initialize mailer |
|
280 | + $phpipam_mail = new phpipam_mail($Scan->settings, $mail_settings); |
|
281 | + $phpipam_mail->initialize_mailer(); |
|
282 | + |
|
283 | + |
|
284 | + |
|
285 | + // set subject |
|
286 | + $subject = "phpIPAM new addresses detected ".date("Y-m-d H:i:s"); |
|
287 | + |
|
288 | + //html |
|
289 | + $content[] = "<h3>phpIPAM found $discovered new hosts</h3>"; |
|
290 | + $content[] = "<table style='margin-left:10px;margin-top:5px;width:auto;padding:0px;border-collapse:collapse;border:1px solid gray;'>"; |
|
291 | + $content[] = "<tr>"; |
|
292 | + $content[] = " <th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>IP</th>"; |
|
293 | + $content[] = " <th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>Subnet</th>"; |
|
294 | + $content[] = " <th style='padding:3px 8px;border:1px solid silver;border-bottom:2px solid gray;'>Section</th>"; |
|
295 | + $content[] = "</tr>"; |
|
296 | + //plain |
|
297 | + $content_plain[] = "phpIPAM found $discovered new hosts\r\n------------------------------"; |
|
298 | + //Changes |
|
299 | + foreach($scan_subnets as $s) { |
|
300 | + if(sizeof(@$s->discovered)>0) { |
|
301 | + foreach($s->discovered as $ip) { |
|
302 | + //set subnet |
|
303 | + $subnet = $Subnets->fetch_subnet(null, $s->id); |
|
304 | + //set section |
|
305 | + $section = $Admin->fetch_object("sections", "id", $s->sectionId); |
|
306 | + |
|
307 | + $content[] = "<tr>"; |
|
308 | + $content[] = " <td style='padding:3px 8px;border:1px solid silver;'>$ip</td>"; |
|
309 | + $content[] = " <td style='padding:3px 8px;border:1px solid silver;'><a href='".rtrim($Scan->settings->siteURL, "/")."".create_link("subnets",$section->id,$subnet->id)."'>".$Subnets->transform_to_dotted($subnet->subnet)."/".$subnet->mask." - ".$subnet->description."</a></td>"; |
|
310 | + $content[] = " <td style='padding:3px 8px;border:1px solid silver;'><a href='".rtrim($Scan->settings->siteURL, "/")."".create_link("subnets",$section->id)."'>$section->name $section->description</a></td>"; |
|
311 | + $content[] = "</tr>"; |
|
312 | + |
|
313 | + //plain content |
|
314 | + $content_plain[] = "\t * $ip (".$Subnets->transform_to_dotted($subnet->subnet)."/".$subnet->mask.")"; |
|
315 | + } |
|
316 | + } |
|
317 | + } |
|
318 | + $content[] = "</table>"; |
|
319 | + |
|
320 | + |
|
321 | + # set content |
|
322 | + $content = $phpipam_mail->generate_message (implode("\r\n", $content)); |
|
323 | + $content_plain = implode("\r\n",$content_plain); |
|
324 | + |
|
325 | + # try to send |
|
326 | + try { |
|
327 | + $phpipam_mail->Php_mailer->setFrom($mail_settings->mAdminMail, $mail_settings->mAdminName); |
|
328 | + //add all admins to CC |
|
329 | + foreach($recepients as $admin) { |
|
330 | + $phpipam_mail->Php_mailer->addAddress(addslashes($admin['email']), addslashes($admin['name'])); |
|
331 | + } |
|
332 | + $phpipam_mail->Php_mailer->Subject = $subject; |
|
333 | + $phpipam_mail->Php_mailer->msgHTML($content); |
|
334 | + $phpipam_mail->Php_mailer->AltBody = $content_plain; |
|
335 | + //send |
|
336 | + $phpipam_mail->Php_mailer->send(); |
|
337 | + } catch (phpmailerException $e) { |
|
338 | + $Result->show_cli("Mailer Error: ".$e->errorMessage(), true); |
|
339 | + } catch (Exception $e) { |
|
340 | + $Result->show_cli("Mailer Error: ".$e->errorMessage(), true); |
|
341 | + } |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | ?> |
@@ -70,9 +70,9 @@ |
||
70 | 70 | elseif ($proxy_enabled == true && proxy_use_auth == true) { |
71 | 71 | stream_context_set_default( |
72 | 72 | array('http' => array( |
73 | - 'proxy' => "tcp://$proxy_server:$proxy_port", |
|
74 | - 'request_fulluri' => true, |
|
75 | - 'header' => "Proxy-Authorization: Basic $proxy_auth" |
|
73 | + 'proxy' => "tcp://$proxy_server:$proxy_port", |
|
74 | + 'request_fulluri' => true, |
|
75 | + 'header' => "Proxy-Authorization: Basic $proxy_auth" |
|
76 | 76 | ))); |
77 | 77 | } |
78 | 78 |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | # check for PEAR functions |
44 | 44 | if ((@include_once 'PEAR.php') != true) { |
45 | - $missingExt[] = "php PEAR support"; |
|
45 | + $missingExt[] = "php PEAR support"; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | # if db ssl = true check version |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | $error .= "<head>"; |
64 | 64 | $error .= "<base href='$url' />"; |
65 | 65 | $error .= '<link rel="stylesheet" type="text/css" href="css/1.2/bootstrap/bootstrap.min.css">'; |
66 | - $error .= '<link rel="stylesheet" type="text/css" href="css/1.2/bootstrap/bootstrap-custom.css">'; |
|
67 | - $error .= "</head>"; |
|
66 | + $error .= '<link rel="stylesheet" type="text/css" href="css/1.2/bootstrap/bootstrap-custom.css">'; |
|
67 | + $error .= "</head>"; |
|
68 | 68 | $error .= "<body style='margin:0px;'>"; |
69 | - $error .= '<div class="row header-install" id="header"><div class="col-xs-12">'; |
|
70 | - $error .= '<div class="hero-unit" style="padding:20px;margin-bottom:10px;">'; |
|
71 | - $error .= '<a href="'.create_link(null,null,null,null,null,true).'">phpipam requirements error</a>'; |
|
72 | - $error .= '</div>'; |
|
73 | - $error .= '</div></div>'; |
|
69 | + $error .= '<div class="row header-install" id="header"><div class="col-xs-12">'; |
|
70 | + $error .= '<div class="hero-unit" style="padding:20px;margin-bottom:10px;">'; |
|
71 | + $error .= '<a href="'.create_link(null,null,null,null,null,true).'">phpipam requirements error</a>'; |
|
72 | + $error .= '</div>'; |
|
73 | + $error .= '</div></div>'; |
|
74 | 74 | |
75 | 75 | /* error */ |
76 | 76 | $error .= "<div class='alert alert-danger' style='margin:auto;margin-top:20px;width:500px;'><strong>"._('The following required PHP extensions are missing').":</strong><br><hr>"; |
@@ -571,8 +571,8 @@ |
||
571 | 571 | { |
572 | 572 | if ($this->_debug_mode) |
573 | 573 | { |
574 | - //save debugging |
|
575 | - $this->debug_text[] = date('Y-m-d H:i:s').' DEBUG: '.$debug_info; |
|
574 | + //save debugging |
|
575 | + $this->debug_text[] = date('Y-m-d H:i:s').' DEBUG: '.$debug_info; |
|
576 | 576 | } |
577 | 577 | } |
578 | 578 |
@@ -11,47 +11,47 @@ discard block |
||
11 | 11 | const FUNCTION_NOT_CALLABLE = 10; |
12 | 12 | const COULD_NOT_FORK = 15; |
13 | 13 | |
14 | - /** |
|
15 | - * possible errors |
|
16 | - * |
|
17 | - * @var array |
|
18 | - */ |
|
14 | + /** |
|
15 | + * possible errors |
|
16 | + * |
|
17 | + * @var array |
|
18 | + */ |
|
19 | 19 | private $errors = array( |
20 | 20 | Thread::FUNCTION_NOT_CALLABLE => 'You must specify a valid function name that can be called from the current scope.', |
21 | 21 | Thread::COULD_NOT_FORK => 'pcntl_fork() returned a status of -1. No new process was created', |
22 | 22 | ); |
23 | 23 | |
24 | - /** |
|
25 | - * callback for the function that should |
|
26 | - * run as a separate thread |
|
27 | - * |
|
28 | - * @var callback |
|
29 | - */ |
|
24 | + /** |
|
25 | + * callback for the function that should |
|
26 | + * run as a separate thread |
|
27 | + * |
|
28 | + * @var callback |
|
29 | + */ |
|
30 | 30 | protected $runnable; |
31 | 31 | |
32 | - /** |
|
33 | - * holds the current process id |
|
34 | - * |
|
35 | - * @var integer |
|
36 | - */ |
|
32 | + /** |
|
33 | + * holds the current process id |
|
34 | + * |
|
35 | + * @var integer |
|
36 | + */ |
|
37 | 37 | private $pid; |
38 | 38 | |
39 | - /** |
|
40 | - * holds the exit code after the child dies |
|
41 | - */ |
|
39 | + /** |
|
40 | + * holds the exit code after the child dies |
|
41 | + */ |
|
42 | 42 | private $exitCode = -1; |
43 | 43 | |
44 | 44 | /** |
45 | - * holds type - needed for fping |
|
46 | - */ |
|
47 | - public $stype = "ping"; |
|
45 | + * holds type - needed for fping |
|
46 | + */ |
|
47 | + public $stype = "ping"; |
|
48 | 48 | |
49 | - /** |
|
50 | - * checks if threading is supported by the current |
|
51 | - * PHP configuration |
|
52 | - * |
|
53 | - * @return boolean |
|
54 | - */ |
|
49 | + /** |
|
50 | + * checks if threading is supported by the current |
|
51 | + * PHP configuration |
|
52 | + * |
|
53 | + * @return boolean |
|
54 | + */ |
|
55 | 55 | public static function available() { |
56 | 56 | $required_functions = array( |
57 | 57 | 'pcntl_fork', |
@@ -66,24 +66,24 @@ discard block |
||
66 | 66 | return true; |
67 | 67 | } |
68 | 68 | |
69 | - /** |
|
70 | - * class constructor - you can pass |
|
71 | - * the callback function as an argument |
|
72 | - * |
|
73 | - * @param callback $_runnable |
|
74 | - */ |
|
69 | + /** |
|
70 | + * class constructor - you can pass |
|
71 | + * the callback function as an argument |
|
72 | + * |
|
73 | + * @param callback $_runnable |
|
74 | + */ |
|
75 | 75 | public function __construct( $_runnable = null ) { |
76 | - if( $_runnable !== null ) { |
|
77 | - $this->setRunnable( $_runnable ); |
|
78 | - } |
|
76 | + if( $_runnable !== null ) { |
|
77 | + $this->setRunnable( $_runnable ); |
|
78 | + } |
|
79 | 79 | } |
80 | 80 | |
81 | - /** |
|
82 | - * sets the callback |
|
83 | - * |
|
84 | - * @param callback $_runnable |
|
85 | - * @return callback |
|
86 | - */ |
|
81 | + /** |
|
82 | + * sets the callback |
|
83 | + * |
|
84 | + * @param callback $_runnable |
|
85 | + * @return callback |
|
86 | + */ |
|
87 | 87 | public function setRunnable( $_runnable ) { |
88 | 88 | if( self::runnableOk( $_runnable ) ) { |
89 | 89 | $this->runnable = $_runnable; |
@@ -93,43 +93,43 @@ discard block |
||
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | - /** |
|
97 | - * gets the callback |
|
98 | - * |
|
99 | - * @return callback |
|
100 | - */ |
|
96 | + /** |
|
97 | + * gets the callback |
|
98 | + * |
|
99 | + * @return callback |
|
100 | + */ |
|
101 | 101 | public function getRunnable() { |
102 | 102 | return $this->runnable; |
103 | 103 | } |
104 | 104 | |
105 | - /** |
|
106 | - * checks if the callback is ok (the function/method |
|
107 | - * actually exists and is runnable from the current |
|
108 | - * context) |
|
109 | - * |
|
110 | - * can be called statically |
|
111 | - * |
|
112 | - * @param callback $_runnable |
|
113 | - * @return boolean |
|
114 | - */ |
|
105 | + /** |
|
106 | + * checks if the callback is ok (the function/method |
|
107 | + * actually exists and is runnable from the current |
|
108 | + * context) |
|
109 | + * |
|
110 | + * can be called statically |
|
111 | + * |
|
112 | + * @param callback $_runnable |
|
113 | + * @return boolean |
|
114 | + */ |
|
115 | 115 | public static function runnableOk( $_runnable ) { |
116 | 116 | return ( function_exists( $_runnable ) && is_callable( $_runnable ) ); |
117 | 117 | } |
118 | 118 | |
119 | - /** |
|
120 | - * returns the process id (pid) of the simulated thread |
|
121 | - * |
|
122 | - * @return int |
|
123 | - */ |
|
119 | + /** |
|
120 | + * returns the process id (pid) of the simulated thread |
|
121 | + * |
|
122 | + * @return int |
|
123 | + */ |
|
124 | 124 | public function getPid() { |
125 | 125 | return $this->pid; |
126 | 126 | } |
127 | 127 | |
128 | - /** |
|
129 | - * checks if the child thread is alive |
|
130 | - * |
|
131 | - * @return boolean |
|
132 | - */ |
|
128 | + /** |
|
129 | + * checks if the child thread is alive |
|
130 | + * |
|
131 | + * @return boolean |
|
132 | + */ |
|
133 | 133 | public function isAlive() { |
134 | 134 | $pid = pcntl_waitpid( $this->pid, $status, WNOHANG ); |
135 | 135 | |
@@ -143,22 +143,22 @@ discard block |
||
143 | 143 | } |
144 | 144 | } |
145 | 145 | |
146 | - /** |
|
147 | - * return exit code of child (-1 if child is still alive) |
|
148 | - * |
|
149 | - * @return int |
|
150 | - */ |
|
146 | + /** |
|
147 | + * return exit code of child (-1 if child is still alive) |
|
148 | + * |
|
149 | + * @return int |
|
150 | + */ |
|
151 | 151 | public function getExitCode() { |
152 | 152 | $this->isAlive(); |
153 | 153 | return $this->exitCode; |
154 | 154 | } |
155 | 155 | |
156 | - /** |
|
157 | - * starts the thread, all the parameters are |
|
158 | - * passed to the callback function |
|
159 | - * |
|
160 | - * @return void |
|
161 | - */ |
|
156 | + /** |
|
157 | + * starts the thread, all the parameters are |
|
158 | + * passed to the callback function |
|
159 | + * |
|
160 | + * @return void |
|
161 | + */ |
|
162 | 162 | public function start() { |
163 | 163 | $pid = @ pcntl_fork(); |
164 | 164 | if( $pid == -1 ) { |
@@ -183,59 +183,59 @@ discard block |
||
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
186 | - /** |
|
187 | - * starts the thread, all the parameters are |
|
188 | - * passed to the callback function |
|
189 | - * |
|
190 | - * modification for fping threading for cron scanning |
|
191 | - * |
|
192 | - * @return void |
|
193 | - */ |
|
186 | + /** |
|
187 | + * starts the thread, all the parameters are |
|
188 | + * passed to the callback function |
|
189 | + * |
|
190 | + * modification for fping threading for cron scanning |
|
191 | + * |
|
192 | + * @return void |
|
193 | + */ |
|
194 | 194 | public function start_fping() { |
195 | - $status = 0; |
|
196 | - $results = null; |
|
197 | - $pid = pcntl_fork(); |
|
195 | + $status = 0; |
|
196 | + $results = null; |
|
197 | + $pid = pcntl_fork(); |
|
198 | 198 | |
199 | - if( $pid == -1 ) { //error forking, no child is created |
|
200 | - throw new Exception( $this->getError( Thread::COULD_NOT_FORK ), Thread::COULD_NOT_FORK ); |
|
201 | - }else if ( $pid ) {// parent |
|
202 | - $this->pid = $pid; |
|
199 | + if( $pid == -1 ) { //error forking, no child is created |
|
200 | + throw new Exception( $this->getError( Thread::COULD_NOT_FORK ), Thread::COULD_NOT_FORK ); |
|
201 | + }else if ( $pid ) {// parent |
|
202 | + $this->pid = $pid; |
|
203 | 203 | |
204 | - } else { // child |
|
205 | - $this->pid = posix_getpid();//pid (child) |
|
206 | - $this->ppid = posix_getppid();//pid (parent) |
|
204 | + } else { // child |
|
205 | + $this->pid = posix_getpid();//pid (child) |
|
206 | + $this->ppid = posix_getppid();//pid (parent) |
|
207 | 207 | |
208 | - pcntl_signal( SIGTERM, array( $this, 'signalHandler' ) ); |
|
209 | - $array_args = func_get_args(); |
|
210 | - if ( !empty( $array_args ) ) { |
|
211 | - $results = call_user_func_array( $this->runnable, $array_args ); |
|
212 | - }else{ |
|
213 | - $results = call_user_func( $this->runnable ); |
|
214 | - } |
|
208 | + pcntl_signal( SIGTERM, array( $this, 'signalHandler' ) ); |
|
209 | + $array_args = func_get_args(); |
|
210 | + if ( !empty( $array_args ) ) { |
|
211 | + $results = call_user_func_array( $this->runnable, $array_args ); |
|
212 | + }else{ |
|
213 | + $results = call_user_func( $this->runnable ); |
|
214 | + } |
|
215 | 215 | |
216 | - $pipe = "/tmp/pipe_".$this->pid;//pid is known by parent |
|
216 | + $pipe = "/tmp/pipe_".$this->pid;//pid is known by parent |
|
217 | 217 | |
218 | - if(!file_exists($pipe)) {//child talks to parent using this pipe |
|
219 | - umask(0); |
|
220 | - posix_mkfifo($pipe, 0600); |
|
221 | - } |
|
222 | - //we have to open the pipe and send the data serialized |
|
223 | - $pipe_descriptor = fopen($pipe, 'w'); |
|
224 | - fwrite($pipe_descriptor, serialize( $results ) ); |
|
218 | + if(!file_exists($pipe)) {//child talks to parent using this pipe |
|
219 | + umask(0); |
|
220 | + posix_mkfifo($pipe, 0600); |
|
221 | + } |
|
222 | + //we have to open the pipe and send the data serialized |
|
223 | + $pipe_descriptor = fopen($pipe, 'w'); |
|
224 | + fwrite($pipe_descriptor, serialize( $results ) ); |
|
225 | 225 | |
226 | - //and kill the child using posix_kill ( exit(0) duplicates headers!! ) |
|
227 | - posix_kill( $this->pid , SIGKILL); |
|
228 | - exit(0); |
|
229 | - } |
|
226 | + //and kill the child using posix_kill ( exit(0) duplicates headers!! ) |
|
227 | + posix_kill( $this->pid , SIGKILL); |
|
228 | + exit(0); |
|
229 | + } |
|
230 | 230 | } |
231 | 231 | |
232 | - /** |
|
233 | - * attempts to stop the thread |
|
234 | - * returns true on success and false otherwise |
|
235 | - * |
|
236 | - * @param integer $_signal - SIGKILL/SIGTERM |
|
237 | - * @param boolean $_wait |
|
238 | - */ |
|
232 | + /** |
|
233 | + * attempts to stop the thread |
|
234 | + * returns true on success and false otherwise |
|
235 | + * |
|
236 | + * @param integer $_signal - SIGKILL/SIGTERM |
|
237 | + * @param boolean $_wait |
|
238 | + */ |
|
239 | 239 | public function stop( $_signal = SIGKILL, $_wait = false ) { |
240 | 240 | if( $this->isAlive() ) { |
241 | 241 | posix_kill( $this->pid, $_signal ); |
@@ -245,22 +245,22 @@ discard block |
||
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
248 | - /** |
|
249 | - * alias of stop(); |
|
250 | - * |
|
251 | - * @return boolean |
|
252 | - */ |
|
248 | + /** |
|
249 | + * alias of stop(); |
|
250 | + * |
|
251 | + * @return boolean |
|
252 | + */ |
|
253 | 253 | public function kill( $_signal = SIGKILL, $_wait = false ) { |
254 | 254 | return $this->stop( $_signal, $_wait ); |
255 | 255 | } |
256 | 256 | |
257 | - /** |
|
258 | - * gets the error's message based on |
|
259 | - * its id |
|
260 | - * |
|
261 | - * @param integer $_code |
|
262 | - * @return string |
|
263 | - */ |
|
257 | + /** |
|
258 | + * gets the error's message based on |
|
259 | + * its id |
|
260 | + * |
|
261 | + * @param integer $_code |
|
262 | + * @return string |
|
263 | + */ |
|
264 | 264 | public function getError( $_code ) { |
265 | 265 | if ( isset( $this->errors[$_code] ) ) { |
266 | 266 | return $this->errors[$_code]; |
@@ -270,11 +270,11 @@ discard block |
||
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
273 | - /** |
|
274 | - * signal handler |
|
275 | - * |
|
276 | - * @param integer $_signal |
|
277 | - */ |
|
273 | + /** |
|
274 | + * signal handler |
|
275 | + * |
|
276 | + * @param integer $_signal |
|
277 | + */ |
|
278 | 278 | protected function signalHandler( $_signal ) { |
279 | 279 | switch( $_signal ) { |
280 | 280 | case SIGTERM: |