Subversion Repositories computer_asset_manager_v1

Rev

Blame | Last modification | View Log | Download | RSS feed

<?php

   define (PROCESS_SYSINFO_SCRIPT, '/home/rodolico/wip/dd_tools/web/computer_asset_manager/modules/sysinfo/cli/process_sysinfo');

   function processAFile( $filename ) {
      $output = PROCESS_SYSINFO_SCRIPT . " < $filename\n";
      $output .= shell_exec(PROCESS_SYSINFO_SCRIPT . " < $filename");
      return $output;
   }

   function processFileContents(  ) {
      $filename = tempnam('/tmp', 'sysinfo');
      $fh = fopen( $filename, "w" );
      fwrite( $fh, $_POST['filecontents'] );
      fclose( $fh );
      $output = processAFile( $filename );
      unlink ($filename);
      return $output;
   }
   
  function uploadFile() {
     $filename = $_FILES['filename']['tmp_name'];
     $output = "processing file $filename\n";
     $output .= processAFile( $filename );
     unlink ($filename);
     return $output;
  }
   
   function UnknownEntries () {
      $data = queryDatabaseExtended( 'select count(*) num from unknown_entry where processed_date is null');
      return $data['data'][0]['num'];
   }
   
   function processUnknownClients() {
     $new = array();
     $aliases = array();
     $result = array();
     foreach ( $_POST as $parameter => $value ) {
        // look for all new and alias entries
        if ( preg_match('/new_(\d+)/', $parameter, $id ) ) {
           if ($value) {
              $new[] = $id[1];
           }
        } elseif ( preg_match('/alias_for_(\d+)/', $parameter, $id ) ) {
           if ($value) {
              $aliases[] = $id[1];
           }
        }
     }
     foreach ( $new as $entryID ) {
        $sql = "insert into client(name, added_date) select client_name, report_date from unknown_entry where unknown_entry_id = $entryID";
        $data = queryDatabaseExtended( $sql );
        $result[] = $sql;
        $sql = "insert into site(client_id,name,added_date) select " . $data['insert_id'] . ", 'Default', report_date from unknown_entry where unknown_entry_id = $entryID";
        queryDatabaseExtended( $sql );
        $result[] = $sql;
     }
     foreach ( $aliases as $entryID ) {
        $client_id = $_POST["alias_for_$entryID"];
        $sql = "insert into client_alias(client_id,alias,added_date) select $client_id, client_name,report_date from unknown_entry where unknown_entry_id = $entryID";
        $result[] = $sql;
        queryDatabaseExtended( $sql );
     }
     return implode( "\n", $result );
   } // function processUnknownClients
   
   function processUnknownDevices() {
     $new = array();
     $aliases = array();
     $result = array();
     foreach ( $_POST as $parameter => $value ) {
        // look for all new and alias entries
        if ( preg_match('/new_(\d+)/', $parameter, $id ) ) {
           if ($value) {
              $new[] = $id[1];
           }
        } elseif ( preg_match('/alias_for_(\d+)/', $parameter, $id ) ) {
           if ($value) {
              $aliases[] = $id[1];
           }
        }
     }
     $whoami = $_SESSION['login_id'];
     foreach ( $new as $entryID ) {
        $sql ="insert into device (site_id, name, device_type_id, added_date)
               select site_id, device_name, device_type_id, report_date
               from unknown_entry join
                     (select min(site_id) site_id, client.name client 
                     from site join client using (client_id)
                     group by client.name 
                     union 
                     select min(site_id) site_id, alias client 
                     from site join client_alias using (client_id)
                     group by alias) site
                     on unknown_entry.client_name = site.client,
                  (select device_type_id from device_type where name = 'Computer') device_type
               where unknown_entry.unknown_entry_id = $entryID";
        $data = queryDatabaseExtended( $sql );
        $result[] = $sql;
        if ($data['insert_id']) {
           $sql = "update unknown_entry set processed_date = now(), processed_by = $whoami where unknown_entry_id = $entryID";
           $result[] = $sql;
           queryDatabaseExtended( $sql );
        }
     }
     foreach ( $aliases as $entryID ) {
        $device_id = $_POST["alias_for_$entryID"];
        $sql = "insert into device_alias(device_id,alias,added_date) select $device_id, device_name,report_date from unknown_entry where unknown_entry_id = $entryID";
        $result[] = $sql;
        $data = queryDatabaseExtended( $sql );
        if ($data['insert_id']) {
           $sql = "update unknown_entry set processed_date = now(), processed_by = $whoami where unknown_entry_id = $entryID";
           $result[] = $sql;
           queryDatabaseExtended( $sql );
        }
     }
     // ensure device_alias contains the device.name also (this can be changed by manual entry)
     $sql = "insert into device_alias (device_id,alias,added_date)
            select device_id,device.name, now()
            from device join device_type using (device_type_id) 
            where device_type.show_as_system = 'Y' 
                  and device_id in (select device_id from sysinfo_report)
                  and concat(device.device_id,device.name) not in ( 
                     select concat(device_id,device_alias.alias) from device_alias order by device_id
                     )";
     queryDatabaseExtended( $sql );
     return implode( "\n", $result );
   } // function processUnknownClients
?>

Generated by GNU Enscript 1.6.5.90.