[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [7755] property: integration on accounting system
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [7755] property: integration on accounting system |
Date: |
Thu, 29 Sep 2011 12:38:46 +0000 |
Revision: 7755
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=7755
Author: sigurdne
Date: 2011-09-29 12:38:45 +0000 (Thu, 29 Sep 2011)
Log Message:
-----------
property: integration on accounting system
Modified Paths:
--------------
trunk/property/inc/cron/default/Import_fra_basware_X205.php
trunk/property/inc/export/default/Basware_X114
trunk/property/templates/base/config.tpl
Modified: trunk/property/inc/cron/default/Import_fra_basware_X205.php
===================================================================
--- trunk/property/inc/cron/default/Import_fra_basware_X205.php 2011-09-29
12:29:57 UTC (rev 7754)
+++ trunk/property/inc/cron/default/Import_fra_basware_X205.php 2011-09-29
12:38:45 UTC (rev 7755)
@@ -76,6 +76,8 @@
$this->like = &
$this->db->like;
$this->dateformat =
$this->db->date_format();
$this->datetimeformat = $this->db->datetime_format();
+ $this->config =
CreateObject('phpgwapi.config','property');
+ $this->config->read();
}
function pre_run($data='')
@@ -147,9 +149,8 @@
public function execute($cron='')
{
- $config = CreateObject('phpgwapi.config','property');
- $config->read();
- $dirname = $config->config_data['import_path'];
+ $this->get_files();
+ $dirname = $this->config->config_data['import_path'];
// prevent path traversal
if ( preg_match('/\./', $dirname)
|| !is_dir($dirname) )
@@ -224,8 +225,91 @@
}
- function import($file)
+ protected function get_files()
{
+ $server =
$this->config->config_data['invoice_ftp_host'];
+ $user =
$this->config->config_data['invoice_ftp_user'];
+ $password =
$this->config->config_data['invoice_ftp_password'];
+ $directory_remote =
rtrim($this->config->config_data['invoice_ftp_import_basedir'],'/');
+ $directory_local =
rtrim($this->config->config_data['import_path'],'/');
+ $port = 22;
+
+ $debug = false;
+
+ if (!function_exists("ssh2_connect"))
+ {
+ die("function ssh2_connect doesn't exist");
+ }
+ if(!($connection = ssh2_connect("$server", $port)))
+ {
+ echo "fail: unable to establish connection\n";
+ }
+ else
+ {
+ // try to authenticate with username root,
password secretpassword
+ if(!ssh2_auth_password($connection, $user,
$password))
+ {
+ echo "fail: unable to authenticate\n";
+ }
+ else
+ {
+ // allright, we're in!
+ echo "okay: logged in...<br/>";
+
+ // execute a command
+ if (!($stream = ssh2_exec($connection,
"ls -al {$directory_remote}" )))
+ {
+ echo "fail: unable to execute
command\n";
+ }
+ else if ($debug)
+ {
+ // collect returning data from
command
+ stream_set_blocking($stream,
true);
+ $data = "";
+ while ($buf =
fread($stream,4096))
+ {
+ $data .= $buf;
+ }
+ fclose($stream);
+ _debug_array($data);
+ }
+ else
+ {
+ $com ="ls {$directory_remote}";
+ $stream =
ssh2_exec($connection, $com);
+
stream_set_blocking($stream,true);
+ $cmd = fread($stream,4096);
+ $arr=explode("\n",$cmd);
+ $total_files=count($arr);
+ $sftp = ssh2_sftp($connection);
+ // _debug_array($arr);
+ for($i=0;$i<$total_files;$i++)
+ {
+
$file_name=trim($arr[$i]);
+ if($file_name!='' &&
stripos( $file_name, 'x205' ) === 0)
+ {
+ $file_remote =
"{$directory_remote}/{$file_name}";
+ $file_local =
"{$directory_local}/{$file_name}";
+
if(ssh2_scp_recv($connection, $file_remote,$file_local))
+ {
+ echo
"File remote: ".$file_remote." was copied to local: $file_local<br/>";
+ if(
ssh2_sftp_rename ($sftp, $file_remote,
"{$directory_remote}/archive/{$file_name}" ))
+ {
+
echo "File remote: ".$file_remote." was moved to remote:
{$directory_remote}/archive/{$file_name}<br/>";
+ }
+ }
+ }
+ }
+ fclose($stream);
+ }
+ }
+ }
+
+ }
+
+
+ protected function import($file)
+ {
// $valid_data= False;
$buffer = array();
Modified: trunk/property/inc/export/default/Basware_X114
===================================================================
--- trunk/property/inc/export/default/Basware_X114 2011-09-29 12:29:57 UTC
(rev 7754)
+++ trunk/property/inc/export/default/Basware_X114 2011-09-29 12:38:45 UTC
(rev 7755)
@@ -40,6 +40,7 @@
var $debug;
var $client_code = 14;
+ protected $connection = false;
function __construct()
{
@@ -356,6 +357,18 @@
$receipt['message'][]= array('msg' =>
$this->transfer_voucher($batchid, $voucher_id, $download, $force_period_year));
}
+ if($this->connection)
+ {
+ switch
($this->config->config_data['invoice_export_method'])
+ {
+ case 'ftp';
+ ftp_quit($this->connection);
+ break;
+ case 'ssh';
+ ssh2_exec($this->connection,
'exit');
+ break;
+ }
+ }
//Lagre melding
if ($download=='on')
{
@@ -745,7 +758,7 @@
}
// -- END
- if( $file_written &&
$this->config->config_data['invoice_export_method'] != 'ftp' )
+ if( $file_written &&
($this->config->config_data['invoice_export_method'] != 'ftp' &&
$this->config->config_data['invoice_export_method'] != 'ssh'))
{
$transfer_ok = true;
}
@@ -837,28 +850,41 @@
protected function
transfer($buffer,$Filnavn,$batchid,$tranfser_bilag)
{
-
-
if($this->config->config_data['invoice_export_method']=='ftp')
+
if($this->config->config_data['invoice_export_method']=='ftp' ||
$this->config->config_data['invoice_export_method']=='ssh')
{
- $ftp = $this->phpftp_connect();
+ if(!$connection = $this->connection)
+ {
+ $connection =
$this->phpftp_connect();
+ }
$basedir =
$this->config->config_data['invoice_ftp_basedir'];
if($basedir)
{
- $newfile = $basedir . '/' .
basename($Filnavn);
+ $remote_file = $basedir . '/' .
basename($Filnavn);
}
else
{
- $newfile = basename($Filnavn);
+ $remote_file = basename($Filnavn);
}
- if (ftp_put($ftp,$newfile, $Filnavn,
FTP_BINARY))
+ switch
($this->config->config_data['invoice_export_method'])
{
+ case 'ftp';
+ $transfer_ok =
ftp_put($connection,$remote_file, $Filnavn, FTP_BINARY);
+ break;
+ case 'ssh';
+ $transfer_ok =
ssh2_scp_send($connection, $Filnavn, $remote_file );
+ break;
+ default:
+ $transfer_ok = false;
+
+ }
+ if ($send_ok)
+ {
for
($i=0;$i<count($tranfser_bilag);$i++)
{
$this->soXport->log_transaction($batchid,$tranfser_bilag[$i],lang('Invoice
pre_transferred %1',basename($Filnavn)));
}
- $transfer_ok = True;
}
else
{
@@ -866,33 +892,54 @@
{
$this->soXport->log_transaction($batchid,$tranfser_bilag[$i],lang('Failed to
pre_transfere %1 to agresso',basename($Filnavn)));
}
- $transfer_ok = False;
}
if(!$transfer_ok)
{
unlink($Filnavn);
}
-
- ftp_quit($ftp);
}
return $transfer_ok;
}
protected function phpftp_connect()
{
- $host = $this->config->config_data['invoice_ftp_host'];
- $user = $this->config->config_data['invoice_ftp_user'];
- $pass =
$this->config->config_data['invoice_ftp_password'];
+ $server =
$this->config->config_data['invoice_ftp_host'];
+ $user =
$this->config->config_data['invoice_ftp_user'];
+ $password =
$this->config->config_data['invoice_ftp_password'];
+ $port = 22;
-// echo "connecting to $host with $user and $pass\n <br>";
- $ftp = ftp_connect($host);
- if($ftp)
+ switch
($this->config->config_data['invoice_export_method'])
{
- if (ftp_login($ftp,$user,$pass))
- {
- return $ftp;
- }
+ case 'ftp';
+ if($connection = ftp_connect($server))
+ {
+
ftp_login($connection,$user,$password);
+ }
+ break;
+ case 'ssh';
+ if (!function_exists("ssh2_connect"))
+ {
+ die("function ssh2_connect
doesn't exist");
+ }
+ if(!($connection =
ssh2_connect("$server", $port)))
+ {
+ $message = "fail: unable to
establish connection";
+ _debug_array($message);
+ //$receipt['error'][]=
array('msg' => $message);
+ }
+ else
+ {
+ // try to authenticate with
username root, password secretpassword
+
if(!ssh2_auth_password($connection, $user, $password))
+ {
+ $message = "fail:
unable to authenticate";
+ _debug_array($message);
+ //$receipt['error'][]=
array('msg' => $message);
+ }
+ }
+ break;
}
+ $this->connection = $connection;
+ return $connection;
}
}
-?>
Modified: trunk/property/templates/base/config.tpl
===================================================================
--- trunk/property/templates/base/config.tpl 2011-09-29 12:29:57 UTC (rev
7754)
+++ trunk/property/templates/base/config.tpl 2011-09-29 12:38:45 UTC (rev
7755)
@@ -97,6 +97,7 @@
<select
name="newsettings[invoice_export_method]">
<option value="local"
{selected_invoice_export_method_local}>Local</option>
<option value="ftp"
{selected_invoice_export_method_ftp}>Local and ftp</option>
+ <option value="ssh"
{selected_invoice_export_method_ssh}>Local and ssh</option>
</select>
</td>
</tr>
@@ -113,9 +114,13 @@
<td><input type ="password"
name="newsettings[invoice_ftp_password]"
value="{value_invoice_ftp_password}"></td>
</tr>
<tr class="row_on">
-
<td>{lang_invoice_ftp_host_basedir_with_NO_trailing_slash}:</td>
+
<td>{lang_invoice_ftp_host_export_basedir_with_NO_trailing_slash}:</td>
<td><input name="newsettings[invoice_ftp_basedir]"
value="{value_invoice_ftp_basedir}"></td>
</tr>
+ <tr class="row_on">
+
<td>{lang_invoice_ftp_host_import_basedir_with_NO_trailing_slash}:</td>
+ <td><input
name="newsettings[invoice_ftp_import_basedir]"
value="{value_invoice_ftp_import_basedir}"></td>
+ </tr>
</tr>
<tr class="row_off">
<td>{lang_dimb_responsible_1}:</td>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [7755] property: integration on accounting system,
Sigurd Nes <=