Autor Tópico: Aplicativo web que funcione como o Central de Programas Ubuntu  (Lida 4035 vezes)

Offline luiz__correia

  • Usuário Ubuntu
  • *
  • Mensagens: 2
    • Ver perfil
Aplicativo web que funcione como o Central de Programas Ubuntu
« Online: 14 de MAR?O de 2011, 14:52 »
Bom dia, é meu primeiro post no forum, embora já tenha passado muito por aqui, mas nas outras vezes as dúvidas da comunidade me bastaram.

Estou precisando desenvolver um sistema como o http://appnr.com pra centralizar os programas da empresa, gostaria de saber como faço para obter uma lista das apps e os repositorios com as imagens, descrições screenshots, procurei bastante e nada agradeceria a ajuda da comunidade.

Offline agente100gelo

  • Administrador
  • Usuário Ubuntu
  • *****
  • Mensagens: 4.369
  • @Ceará
    • Ver perfil
Re: Aplicativo web que funcione como o Central de Programas Ubuntu
« Resposta #1 Online: 14 de MAR?O de 2011, 15:25 »
Fiz um sistema similar http://apturl.net

Você deve baixar o arquivo (exemplo) http://archive.ubuntu.com/ubuntu/dists/natty/main/binary-i386/Packages.gz

Mudando só o nome da versão marcada.

O script que fazia a atualização está aqui:
Código: [Selecionar]
<?

ini_set("memory_limit","200M");

echo "----------------------------------------------\n";
echo "APT-URL - Download e conversão de arquivos\n";
echo "----------------------------------------------\n";

require("config/connection.php");

$conexao = mysql_pconnect($server,$user,$password) or die($msg[0]);
mysql_select_db($database,$conexao) or die($msg[1]);

$result = mysql_query("delete from apt_package");

$sql = "select * from apt_version";
$result = mysql_query($sql);

while ( $reg_version = mysql_fetch_array($result)) {

  $sql = "select * from apt_architeture";
  $result2 = mysql_query($sql);

  while ( $reg_arch = mysql_fetch_array($result2)) {

    $sql = "select * from apt_repository";
    $result3 = mysql_query($sql);

    while ( $reg_repo = mysql_fetch_array($result3)) {
      echo "Configurando: " . strtoupper($reg_version["name"]) . " " .strtoupper($reg_arch["name"]).
            " " . strtoupper($reg_repo["name"]) . "\n\n";

      echo "--------------------------------------\n";
      echo "Download files\n";
      echo "--------------------------------------\n";
      echo "Start: " . date("d/m/Y h:i:s") . "\n";

      $file = "./data/download/" . strtolower($reg_version["name"]) . "_" . strtolower($reg_arch["name"]) . "_" . strtolower($reg_repo["name"]) . "";

      $Arquivo = new Arquivo;
      $Arquivo->Diretorio = URL_INTERNET;
      $Arquivo->Local = $file .".gz";
      $Arquivo->URL = "http://archive.ubuntu.com/ubuntu/dists/" . strtolower($reg_version["name"]) . "/" . strtolower($reg_repo["name"]) . "/binary-" . strtolower($reg_arch["name"]) . "/Packages.gz";
      $Arquivo->Baixar();
      $output = shell_exec('uncompress -f ./data/download/' . strtolower($reg_version["name"]) . '_' . strtolower($reg_arch["name"]) . "_" . strtolower($reg_repo["name"]) . '.gz');
      #echo "$output\n";

      echo "End: " . date("d/m/Y h:i:s") . "\n\n";

      analisar(strtolower($reg_version["name"]),strtolower($reg_arch["name"]),$file);
    }
  }

}






# -------------------------------------------------------------------
# -------------------------------------------------------------------
# -------------------------------------------------------------------

class Arquivo {
  var $Nome;
  var $Local; // Destino do arquivo baixado
  var $URL; // Arquivo Fonte
  var $Diretorio;
  var $Caminho;
  var $DiasParaRenovacao;
  var $Erro;
  var $Tipo,$Numero;

  # ---------------------------------------------

  function Arquivo() {
    $this->DiasParaRenovacao = DATA_PARA_RENOVACAO;
  }

  # ---------------------------------------------

  function Existe() {
    return file_exists($this->Diretorio . $this->Local);
  }



# ---------------------------------------------

  function Baixar() {

    if (!$this->url_exist($this->URL) or ( URL_INTERNET == $this->URL)) {
      echo " !!False "  . $this->URL . "\n";
      return false;

    } else {

      $ch = curl_init($this->URL);
      echo "       Location: " . $this->Localizacao() . "\n";
      $fp = fopen($this->Localizacao(), "w");

      curl_setopt($ch, CURLOPT_TIMEOUT, 120);
      curl_setopt($ch, CURLOPT_FILE, $fp);
      curl_setopt($ch, CURLOPT_HEADER, 0);

      curl_exec($ch);
      curl_close($ch);
      fclose($fp);

      return true;

      }


      return true;
  }


  # ---------------------------------------------

  function url_exist($url)
  {
    $handle = @fopen($url, "r");
    if ($handle === false)
      return false;
     fclose($handle);
     return true;
  }

  # ---------------------------------------------

  function Localizacao() {
    return  $this->Local;
  }

}

# -------------------------------------------------------------------
# -------------------------------------------------------------------
# -------------------------------------------------------------------


function analisar($distro,$architeture,$file) {
  echo "Conversion\n";
  echo "--------------------------------------\n";
  echo "Start: " . date("d/m/Y h:i:s") . "\n";

  $lines = file($file);

  // Percorre o array, mostrando o fonte HTML com numeração de linhas.
  foreach ($lines as $line) {
    $i++;
    #if ($i == 30) { exit; }

    $data = split(": ",$line);

    #echo strlen($line) . ") " . substr($line,0,40);

    if ( strlen($line) == 1 ) {
        $sql = ("insert into apt_package (distro,architeture,name,section,subsection,version,size,description) values ('$distro','$architeture'," . $values ."'$description')");
        $result = mysql_query($sql);
        #echo "i<br>$sql";
        $values = "";
    } else {
      if ( $in_description ) {
        if ($data[0] != "Bugs") {
          $line = str_replace(" .","",$line);
          $description .= $line;
        } else {
           #$description .= "'";
           $in_description = false;
           #$values .= $description;
      }
      } else {

        switch ($data[0]) {
          case "Package":
            $values = "'" . trim($data[1]) . "'," ;
            break;
          case "Section":
            $section = split("/",$data[1]);
            $values .= "'" . trim($section[0]) . "','" . trim($section[1]) . "'," ;
            break;
          case "Version":
            $values .= "'" . trim($data[1]) . "'," ;
            break;
          case "Size":
            $values .= "'" . trim($data[1]) . "'," ;
            break;
          case "Description":
            # $description = "" . $data[1];
            $description = "";
            $in_description = true;
            break;
        }
      }
    }

   }
  echo "End: " . date("d/m/Y h:i:s") . "\n";
}


?>
Advogado e analista de sistema cearense.
Twitter: @glaydson

Offline luiz__correia

  • Usuário Ubuntu
  • *
  • Mensagens: 2
    • Ver perfil
Re: Aplicativo web que funcione como o Central de Programas Ubuntu
« Resposta #2 Online: 14 de MAR?O de 2011, 18:14 »
agente100gelo, rapaz você me ajudau muito, agradeço...

Você conseguiu linkar imagens junto com os apps?