Ejemplo n.º 1
2
 function readFromZiraatTxt($tesvikid)
 {
     $sftp = new Net_SFTP(ZIRAAT_FTP_HOST);
     if ($sftp->login(ZIRAAT_FTP_USER, ZIRAAT_FTP_PASS)) {
         //ilk önce doğru txt mi ??
         $directory_temp = EK_FOLDER . "ziraat_eft/temp_bankadan_kuruma/";
         if (!file_exists($directory_temp)) {
             mkdir($directory_temp, 0777, true);
         }
         //$fileTo
         $fileFrom = "/bankadan_kuruma/";
         $filelist = $sftp->nlist($fileFrom);
         $control = false;
         $fileth = count($filelist) - 1;
         do {
             $file = $filelist[$fileth];
             $fileTo = $directory_temp . $file;
             $sftp->get($fileFrom . $file, $fileTo);
             $control = $this->checkTxtFileForTesvik($tesvikid, $fileTo);
             if ($control == false) {
                 unlink($fileTo);
                 $fileth--;
             }
             if ($fileth == 0) {
                 break;
             }
         } while ($control == false);
         if ($control == true) {
             $directory = EK_FOLDER . "ziraat_eft/bankadan_kuruma/" . date('Ymd');
             if (!file_exists($directory)) {
                 mkdir($directory, 0777, true);
             }
             $files = explode('/', $fileTo);
             rename($fileTo, $directory . '/' . end($files));
             $return['FILE'] = date('Ymd') . '/' . end($files);
             $return['STATUS'] = true;
             $return['TEXT'] = "Dosya basariyla indirildi";
         } else {
             $return['STATUS'] = false;
             $return['TEXT'] = "Dosya indirme hatasi";
         }
     } else {
         $return['STATUS'] = false;
         $return['TEXT'] = "ftp bağlanti hatasi";
     }
     return $return;
 }
Ejemplo n.º 2
0
 /**
  * Read a file
  *
  */
 public function read($filename, $dest = null)
 {
     if (is_null($dest)) {
         $dest = false;
     }
     return $this->_connection->get($filename, $dest);
 }
Ejemplo n.º 3
0
 /**
  * get a file
  *
  * @param String $source_file      the target file to download
  * @param bool   $destination_file the save path
  *
  * @return String
  * @throws CMbException
  */
 private function _getFile($source_file, $destination_file = false)
 {
     if (!$this->connexion) {
         throw new CMbException("CSourceSFTP-connexion-failed", $this->hostname);
     }
     // Download the file
     if (!($data = $this->connexion->get($source_file, $destination_file))) {
         throw new CMbException("CSourceSFTP-download-file-failed", $source_file, $destination_file);
     }
     return $data;
 }
Ejemplo n.º 4
0
 /**
  * copy a file from the remote server to the local install
  * @param $source string
  * @param $destination string
  * @return bool
  */
 public function scpRemoteLocal($source, $destination)
 {
     $sftp = new \Net_SFTP(Setting::getSetting('remote:host'));
     $key = new Crypt_RSA();
     $key->loadKey(file_get_contents(Setting::getSetting('ssh:priv_key')));
     if (!$sftp->login(Setting::getSetting('remote:user'), $key)) {
         $cli = new CLImate();
         $cli->error("Could not connect to server");
         return false;
     }
     $sftp->get($source, $destination);
 }
Ejemplo n.º 5
0
 /**
  * @param string $remotePath
  * @param string $destFile
  * @param int    $resumePos
  *
  * @return bool
  */
 public function get($remotePath, $destFile, $resumePos = 0)
 {
     switch ($this->_connType) {
         case SftpHelper::TYPE_SFTP:
         default:
             $res = $this->_connection->get($remotePath, $destFile, $resumePos);
             break;
         case SftpHelper::TYPE_FTP:
             $res = @ftp_get($this->_connection, $destFile, $remotePath, FTP_BINARY, $resumePos);
             break;
     }
     return $res;
 }
Ejemplo n.º 6
0
     if (!$mail->Send()) {
         echo "Mailer Error: " . $mail->ErrorInfo;
     } else {
         echo "Message sent!";
     }
     //unlink('/tmp/kontakti.txt');
     $sftp = new Net_SFTP('podrska.bbtrade.rs');
     if (!$sftp->login('root', 'bbsb100$')) {
         echo "Login Failed";
         exit('Login Failed');
     }
     // outputs the contents of filename.remote to the screen
     //echo $sftp->get('/tmp/kontakti.txt');
     // copies filename.remote to filename.local from the SFTP server
     //$sftp->get('/tmp/kontakti.txt', '\\C$\Users\%username%\Desktop\kontakti.txt');
     $sftp->get('/tmp/izvestaj_op.csv', 'C:/storno/izvestaj.txt');
     if ($sftp->delete('/tmp/izvestaj_op.csv')) {
         // doesn't delete directories
         echo "File /tmp/izvestaj_op.csv je obrisan!";
     } else {
         echo "File /tmp/izvestaj_op.csv nije obrisan!";
     }
     echo '<br />';
     /*echo "Izvrsen je sledeci upit:";
     		echo '<br />';
     		echo $sql;*/
     echo '<br />';
     echo "Ako ste upisali ispravnu email adresu, fajl ce Vam biti isporucen putem email-a.";
 } else {
     //Besmisleno je jer bi ovako bio prevelik fajl
     /*
Ejemplo n.º 7
0
<?php

session_start();
include 'header.php';
include 'Net/SFTP.php';
$fileToGet = $_GET['file'];
$localFile = 'uploads/' . $fileToGet;
$sftp = new Net_SFTP(SSH_HOST);
if ($sftp->login($_SESSION['id'], $_SESSION['passwd'])) {
    $sftp->get('/scratch/' . $_SESSION['id'] . '/meshslicer/' . $fileToGet, $localFile);
    $reply = json_encode(array('Error' => '0', 'Message' => ""));
    //unlink($localFile);
} else {
    $reply = json_encode(array('Error' => '1', 'Message' => "Astral problem. Please try again."));
}
echo $reply;
Ejemplo n.º 8
0
 private function downloadJob($result, $silverpop, $type, $listId = array())
 {
     if (empty($result['JOB_ID'])) {
         $this->logMessage("WARNING: Last job was not successfully created. Check the source in Silverpop.");
         return;
     }
     $file = str_replace('/download/', '', $result['FILE_PATH']);
     // Wait till its done
     $counter = 0;
     do {
         sleep(2);
         $status = $silverpop->getJobStatus($result['JOB_ID']);
         $counter++;
     } while (!in_array($status['JOB_STATUS'], array('COMPLETE', 'CANCELLED', 'ERROR')) && $counter < 3600);
     // Check if everything happend OK
     if ($status['JOB_STATUS'] != 'COMPLETE') {
         throw new SilverpopException('An error occured while creating report in Silverpop. Last job status: ' . $status['JOB_STATUS'] . '. Last job status response: ' . json_encode($status));
     }
     $this->logMessage('Job finished for ID ' . $result['JOB_ID']);
     // ================== Download data from SFTP ==================
     $sftp = new Net_SFTP('transfer' . $this->config['engage_server'] . '.silverpop.com');
     if (!$sftp->login($this->config['username'], $this->config['#password'])) {
         exit('Login Failed');
     }
     $sftp->get("{$this->remoteDir}{$file}", $this->localDir . $file);
     if ($type == 'contact_lists') {
         $this->loadFile($this->localDir . $file, $this->config['bucket'], $type, false, array('LIST_NAME', 'LIST_ID'), $listId);
     } else {
         if ($type == 'events') {
             $this->extractAndLoad($this->localDir . $file, $this->config['bucket'], array('Raw Recipient Data Export' => 'events'), array('LIST_NAME', 'LIST_ID'), $listId);
         } else {
             $this->extractAndLoad($this->localDir . $file, $this->config['bucket']);
         }
     }
     $this->logMessage('Data downloaded for job ' . $result['JOB_ID']);
 }
Ejemplo n.º 9
0
        $sslpassword = $query_row['sslpassword'];
    }
    $path = getcwd();
    chdir('..');
    chdir('..');
    $path = getcwd();
    chdir('php/pear');
    $path = getcwd();
    set_include_path($path);
    set_include_path(get_include_path() . '/' . 'phpsec');
    include 'Net/SSH2.php';
    include 'File/ANSI.php';
    include '/Net/SFTP.php';
    $sftp = new Net_SFTP(@$hostname);
    if (@$sftp->login(@$sslusername, @$sslpassword)) {
        $data = $sftp->get('/proc/stat');
        $data = explode("\n", $data);
        $cores = array();
        foreach ($data as $line) {
            if (preg_match('/^cpu[0-9]/', $line)) {
                $info = explode(' ', $line);
                $cores[] = array('user' => round($info[1] / ($info[1] + $info[2] + $info[3] + $info[4] + $info[5] + $info[6] + $info[7] + $info[8] + $info[9]) * 100, 2) . '%', 'sys' => round($info[3] / ($info[1] + $info[2] + $info[3] + $info[4] + $info[5] + $info[6] + $info[7] + $info[8] + $info[9]) * 100, 2) . '%', 'idle' => round($info[4] / ($info[1] + $info[2] + $info[3] + $info[4] + $info[5] + $info[6] + $info[7] + $info[8] + $info[9]) * 100, 2) . '%');
            }
        }
        echo json_encode($cores);
    } else {
        echo "[]";
    }
} else {
    echo "[]";
}
Ejemplo n.º 10
0
/**
 * Poll all eligible labs for new results and store them in the database.
 *
 * @param  array   &$messages  Receives messages of interest.
 * @return string  Error text, or empty if no errors.
 */
function poll_hl7_results(&$messages)
{
    global $srcdir;
    $messages = array();
    $filecount = 0;
    $badcount = 0;
    $ppres = sqlStatement("SELECT * FROM procedure_providers ORDER BY name");
    while ($pprow = sqlFetchArray($ppres)) {
        $protocol = $pprow['protocol'];
        $remote_host = $pprow['remote_host'];
        $hl7 = '';
        if ($protocol == 'SFTP') {
            ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . "{$srcdir}/phpseclib");
            require_once "{$srcdir}/phpseclib/Net/SFTP.php";
            // Compute the target path name.
            $pathname = '.';
            if ($pprow['results_path']) {
                $pathname = $pprow['results_path'] . '/' . $pathname;
            }
            // Connect to the server and enumerate files to process.
            $sftp = new Net_SFTP($remote_host);
            if (!$sftp->login($pprow['login'], $pprow['password'])) {
                return xl('Login to remote host') . " '{$remote_host}' " . xl('failed');
            }
            $files = $sftp->nlist($pathname);
            foreach ($files as $file) {
                if (substr($file, 0, 1) == '.') {
                    continue;
                }
                ++$filecount;
                $hl7 = $sftp->get("{$pathname}/{$file}");
                // Archive the results file.
                $prpath = $GLOBALS['OE_SITE_DIR'] . "/procedure_results";
                if (!file_exists($prpath)) {
                    mkdir($prpath);
                }
                $prpath .= '/' . $pprow['ppid'];
                if (!file_exists($prpath)) {
                    mkdir($prpath);
                }
                $fh = fopen("{$prpath}/{$file}", 'w');
                if ($fh) {
                    fwrite($fh, $hl7);
                    fclose($fh);
                } else {
                    $messages[] = xl('File') . " '{$file}' " . xl('cannot be archived, ignored');
                    ++$badcount;
                    continue;
                }
                // Now delete it from its ftp directory.
                if (!$sftp->delete("{$pathname}/{$file}")) {
                    $messages[] = xl('File') . " '{$file}' " . xl('cannot be deleted, ignored');
                    ++$badcount;
                    continue;
                }
                // Parse and process its contents.
                $msg = receive_hl7_results($hl7);
                if ($msg) {
                    $messages[] = xl('Error processing file') . " '{$file}':" . $msg;
                    ++$badcount;
                    continue;
                }
                $messages[] = xl('New file') . " '{$file}' " . xl('processed successfully');
            }
        }
        // TBD: Insert "else if ($protocol == '???') {...}" to support other protocols.
    }
    if ($badcount) {
        return "{$badcount} " . xl('error(s) encountered from new results');
    }
    return '';
}
Ejemplo n.º 11
0
        $sslusername = $query_row['sslusername'];
        $sslpassword = $query_row['sslpassword'];
    }
    $path = getcwd();
    chdir('..');
    chdir('..');
    $path = getcwd();
    chdir('php/pear');
    $path = getcwd();
    set_include_path($path);
    set_include_path(get_include_path() . '/' . 'phpsec');
    include 'Net/SSH2.php';
    include 'File/ANSI.php';
    include '/Net/SFTP.php';
    $sftp = new Net_SFTP(@$hostname);
    if (@$sftp->login(@$sslusername, @$sslpassword)) {
        $contents = $sftp->get('/proc/meminfo');
        $data = explode("\n", $contents);
        $meminfo = array();
        foreach ($data as $line) {
            @(list($key, $val) = explode(":", $line));
            $meminfo[$key] = trim($val);
        }
        $json[] = $meminfo;
        echo json_encode($json);
    } else {
        echo "[]";
    }
} else {
    echo "[]";
}
Ejemplo n.º 12
0
function tsdns($action, $sship, $sshport, $sshuser, $keyuse, $sshkey, $sshpw, $notified, $path, $bitversion, $tsip, $tsport, $tsdns, $reseller_id, $maxnotified = 2)
{
    global $sql;
    $sshSftpObject = new Net_SFTP($sship, $sshport);
    if ($keyuse != 'N') {
        $privateKey = EASYWIDIR . '/keys/' . removePub($sshkey);
        $sshpw = new Crypt_RSA();
        if ($keyuse == 'B') {
            $sshpw->setPassword($sshpw);
        }
        $keyContent = @file_get_contents($privateKey);
        if ($keyContent) {
            $sshpw->loadKey($keyContent);
        }
    }
    if ($sshSftpObject->login($sshuser, $sshpw)) {
        $split_config = preg_split('/\\//', $path, -1, PREG_SPLIT_NO_EMPTY);
        $folderfilecount = count($split_config) - 1;
        $i = 0;
        $folders = substr($path, 0, 1) == '/' ? '/' : '';
        $lastFolder = '';
        while ($i <= $folderfilecount) {
            $folders .= $split_config[$i] . '/';
            $lastFolder = $split_config[$i];
            $i++;
        }
        if ($lastFolder != 'tsdns' or substr($path, 0, 1) != '/') {
            $folders .= 'tsdns/';
        }
        if ($action == 'md' or $action == 'dl') {
            $newip = $tsip[0];
            $oldip = isset($tsip[1]) ? $tsip[1] : '';
            $newport = $tsport[0];
            $oldport = isset($tsport[1]) ? $tsport[1] : '';
            $newdns = $tsdns[0];
            $olddns = isset($tsdns[1]) ? $tsdns[1] : '';
        } else {
            $dnsarray = array();
        }
        $file = substr($path, 0, 1) == '/' ? $folders . 'tsdns_settings.ini' : '/home/' . $sshuser . '/' . $folders . 'tsdns_settings.ini';
        if ($action != 'rs') {
            $data = $sshSftpObject->get($file);
            $data = str_replace(array("", "\\b", "\r", "\\Z"), '', $data);
        }
        if ($action != 'rs' and $action != 'mw') {
            $edited = false;
            $ca = array();
            foreach (preg_split('/\\n/', $data, -1, PREG_SPLIT_NO_EMPTY) as $configLine) {
                if ($action != 'li' and $configLine != $olddns . '=' . $oldip . ':' . $oldport and $configLine != $newdns . '=' . $newip . ':' . $newport) {
                    $ca[] = $configLine . "\r\n";
                } else {
                    if ($action == 'md' and $edited == false and ($configLine == $olddns . '=' . $oldip . ':' . $oldport or $configLine == $newdns . '=' . $newip . ':' . $newport)) {
                        $edited = true;
                        $ca[] = $newdns . '=' . $newip . ':' . $newport . "\r\n";
                    }
                }
                if ($action == 'li' and $configLine != '' and !preg_match('/^#(|\\s+)(.*)$/', $configLine)) {
                    $dnsconfig = explode('=', $configLine);
                    if (isset($dnsconfig[1])) {
                        $linedns = $dnsconfig[0];
                        $lineserver = $dnsconfig[1];
                        $dnsarray[$lineserver] = $linedns;
                    }
                }
            }
            if ($action == 'md' and $edited == false) {
                $ca[] = $newdns . '=' . $newip . ':' . $newport . "\r\n";
            }
            if ($action != 'li') {
                $ca = array_unique($ca);
                sort($ca);
                $newcfg = '';
                foreach ($ca as $line) {
                    $newcfg .= $line;
                }
                if ($newcfg == '') {
                    $newcfg = '# No TSDNS data entered';
                }
                $sshSftpObject->put($file, $newcfg);
            }
        }
        if ($action == 'mw' and isset($data)) {
            $usedIPs = array();
            foreach (preg_split('/\\n/', $data, -1, PREG_SPLIT_NO_EMPTY) as $configLine) {
                if ($configLine != '' and !preg_match('/^#(|\\s+)(.*)$/', $configLine)) {
                    $splittedLine = preg_split('/\\=/', $configLine, -1, PREG_SPLIT_NO_EMPTY);
                    $usedIPs[] = isset($splittedLine[1]) ? array('dns' => $splittedLine[0], 'address' => $splittedLine[1]) : $configLine;
                } else {
                    $usedIPs[] = $configLine;
                }
            }
            foreach ($tsip as $newLine) {
                $splittedLine = preg_split('/\\=/', strtolower($newLine), -1, PREG_SPLIT_NO_EMPTY);
                if (isset($splittedLine[1]) and !array_key_exists($splittedLine[1], $usedIPs)) {
                    $usedIPs[] = array('dns' => $splittedLine[0], 'address' => $splittedLine[1]);
                }
            }
            function array_multi_dimensional_unique($multi)
            {
                $unique = array();
                foreach ($multi as $sub) {
                    if (!in_array($sub, $unique)) {
                        $unique[] = $sub;
                    }
                }
                return $unique;
            }
            $newCfg = '';
            $usedIPs = array_multi_dimensional_unique($usedIPs);
            sort($usedIPs);
            foreach ($usedIPs as $value) {
                $newCfg .= (isset($value['dns']) and isset($value['address']) and !preg_match('/^#(|\\s+)(.*)$/', $value['dns'])) ? $value['dns'] . '=' . $value['address'] . "\r\n" : $value . "\r\n";
            }
            if ($newCfg == '') {
                $bad = 'Nothing to write';
            } else {
                $sshSftpObject->put($file, $newCfg);
            }
        }
        if (!isset($bad) and $action != 'li') {
            $sshObject = new Net_SSH2($sship, $sshport);
            if ($sshObject->error === false) {
                if ($sshObject->login($sshuser, $sshpw)) {
                    $bin = $bitversion == 32 ? 'tsdnsserver_linux_x86' : 'tsdnsserver_linux_amd64';
                    $ssh2cmd = 'cd ' . $folders . ' && function restart () { if [ "`ps fx | grep ' . $bin . ' | grep -v grep`" == "" ]; then ./' . $bin . ' > /dev/null & else ./' . $bin . ' --update > /dev/null & fi }; restart& ';
                    $sshObject->exec($ssh2cmd);
                    if ($notified > 0) {
                        $query = $sql->prepare("UPDATE `voice_masterserver` SET `notified`=0 WHERE `ssh2ip`=? AND `resellerid`=? LIMIT 1");
                        $query->execute(array($sship, $reseller_id));
                    }
                } else {
                    $bad = 'The login data does not work';
                    $notified++;
                }
            } else {
                $bad = 'Could not connect to Server';
                $notified++;
            }
        }
    } else {
        $bad = 'Could not connect to Server';
    }
    if (isset($bad) and $notified == $maxnotified) {
        if ($reseller_id == 0) {
            $query = $sql->prepare("SELECT `id`,`mail_serverdown` FROM `userdata` WHERE `resellerid`=0 AND `accounttype`='a'");
            $query->execute();
        } else {
            $query = $sql->prepare("SELECT `id`,`mail_serverdown` FROM `userdata` WHERE (`id`=? AND `id`=`resellerid`) OR (`resellerid`=0 AND `accounttype`='a')");
            $query->execute(array($reseller_id));
        }
        while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
            if ($row['mail_serverdown'] == 'Y') {
                sendmail('emaildown', $row['id'], 'TS3 Master ' . $sship . ' ( ' . $bad . ' )', '');
            }
        }
        $query = $sql->prepare("UPDATE `voice_masterserver` SET `notified`=`notified`+1 WHERE `ssh2ip`=? AND `resellerid`=? LIMIT 1");
        $query->execute(array($sship, $reseller_id));
        return $bad;
    } else {
        if (isset($bad)) {
            return $bad;
        } else {
            if ($action == 'li' and isset($dnsarray)) {
                return $dnsarray;
            }
        }
    }
    return 'ok';
}
Ejemplo n.º 13
0
 public function download($localfile, $remotefile = '', $mode = 'A')
 {
     return $this->conn->get($remotefile, $localfile);
 }
Ejemplo n.º 14
0
}
$sftp->chdir('out');
$files = $sftp->nlist();
$wr1 = array();
foreach ($files as $filename) {
    if (substr($filename, 0, 4) == '7760' && substr($filename, -4) == '.wr1') {
        $wr1[] = $filename;
    }
}
sort($wr1);
foreach ($wr1 as $filename) {
    echo $filename . '<br />';
    $sql = "SELECT * FROM `wr1` WHERE `filename` = ?s";
    $result = $msql->query($sql, substr($filename, 0, 8));
    if (!$result->num_rows) {
        $wr1File = $sftp->get($filename);
        if (strlen($wr1File) != 802) {
            preg_match_all('/^.{3}7760.{43}LJ(\\d+).*$/m', $wr1File, $matches);
            $orderIDs = array_unique($matches[1]);
            sort($orderIDs);
            $ordersArr = array();
            foreach ($orderIDs as $order) {
                $ordersArr[] = '(' . (int) $order . ')';
            }
            unset($orderIDs);
            $sql = "INSERT IGNORE INTO `wr1_orders` (`order_id`) VALUES " . implode(',', $ordersArr);
            $msql->query($sql);
        }
        $sql = "INSERT IGNORE INTO `wr1` (`filename`) VALUES (?s)";
        $msql->query($sql, substr($filename, 0, 8));
    }
Ejemplo n.º 15
0
 /**
  * Downloads backup file from server from remote ftp server to root folder on local server.
  *
  * @param 	array 	$args	arguments passed to the function
  * [ftp_username] -> ftp username on remote server
  * [ftp_password] -> ftp password on remote server
  * [ftp_hostname] -> ftp hostname of remote host
  * [ftp_remote_folder] -> folder on remote site which backup file should be downloaded from
  * [ftp_site_folder] -> subfolder with site name in ftp_remote_folder which backup file should be downloaded from
  * [backup_file] -> absolute path of backup file on local server
  * @return 	string|array	absolute path to downloaded file is successful, array with error message if not
  */
 function get_sftp_backup($args)
 {
     extract($args);
     file_put_contents("sftp_log.txt", "get_sftp_backup", FILE_APPEND);
     $port = $sftp_port ? $sftp_port : 22;
     //default port is 21        $sftp_hostname = $sftp_hostname?$sftp_hostname:"";
     file_put_contents("sftp_log.txt", "sftp port:" . $sftp_port, FILE_APPEND);
     $sftp_username = $sftp_username ? $sftp_username : "";
     $sftp_password = $sftp_password ? $sftp_password : "";
     file_put_contents("sftp_log.txt", "sftp host:" . $sftp_hostname . ";username:"******";password:"******"sftp_log.txt", "sftp login failed in get_sftp_backup", FILE_APPEND);
         return false;
     }
     $remote = $sftp_remote_folder ? trim($sftp_remote_folder, "/") . "/" : '';
     if ($ftp_site_folder) {
         $remote .= '/' . $this->site_name;
     }
     $temp = ABSPATH . 'mwp_temp_backup.zip';
     $get = $sftp->get($remote . '/' . $backup_file, $temp);
     $sftp->disconnect();
     if ($get === false) {
         file_put_contents("sftp_log.txt", "sftp get failed in get_sftp_backup", FILE_APPEND);
         return false;
     }
     return $temp;
 }
