root/trunk/install/perl/foltialib.pl

リビジョン 70, 5.3 kB (コミッタ: sorshi, コミット時期: 17 年 前)

環境ポリシー機能搭載

  • svn:executable 属性の設定値:
Line 
1
2 #config load
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 #  foltia lib
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 }#end writelog
39
40 sub syobocaldate2foltiadate{
41 #20041114213000 -> 200411142130
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 #EPGをEPOCに
54 # 2004 11 14 21 30
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 #foltia開始時刻、folti終了時刻
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 #引き数:foltia時刻、オフセット(+/-)分
112 #戻り値]foltia時刻
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 #引き数:局文字列(NHK総合)
124 #戻り値:1
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 #チャンネルID取得
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 #局ID
142 $stationid  = $stationinfo[0];
143 #print "StationID:$stationid \n";
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 ##$DBQuery =  "insert into  foltia_station values ('$stationid'  ,'$item{ChName}','0','','','','','','')";
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 #print "Add station;$DBQuery\n";
160 &writelog("foltialib Add station;$DBQuery");
161 }else{
162
163 #print "Error  getstationid $stationcount[0] stations found. $DBQuery\n";
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++;#範囲を0-11から1-12へ
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                 #print "process found:$_\n";
207                 $chkflag++ ;
208                 }else{
209                 #print "process NOT found:$_\n";
210                 }
211         }
212
213 }
214 return ($chkflag);
215 }#endsub
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 sub getphpstyleconfig{
230 my $key = $_[0];
231 my $phpconfigpath = "";
232 my $configline = "";
233  # read
234 if (-e "$phptoolpath/php/foltia_config2.php"){
235         $phpconfigpath = "$phptoolpath/php/foltia_config2.php";
236 }elsif(-e "$toolpath/php/foltia_config2.php"){
237         $phpconfigpath = "$toolpath/php/foltia_config2.php";
238 }else{
239         $phpconfigpath = `locate foltia_config2.php | head -1`;
240         chomp($phpconfigpath);
241 }
242
243
244 if (-r $phpconfigpath ){
245 open (CONFIG ,"$phpconfigpath") || die "File canot read.$!";
246 while(<CONFIG>){
247         if (/$key/){
248         $configline = $_;
249         $configline =~ s/\/\/.*$//;
250         $configline =~ s/\/\*.*\*\///;
251         }else{
252         }
253 }
254 close(CONFIG);
255 }#end if -r $phpconfigpath
256 return ($configline);
257 }#end sub getphpstyleconfig
258
259
260 1;
261
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed