2012-06-25 14:05:12 +00:00
< ? php
$link = pg_connect ( " dbname=metadata user=gis password=gispassword host=210.77.68.241 " );
if ( ! $link )
{
die ( " Error in connection: " . pg_last_error ());
}
//安全检查: 只接受来自westdc.westgis.ac.cn的访问
2012-06-26 04:55:33 +00:00
if ( @ $_SERVER [ 'HTTP_CLIENT_IP' ]){
2012-06-25 14:05:12 +00:00
$onlineip = $_SERVER [ 'HTTP_CLIENT_IP' ];
2012-06-26 04:55:33 +00:00
} elseif ( @ $_SERVER [ 'HTTP_X_FORWARDED_FOR' ]){
2012-06-25 14:05:12 +00:00
$onlineip = $_SERVER [ 'HTTP_X_FORWARDED_FOR' ];
} else {
$onlineip = $_SERVER [ 'REMOTE_ADDR' ];
}
2013-03-13 07:55:18 +00:00
if ( $onlineip != '210.77.68.241' && $onlineip != '2001:cc0:f006::9' )
2012-06-28 07:12:52 +00:00
die ( " error! You are not permitted to visit this page. " . $onlineip );
2012-06-25 14:05:12 +00:00
//文件生成
2012-06-26 04:55:33 +00:00
$onlineappid = ( int ) @ $_GET [ 'onlineappid' ];
$offlineappid = ( int ) @ $_GET [ 'offlineappid' ];
2012-06-25 14:05:12 +00:00
if ( ! ( $onlineappid > 0 || $offlineappid > 0 ))
{
die ( " Error in parameter. " );
}
$sql = " select dataorder.userid,dataset.path from dataorder left join dataset on dataorder.uuid=dataset.uuid
2013-10-28 14:54:21 +00:00
where dataorder . status in ( 0 , 5 ) and dataset . host = 'ftp2.westgis.ac.cn' and dataset . path <> '' and dataorder . selection is null " ;
2012-06-25 14:05:12 +00:00
if ( $onlineappid > 0 )
$sql .= " and dataorder.onlineappid= " . $onlineappid ;
else if ( $offlineappid > 0 )
$sql .= " and dataorder.offlineappid= " . $offlineappid ;
2012-11-17 03:22:19 +00:00
$result = pg_query ( $link , $sql );
$numrows = pg_num_rows ( $result );
2012-06-25 14:05:12 +00:00
// Loop on rows in the result set.
$content = '' ;
for ( $ri = 0 ; $ri < $numrows ; $ri ++ )
{
$row = pg_fetch_array ( $result , $ri );
$content .= '# path: ' . $row [ 'path' ] . " \n " ;
2012-11-16 15:48:07 +00:00
$content .= 'mkdir -p "/home/ftp/westdc_' . $row [ 'userid' ] . '/' . preg_replace ( '/^.+[\\\\\\/]/' , '' , rtrim ( $row [ 'path' ], '/' )) . '"' . " \n " ;
2012-10-18 03:02:13 +00:00
$content .= 'mount --bind "' . $row [ 'path' ] . '" "/home/ftp/westdc_' . $row [ 'userid' ] . '/' . preg_replace ( '/^.+[\\\\\\/]/' , '' , rtrim ( $row [ 'path' ], '/' )) . '"' . " \n " ;
2012-06-25 14:05:12 +00:00
}
2013-10-28 14:54:21 +00:00
$sql = " select distinct dataorder.userid,dataset.path,dataservice.uuid from dataorder left join dataset on dataorder.uuid=dataset.uuid left join dataservice on dataorder.uuid=dataservice.uuid
where dataorder . status in ( 0 , 5 ) and dataset . host = 'ftp2.westgis.ac.cn' and dataset . path <> '' and dataorder . selection is not null and dataservice . service_type in ( 1 , 2 ) " ;
if ( $onlineappid > 0 )
$sql .= " and dataorder.onlineappid= " . $onlineappid ;
else if ( $offlineappid > 0 )
$sql .= " and dataorder.offlineappid= " . $offlineappid ;
$result = pg_query ( $link , $sql );
$numrows = pg_num_rows ( $result );
$basepath = '/disk1/WestDC/wsndata/' ;
for ( $ri = 0 ; $ri < $numrows ; $ri ++ )
{
$row = pg_fetch_array ( $result , $ri );
$content .= '# path: ' . $row [ 'path' ] . " \n " ;
$content .= 'mkdir -p "/home/ftp/westdc_' . $row [ 'userid' ] . '/wsn_' . $row [ 'userid' ] . '"' . " \n " ;
$content .= 'mount --bind "' . $basepath . 'wsn_' . $row [ 'userid' ] . '" "/home/ftp/westdc_' . $row [ 'userid' ] . '/wsn_' . $row [ 'userid' ] . '"' . " \n " ;
}
2012-06-25 14:05:12 +00:00
$filename = './proftp-user.sh' ;
if ( ! empty ( $content ))
if ( ! file_put_contents ( $filename , $content , LOCK_EX ))
{
sleep ( 1 );
if ( ! file_put_contents ( $filename , $content , LOCK_EX ))
{
sleep ( 1 );
if ( ! file_put_contents ( $filename , $content , LOCK_EX ))
die ( " error in write proftp-user.sh " );
}
}
pg_free_result ( $result );
pg_close ( $link );
?>