1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
$path = $0; |
---|
5 |
$path =~ s/foltialib.pl$//i; |
---|
6 |
if ($pwd ne "./"){ |
---|
7 |
push( @INC, "$path"); |
---|
8 |
} |
---|
9 |
require "foltia_conf1.pl"; |
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
use DBI; |
---|
14 |
use DBD::Pg; |
---|
15 |
|
---|
16 |
|
---|
17 |
$DBDriv=$main::DBDriv; |
---|
18 |
$DBHost=$main::DBHost; |
---|
19 |
$DBPort=$main::DBPort; |
---|
20 |
$DBName=$main::DBName; |
---|
21 |
$DBUser=$main::DBUser; |
---|
22 |
$DBPass=""; |
---|
23 |
|
---|
24 |
|
---|
25 |
|
---|
26 |
sub writelog{ |
---|
27 |
my $messages = $_[0]; |
---|
28 |
my $timestump = `date +%Y/%m/%d_%H:%M:%S`; |
---|
29 |
chomp($timestump); |
---|
30 |
if ($debugmode == 1){ |
---|
31 |
open (DEBUGLOG , ">>$toolpath/debuglog.txt") || die "Cant write log file.$! \n "; |
---|
32 |
}else{ |
---|
33 |
open (DEBUGLOG , '>-') || die "Cant write log file.$! \n "; |
---|
34 |
} |
---|
35 |
$messages =~ s/\n//gio; |
---|
36 |
print DEBUGLOG "$timestump $messages\n"; |
---|
37 |
close (DEBUGLOG); |
---|
38 |
} |
---|
39 |
|
---|
40 |
sub syobocaldate2foltiadate{ |
---|
41 |
|
---|
42 |
my $foltiadate = $_[0] ; |
---|
43 |
|
---|
44 |
$foltiadate = substr($foltiadate,0,12); |
---|
45 |
|
---|
46 |
return $foltiadate; |
---|
47 |
|
---|
48 |
} |
---|
49 |
|
---|
50 |
|
---|
51 |
sub foldate2epoch{ |
---|
52 |
my $foltiadate = $_[0] ; |
---|
53 |
|
---|
54 |
|
---|
55 |
my $eyear = substr($foltiadate , 0, 4); |
---|
56 |
my $emon = substr($foltiadate, 4, 2); |
---|
57 |
$emon--; |
---|
58 |
my $emday = substr($foltiadate , 6, 2); |
---|
59 |
my $q_start_time_hour = substr($foltiadate , 8, 2); |
---|
60 |
my $q_start_time_min = substr($foltiadate , 10, 2); |
---|
61 |
|
---|
62 |
my $epoch = timelocal(0,$q_start_time_min,$q_start_time_hour, $emday, $emon , $eyear); |
---|
63 |
|
---|
64 |
return $epoch; |
---|
65 |
} |
---|
66 |
|
---|
67 |
|
---|
68 |
sub epoch2foldate{ |
---|
69 |
my $s; |
---|
70 |
my $mi; |
---|
71 |
my $h; |
---|
72 |
my $d; |
---|
73 |
my $mo; |
---|
74 |
my $y; |
---|
75 |
my $w; |
---|
76 |
|
---|
77 |
($s, $mi, $h, $d, $mo, $y, $w) = localtime($_[0]); |
---|
78 |
$mo++; $y += 1900; |
---|
79 |
|
---|
80 |
my $foltiadate; |
---|
81 |
$mo = sprintf("%02d",$mo); |
---|
82 |
$d = sprintf("%02d",$d); |
---|
83 |
|
---|
84 |
$h = sprintf("%02d",$h); |
---|
85 |
$mi = sprintf("%02d",$mi); |
---|
86 |
$foltiadate = "$y$mo$d$h$mi"; |
---|
87 |
|
---|
88 |
return $foltiadate; |
---|
89 |
} |
---|
90 |
|
---|
91 |
sub calclength{ |
---|
92 |
|
---|
93 |
|
---|
94 |
my $sttime = $_[0] ; |
---|
95 |
my $edtime = $_[1] ; |
---|
96 |
my $length = -1; |
---|
97 |
$sttime = &foldate2epoch($sttime); |
---|
98 |
$edtime = &foldate2epoch($edtime); |
---|
99 |
|
---|
100 |
if ($edtime >= $sttime){ |
---|
101 |
$length = $edtime - $sttime; |
---|
102 |
}else{ |
---|
103 |
$length = $sttime - $edtime; |
---|
104 |
} |
---|
105 |
$length = $length / 60; |
---|
106 |
|
---|
107 |
return $length ; |
---|
108 |
} |
---|
109 |
|
---|
110 |
sub calcoffsetdate{ |
---|
111 |
|
---|
112 |
|
---|
113 |
my $foltime = $_[0] ; |
---|
114 |
my $offsetmin = $_[1] ; |
---|
115 |
|
---|
116 |
my $epoch = &foldate2epoch($foltime ); |
---|
117 |
$epoch = $epoch + ($offsetmin * 60 ); |
---|
118 |
$foltime = &epoch2foldate($epoch); |
---|
119 |
return $foltime ; |
---|
120 |
} |
---|
121 |
|
---|
122 |
sub getstationid{ |
---|
123 |
|
---|
124 |
|
---|
125 |
my $stationname = $_[0] ; |
---|
126 |
my $stationid ; |
---|
127 |
my $DBQuery = "SELECT count(*) FROM foltia_station WHERE stationname = '$item{ChName}'"; |
---|
128 |
|
---|
129 |
my $sth; |
---|
130 |
$sth = $dbh->prepare($DBQuery); |
---|
131 |
$sth->execute(); |
---|
132 |
my @stationcount; |
---|
133 |
@stationcount= $sth->fetchrow_array; |
---|
134 |
|
---|
135 |
if ($stationcount[0] == 1){ |
---|
136 |
|
---|
137 |
$DBQuery = "SELECT stationid,stationname FROM foltia_station WHERE stationname = '$item{ChName}'"; |
---|
138 |
$sth = $dbh->prepare($DBQuery); |
---|
139 |
$sth->execute(); |
---|
140 |
@stationinfo= $sth->fetchrow_array; |
---|
141 |
|
---|
142 |
$stationid = $stationinfo[0]; |
---|
143 |
|
---|
144 |
|
---|
145 |
}elsif($stationcount[0] == 0){ |
---|
146 |
|
---|
147 |
$DBQuery = "SELECT max(stationid) FROM foltia_station"; |
---|
148 |
$sth = $dbh->prepare($DBQuery); |
---|
149 |
$sth->execute(); |
---|
150 |
@stationinfo= $sth->fetchrow_array; |
---|
151 |
my $stationid = $stationinfo[0] ; |
---|
152 |
$stationid ++; |
---|
153 |
|
---|
154 |
|
---|
155 |
$DBQuery = "insert into foltia_station (stationid , stationname ,stationrecch ) values ('$stationid' ,'$item{ChName}','-10')"; |
---|
156 |
|
---|
157 |
$sth = $dbh->prepare($DBQuery); |
---|
158 |
$sth->execute(); |
---|
159 |
|
---|
160 |
&writelog("foltialib Add station;$DBQuery"); |
---|
161 |
}else{ |
---|
162 |
|
---|
163 |
|
---|
164 |
&writelog("foltialib [ERR] getstationid $stationcount[0] stations found. $DBQuery"); |
---|
165 |
} |
---|
166 |
|
---|
167 |
|
---|
168 |
return $stationid ; |
---|
169 |
} |
---|
170 |
|
---|
171 |
sub calcatqparam{ |
---|
172 |
my $seconds = $_[0]; |
---|
173 |
my $processstarttimeepoch = ""; |
---|
174 |
$processstarttimeepoch = &foldate2epoch($startdatetime); |
---|
175 |
$processstarttimeepoch = $processstarttimeepoch - $seconds ; |
---|
176 |
my $sec = ""; |
---|
177 |
my $min = ""; |
---|
178 |
my $hour = ""; |
---|
179 |
my $mday = ""; |
---|
180 |
my $mon = ""; |
---|
181 |
my $year = ""; |
---|
182 |
my $wday = ""; |
---|
183 |
my $yday = ""; |
---|
184 |
my $isdst = ""; |
---|
185 |
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($processstarttimeepoch) ; |
---|
186 |
$year+=1900; |
---|
187 |
$mon++; |
---|
188 |
my $atdateparam = ""; |
---|
189 |
$atdateparam = sprintf ("%04d%02d%02d%02d%02d",$year,$mon,$mday,$hour,$min); |
---|
190 |
|
---|
191 |
return $atdateparam ; |
---|
192 |
} |
---|
193 |
|
---|
194 |
|
---|
195 |
|
---|
196 |
sub processfind{ |
---|
197 |
my $findprocess = $_[0]; |
---|
198 |
|
---|
199 |
my @processes ; |
---|
200 |
@processes = `ps ax | grep -i $findprocess `; |
---|
201 |
my $chkflag = 0; |
---|
202 |
|
---|
203 |
foreach (@processes ){ |
---|
204 |
if (/$findprocess/i){ |
---|
205 |
unless (/grep/){ |
---|
206 |
|
---|
207 |
$chkflag++ ; |
---|
208 |
}else{ |
---|
209 |
|
---|
210 |
} |
---|
211 |
} |
---|
212 |
|
---|
213 |
} |
---|
214 |
return ($chkflag); |
---|
215 |
} |
---|
216 |
|
---|
217 |
|
---|
218 |
sub filenameinjectioncheck{ |
---|
219 |
my $filename = $_[0]; |
---|
220 |
$filename =~ s/\///gi; |
---|
221 |
$filename =~ s/\;//gi; |
---|
222 |
$filename =~ s/\&//gi; |
---|
223 |
$filename =~ s/\|//gi; |
---|
224 |
|
---|
225 |
return ($filename ); |
---|
226 |
} |
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 |
1; |
---|
231 |
|
---|