forked from MatteoRagni/Force
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobals.php
More file actions
executable file
·124 lines (98 loc) · 3.95 KB
/
globals.php
File metadata and controls
executable file
·124 lines (98 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?
$world['ClusterName'] = "X-CLUSTER";
$world['ClusterLogo'] = "img/x-cluster-logo.png";
$world['UniLogo'] = "img/unitn-logo.png";
$world['GangliaURL'] = 'http://ganglia.wikimedia.org/latest/';
$world['AdminMail'] = "matteo.ragni.it@gmail.com";
$world['University'] = "Università degli studi di Trento";
$world['queue_list'] = array("batch","Another_queue1","Another_queue2");
$world['tmp'] = '/tmp';
$debug = true;
// List server
$world['server_list'][0] = 'localhost:22';
$world['server_list'][1] = '192.168.1.10:22';
// Bisogna ricordarsi di settare il parametro di upload_temp_dir
// ----- DO NOT EDIT -------
$world['ClusterLogo2'] = "<img src=\"" . $world['ClusterLogo'] . "\" width=\"150px\">";
$world['UniLogo2'] = "<img src=\"" . $world['UniLogo'] . "\" width=\"150px\">";
$world['GangliaURL2'] = '<a href="' . $world['GangliaURL'] . '" class="titolo_nav"><i class="icon-eye-open icon-white"></i> Ganglia</a>';
$world['AdminMail2'] = "<a href=\"mailto:" . $world['AdminMail'] . "\">Contact Admin</a>";
$world['AdminMail3'] = "<a href=\"mailto:" . $world['AdminMail'] . "\">here</a>";
$VERSION = 'v0.7Alpha - Linux';
if($debug) { $VERSION .= ' - DebugOn'; }
?>
<?php
// Dichiarazione di alcune comode funzioni per il login
// funzione che esegue un comando in ssh, aprendo e chiudendo la connessione
// richiede username e password. Ritorna lo stdout del comando. Per ottenere
// lo stderr si dovrebbe ridefinire la funzione cambiando il tipo di stream
// Il server è quello definito nella sessione globale
// ssh2_exec2(username, password, "stringa con il comando da eseguire")
function ssh2_exec2($username, $password, $command)
{
global $world;
// Apre la risorsa SSH
$connection_handler = ssh2_connect($_SESSION['sshserver'],$_SESSION['sshport']);
if(!$connection_handler) {
die("[globals.php] Connection Failed: ". $_SESSION['sshserver']." at ".$_SESSION['sshport']);
}
// Esegue la autenticazione in SSH con password plain
$connection = ssh2_auth_password($connection_handler,$username,$password);
if (!$connection) {
die("[globals.php] AuthPass Connection Failed!");
}
// Esegue il comando e ritorna lo stream
$ssh_stream = ssh2_exec($connection_handler, $command);
if (!$ssh_stream) {
die("[globals.php: line 41] Cannot execute: $command");
}
else {
// Estrai lo stream
stream_set_blocking($ssh_stream, true);
$output = "";
while ($buf = fread($ssh_stream,4096*8)) {
$output .= $buf;
}
fclose($ssh_stream);
}
return $output;
};
function redirectssl() {
if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == ""){
$redirect = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header("Location: $redirect");
}
}
function ssh2_exec3($connection, $command) {
$ssh_stream = ssh2_exec($connection, $command);
if (!$ssh_stream) {
die("[globals.php: line 41] Cannot execute: $command");
}
else {
// Estrai lo stream
stream_set_blocking($ssh_stream, true);
$output = "";
while ($buf = fread($ssh_stream,4096*8)) {
$output .= $buf;
}
fclose($ssh_stream);
}
return $output;
}
function ssh2_sftp_down($username, $password, $abs_path) {
global $world;
// Apre la risorsa SSH
$connection_handler = ssh2_connect($_SESSION['sshserver'],$_SESSION['sshport']);
if(!$connection_handler) {
die("[globals.php] Connection Failed: ". $_SESSION['sshserver']." at ".$_SESSION['sshport']);
}
// Esegue la autenticazione in SSH con password plain
$connection = ssh2_auth_password($connection_handler,$username,$password);
if (!$connection) {
die("[globals.php] AuthPass Connection Failed!");
}
$sftp = ssh2_sftp($connection_handler);
$stream = fopen("ssh2.sftp://$sftp$abs_path", 'r');
return $stream;
}
?>