Ejemplo n.º 16
0
} else {
    if (strpos($fileToGet, '.eparts.') !== false) {
        $tmp = explode(".out.eparts.", $fileToGet, 2)[0];
        $initialGraph = 'uploads/' . $tmp;
        $resultFile = explode("eparts", $fileToGet, 2)[0] . "parts" . explode("eparts", $fileToGet, 2)[1];
    } else {
        $tmp = explode(".parts.", $fileToGet, 2)[0];
        $initialGraph = 'uploads/' . substr($tmp, 0, strrpos($tmp, '.'));
        $tmp = substr($tmp, 0, strrpos($tmp, '.'));
        $resultFile = $fileToGet;
    }
}
$statsResults = 'uploads/' . $fileToGet . '.stats';
$sftp = new Net_SFTP(SSH_HOST);
if ($sftp->login($_SESSION['id'], $_SESSION['passwd'])) {
    $sftp->get('/scratch/' . $_SESSION['id'] . '/meshslicer/' . $fileToGet, $graphPartition);
    $sftp->get('/scratch/' . $_SESSION['id'] . '/meshslicer/' . $tmp, $initialGraph);
    $sftp->get('/scratch/' . $_SESSION['id'] . '/meshslicer/results/' . $resultFile, $statsResults);
    if ($txt_file = file_get_contents($initialGraph)) {
        $rows = explode("\n", $txt_file);
        $N = intval(explode(" ", array_shift($rows))[0]);
        $Nodes = [];
        if (strpos($fileToGet, '.nparts.') !== false) {
            $txt_file = file_get_contents($graphPartition);
            $colorRows = explode("\n", $txt_file);
            $color = [];
            $max = 0;
            for ($i = 1; $i <= $N; $i++) {
                $r = explode(" ", $rows[$i]);
                foreach ($r as $k => $v) {
                    $val = intval($v);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Minecraft Game Panel</title>
</head>
<body>
<?php 
    require 'includes/settings.php';
    $connection = new Net_SFTP($server_SSH_address);
    $connection->login($server_SSH_username, $server_SSH_password);
    if (isset($_POST['submit'])) {
        $connection->put('/srv/games/minecraft/server.properties', $_POST['serverProperties']);
        $connection->put('/srv/games/minecraft/ops.txt', $_POST['serverOPs']);
    }
    $current_serverProperties = $connection->get('/srv/games/minecraft/server.properties');
    $current_serverOPs = $connection->get('/srv/games/minecraft/ops.txt');
    ?>
<form action="<?php 
    echo $_SERVER["PHP_SELF"];
    ?>
" method="post">
  server.properties<br>
  <textarea rows="25" cols="100" name="serverProperties"><?php 
    echo $current_serverProperties;
    ?>
</textarea>
  <br />ops.txt<br />
  <textarea rows="25" cols="100" name="serverOPs"><?php 
    echo $current_serverOPs;
    ?>
Ejemplo n.º 18
0
 public function getFile($path, $target)
 {
     $this->client->get($path, $target);
 }
Ejemplo n.º 19
0
$ssh->write("cd /code/spopt-stable\n");
//2. 'read' command to ensure script is called from the proper directory
$ssh->read('rlgruver@cr2g01:/code/spopt-stable$');
//3. run the solver script with the test from the current session
$ssh->write("python SpOpt.py tests/" . $session . "/input.txt\n");
//start timerin case anything gets stuck, will break within 120 minutes (7200 sec)
$starttime = time();
//ssh will break within 120 minutes (7200 sec) regardless of execution status
while ($ssh->isConnected()) {
    $now = time() - $starttime;
    if ($now > 7200) {
        break;
    }
    sleep(3);
    //retrieve all solutions/discarded from cr2g and store in local
    $sftp->get($remoteSolutionsFile, $localSolutionsFile);
    $sftp->get($remoteDiscardedFile, $localDiscardedFile);
    //function to provide discarded solutions during session
    parseDiscarded($session);
    //if final output file gets created from the cr2g sever, store it in local and complete
    if ($sftp->get($remoteOutputFile, $localOutputFile)) {
        $done = "true";
        break;
    }
}
//function to delete old session directories to reduce clutter
function deleteDirectory($dir)
{
    if (!file_exists($dir)) {
        return true;
    }
Ejemplo n.º 20
0
     }
 }
 foreach ($containerstobackup as $container) {
     $log .= 'Backing up CT ' . $container . PHP_EOL;
     $vzstarttime = time();
     if ($isproxmox) {
         $log .= $ssh->exec(escapeshellcmd('vzdump -mode snapshot -compress gzip -dumpdir /tmp/' . $dirname . ' ' . $container)) . PHP_EOL;
         $log .= $ssh->exec(escapeshellcmd('mv vzdump-openvz-*.tgz vzdump-' . $container . '.tgz')) . PHP_EOL;
     } else {
         $log .= $ssh->exec(escapeshellcmd('vzdump --snapshot --compress --dumpdir /tmp/' . $dirname . ' ' . $container)) . PHP_EOL;
     }
     if (!$sftp->size('vzdump-' . $container . '.tgz')) {
         $log .= 'vzdump-' . $container . '.tgz not found' . PHP_EOL;
     } else {
         $log .= 'CT backup completed, transferring CT ' . $container . PHP_EOL;
         $sftpfiletransfer = $sftp->get('vzdump-' . $container . '.tgz', $dirname . '-vzdump-' . $container . '.tgz') . PHP_EOL;
         if (!$sftpfiletransfer) {
             $log .= 'CT transfer failed' . PHP_EOL;
         } else {
             $log .= $sftpfiletransfer;
             $log .= $ssh->exec(escapeshellcmd('rm -f /tmp/' . $dirname . '/vzdump-' . $container . '.tgz')) . PHP_EOL;
             $log .= rename($dirname . '-vzdump-' . $container . '.tgz', $config['path'] . '/files/' . $dirname . '-vzdump-' . $container . '.tgz') . PHP_EOL;
             if (isset($backupjob['encryption']) && ($backupjob['encryption'] = 'AES-256')) {
                 $log .= 'Encrypting file with AES-256' . PHP_EOL;
                 $cipher = new Crypt_AES(CRYPT_AES_MODE_ECB);
                 $cipher->setKey($backupjob['encryptionkey']);
                 file_put_contents($config['path'] . '/files/' . $dirname . '-vzdump-' . $container . '.tgz', $cipher->encrypt(file_get_contents($config['path'] . '/files/' . $dirname . '-vzdump-' . $container . '.tgz')));
             } elseif (isset($backupjob['encryption']) && $backupjob['encryption'] == 'GPG') {
                 $log .= 'Encrypting file with GPG' . PHP_EOL;
                 require_once $config['path'] . '/libs/php-gpg-master/GPG.php';
                 $gpg = new GPG();
Ejemplo n.º 21
0
         die;
     }
     ###
     $aes = new Crypt_AES();
     $aes->setKeyLength(256);
     $aes->setKey(CRYPT_KEY);
     // Get SFTP
     $sftp = new Net_SFTP($box['ip'], $box['sshport']);
     if (!$sftp->login($box['login'], $aes->decrypt($box['password']))) {
         $_SESSION['msg1'] = T_('Connection Error!');
         $_SESSION['msg2'] = '';
         $_SESSION['msg-type'] = 'error';
         header("Location: server.php?id=" . urlencode($serverid));
         die;
     }
     $log = $sftp->get(dirname($server['path']) . '/screenlog.0');
     $sftp->disconnect();
     //Adding event to the database
     $message = mysql_real_escape_string($server['name']) . ' : screenlog downloaded';
     query_basic("INSERT INTO `" . DBPREFIX . "log` SET `serverid` = '" . $serverid . "', `message` = '" . $message . "', `name` = '" . $_SESSION['clientfirstname'] . " " . $_SESSION['clientlastname'] . "', `ip` = '" . $_SERVER['REMOTE_ADDR'] . "'");
     ###
     header('Content-type: text/plain');
     header('Content-Disposition: attachment; filename="' . $server['screen'] . '_' . date('Y-m-d') . '.screenlog"');
     echo $log;
     ###
     die;
     break;
 case 'serverstart':
     require_once "./libs/gameinstaller/gameinstaller.php";
     ###
     $serverid = $_GET['serverid'];
Ejemplo n.º 22
0
         if (!$mail->Send()) {
             echo "Mailer Error: " . $mail->ErrorInfo;
         } else {
             echo "Message sent!";
         }
         //unlink('/tmp/kontakti.txt');
         $sftp = new Net_SFTP('podrska.bbtrade.rs');
         if (!$sftp->login('root', 'bbsb100$')) {
             echo "Login Failed";
             exit('Login Failed');
         }
         // outputs the contents of filename.remote to the screen
         //echo $sftp->get('/tmp/kontakti.txt');
         // copies filename.remote to filename.local from the SFTP server
         //$sftp->get('/tmp/kontakti.txt', '\\C$\Users\%username%\Desktop\kontakti.txt');
         $sftp->get('/tmp/izvestaj.csv', '/cygdrive/c/storno/izvestaj.txt');
         //ssh2.sftp://{$resSFTP}/cygdrive/c/to/path
         if ($sftp->delete('/tmp/izvestaj.csv')) {
             // doesn't delete directories
             echo "File /tmp/izvestaj.csv je obrisan!";
         } else {
             echo "File /tmp/izvestaj.csv nije obrisan!";
         }
         echo '<br />';
         /*echo "Izvrsen je sledeci upit:";
         		echo '<br />';
         		echo $sql;*/
         echo '<br />';
         echo "Ako ste upisali ispravnu email adresu, fajl ce Vam biti isporucen putem email-a.";
     }
 }
Ejemplo n.º 23
0
/**
 * Poll all eligible labs for new results and store them in the database.
 *
 * @param  array   &$info  Conveys information to and from the caller:
 * FROM THE CALLER:
 * $info["$ppid/$filename"]['delete'] = a non-empty value if file deletion is requested.
 * $info['select'] = array of patient matching responses where key is serialized patient
 *   attributes and value is selected pid for this patient, or 0 to create the patient.
 * TO THE CALLER:
 * $info["$ppid/$filename"]['mssgs'] = array of messages from this function.
 * $info['match'] = array of patient matching requests where key is serialized patient
 *   attributes (ss, fname, lname, DOB) and value is TRUE (irrelevant).
 *
 * @return string  Error text, or empty if no errors.
 */
function poll_hl7_results(&$info)
{
    global $srcdir;
    // echo "<!-- post: "; print_r($_POST); echo " -->\n"; // debugging
    // echo "<!-- in:   "; print_r($info); echo " -->\n"; // debugging
    $filecount = 0;
    $badcount = 0;
    if (!isset($info['match'])) {
        $info['match'] = array();
    }
    // match requests
    if (!isset($info['select'])) {
        $info['select'] = array();
    }
    // match request responses
    $ppres = sqlStatement("SELECT * FROM procedure_providers ORDER BY name");
    while ($pprow = sqlFetchArray($ppres)) {
        $ppid = $pprow['ppid'];
        $protocol = $pprow['protocol'];
        $remote_host = $pprow['remote_host'];
        $hl7 = '';
        if ($protocol == 'SFTP') {
            $remote_port = 22;
            // Hostname may have ":port" appended to specify a nonstandard port number.
            if ($i = strrpos($remote_host, ':')) {
                $remote_port = 0 + substr($remote_host, $i + 1);
                $remote_host = substr($remote_host, 0, $i);
            }
            ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . "{$srcdir}/phpseclib");
            require_once "{$srcdir}/phpseclib/Net/SFTP.php";
            // Compute the target path name.
            $pathname = '.';
            if ($pprow['results_path']) {
                $pathname = $pprow['results_path'] . '/' . $pathname;
            }
            // Connect to the server and enumerate files to process.
            $sftp = new Net_SFTP($remote_host, $remote_port);
            if (!$sftp->login($pprow['login'], $pprow['password'])) {
                return xl('Login to remote host') . " '{$remote_host}' " . xl('failed');
            }
            $files = $sftp->nlist($pathname);
            foreach ($files as $file) {
                if (substr($file, 0, 1) == '.') {
                    continue;
                }
                ++$filecount;
                if (!isset($info["{$ppid}/{$file}"])) {
                    $info["{$ppid}/{$file}"] = array();
                }
                // Ensure that archive directory exists.
                $prpath = $GLOBALS['OE_SITE_DIR'] . "/procedure_results";
                if (!file_exists($prpath)) {
                    mkdir($prpath);
                }
                $prpath .= '/' . $pprow['ppid'];
                if (!file_exists($prpath)) {
                    mkdir($prpath);
                }
                // Get file contents.
                $hl7 = $sftp->get("{$pathname}/{$file}");
                // If user requested reject and delete, do that.
                if (!empty($info["{$ppid}/{$file}"]['delete'])) {
                    $fh = fopen("{$prpath}/{$file}.rejected", 'w');
                    if ($fh) {
                        fwrite($fh, $hl7);
                        fclose($fh);
                    } else {
                        return xl('Cannot create file') . ' "' . "{$prpath}/{$file}.rejected" . '"';
                    }
                    if (!$sftp->delete("{$pathname}/{$file}")) {
                        return xl('Cannot delete (from SFTP server) file') . ' "' . "{$pathname}/{$file}" . '"';
                    }
                    continue;
                }
                // Do a dry run of its contents and check for errors and match requests.
                $tmp = receive_hl7_results($hl7, $info['match'], $ppid, $pprow['direction'], true, $info['select']);
                $info["{$ppid}/{$file}"]['mssgs'] = $tmp['mssgs'];
                // $info["$ppid/$file"]['match'] = $tmp['match'];
                if (!empty($tmp['fatal']) || !empty($tmp['needmatch'])) {
                    // There are errors or matching requests so skip this file.
                    continue;
                }
                // Now the money shot - not a dry run.
                $tmp = receive_hl7_results($hl7, $info['match'], $ppid, $pprow['direction'], false, $info['select']);
                $info["{$ppid}/{$file}"]['mssgs'] = $tmp['mssgs'];
                // $info["$ppid/$file"]['match'] = $tmp['match'];
                if (empty($tmp['fatal']) && empty($tmp['needmatch'])) {
                    // It worked, archive and delete the file.
                    $fh = fopen("{$prpath}/{$file}", 'w');
                    if ($fh) {
                        fwrite($fh, $hl7);
                        fclose($fh);
                    } else {
                        return xl('Cannot create file') . ' "' . "{$prpath}/{$file}" . '"';
                    }
                    if (!$sftp->delete("{$pathname}/{$file}")) {
                        return xl('Cannot delete (from SFTP server) file') . ' "' . "{$pathname}/{$file}" . '"';
                    }
                }
            }
            // end of this file
        } else {
            if ($protocol == 'FS') {
                // Filesystem directory containing results files.
                $pathname = $pprow['results_path'];
                if (!($dh = opendir($pathname))) {
                    return xl('Unable to access directory') . " '{$pathname}'";
                }
                // Sort by filename just because.
                $files = array();
                while (false !== ($file = readdir($dh))) {
                    if (substr($file, 0, 1) == '.') {
                        continue;
                    }
                    $files[$file] = $file;
                }
                closedir($dh);
                ksort($files);
                // For each file...
                foreach ($files as $file) {
                    ++$filecount;
                    if (!isset($info["{$ppid}/{$file}"])) {
                        $info["{$ppid}/{$file}"] = array();
                    }
                    // Ensure that archive directory exists.
                    $prpath = $GLOBALS['OE_SITE_DIR'] . "/procedure_results";
                    if (!file_exists($prpath)) {
                        mkdir($prpath);
                    }
                    $prpath .= '/' . $pprow['ppid'];
                    if (!file_exists($prpath)) {
                        mkdir($prpath);
                    }
                    // Get file contents.
                    $hl7 = file_get_contents("{$pathname}/{$file}");
                    // If user requested reject and delete, do that.
                    if (!empty($info["{$ppid}/{$file}"]['delete'])) {
                        $fh = fopen("{$prpath}/{$file}.rejected", 'w');
                        if ($fh) {
                            fwrite($fh, $hl7);
                            fclose($fh);
                        } else {
                            return xl('Cannot create file') . ' "' . "{$prpath}/{$file}.rejected" . '"';
                        }
                        if (!unlink("{$pathname}/{$file}")) {
                            return xl('Cannot delete file') . ' "' . "{$pathname}/{$file}" . '"';
                        }
                        continue;
                    }
                    // Do a dry run of its contents and check for errors and match requests.
                    $tmp = receive_hl7_results($hl7, $info['match'], $ppid, $pprow['direction'], true, $info['select']);
                    $info["{$ppid}/{$file}"]['mssgs'] = $tmp['mssgs'];
                    // $info["$ppid/$file"]['match'] = $tmp['match'];
                    if (!empty($tmp['fatal']) || !empty($tmp['needmatch'])) {
                        // There are errors or matching requests so skip this file.
                        continue;
                    }
                    // Now the money shot - not a dry run.
                    $tmp = receive_hl7_results($hl7, $info['match'], $ppid, $pprow['direction'], false, $info['select']);
                    $info["{$ppid}/{$file}"]['mssgs'] = $tmp['mssgs'];
                    // $info["$ppid/$file"]['match'] = $tmp['match'];
                    if (empty($tmp['fatal']) && empty($tmp['needmatch'])) {
                        // It worked, archive and delete the file.
                        $fh = fopen("{$prpath}/{$file}", 'w');
                        if ($fh) {
                            fwrite($fh, $hl7);
                            fclose($fh);
                        } else {
                            return xl('Cannot create file') . ' "' . "{$prpath}/{$file}" . '"';
                        }
                        if (!unlink("{$pathname}/{$file}")) {
                            return xl('Cannot delete file') . ' "' . "{$pathname}/{$file}" . '"';
                        }
                    }
                }
                // end of this file
            }
        }
        // end FS protocol
        // TBD: Insert "else if ($protocol == '???') {...}" to support other protocols.
    }
    // end procedure provider
    // echo "<!-- out: "; print_r($info); echo " -->\n"; // debugging
    return '';
}
Ejemplo n.º 24
0
}
echo '<pre>';
print_r($contents);
echo '</pre>';
foreach ($contents as $file) {
    if (substr($file, -4, 4) == '.csv') {
        $arrayCsvFiles[] = $arrayCsvFilesClear[] = $file;
    }
}
foreach ($arrayCsvFiles as $file) {
    if (isset($result["{$file}"])) {
        continue;
    }
    $localFileNeme = time() . rand(1, 1000);
    $downloadFilePath = AF::path($localFileNeme, array('files', 'csv', 'rockets'), 'csv');
    if ($sftp->get($dPath . '/' . $file, $downloadFilePath)) {
        parse_csv_file($downloadFilePath);
        $sql = "INSERT INTO `fulfillment_files` (`fulfillment_id`, `filename`, `time`) VALUES (?i, ?s, NOW())";
        $msql->query($sql, $fulfillmentID, $file);
    }
}
$sftp->_disconnect(0);
function parse_csv_file($downloadFilePath)
{
    global $fulfillmentID, $msql;
    $header = NULL;
    $data = array();
    if (($handle = fopen($downloadFilePath, 'r')) !== FALSE) {
        while (($row = fgetcsv($handle, 1000, ',')) !== FALSE) {
            if (!$header) {
                $header = $row;
Ejemplo n.º 25
0
 function get_ftp_backup($args, $current_file_num = 0)
 {
     extract($args);
     if (isset($use_sftp) && $use_sftp == 1) {
         $port = $ftp_port ? $ftp_port : 22;
         //default port is 22
         /*
          * SFTP section start here phpseclib library is used for this functionality
          */
         $iwp_mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
         $path = $iwp_mmb_plugin_dir . '/lib/phpseclib';
         set_include_path(get_include_path() . PATH_SEPARATOR . $path);
         include_once 'Net/SFTP.php';
         $sftp = new Net_SFTP($ftp_hostname, $port);
         if (!$sftp) {
             return array('error' => 'Failed to connect to ' . $ftp_hostname, 'partial' => 1);
         }
         if (!$sftp->login($ftp_username, $ftp_password)) {
             return array('error' => 'FTP login failed for ' . $ftp_username . ', ' . $ftp_password, 'partial' => 1);
         } else {
             if ($ftp_site_folder) {
                 $ftp_remote_folder .= '/' . $this->site_name;
             }
             $remote_loation = basename($backup_file);
             $local_location = $backup_file;
             $sftp->chdir($ftp_remote_folder);
             //$sftp->delete(basename($backup_file));
             $temp = wp_tempnam('iwp_temp_backup.zip');
             $get = $sftp->get(basename($backup_file), $temp);
             if ($get === false) {
                 return false;
             } else {
                 return $temp;
             }
             //SFTP library has automatic connection closed. So no need to call seperate connection close function
         }
     } else {
         //Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder
         $port = $ftp_port ? $ftp_port : 21;
         //default port is 21
         if ($ftp_ssl && function_exists('ftp_ssl_connect')) {
             $conn_id = ftp_ssl_connect($ftp_hostname, $port);
         } else {
             if (function_exists('ftp_connect')) {
                 $conn_id = ftp_connect($ftp_hostname, $port);
                 if ($conn_id === false) {
                     return false;
                 }
             }
         }
         $login = @ftp_login($conn_id, $ftp_username, $ftp_password);
         if ($login === false) {
             return false;
         }
         if ($ftp_site_folder) {
             $ftp_remote_folder .= '/' . $this->site_name;
         }
         if ($ftp_passive) {
             @ftp_pasv($conn_id, true);
         }
         //$temp = ABSPATH . 'iwp_temp_backup.zip';
         $temp = wp_tempnam('iwp_temp_backup.zip');
         $get = ftp_get($conn_id, $temp, $ftp_remote_folder . '/' . $backup_file, FTP_BINARY);
         if ($get === false) {
             return false;
         } else {
         }
         ftp_close($conn_id);
         return $temp;
     }
 }
Ejemplo n.º 26
0
 /**
  * This method is called in response to fread() and fgets()
  *
  * Reads from stream
  *
  * @param Integer $count
  * @return mixed
  * @access public
  */
 public function stream_read($count)
 {
     switch ($this->mode) {
         case 'w':
         case 'a':
         case 'x':
         case 'x+':
         case 'c':
             return FALSE;
     }
     $chunk = $this->sftp->get($this->path, FALSE, $this->position, $count);
     $this->position += strlen($chunk);
     return $chunk;
 }
Ejemplo n.º 27
0
 public function downloadFromFulfillment()
 {
     $arrayCsvFiles = array();
     $arrayCsvFilesClear = array();
     $sql = "SELECT *\n                FROM `fulfillment_files`\n                WHERE `fulfillment_id`=?i";
     $result = self::$_msql->getInd('filename', $sql, $this->fulfillment_id);
     if ($this->ssl) {
         $sftp = new Net_SFTP($this->server);
         if (!$sftp->login($this->username, $this->password)) {
             exit('Login Failed');
         }
         //$contents = $sftp->nlist("{$this->download_path}");
         $dPath = trim($this->download_path, '/');
         $contents = $sftp->nlist("{$dPath}");
         if (!$contents) {
             return;
         }
         foreach ($contents as $file) {
             if (substr($file, -4, 4) == '.csv') {
                 $arrayCsvFiles[] = $arrayCsvFilesClear[] = $file;
             }
         }
         foreach ($arrayCsvFiles as $file) {
             $tF = explode('/', $file);
             $fName = array_pop($tF);
             if (isset($result["{$fName}"])) {
                 continue;
             }
             $downloadFilePath = AF::path(time() . rand(1, 1000), array('files', 'csv', 'temp'), 'csv');
             if ($sftp->get($dPath . '/' . $file, $downloadFilePath)) {
                 self::parserCsvFiles($downloadFilePath);
                 $sql = "INSERT INTO `fulfillment_files` (`fulfillment_id`, `filename`, `time`) VALUES (?i, ?s, NOW())";
                 self::$_msql->query($sql, $this->fulfillment_id, $fName);
             }
         }
         $sftp->_disconnect(0);
     } else {
         $ftp = ftp_connect($this->server, $this->port, 300);
         if (!$ftp) {
             return;
         }
         if ($this->username && $this->password) {
             ftp_login($ftp, $this->username, $this->password);
         }
         ftp_pasv($ftp, true);
         // Passive mode
         $contents = ftp_nlist($ftp, "{$this->download_path}");
         if (!$contents) {
             return;
         }
         foreach ($contents as $file) {
             if (substr($file, -4, 4) == '.csv') {
                 $file = str_replace('\\', '/', $file);
                 $arrayCsvFiles[] = $file;
                 $tF = explode('/', $file);
                 $arrayCsvFilesClear[] = (string) trim(array_pop($tF));
             }
         }
         foreach ($arrayCsvFiles as $file) {
             $tF = explode('/', $file);
             $fName = (string) trim(array_pop($tF));
             if (isset($result["{$fName}"])) {
                 continue;
             }
             $downloadFilePath = AF::path(time() . rand(1, 1000), array('files', 'csv', 'temp'), 'csv');
             if (ftp_get($ftp, $downloadFilePath, $file, FTP_ASCII)) {
                 self::parserCsvFiles($downloadFilePath);
                 $sql = "INSERT INTO `fulfillment_files` (`fulfillment_id`, `filename`, `time`) VALUES (?i, ?s, NOW())";
                 self::$_msql->query($sql, $this->fulfillment_id, $fName);
             }
         }
         ftp_close($ftp);
     }
     $sql = "DELETE FROM `fulfillment_files`\n                WHERE `fulfillment_id` = ?i\n                AND `filename` NOT IN (?a)";
     self::$_msql->query($sql, $this->fulfillment_id, $arrayCsvFilesClear);
 }
Ejemplo n.º 28
0
require_once "includes/settings.php";
require_once "classes/Login.php";
$login = new Login();
if ($login->isUserLoggedIn() == true) {
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Minecraft Game Panel</title>
</head>
<body>
<?php 
    $connection = new Net_SFTP($server_SSH_address);
    $connection->login($server_SSH_username, $server_SSH_password);
    $currentLog = $connection->get('/srv/games/minecraft/logs/latest.log');
    ?>
	latest.log<br>
	<textarea rows="25" cols="100" name="serverProperties"><?php 
    echo $currentLog;
    ?>
</textarea>
<br />
<a href="index.php">Go Back</a>
</body>
</html>
<?php 
} else {
    include "views/not_logged_in.php";
}
Ejemplo n.º 29
0
 public function get($from, $to)
 {
     return $this->ftp->get($from, $to);
 }
Ejemplo n.º 30
0
 public function dhcpFiles()
 {
     foreach ($this->dhcpData as $k => $v) {
         if (count($v['actions']) > 0) {
             unset($tempBad, $changed);
             # https://github.com/easy-wi/developer/issues/70
             $privateKey = EASYWIDIR . '/keys/' . removePub($v['keyname']);
             $sftpObject = new Net_SFTP($v['ip'], $v['port']);
             if (file_exists($privateKey) and $sftpObject->error === false) {
                 if ($v['publickey'] != 'N') {
                     $ssh2Pass = new Crypt_RSA();
                     if ($v['publickey'] == 'B') {
                         $ssh2Pass->setPassword($v['pass']);
                     }
                     $ssh2Pass->loadKey(file_get_contents($privateKey));
                 } else {
                     $ssh2Pass = $v['pass'];
                 }
                 if ($sftpObject->login($v['user'], $ssh2Pass)) {
                     $file = substr($v['dhcpFile'], 0, 1) == '/' ? $v['dhcpFile'] : '/home/' . $v['user'] . '/' . $v['dhcpFile'];
                     $buffer = $sftpObject->get($file);
                     $config = $this->parseDhcpConfig(str_replace(array("", "\\b", "\r", "\\Z"), '', $buffer));
                     if (is_array($config)) {
                         foreach ($v['actions'] as $a) {
                             if ($a['action'] == 'del') {
                                 if (isset($config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']])) {
                                     unset($config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]);
                                     $changed = true;
                                 } else {
                                     if (isset($config['vlan'][$this->ID[$a['type']][$a['id']]['oldVlan']][$this->ID[$a['type']][$a['id']]['oldSubnet']][$this->ID[$a['type']][$a['id']]['hostname']])) {
                                         unset($config['vlan'][$this->ID[$a['type']][$a['id']]['oldVlan']][$this->ID[$a['type']][$a['id']]['oldSubnet']][$this->ID[$a['type']][$a['id']]['hostname']]);
                                         $changed = true;
                                     } else {
                                         if (isset($config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']])) {
                                             unset($config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]);
                                             $changed = true;
                                         } else {
                                             if (isset($config['subnet'][$this->ID[$a['type']][$a['id']]['oldSubnet']][$this->ID[$a['type']][$a['id']]['hostname']])) {
                                                 unset($config['subnet'][$this->ID[$a['type']][$a['id']]['oldSubnet']][$this->ID[$a['type']][$a['id']]['hostname']]);
                                                 $changed = true;
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (isset($this->ID[$a['type']][$a['id']])) {
                                     if (isset($this->ID[$a['type']][$a['id']]['vlan'])) {
                                         if (!isset($config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['hardware ethernet']) or $config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['hardware ethernet'] != $this->ID[$a['type']][$a['id']]['mac'] . ';') {
                                             $config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['hardware ethernet'] = $this->ID[$a['type']][$a['id']]['mac'] . ';';
                                             $changed = true;
                                         }
                                         if (!isset($config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['fixed-address']) or $config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['fixed-address'] != $this->ID[$a['type']][$a['id']]['ip'] . ';') {
                                             $config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['fixed-address'] = $this->ID[$a['type']][$a['id']]['ip'] . ';';
                                             $changed = true;
                                         }
                                         if ($this->ID[$a['type']][$a['id']]['usePXE'] == 'Y' and (!isset($config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['filename']) or $config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['filename'] != 'pxelinux.0;')) {
                                             $config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['filename'] = 'pxelinux.0;';
                                             $changed = true;
                                         }
                                         if ($this->ID[$a['type']][$a['id']]['usePXE'] == 'Y' and (!isset($config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['next-server']) or $config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['next-server'] != $this->ID[$a['type']][$a['id']]['pxeIP'] . ';')) {
                                             $config['vlan'][$this->ID[$a['type']][$a['id']]['vlan']][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['next-server'] = $this->ID[$a['type']][$a['id']]['pxeIP'] . ';';
                                             $changed = true;
                                         }
                                     } else {
                                         if (!isset($config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['hardware ethernet']) or $config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['hardware ethernet'] != $this->ID[$a['type']][$a['id']]['mac'] . ';') {
                                             $config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['hardware ethernet'] = $this->ID[$a['type']][$a['id']]['mac'] . ';';
                                             $changed = true;
                                         }
                                         if (!isset($config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['fixed-address']) or $config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['fixed-address'] != $this->ID[$a['type']][$a['id']]['ip'] . ';') {
                                             $config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['fixed-address'] = $this->ID[$a['type']][$a['id']]['ip'] . ';';
                                             $changed = true;
                                         }
                                         if ($this->ID[$a['type']][$a['id']]['usePXE'] == 'Y' and (!isset($config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['filename']) or $config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['filename'] != 'pxelinux.0;')) {
                                             $config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['filename'] = 'pxelinux.0;';
                                             $changed = true;
                                         }
                                         if ($this->ID[$a['type']][$a['id']]['usePXE'] == 'Y' and (!isset($config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['next-server']) or $config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['next-server'] != $this->ID[$a['type']][$a['id']]['pxeIP'] . ';')) {
                                             $config['subnet'][$this->ID[$a['type']][$a['id']]['subnet']][$this->ID[$a['type']][$a['id']]['hostname']]['next-server'] = $this->ID[$a['type']][$a['id']]['pxeIP'] . ';';
                                             $changed = true;
                                         }
                                     }
                                 }
                             }
                         }
                         if (isset($changed)) {
                             $sftpObject->put($file, $this->assembleDhcpConfig($config, $k));
                             $sshObject = new Net_SSH2($v['ip'], $v['port']);
                             if ($sshObject->error === false) {
                                 if ($v['publickey'] != 'N') {
                                     $ssh2Pass = new Crypt_RSA();
                                     if ($v['publickey'] == 'B') {
                                         $ssh2Pass->setPassword($v['pass']);
                                     }
                                     $ssh2Pass->loadKey(file_get_contents($privateKey));
                                 } else {
                                     $ssh2Pass = $v['pass'];
                                 }
                                 if ($sshObject->login($v['user'], $ssh2Pass)) {
                                     $sshObject->exec($v['startCmd'] . ' &');
                                 } else {
                                     $tempBad[] = 'Could login to DHCP server: ' . $v['ip'] . ':' . $v['port'];
                                 }
                             } else {
                                 $tempBad[] = 'Could not connect to DHCP server: ' . $v['ip'] . ':' . $v['port'];
                             }
                         }
                     } else {
                         $tempBad[] = 'Could not process DHCP file ' . $file . ' at DHCP server: ' . $v['ip'] . ':' . $v['port'];
                     }
                 } else {
                     $tempBad[] = 'Could not login to DHCP server: ' . $v['ip'] . ':' . $v['port'];
                 }
             } else {
                 $tempBad[] = 'Could not connect to DHCP server: ' . $v['ip'] . ':' . $v['port'];
             }
             if (isset($tempBad) and isset($bad)) {
                 $bad = array_merge($bad, $tempBad);
             } else {
                 if (isset($tempBad) and !isset($bad)) {
                     $bad = $tempBad;
                 }
             }
         }
     }
     if (isset($bad)) {
         return implode(' ', $bad);
     }
     return true;
 }