3 // Thierry Parmentelat -- INRIA
4 // first draft for a revival of former (3.x?) alpina-logs in 5.0
6 // this needs be created with proper permissions at package install time
9 // limit: applies to uploads coming from an unrecognized IP
12 $default_hostname="unknown";
14 function mkdir_if_needed ($dirname) {
15 if (is_dir ($dirname))
17 mkdir ($dirname) or die ("Cannot create dir " . $dirname);
20 // Get admin API handle
21 require_once 'plc_api.php';
24 // find the node that these longs should belong to by looking for a node_id
25 // with an ip the same as the http requestor ip
26 $ip = $_SERVER['REMOTE_ADDR'];
28 $hostname=$default_hostname;
29 // locate hostname from DB based on this IP
30 $interfaces=$adm->GetInterfaces(array("ip"=>$ip));
31 if (! empty($interfaces) ) {
32 $interface=$interfaces[0];
33 $node_id=$interface['node_id'];
34 $nodes=$adm->GetNodes($node_id,array("hostname"));
36 $hostname=$nodes[0]['hostname'];
40 // store the actual data in /var/log/bm/raw/2008-11-31-20-02-onelab01.inria.fr-138.96.250.141.txt
42 $rawdir=$logdir . "/raw";
43 $date=strftime("%Y-%m-%d-%H-%M");
44 $log_name=$date . "-" . $hostname . "-" . $ip . ".txt";
45 $log_path=$rawdir . "/" . $log_name;
46 $month=strftime("%Y-%m");
47 $time=strftime("%d-%H-%M");
49 mkdir_if_needed ($rawdir);
51 ////////////////////////////////////////
53 $log=fopen($log_path,"w") or die ("Cannot open logfile "+$log_path);
55 $uploaded_name= $_FILES['log']['tmp_name'];
56 $uploaded_size=filesize($uploaded_name);
58 fprintf ($log, "BootManager log created on: %s-%s\n",$month,$time);
59 fprintf( $log, "From IP: %s\n",$ip);
60 fprintf( $log, "hostname: %s\n",$hostname);
61 fprintf ( $log, "uploaded file: %s (%d bytes)\n",$uploaded_name,$uploaded_size);
62 if ( ( strcmp($hostname,$default_hostname)==0) && ( $uploaded_size >= $limit_bytes) ) {
63 fprintf ( $log, "contents from an unrecognized IP address was truncated to %d bytes\n",$limit_bytes);
65 $uploaded_size=$limit_bytes;
68 fprintf( $log, "-----------------\n\n" );
69 $uploaded = fopen($uploaded_name,'r');
70 $contents = fread($uploaded, $uploaded_size);
72 fwrite($log,$contents);
74 fwrite ($log, " ..<" . "truncated" . ">..\n");
77 ////////////////////////////////////////
79 // create symlinks for easy browsing
81 // /var/log/bm/per-month/2008-11/onelab1.inria.fr/31-20-02.bmlog
83 $linkdir=$linkdir . "/per-month";
84 mkdir_if_needed ($linkdir);
85 $linkdir=$linkdir . "/" . $month;
86 mkdir_if_needed ($linkdir);
87 $linkdir = $linkdir . "/" . $hostname;
88 mkdir_if_needed ($linkdir);
89 $link = $linkdir . "/" . $time ;
90 symlink ("../../../raw/".$log_name,$link);
92 # /var/log/bm/per-hostname/onelab1.inria.fr/2008-11-31-20-02.bmlog
94 $linkdir=$linkdir . "/per-hostname";
95 mkdir_if_needed ($linkdir);
96 $linkdir=$linkdir . "/" . $hostname;
97 mkdir_if_needed ($linkdir);
98 $link = $linkdir . "/" . $month . "-" . $time ;
99 symlink ("../../raw/".$log_name,$link);
101 # /var/log/bm/per-ip/138.96.250.141/2008-11-31-20-02.bmlog
103 $linkdir=$linkdir . "/per-ip";
104 mkdir_if_needed ($linkdir);
105 $linkdir=$linkdir . "/" . $ip;
106 mkdir_if_needed ($linkdir);
107 $link = $linkdir . "/" . $month . "-" . $time ;
108 symlink ("../../raw/".$log_name,$link);