home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/php -q
- <?php
- // header_grabber.php
- // Version : 1.0
- // Date : 23/03/02
- // Authors : franck tabary ftab@free.fr franck@exeprod.com
- //
- // URL : http://exeprod.com/phpgtk/
- //
- // TODO for next version :
- // - correct a visual bug when host select (combo)
- // - write \r\n when we are under windows, \n under *nix
- // - do nothing when entry combo is empty
- // - Learn english
- //
- // Next PHPGTK Project
- // - vulnerabilitie & attack scanner
- // - site mapper & url checker
-
- ///// INITIALISATION
- if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { dl('php_gtk.dll');} else { dl('php_gtk.so');}
-
- ///// CONSTANTS
- $item1=array(
- 'GET' =>array('change_method','GET'),
- 'POST' =>array('change_method','POST'),
- 'PUT' =>array('change_method','PUT'),
- 'HEAD' =>array('change_method','HEAD'),
- 'REPLY' =>array('change_method','REPLY'),
- 'DELETE' =>array('change_method','DELETE'),
- 'LINK' =>array('change_method','LINK'),
- 'UNLINK' =>array('change_method','UNLINK'),
- 'CHECKIN' =>array('change_method','CHECKIN'),
- 'CHECKOUT' =>array('change_method','CHECKOUT'),
- 'SHOWMETHOD' =>array('change_method','SHOWMETHOD'),
- 'TEXTSEARCH' =>array('change_method','TEXTSEARCH'),
- 'SPACEJUMP' =>array('change_method','SPACEJUMP'),
- 'SEARCH' =>array('change_method','SEARCH'),
- );
-
- $METHOD="GET";
- $CONF_FILE="./header_grabber.conf";
-
- ///// FUNCTIONS DECLARATIONS
- function delete_event() { return false; }
- function destroy() { Gtk::main_quit(); }
- function quit() { global $window; $window->destroy(); }
- function change_method($menu_item,$value) {global $METHOD;$METHOD=$value;}
- function close_window($widget) {$window = $widget->get_toplevel(); Gtk::grab_remove($window); $window->hide();}
- function clear_entry() { global $entry1; $entry1->set_text("");}
- function clear_result() {global $text1;$text1->delete_text(0,-1);}
- function build_option_menu($items,$history=null) {
- $omenu=&new GtkOptionMenu();
- $menu=&new GtkMenu();
- foreach ($items as $item_name => $callback_data) {
- $menu_item=&new GtkMenuItem($item_name);
- array_unshift($callback_data,'activate');
- call_user_func_array(array(&$menu_item,'connect'),$callback_data);
- $menu->append($menu_item);
- $menu_item->show;
- }
- $omenu->set_menu($menu);
- if ($history!==null) { $omenu->set_history($history);}
- return $omenu;
- }
-
- function help_about() {
-
- $msg ="Php Header Grabber by franck tabary ( ftab@free.fr,franck@exeprod.com )\n\n";
- $msg.="version 1, ( free version ) \n\n";
- $msg.="URL for this little project : http://exeprod.com/phpgtk/\n";
- $msg.="PHP manual is at http://www.php.net\n";
- $msg.="Get Latest PHPGtk at http://gtk.php.net";
-
- $about = &new gtkwindow();
- Gtk::grab_add($about);
- $about->set_border_width(10);
- $about->set_usize(550,300);
- $about->set_policy(FALSE,FALSE,FALSE);
- $about->set_position(GTK_WIN_POS_CENTER);
- $about->set_title("About");
- $about->connect('destroy', destroy);
- $about->connect('delete-event', delete_event);
- $box1 = &new gtkvbox(FALSE,0);
- $about->add($box1);
- $box1->show();
- $label1 = &new gtklabel($msg);
- $label1->set_justify(GTK_JUSTIFY_FILL);
- $box1->pack_start($label1,TRUE,TRUE,10);
- $label1->show();
- $bbox = &new gtkhbuttonbox();
- $box1->pack_start($bbox,TRUE,TRUE,10);
- $bbox->show();
- $button = &new GtkButton('OK');
- $bbox->pack_start($button,FALSE,FALSE,0);
- $button->connect_object("clicked", "close_window", $about);
- $button->show();
- $about->show();
- }
-
- function hit_enter($entry,$event) {
- $value=$event->keyval;
- global $quit;
- if ($value==GDK_KEY_Return) {
- evaluate_entry();
- } else {
- if ($value=="65507") {
- $quit=1;
- } else {
- if ($value=="88"&&$quit) {
- quit();
- }
- }
- }
- }
-
- function create_file_selection() {
- global $windows;
- if (!isset($windows['file_selection'])) {
- $window = &new GtkFileSelection('File selection dialog');
- $windows['file_selection'] = $window;
- $window->hide_fileop_buttons();
- $window->set_position(GTK_WIN_POS_MOUSE);
- $window->connect('delete_event', 'delete_event');
-
- $button_ok = $window->ok_button;
- $button_ok->connect('clicked', 'file_selection_ok',$window);
-
- $button_cancel = $window->cancel_button;
- $button_cancel->connect('clicked', 'close_window');
-
- $action_area = $window->action_area;
- /*
- $button = &new GtkButton('Hide Fileops');
- $button->show();
- $button->connect_object('clicked', create_function('$w', '$w->hide_fileop_buttons();'), $window);
- $action_area->pack_start($button, false, false, 0);
-
- $button = &new GtkButton('Show Fileops');
- $button->show();
- $button->connect_object('clicked', create_function('$w', '$w->show_fileop_buttons();'), $window);
- $action_area->pack_start($button, false, false, 0);
- */
- }
- if ($windows['file_selection']->flags() & GTK_VISIBLE)
- $windows['file_selection']->hide();
- else
- $windows['file_selection']->show();
- }
-
- function file_selection_ok($button,$window) {
- global $text1;
- $file=$window->get_filename();
- $string = $text1->get_chars(0,-1);
- $fp=fopen($file,"w");
- fwrite($fp,$string);
- fclose($fp);
- close_window($window);
- }
-
- function evaluate_entry() {
- global $text1;
- global $entry1;
- global $lenprev;
- global $METHOD;
- global $lentotal;
- global $status;
-
- $status_context = $status->get_context_id("foo");
- $status->push($status_context, "Contacting host $host ...");
- while (gtk::events_pending()) gtk::main_iteration();
- add_one();
-
- $host = $entry1->get_text();
- if (ereg("https",$host)) {$port=443;} else {$port=80;}
- $host=ereg_replace("https?://","",$host);
- $position=0;
- clear_result();
- $url=strstr($host,"/");
- if (!$url) {$url="/";} else {$host=ereg_replace($url,"",$host);}
-
- $fp=fsockopen($host,$port,$errno,$errstr,10);
- if (!$fp) {
- $header="$errstr ($errno)\n";
- if (!$errno) { $header="Host $host not found\n";}
- } else {
- $entry1->set_sensitive(false);
- $phrase="$METHOD $url HTTP/1.0";
- $phrase.="\r\n";
- $phrase.="Host: $host";
- $phrase.="\r\n\r\n";
- $phrase2="$METHOD $url HTTP/1.0";
- $phrase2.="\n";
- $phrase2.="Host: $host";
- $phrase2.="\n\n";
-
- $text1->insert_text($phrase2,1);
- $text1->thaw();
- fputs($fp,$phrase);
- $ok=0;
- while (!feof($fp)&&!$ok) {
- $l=fgets($fp,128);
- $l=ereg_replace("\n","",$l);
- $l=chop(trim($l));
- if ($l=="") {
- $ok=1;
- } else {
- $header.=$l."\n";
- }
- }
- fclose($fp);
- }
- if ($header) {
- $text1->insert_text($header,strlen($phrase2));
- $text1->thaw();
- $text1->freeze();
- }
- $entry1->set_sensitive(true);
- $status->push($status_context, "Terminated.");
- while (gtk::events_pending()) gtk::main_iteration();
- }
-
-
- function add_one() {
- global $strings,$entry1,$entry0,$CONF_FILE;
- $entered = $entry1->get_text();
- $entered=ereg_replace("\n","",$entered);
- $entered=ereg_replace("\r","",$entered);
- $entry0->disable_activate();
- if (!in_array($entered,$strings)) {
- $strings[]= $entered;
- $strings=array_unique($strings);
- $max=count($strings);
- $entry0->set_popdown_strings($strings);
- $i=0;
- $fp=fopen($CONF_FILE,"w");
- while ($i<$max) {
- $s=$strings[$i];
- $s=ereg_replace("\n","",$s);
- $s=ereg_replace("\r","",$s);
- if ($s) {
- fwrite($fp,$s."\r\n");
- if ($s==$entered) {
- $sel=$i;
- }
- }
- $i++;
- }
- fclose($fp);
- //$entry0->set_value_in_list($sel,0);
- }
- $entry1->set_text($entered);
- $entry1->grab_focus();
- }
-
- // APPLICATION CONSTRUCTION
- $window = &new GtkWindow();
- $window->connect('destroy', destroy);
- $window->connect('delete-event', delete_event);
-
- $window->set_usize(700,400);
- $window->set_policy(TRUE,TRUE,FALSE);
- $window->set_title("Php Header Grabber");
- $window->set_position(GTK_WIN_POS_CENTER);
-
- $box1 = &new GtkVBox(FALSE,0);
- $window->add($box1);
- $box1->show();
-
- $ag = &new GtkAccelGroup();
- $itemf = &new GtkItemFactory(GtkMenuBar::get_type(), '<main>', $ag);
- $window->add_accel_group($ag);
- $itemf->create_items(array(
- array('/_File', '', null, 0,'<Branch>'),
- array('/_File/_Save ...', '', 'create_file_selection',2,''),
- array('/_File/E_xit', '<control>X', 'quit', 2,''),
- array('/_Help', '', null, 0, '<LastBranch>'),
- array('/_Help/_About', 'F1', help_about, 0,''))
- );
- $box1->pack_start($itemf->get_widget('<main>'),FALSE,FALSE,0);
-
- $box2 = &new gtkhbox(FALSE,0);
- $box1->pack_start($box2,FALSE,FALSE,0);
- $box2->show();
-
- $popup=build_option_menu($item1,0);
- $box2->pack_start($popup,TRUE,TRUE,1);
-
- $s=file($CONF_FILE);
- $i=0;
- $max=count($s);
- while ($i<$max) {
- $t=$s[$i];
- $t=ereg_replace("\n","",$t);
- $t=ereg_replace("\r","",$t);
- if ($t) {
- $strings[$i]=$t;
- }
- $i++;
- }
-
-
- $entry0 = &new GtkCombo();
- $entry0->set_usize(500,20);
- $entry0->set_popdown_strings($strings);
- $entry1= $entry0->entry;
- $entry1->select_region(0, -1);
- $entry1->set_text("");
- $box2->pack_start($entry0);
- //$list=$entry0->list;$list->connect('select-child', 'combo_select',$listed);
- $entry0->show();
-
- $box2->pack_start($entry1,TRUE,TRUE,0);
- $entry1->show;
-
- $button = &new GtkButton(' Get headers ');
- $button->connect('clicked', 'evaluate_entry');
-
- $box2->pack_start($button,FALSE,FALSE,0);
- $button->show();
-
- $box3 = &new GtkHbox(FALSE,0);
- $box1->pack_start($box3,TRUE,TRUE,0);
- $box3->show();
-
- $text1 = &new gtktext();
- $text1->set_editable(TRUE);
- $box3->pack_start($text1,TRUE,TRUE,0);
- $text1->show();
-
- $scroll = &new gtkvscrollbar($text1->vadj);
- $box3->pack_start($scroll,FALSE,TRUE,0);
- $scroll->show();
-
- $box4 = &new GtkVbox(FALSE,0);
- $box1->pack_start($box4,FALSE,FALSE,0);
- $box4->show();
-
- $status=&new GtkStatusBar();
- $box1->pack_start($status,FALSE,FALSE,0);
-
- $window->show_all();
-
- $entry1->grab_focus();
- $entry1->connect('key-press-event','hit_enter');
-
- /* Run the main loop. */
- Gtk::main();
- ?>
-