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));
32 if (empty($interfaces) ) { // maybe its a node with a NAT'd IP addresses
33 // look up an interface tag using the public IP address value
34 $interfacetags=$adm->GetInterfaceTags(array("tagname"=>"public_ip_address","value"=>$ip));
35 if (! empty($interfacetags)) {
36 // using the interface_id now get the interface with the node_id information
37 $interface_id=$interfacetags[0]['interface_id'];
38 $interfaces=$adm->GetInterfaces($interface_id);
39 // fall thru to the conditional below ...
43 if (! empty($interfaces) ) {
44 $interface=$interfaces[0];
45 $node_id=$interface['node_id'];
46 $nodes=$adm->GetNodes($node_id,array("hostname"));
48 $hostname=$nodes[0]['hostname'];
52 // store the actual data in /var/log/bm/raw/2008-11-31-20-02-onelab01.inria.fr-138.96.250.141.txt
54 $rawdir=$logdir . "/raw";
55 $date=strftime("%Y-%m-%d-%H-%M");
56 $log_name=$date . "-" . $hostname . "-" . $ip . ".txt";
57 $log_path=$rawdir . "/" . $log_name;
58 $month=strftime("%Y-%m");
59 $time=strftime("%d-%H-%M");
61 mkdir_if_needed ($rawdir);
63 ////////////////////////////////////////
65 $log=fopen($log_path,"w") or die ("Cannot open logfile "+$log_path);
67 $uploaded_name= $_FILES['log']['tmp_name'];
68 $uploaded_size=filesize($uploaded_name);
70 fprintf ($log, "BootManager log created on: %s-%s\n",$month,$time);
71 fprintf( $log, "From IP: %s\n",$ip);
72 fprintf( $log, "hostname: %s\n",$hostname);
73 fprintf ( $log, "uploaded file: %s (%d bytes)\n",$uploaded_name,$uploaded_size);
74 if ( ( strcmp($hostname,$default_hostname)==0) && ( $uploaded_size >= $limit_bytes) ) {
75 fprintf ( $log, "contents from an unrecognized IP address was truncated to %d bytes\n",$limit_bytes);
77 $uploaded_size=$limit_bytes;
82 fprintf( $log, "-----------------\n\n" );
83 $uploaded = fopen($uploaded_name,'r');
84 $contents = fread($uploaded, $uploaded_size);
86 fwrite($log,$contents);
88 fwrite ($log, " ..<" . "truncated" . ">..\n");
91 ////////////////////////////////////////
93 // create symlinks for easy browsing
95 // /var/log/bm/per-month/2008-11/onelab1.inria.fr/31-20-02.bmlog
97 $linkdir=$linkdir . "/per-month";
98 mkdir_if_needed ($linkdir);
99 $linkdir=$linkdir . "/" . $month;
100 mkdir_if_needed ($linkdir);
101 $linkdir = $linkdir . "/" . $hostname;
102 mkdir_if_needed ($linkdir);
103 $link = $linkdir . "/" . $time ;
104 symlink ("../../../raw/".$log_name,$link);
106 # /var/log/bm/per-hostname/onelab1.inria.fr/2008-11-31-20-02.bmlog
108 $linkdir=$linkdir . "/per-hostname";
109 mkdir_if_needed ($linkdir);
110 $linkdir=$linkdir . "/" . $hostname;
111 mkdir_if_needed ($linkdir);
112 $link = $linkdir . "/" . $month . "-" . $time ;
113 symlink ("../../raw/".$log_name,$link);
115 # /var/log/bm/per-ip/138.96.250.141/2008-11-31-20-02.bmlog
117 $linkdir=$linkdir . "/per-ip";
118 mkdir_if_needed ($linkdir);
119 $linkdir=$linkdir . "/" . $ip;
120 mkdir_if_needed ($linkdir);
121 $link = $linkdir . "/" . $month . "-" . $time ;
122 symlink ("../../raw/".$log_name,$link);